:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, "PingFang SC", "Noto Sans CJK SC", sans-serif;
  background: #06090e;
  color: #f1f5f9;
  --muted: #8b98ab;
  --accent: #42dccb;
  --accent-hover: #72eadc;
  --panel-bg: #111620;
  --border: #222c3c;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #06090e;
  user-select: none;
  -webkit-user-select: none;
}

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

button {
  border: 0;
  border-radius: 14px;
  min-height: 54px;
  padding: 12px 20px;
  font-family: inherit;
  font-weight: 600;
  font-size: 17px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

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

button:focus-visible, a:focus-visible, .progress-bar:focus-visible {
  outline: 3px solid #72f7e7;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.primary {
  background: var(--accent);
  color: #042826;
}

.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.secondary {
  background: #1d2533;
  color: #e6edf6;
}

.secondary:hover:not(:disabled) {
  background: #2b3548;
}

.full-width {
  width: 100%;
}

/* Top Cockpit Bar */
header {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: #090d14;
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  font-size: 20px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: #123731;
  color: var(--accent);
  font-size: 18px;
}

.brand small {
  display: inline-block;
  margin-left: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.local-badge {
  border: 1px solid #263143;
  background: #101622;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: #9eabbf;
  white-space: nowrap;
}

.account-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  background: #17202e;
  border: 1px solid #2c394e;
  color: #f1f5f9;
  font-size: 15px;
  font-weight: 600;
}

.account-pill:hover {
  background: #222e42;
}

.account-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
}

.account-dot.connected {
  background: #34d399;
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.7);
}

/* Main Cockpit Layout */
main {
  height: calc(100dvh - 64px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 16px;
  padding: 14px 20px;
  width: 100%;
  margin: 0;
  overflow: hidden;
}

body.drawer-closed main {
  grid-template-columns: minmax(0, 1fr);
}

body.drawer-closed .account-panel {
  display: none;
}

.player-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

/* Video Stage */
.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #020407;
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: pointer;
}

.stage canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.placeholder {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  cursor: pointer;
}

.play-outline {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: rgba(66, 220, 203, 0.14);
  border: 2px solid rgba(66, 220, 203, 0.45);
  font-size: 40px;
  color: var(--accent);
  line-height: 1;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  transition: transform 0.18s, background 0.18s;
}

.placeholder:hover .play-outline {
  transform: scale(1.06);
  background: rgba(66, 220, 203, 0.24);
}

.placeholder h1 {
  font-size: 26px;
  margin: 20px 0 8px;
}

.placeholder p {
  font-size: 15px;
  color: var(--muted);
  margin: 0;
}

/* Floating Unmute Banner & Stage Toast */
.unmute-banner {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  min-height: 50px;
  padding: 10px 24px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.94);
  color: #081018;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.stage-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 14;
  padding: 16px 28px;
  border-radius: 18px;
  background: rgba(10, 15, 24, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  color: #f8fafc;
  font-size: 20px;
  font-weight: 700;
  pointer-events: none;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

/* Floating Video Info Overlay */
.video-meta {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 16px;
  z-index: 10;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(4, 7, 12, 0) 0%, rgba(4, 7, 12, 0.78) 100%);
  padding: 14px 18px;
  border-radius: 16px;
}

.video-author-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

#video-author {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85);
}

.gesture-hint {
  font-size: 12px;
  color: rgba(226, 232, 240, 0.72);
  background: rgba(15, 23, 42, 0.65);
  padding: 4px 10px;
  border-radius: 999px;
}

#video-title {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
  color: #e2e8f0;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Bottom Car Dock: Scrubber + Large Touch Controls */
.player-dock {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.progress-bar {
  flex: 1;
  height: 28px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: #232d3f;
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  transition: height 0.12s;
}

.progress-bar:hover .progress-track,
.progress-bar:active .progress-track {
  height: 12px;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #2dd4bf, #42dccb);
  border-radius: 999px;
}

#play-time {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 600;
  color: #cbd5e1;
  min-width: 98px;
  text-align: right;
}

.player-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.controls-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.car-btn {
  min-height: 56px;
  padding: 12px 22px;
  font-size: 17px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.controls-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
  min-width: 0;
}

.auto-next-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #cbd5e1;
  cursor: pointer;
  white-space: nowrap;
}

.auto-next-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

#media-status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 340px;
}

/* Collapsible Right Account Drawer */
.account-panel {
  padding: 20px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  height: 100%;
  overflow-y: auto;
  min-width: 0;
  user-select: text;
  -webkit-user-select: text;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.section-heading-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.drawer-close-btn {
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #1e2736;
  color: #cbd5e1;
  font-size: 13px;
}

.eyebrow {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.status-badge {
  font-size: 12px;
  padding: 5px 10px;
  background: #263040;
  border-radius: 30px;
  color: #bfcbdb;
}

.status-badge.connected {
  background: #123a31;
  color: #63efd0;
}

h2 {
  font-size: 22px;
  letter-spacing: -0.3px;
  margin: 14px 0 8px;
}

.description {
  color: #a4b0c2;
  line-height: 1.55;
  font-size: 14px;
  margin: 0 0 14px;
  overflow-wrap: anywhere;
}

.qr-box {
  background: #fff;
  padding: 12px;
  border-radius: 16px;
  margin: 12px auto 14px;
  text-align: center;
  width: 280px;
  max-width: 100%;
}

.qr-box img {
  display: block;
  width: 256px;
  max-width: 100%;
  height: auto;
  aspect-ratio: 1;
  margin: auto;
}

.qr-caption {
  display: block;
  color: #526174;
  font-size: 12px;
  margin-top: 8px;
}

.login-actions {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 10px;
}

.login-actions button {
  min-height: 48px;
  padding: 10px;
  font-size: 15px;
}

.account-message {
  font-size: 13px;
  color: #cad6e5;
  min-height: 20px;
  line-height: 1.6;
  margin: 12px 0 0;
  overflow-wrap: anywhere;
}

.footnote {
  font-size: 12px;
  line-height: 1.6;
  color: #7f8da1;
  padding-top: 12px;
  margin: 12px 0 0;
  border-top: 1px solid #283140;
}

.connected-card {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 8px;
  margin: 18px 0;
}

.connected-card strong {
  overflow-wrap: anywhere;
}

.connected-card > span:last-child {
  font-size: 13px;
  color: var(--muted);
}

.account-avatar {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #16392f;
  color: var(--accent);
  font-size: 24px;
}

#disconnect-account {
  margin-top: 10px;
  min-height: 46px;
}

/* Challenge View */
.challenge-view {
  border: 1px solid #3a495b;
  border-radius: 14px;
  padding: 12px;
  margin: 12px 0;
  background: #101721;
  min-width: 0;
}

.challenge-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.challenge-heading strong {
  font-size: 15px;
}

.challenge-view button {
  min-height: 42px;
  padding: 8px 12px;
  font-size: 14px;
}

.challenge-help {
  font-size: 12px;
  color: #b7c7da;
  line-height: 1.5;
  margin: 8px 0;
}

.challenge-image-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 90px;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
}

.challenge-image-wrap img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 1280px;
  object-fit: contain;
  object-position: center center;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
  cursor: pointer;
}

.challenge-click-marker {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  display: block;
  width: 26px;
  height: 26px;
  border: 3px solid #ffce67;
  border-radius: 50%;
  background: rgba(255, 206, 103, 0.2);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
}

.challenge-click-marker.accepted {
  border-color: #42dccb;
  background: rgba(66, 220, 203, 0.22);
}

.challenge-click-marker.failed {
  border-color: #ff7b86;
  background: rgba(255, 123, 134, 0.25);
}

.challenge-text-controls {
  margin-top: 10px;
}

.challenge-text-controls label {
  display: block;
  color: #b7c7da;
  font-size: 12px;
  margin-bottom: 6px;
}

.challenge-text-controls > div {
  display: flex;
  gap: 8px;
}

.challenge-text-controls input {
  font: inherit;
  font-size: 15px;
  width: 0;
  min-width: 0;
  flex: 1;
  border: 1px solid #526278;
  border-radius: 8px;
  background: #080d14;
  color: #f1f5f9;
  padding: 10px;
}

.challenge-keys {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.challenge-keys button {
  flex: 1;
  white-space: nowrap;
}

.challenge-view.expanded {
  position: fixed;
  inset: 12px;
  z-index: 1000;
  padding: 18px;
  overflow: auto;
  box-shadow: 0 0 0 20px rgba(0, 0, 0, 0.85);
  margin: 0;
}

.cookie-toggle {
  margin-top: 10px;
  min-height: 46px;
  font-size: 15px;
}

.cookie-import-panel {
  border: 1px solid #30394a;
  border-radius: 14px;
  padding: 12px;
  margin-top: 10px;
  background: #0d121a;
}

.cookie-import-panel label {
  display: block;
  font-size: 12px;
  color: #b7c7da;
  margin-bottom: 6px;
}

.cookie-import-panel textarea {
  width: 100%;
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid #455368;
  border-radius: 10px;
  background: #080b10;
  color: #f1f5f9;
  padding: 10px;
  resize: vertical;
}

.cookie-import-actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.cookie-import-actions button {
  min-height: 42px;
  padding: 8px 12px;
  font-size: 14px;
}

/* Responsive adjustments for smaller or portrait screens */
@media (max-width: 960px) {
  main {
    grid-template-columns: minmax(0, 1fr);
    position: relative;
  }
  .account-panel {
    position: absolute;
    top: 10px;
    right: 12px;
    bottom: 10px;
    width: min(390px, calc(100vw - 24px));
    z-index: 30;
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.75);
  }
  .brand small,
  .local-badge {
    display: none;
  }
  .car-btn {
    min-height: 50px;
    padding: 10px 14px;
    font-size: 15px;
  }
}
