:root {
  color-scheme: dark;
  --bg: #04201f;
  --surface: #062a28;
  --surface-raised: #0a3532;
  --line: rgba(244, 243, 238, 0.14);
  --text: #f4f3ee;
  --muted: #9fb0ac;
  --accent: #00f994;
  --accent-deep: #00b56c;
  --danger: #ff6b6b;
  --focus: #9dffd2;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--text);
  background: var(--bg);
}

button,
input {
  font: inherit;
}

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

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app-shell {
  width: min(1480px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(10px, 1.6vw, 24px);
}

.compact-brand,
.source-panel,
.url-form,
.source-actions,
.control-deck,
.control-group,
.error-actions {
  display: flex;
  align-items: center;
}

.compact-brand {
  flex: 0 0 auto;
  gap: 10px;
}

.brand-icon {
  display: block;
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

.state-kicker,
.control-label {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 0.95rem;
  line-height: 1;
  letter-spacing: -0.02em;
}

.source-panel {
  position: relative;
  gap: 14px;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.url-form {
  flex: 1;
  gap: 10px;
}

.source-actions {
  flex: 0 0 auto;
  gap: 10px;
}

#youtube-url {
  min-width: 0;
  min-height: 48px;
  flex: 1;
  padding: 0 16px;
  border: 1px solid rgba(193, 255, 222, 0.18);
  border-radius: 12px;
  color: var(--text);
  background: rgba(2, 8, 6, 0.72);
}

#youtube-url::placeholder {
  color: #708278;
}

.primary-button,
.secondary-button,
.quality-confirm-button,
.icon-button,
.play-button,
.mini-button,
.utility-button {
  min-height: 44px;
  border: 0;
  color: var(--text);
  cursor: pointer;
}

.primary-button {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 22px;
  justify-content: space-between;
  padding: 0 18px;
  border-radius: 12px;
  color: #02150a;
  font-weight: 800;
  background: var(--accent);
  box-shadow: 0 10px 28px rgba(0, 249, 148, 0.16);
}

.fullscreen-option {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid rgba(0, 249, 148, 0.35);
  border-radius: 12px;
  color: var(--focus);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  background: rgba(2, 8, 6, 0.72);
}

.fullscreen-option input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.help-button {
  width: 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  color: var(--focus);
  font-size: 1rem;
  font-weight: 900;
}

.field-error {
  position: absolute;
  margin: 0;
  color: var(--danger);
  font-size: 0.78rem;
  transform: translateY(24px);
}

.viewer-shell {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #020403;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.38);
}

.quality-gate {
  display: flex;
  align-items: center;
  gap: 24px;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(0, 249, 148, 0.28);
  background: linear-gradient(90deg, rgba(15, 56, 34, 0.98), rgba(8, 28, 19, 0.98));
}

.quality-gate-copy h2,
.quality-gate-copy p,
.quality-gate-actions p {
  margin-bottom: 0;
}

.quality-gate-copy h2 {
  margin-bottom: 4px;
  font-size: 1rem;
}

.quality-gate-copy > p:last-child {
  color: #d2e6d9;
  font-size: 0.8rem;
}

.quality-kicker {
  margin-bottom: 3px !important;
  color: var(--accent);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.15em;
}

.quality-gate-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
}

.quality-status {
  color: var(--focus);
  font-size: 0.76rem;
  font-weight: 700;
}

.quality-confirm-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 10px;
  color: #02150a;
  font-size: 0.82rem;
  font-weight: 800;
  background: var(--accent);
}

.live-readout {
  position: absolute;
  z-index: 5;
  top: 12px;
  left: 12px;
  display: flex;
  min-width: 72px;
  align-items: center;
  gap: 8px;
  justify-content: center;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--focus);
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  font-weight: 800;
  background: rgba(2, 8, 6, 0.72);
  pointer-events: none;
}

.quality-settings-button {
  position: absolute;
  z-index: 5;
  top: 12px;
  right: 12px;
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 6px;
  padding: 0 11px;
  border: 1px solid rgba(183, 255, 207, 0.3);
  border-radius: 999px;
  color: var(--focus);
  font-size: 0.76rem;
  font-weight: 800;
  cursor: pointer;
  background: rgba(2, 8, 6, 0.78);
  backdrop-filter: blur(8px);
}

.quality-settings-button:hover {
  border-color: rgba(183, 255, 207, 0.55);
  background: rgba(12, 44, 27, 0.9);
}

.readout-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.viewer-viewport {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #000;
}

.player-transform,
.player-transform iframe,
.player-transform .html-video,
#player-mount {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.player-transform {
  transform-origin: 50% 50%;
  will-change: transform;
}

.player-transform.is-zoom-animating {
  transition: transform 350ms cubic-bezier(0.22, 1, 0.36, 1);
}

.player-transform iframe {
  border: 0;
}

.player-transform .html-video {
  display: block;
  object-fit: contain;
  background: #000;
}

.gesture-layer {
  position: absolute;
  z-index: 4;
  inset: 0;
  cursor: grab;
  touch-action: none;
}

.viewer-viewport[data-interaction-mode="youtube"] .gesture-layer {
  pointer-events: none;
}

.viewer-viewport[data-interaction-mode="youtube"] .live-readout {
  display: none;
}

.gesture-layer:active,
.gesture-layer.is-dragging {
  cursor: grabbing;
}

.viewer-state {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 28px;
  text-align: center;
  background: rgba(4, 32, 31, 0.9);
  backdrop-filter: blur(8px);
}

.viewer-state h2 {
  margin-bottom: 9px;
  font-size: clamp(1.3rem, 3vw, 2.5rem);
  letter-spacing: -0.035em;
}

.viewer-state p:not(.state-kicker) {
  max-width: 34rem;
  margin-bottom: 0;
  color: var(--muted);
}

.loader {
  width: 42px;
  height: 42px;
  margin-bottom: 18px;
  border: 3px solid rgba(0, 249, 148, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.error-state {
  background: rgba(17, 6, 7, 0.92);
}

.error-state .state-kicker {
  color: #ff8b8b;
}

.error-actions {
  gap: 18px;
  margin-top: 22px;
}

.secondary-button,
.utility-button,
.icon-button,
.mini-button {
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.055);
}

.text-link {
  color: var(--focus);
  font-weight: 700;
  text-decoration: none;
}

.toast {
  position: absolute;
  z-index: 8;
  right: 16px;
  bottom: 16px;
  max-width: min(360px, calc(100% - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(5, 12, 9, 0.94);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

.control-deck {
  min-height: 64px;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  background: #09120f;
}

.control-group {
  gap: 7px;
}

.transport-controls {
  padding-right: 11px;
  border-right: 1px solid var(--line);
}

.play-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #02150a;
  font-size: 1rem;
  background: var(--accent);
}

.icon-button {
  min-width: 48px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.zoom-controls {
  min-width: 270px;
  flex: 1;
}

.mini-button {
  min-width: 44px;
  height: 40px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.mini-button:hover,
.utility-button:hover,
.icon-button:hover {
  border-color: rgba(183, 255, 207, 0.34);
  color: var(--text);
  background: rgba(0, 249, 148, 0.1);
}

.zoom-slider-label {
  display: flex;
  min-width: 100px;
  flex: 1;
  align-items: center;
}

#zoom-slider {
  width: 100%;
  accent-color: var(--accent);
}

.utility-controls {
  margin-left: auto;
}

.utility-button {
  white-space: nowrap;
}

.is-hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.viewer-shell:fullscreen {
  display: flex;
  width: 100vw;
  height: 100vh;
  flex-direction: column;
  border: 0;
  border-radius: 0;
  background: #000;
}

.viewer-shell.is-pseudo-fullscreen {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: flex;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  flex-direction: column;
  border: 0;
  border-radius: 0;
  background: #000;
}

.viewer-shell:fullscreen .viewer-viewport {
  min-height: 0;
  flex: 1;
  aspect-ratio: auto;
}

.viewer-shell.is-pseudo-fullscreen .viewer-viewport {
  min-height: 0;
  flex: 1;
  aspect-ratio: auto;
}

.viewer-shell:fullscreen .quality-gate {
  position: absolute;
  z-index: 10;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  width: min(720px, calc(100vw - 24px));
  min-height: 0;
  align-items: center;
  flex-direction: row;
  gap: 16px;
  padding: 10px 12px;
  border: 1px solid rgba(0, 249, 148, 0.4);
  border-radius: 14px;
  background: rgba(5, 22, 14, 0.9);
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  transform: translateX(-50%);
}

.viewer-shell.is-pseudo-fullscreen .quality-gate {
  position: absolute;
  z-index: 10;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  width: min(720px, calc(100vw - 24px));
  min-height: 0;
  align-items: center;
  flex-direction: row;
  gap: 16px;
  padding: 10px 12px;
  border: 1px solid rgba(0, 249, 148, 0.4);
  border-radius: 14px;
  background: rgba(5, 22, 14, 0.9);
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  transform: translateX(-50%);
}

.viewer-shell:fullscreen .quality-gate-copy h2 {
  font-size: 0.88rem;
}

.viewer-shell.is-pseudo-fullscreen .quality-gate-copy h2 {
  font-size: 0.88rem;
}

.viewer-shell:fullscreen .quality-gate-copy > p:last-child {
  font-size: 0.7rem;
}

.viewer-shell.is-pseudo-fullscreen .quality-gate-copy > p:last-child {
  font-size: 0.7rem;
}

.viewer-shell:fullscreen .quality-gate-actions {
  width: auto;
  align-items: center;
  flex-direction: row;
  gap: 8px;
}

.viewer-shell.is-pseudo-fullscreen .quality-gate-actions {
  width: auto;
  align-items: center;
  flex-direction: row;
  gap: 8px;
}

.viewer-shell:fullscreen .quality-status {
  font-size: 0.68rem;
}

.viewer-shell.is-pseudo-fullscreen .quality-status {
  font-size: 0.68rem;
}

.viewer-shell:fullscreen .quality-confirm-button {
  width: auto;
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.76rem;
}

.viewer-shell.is-pseudo-fullscreen .quality-confirm-button {
  width: auto;
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.76rem;
}

.viewer-shell:fullscreen .control-deck {
  display: none;
}

.viewer-shell.is-pseudo-fullscreen .control-deck {
  display: none;
}

.viewer-shell:fullscreen .live-readout {
  display: none;
}

.viewer-shell.is-pseudo-fullscreen .live-readout {
  display: none;
}

.shortcut-help {
  width: min(760px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 32px));
  padding: 0;
  overflow: auto;
  border: 1px solid rgba(183, 255, 207, 0.24);
  border-radius: 20px;
  color: var(--text);
  background: #0a1511;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.72);
}

.shortcut-help::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(7px);
}

.shortcut-help-card {
  padding: clamp(20px, 4vw, 34px);
}

.shortcut-help-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.shortcut-help-header h2 {
  margin-bottom: 0;
}

.help-close-button {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.055);
}

.shortcut-help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px 32px;
}

.shortcut-help-grid section:last-child {
  grid-column: 1 / -1;
}

.shortcut-help-grid h3 {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.shortcut-help-grid dl {
  margin: 0;
}

.shortcut-help-grid dl > div {
  display: grid;
  grid-template-columns: minmax(120px, 0.85fr) 1.15fr;
  gap: 12px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.shortcut-help-grid dt,
.shortcut-help-grid dd {
  margin: 0;
}

.shortcut-help-grid dd {
  color: var(--muted);
  font-size: 0.8rem;
}

kbd {
  display: inline-block;
  min-width: 28px;
  padding: 4px 7px;
  border: 1px solid rgba(183, 255, 207, 0.2);
  border-radius: 6px;
  color: var(--text);
  font: 700 0.72rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 -2px rgba(0, 0, 0, 0.25);
}

@media (max-width: 960px) {
  .compact-brand h1 {
    display: none;
  }

  .control-deck {
    flex-wrap: wrap;
  }

  .quality-gate {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .quality-gate-actions {
    width: 100%;
    justify-content: space-between;
  }

  .zoom-controls {
    min-width: min(360px, 100%);
  }

  .utility-controls {
    margin-left: 0;
  }
}

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

  .compact-brand,
  .control-label {
    display: none;
  }

  .url-form {
    align-items: stretch;
    flex-direction: column;
  }

  .source-actions {
    width: 100%;
    /* Longer pt/es labels do not fit one row on phones; wrap only when needed. */
    flex-wrap: wrap;
  }

  .source-actions .primary-button,
  .source-actions .fullscreen-option {
    flex: 1 1 auto;
    white-space: nowrap;
  }

  .shortcut-help-grid {
    grid-template-columns: 1fr;
  }

  .shortcut-help-grid section:last-child {
    grid-column: auto;
  }

  .field-error {
    position: static;
    transform: none;
  }

  .viewer-shell {
    border-radius: 16px;
  }

  .control-deck {
    justify-content: center;
  }

  .quality-gate-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .quality-confirm-button {
    width: 100%;
  }

  .transport-controls {
    border-right: 0;
  }

  .zoom-controls,
  .framing-controls,
  .utility-controls {
    width: 100%;
    justify-content: center;
  }

  .zoom-slider-label {
    max-width: 180px;
  }

  .viewer-shell:fullscreen .quality-gate,
  .viewer-shell:fullscreen .control-deck {
    flex: 0 0 auto;
  }

  .viewer-shell.is-pseudo-fullscreen .quality-gate,
  .viewer-shell.is-pseudo-fullscreen .control-deck {
    flex: 0 0 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

.guide-link {
  display: inline-grid;
  min-height: 38px;
  padding: 0 12px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.guide-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Language menu: a one-code button that opens the list, so it fits the narrow top bar. */
.lang-menu {
  position: relative;
}

.lang-menu > summary {
  list-style: none;
  cursor: pointer;
}

.lang-menu > summary::-webkit-details-marker {
  display: none;
}

.lang-menu[open] > summary {
  border-color: var(--accent);
  color: var(--accent);
}

.lang-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  min-width: 9.5em;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.lang-menu-list a {
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.lang-menu-list a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent);
}

.lang-menu-list a[aria-current] {
  color: var(--accent);
  pointer-events: none;
}

/* On phones the language button may sit at the left of the second row,
   so the list hangs from the whole panel instead of from the button. */
@media (max-width: 640px) {
  .lang-menu {
    position: static;
  }

  .lang-menu-list {
    right: 10px;
  }
}

/* Kept separate from the :fullscreen rules so browsers that do not know
   :fullscreen (older iOS Safari) still apply the pseudo fullscreen layer. */
html.has-pseudo-fullscreen,
html.has-pseudo-fullscreen body {
  overflow: hidden;
  overscroll-behavior: none;
}

.exit-fullscreen-button {
  position: absolute;
  z-index: 5;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: none;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  background: rgba(2, 8, 6, 0.7);
  backdrop-filter: blur(8px);
}

.viewer-shell.is-pseudo-fullscreen .exit-fullscreen-button {
  display: grid;
}
