:root {
  color-scheme: dark;
  font-family:
    Inter, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
  --bg: #101113;
  --panel: #181b20;
  --panel-strong: #20242b;
  --text: #f1f3f5;
  --muted: #a8b0bb;
  --line: #303640;
  --accent: #00d1a7;
  --accent-strong: #7cf6db;
  --danger: #ff796f;
  --warning: #f4cb72;
  --shadow: 0 18px 60px rgb(0 0 0 / 28%);
  --panel-alpha: rgb(24 27 32 / 92%);
  --card-alpha: rgb(24 27 32 / 94%);
  --input-bg: #0d0f12;
  --focus-ring: rgb(0 209 167 / 18%);
  --body-gradient-a: rgb(0 209 167 / 10%);
  --body-gradient-b: rgb(255 121 111 / 10%);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-strong: #edf1f0;
  --text: #111816;
  --muted: #5f6c71;
  --line: #d6dedb;
  --accent: #008f76;
  --accent-strong: #006f5d;
  --danger: #b42318;
  --warning: #8f5d00;
  --shadow: 0 18px 48px rgb(23 38 34 / 12%);
  --panel-alpha: rgb(255 255 255 / 92%);
  --card-alpha: rgb(255 255 255 / 96%);
  --input-bg: #ffffff;
  --focus-ring: rgb(0 143 118 / 18%);
  --body-gradient-a: rgb(0 143 118 / 10%);
  --body-gradient-b: rgb(191 82 66 / 10%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, var(--body-gradient-a), transparent 30%),
    linear-gradient(315deg, var(--body-gradient-b), transparent 26%),
    var(--bg);
  color: var(--text);
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 56px;
}

.search {
  display: grid;
  grid-template-columns: minmax(240px, 0.7fr) minmax(0, 1.3fr);
  gap: 24px;
  align-items: end;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-alpha);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  max-width: 560px;
  margin: 0;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.08;
  letter-spacing: 0;
}

.controls {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(180px, 1.1fr) minmax(132px, 0.8fr) minmax(132px, 0.8fr);
  gap: 12px;
  align-items: end;
}

.theme-control {
  display: flex;
  justify-content: flex-end;
  grid-column: 1 / -1;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--muted);
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: #59616e;
}

.theme-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: inset -5px -3px 0 rgb(7 18 16 / 42%);
}

:root[data-theme="light"] .theme-icon {
  box-shadow: 0 0 0 4px rgb(0 143 118 / 16%);
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  grid-column: 1 / 4;
}

.presets button,
.submit {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.presets button {
  background: var(--panel-strong);
  color: var(--muted);
}

.presets button:hover {
  color: var(--text);
  border-color: #59616e;
}

.submit {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-color: transparent;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.submit:hover {
  background: var(--accent-strong);
}

.spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgb(255 255 255 / 34%);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.loading .spinner {
  display: inline-block;
}

.status {
  min-height: 56px;
  padding: 18px 0;
  color: var(--muted);
}

.status strong {
  color: var(--text);
}

.status .error {
  color: var(--danger);
}

.status .warning {
  margin-top: 8px;
  color: var(--warning);
}

.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.clip-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-alpha);
}

.thumb-link {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  background: var(--panel-strong);
  text-decoration: none;
}

.thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.duration {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 4px 7px;
  border-radius: 4px;
  background: rgb(0 0 0 / 76%);
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.clip-body {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.clip-title {
  min-height: 44px;
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.45;
  text-decoration: none;
}

.clip-title:hover {
  color: var(--accent-strong);
}

.meta {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.meta div {
  display: grid;
  gap: 4px;
}

.meta dt,
.meta dd {
  margin: 0;
}

.meta dt {
  color: var(--muted);
}

.meta dd {
  color: var(--text);
  font-weight: 700;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 820px) {
  .app {
    width: min(100% - 24px, 680px);
    padding-top: 18px;
  }

  .search {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .field-login,
  .field-title,
  .presets,
  .submit {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .controls,
  .results {
    grid-template-columns: 1fr;
  }

  .meta {
    grid-template-columns: 1fr 1fr;
  }

  .presets {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  h1 {
    font-size: 28px;
  }
}
