:root {
  color-scheme: light;
  --page: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #f1f5f9;
  --ink: #111827;
  --muted: #566273;
  --faint: #7c8797;
  --line: #d9e0e8;
  --line-strong: #aeb8c5;
  --red: #e53935;
  --red-dark: #c62828;
  --green: #168b56;
  --blue: #2563eb;
  --shadow: 0 18px 48px rgba(17, 24, 39, 0.08);
  --radius: 8px;
  --radius-small: 6px;
  --focus: 0 0 0 4px rgba(37, 99, 235, 0.22);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100%;
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

[hidden] { display: none !important; }

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 0;
  box-shadow: var(--focus);
}

a {
  color: var(--ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover { color: var(--red-dark); }

.tool-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px 20px 44px;
}

.tool-topbar,
.console-head,
.player-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tool-topbar {
  min-height: 48px;
  margin-bottom: 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.brand span {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-small);
  background: var(--red);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-actions a,
.ghost {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 8px 13px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

#languageSelect {
  width: auto;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 0 32px 0 12px;
  font-size: 13px;
  font-weight: 700;
}

.workbench {
  display: grid;
  gap: 18px;
}

.console-head {
  align-items: flex-end;
}

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

h1 {
  max-width: 720px;
  margin: 0;
  font-size: 52px;
  line-height: 1.05;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

h1::after { content: ""; }

.subhead {
  max-width: 680px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 18px;
}

.status-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: min(320px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 11px 12px;
  box-shadow: none;
}

.status-card strong {
  display: block;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}

.status-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--faint);
}

.status-dot.good { background: var(--green); }
.status-dot.bad { background: var(--red); }

.paste-box,
.preview-card,
.player-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.paste-box {
  padding: 18px;
}

.paste-box label,
.download-choice label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  gap: 12px;
  margin-top: 10px;
}

input,
select {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  background: #fff;
  color: var(--ink);
  padding: 12px 14px;
}

input:focus,
select:focus {
  border-color: var(--blue);
  outline: 0;
  box-shadow: var(--focus);
}

#urlInput {
  min-height: 58px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0;
}

button {
  min-height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  background: #fff;
  color: var(--ink);
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0;
  text-align: center;
}

button:hover {
  border-color: #8d99a8;
  background: var(--panel-soft);
}

button:active,
button.is-pressed {
  transform: translateY(1px) scale(0.99);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#checkButton,
.download-button {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

#checkButton:hover,
.download-button:hover {
  border-color: #000;
  background: #000;
}

#checkButton::after { content: ""; }

.hint {
  margin: 10px 0 0;
  color: var(--faint);
  font-size: 13px;
}

.status-line {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.status-line[data-type="error"] { color: var(--red-dark); }
.status-line[data-type="ok"] { color: var(--green); }

.primary-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.action {
  display: grid;
  gap: 6px;
  align-content: center;
  min-height: 96px;
  border-radius: var(--radius);
  text-align: left;
}

.primary-actions .action {
  min-height: 132px;
  border-color: transparent;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.primary-actions .action:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: #fff;
}

.primary-actions .action.is-pressed {
  transform: translateY(2px) scale(0.985);
}

.primary-actions.is-emphasized .action {
  animation: action-pop 1.1s ease-in-out 2;
}

.primary-actions.is-emphasized .watch-action,
.watch-action.is-loading {
  border-color: rgba(229, 57, 53, 0.42);
  box-shadow: 0 0 0 4px rgba(229, 57, 53, 0.14), var(--shadow);
}

.primary-actions.is-emphasized .listen-action,
.listen-action.is-loading {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.16), var(--shadow);
}

.action.is-loading {
  position: relative;
  pointer-events: auto;
}

.action.is-loading::after {
  content: "";
  position: absolute;
  top: 14px;
  right: 14px;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(17, 24, 39, 0.18);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.action.is-muted {
  opacity: 0.72;
}

.watch-action {
  border-left: 6px solid var(--red) !important;
}

.listen-action {
  border-left: 6px solid var(--blue) !important;
}

.action span,
.download-choice span {
  width: fit-content;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--blue);
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 900;
}

.action b {
  color: inherit;
  font-size: 28px;
  line-height: 1.05;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.action small {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(360px, 1.08fr);
  gap: 18px;
  align-items: start;
}

.tool-grid:has(.download-options[hidden]) {
  grid-template-columns: minmax(0, 760px);
}

.preview-card {
  padding: 16px;
}

.thumb-wrap {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: linear-gradient(135deg, #e9edf3, #f8fafc);
}

#thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-empty {
  display: grid;
  gap: 6px;
  place-items: center;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.thumb-empty span {
  color: var(--ink);
  font-size: 21px;
  font-weight: 900;
  letter-spacing: 0;
}

.thumb-empty small {
  color: var(--faint);
  font-size: 13px;
}

.video-meta { margin-top: 14px; }

#videoTitle {
  display: block;
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: 0;
}

#videoMeta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.examples button {
  min-height: 36px;
  padding: 8px 12px;
}

.secondary-link {
  width: 100%;
  min-height: 42px;
  margin-top: 14px;
  border-color: transparent;
  background: var(--panel-soft);
  color: var(--muted);
}

.download-options {
  display: grid;
  gap: 12px;
}

.section-head {
  display: grid;
  gap: 4px;
}

.section-head strong {
  font-size: 20px;
}

.section-head p,
.download-choice p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.download-choice-grid {
  display: grid;
  gap: 12px;
}

.download-choice {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 16px;
  box-shadow: none;
}

.download-choice strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1.1;
}

.download-button {
  width: 100%;
}

.download-button.secondary {
  border-color: var(--line-strong);
  background: #fff;
  color: var(--ink);
}

.download-button.secondary:hover {
  border-color: var(--blue);
  background: var(--panel-soft);
}

#playerTitle {
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0;
}

.download-result {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  padding: 14px;
}

.download-result strong {
  font-size: 15px;
}

.download-result p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.download-result a {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  min-height: 38px;
  align-items: center;
  border: 1px solid var(--green);
  border-radius: var(--radius-small);
  padding: 8px 12px;
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.player-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.player-card.is-pending {
  border-color: rgba(37, 99, 235, 0.55);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12), var(--shadow);
}

.player-card.is-error {
  border-color: rgba(229, 57, 53, 0.72);
  box-shadow: 0 0 0 4px rgba(229, 57, 53, 0.12), var(--shadow);
}

.background-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.background-toggle input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--blue);
}

video,
audio {
  display: block;
  width: 100%;
  border-radius: var(--radius-small);
  background: #000;
}

video {
  aspect-ratio: 16 / 9;
  object-fit: contain;
}

audio {
  min-height: 54px;
}

@keyframes action-pop {
  0%, 100% { transform: translateY(0); }
  35% { transform: translateY(-3px); }
  65% { transform: translateY(1px); }
}

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

@media (max-width: 900px) {
  .console-head,
  .tool-grid {
    grid-template-columns: 1fr;
  }

  .console-head {
    display: grid;
    align-items: start;
  }

  .status-card {
    width: 100%;
  }

  h1 {
    font-size: 44px;
  }
}

@media (max-width: 640px) {
  .tool-shell {
    padding: 14px 12px 32px;
  }

  .workbench {
    gap: 14px;
  }

  .tool-topbar {
    align-items: flex-start;
    margin-bottom: 14px;
  }

  .header-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .header-actions a {
    display: none;
  }

  h1 {
    font-size: 32px;
  }

  .subhead {
    margin-top: 10px;
    font-size: 14px;
  }

  .status-card {
    min-height: 42px;
    padding: 10px 12px;
  }

  .status-card p {
    display: none;
  }

  .paste-box,
  .preview-card,
  .player-card {
    padding: 14px;
  }

  .input-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .primary-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .primary-actions .action {
    min-height: 104px;
    padding: 14px 12px;
  }

  #urlInput {
    min-height: 54px;
    font-size: 16px;
  }

  .download-choice strong {
    font-size: 20px;
  }

  .primary-actions .action b {
    font-size: 20px;
  }

  .primary-actions .action small {
    font-size: 12px;
    line-height: 1.25;
  }
}
