/* © 2026 FunApp https://funapp.io */

:root {
  color-scheme: light;
  --table-bg: #d9b68c;
  --paper: #faf8f2;
  --paper-glass: rgba(250, 248, 242, 0.94);
  --paper-alt: #f1ede3;
  --ink: #23201b;
  --ink-muted: #665e51;
  --border: rgba(74, 55, 31, 0.14);
  --border-strong: rgba(74, 55, 31, 0.28);
  --emerald: #179c52;
  --emerald-dark: #10783e;
  --emerald-soft: rgba(23, 156, 82, 0.13);
  --amber: #d88f22;
  --amber-soft: #fdf4df;
  --teal: #1da9a5;
  --focus-ring: #0c6e3b;
  --shadow-pill: 0 8px 24px rgba(56, 36, 15, 0.14), 0 1px 2px rgba(56, 36, 15, 0.08);
  --font-display: "Bahnschrift", "Trebuchet MS", "Noto Sans TC", system-ui, sans-serif;
  --font-body: "Noto Sans TC", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--table-bg);
  color: var(--ink);
  font-family: var(--font-body);
  overscroll-behavior: none;
}

button,
select,
a {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

button:focus-visible,
select:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

#app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 356px;
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  overflow: hidden;
  background: linear-gradient(160deg, #e7d7bf 0%, #cfb089 100%);
}

/* Stage Container */
#stage-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 42%, #e9dac1 0%, #c89d6d 80%);
}

#scene-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#scene-canvas.dragging-car {
  cursor: grabbing;
}

/* Floating Cream Pill Bars */
.floating-pill-bar {
  position: absolute;
  left: 14px;
  right: 14px;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--paper-glass);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-pill);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#top-pill-bar {
  top: 12px;
  flex-wrap: nowrap;
}

#bottom-pill-bar.bottom-bar {
  top: auto;
  bottom: 14px;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: fit-content;
  max-width: calc(100% - 28px);
  justify-content: center;
  flex-wrap: nowrap;
  padding: 4px 10px;
}

.bar-left,
.bar-right,
.bar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.bar-divider {
  width: 1px;
  height: 24px;
  background: var(--border-strong);
  margin: 0 2px;
}

/* Brand & Back Link */
.back-pill,
.pill-chip,
.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 140ms ease, border-color 140ms ease, transform 120ms ease;
}

.pill-btn {
  border-color: transparent;
  background: transparent;
  padding: 0 9px;
  font-size: 0.8rem;
}

.back-pill:hover,
.pill-chip:hover,
.pill-btn:hover {
  background: rgba(235, 226, 208, 0.9);
}

.pill-btn.active {
  background: var(--ink);
  color: var(--paper);
}

.pill-chip.accent-chip {
  background: #1d1b18;
  border-color: #1d1b18;
  color: #faf8f2;
}

.pill-chip.accent-chip:hover {
  background: #332f29;
}

.pill-chip.icon-chip {
  padding: 0 11px;
}

.brand-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding-right: 4px;
}

.brand-badge {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #24b7b2, #178a88);
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 800;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-sub {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--paper-alt);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-muted);
  white-space: nowrap;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
  flex-shrink: 0;
}

.live-dot.green {
  background: var(--emerald);
  box-shadow: 0 0 0 3px rgba(23, 156, 82, 0.18);
}

/* Airy Ready Prompt Banner (tucked upper-right so both boards & dining backdrop stay unobstructed) */
#ready-banner {
  position: absolute;
  top: 72px;
  right: 16px;
  left: auto;
  transform: none;
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(470px, calc(100% - 32px));
  padding: 6px 8px 6px 14px;
  border-radius: 999px;
  background: rgba(250, 248, 242, 0.94);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-pill);
}

#app-shell:not([data-phase="ready"]) #ready-banner {
  display: none;
}

.ready-banner-copy {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--ink);
  font-weight: 500;
}

.ready-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--teal);
  flex-shrink: 0;
}

.primary-action-btn,
.secondary-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 120ms ease, background-color 140ms ease;
}

.primary-action-btn {
  background: var(--emerald);
  color: #ffffff;
}

.primary-action-btn:hover {
  background: var(--emerald-dark);
}

.secondary-action-btn {
  background: var(--paper-alt);
  border-color: var(--border-strong);
  color: var(--ink);
}

.secondary-action-btn:hover {
  background: #e7dfd0;
}

/* Accessible Nudge Dock */
#nudge-dock {
  position: absolute;
  top: 72px;
  right: 16px;
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 12px;
  border-radius: 999px;
  background: rgba(250, 248, 242, 0.92);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-pill);
}

#app-shell[data-phase="ready"] #nudge-dock {
  display: none;
}

.nudge-selected {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-muted);
  white-space: nowrap;
}

.nudge-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
}

.compact-btn {
  padding: 0 10px;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--border);
}

/* Overlays */
.bench-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(34, 24, 14, 0.34);
  backdrop-filter: blur(4px);
}

.bench-card {
  width: min(440px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 22px 24px;
  border-radius: 22px;
  background: var(--paper);
  border: 1px solid var(--border-strong);
  box-shadow: 0 22px 48px rgba(32, 20, 9, 0.28);
  text-align: center;
}

.bench-card.wide-card {
  width: min(560px, 100%);
  text-align: left;
}

.card-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.card-badge.emerald {
  background: var(--emerald-soft);
  color: var(--emerald-dark);
}

.card-badge.amber {
  background: var(--amber-soft);
  color: #965d08;
}

.card-title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.38rem;
  font-weight: 800;
}

.card-sub {
  margin: 0 0 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink-muted);
}

.card-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.card-metrics.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric-cell {
  padding: 10px;
  border-radius: 14px;
  background: var(--paper-alt);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-label {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.9rem;
  font-weight: 600;
}

.settings-select {
  min-height: 44px;
  min-width: 160px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: #ffffff;
  color: var(--ink);
  font-size: 1rem;
}

.compact-toggle {
  min-height: 44px;
  min-width: 84px;
}

.version-stamp {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--ink-muted);
  font-family: var(--font-mono);
}

.decisions-meta {
  padding: 12px;
  margin-bottom: 14px;
  border-radius: 14px;
  background: var(--paper-alt);
  border: 1px solid var(--border);
}

.trace-box {
  margin: 8px 0 0;
  padding: 10px;
  border-radius: 10px;
  background: #232830;
  color: #edf1f4;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1.45;
  white-space: pre-wrap;
  max-height: 150px;
  overflow-y: auto;
}

/* Right Cream Live Telemetry Sidebar */
#telemetry-sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  padding: 14px 16px 14px;
  background: var(--paper);
  border-left: 1px solid var(--border-strong);
  overflow-y: auto;
}

.telemetry-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.live-race-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  text-transform: uppercase;
}

.lap-clock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.clock-readout {
  font-family: var(--font-mono);
  font-size: 2.05rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.lap-badge {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.status-pill-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.status-badge {
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--amber-soft);
  border: 1px solid rgba(216, 143, 34, 0.25);
  color: #8c5709;
  font-size: 0.78rem;
  font-weight: 700;
}

.moves-counter {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.hint-callout {
  padding: 8px 11px;
  border-radius: 10px;
  background: var(--emerald-soft);
  border: 1px solid rgba(23, 156, 82, 0.25);
  color: var(--emerald-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

/* Lap Table */
.lap-table-wrap {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #ffffff;
  overflow: hidden;
}

.lap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.lap-table th {
  padding: 7px 8px;
  text-align: left;
  font-size: 0.69rem;
  font-weight: 800;
  color: var(--ink-muted);
  background: var(--paper-alt);
  border-bottom: 1px solid var(--border);
}

.lap-table td {
  padding: 7px 8px;
  border-bottom: 1px solid rgba(74, 55, 31, 0.08);
  color: var(--ink);
  white-space: nowrap;
}

.lap-table tr:last-child td {
  border-bottom: none;
  font-weight: 800;
  background: var(--paper-alt);
}

.lap-table tr.active-lap td {
  background: #fef8e7;
  font-weight: 700;
}

.delta-pos {
  color: var(--emerald-dark);
  font-weight: 800;
}

.delta-neg {
  color: #b44620;
  font-weight: 700;
}

/* Model's View & Live Thoughts Card */
.model-view-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #ffffff;
  border: 1px solid var(--border);
  margin-top: auto;
}

.model-view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.78rem;
}

.model-head-right {
  display: flex;
  align-items: center;
  gap: 5px;
}

.turn-tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-muted);
}

.stream-badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--emerald-soft);
  color: var(--emerald-dark);
  font-size: 0.65rem;
  font-weight: 800;
}

.minimap-frame {
  position: relative;
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #cbb08a;
}

#ai-minimap-canvas {
  display: block;
  width: 100%;
  height: auto;
}

.sent-png-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(24, 24, 22, 0.72);
  color: #f8f5ef;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
}

.thought-log {
  min-height: 48px;
  max-height: 64px;
  overflow-y: auto;
  padding: 7px 34px 7px 9px;
  border-radius: 9px;
  background: var(--paper-alt);
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--ink);
}

.thought-prefix {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 800;
  color: var(--emerald-dark);
  margin-bottom: 2px;
}

/* FunApp gtm.js bottom-left star spacing */
.gtm-favorite-btn,
#funapp-favorite-btn {
  z-index: 15 !important;
}

/* Portrait & Compact Screens (no floating chrome overlapping playable grid) */
@media (max-width: 959px) {
  #app-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  #stage-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    align-items: stretch;
  }

  .floating-pill-bar {
    position: static;
    transform: none;
    left: auto;
    right: auto;
    bottom: auto;
    top: auto;
    border-radius: 0;
    border-left: none;
    border-right: none;
    max-width: 100%;
    width: 100%;
    box-shadow: none;
  }

  #top-pill-bar {
    grid-row: 1;
    flex-wrap: wrap;
    padding: 4px 8px;
  }

  #ready-banner {
    grid-row: 2;
    position: static;
    transform: none;
    max-width: 100%;
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 10px;
  }

  #scene-canvas {
    grid-row: 3;
    min-height: 0;
  }

  #nudge-dock {
    grid-row: 4;
    position: static;
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 4px 8px;
  }

  #bottom-pill-bar.bottom-bar {
    grid-row: 5;
    position: static;
    transform: none;
    max-width: 100%;
    width: 100%;
    padding: 4px 8px;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .bar-divider {
    display: none;
  }

  .brand-sub,
  .back-text {
    display: none;
  }

  .pill-chip,
  .pill-btn,
  .back-pill {
    padding: 0 9px;
    font-size: 0.78rem;
  }

  #telemetry-sidebar {
    border-left: none;
    border-top: 1px solid var(--border-strong);
    max-height: 204px;
    padding: 8px 12px 46px;
    gap: 6px;
  }

  .clock-readout {
    font-size: 1.45rem;
  }

  .model-view-card {
    display: none;
  }
}

@media (max-width: 480px) {
  .rival-pill {
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #ready-banner {
    padding: 5px 8px;
  }

  .ready-banner-copy {
    font-size: 0.78rem;
  }
}

/* Short Landscape Phone (e.g. 844x390 / 667x375) */
@media (max-height: 460px) and (min-width: 560px) {
  #app-shell {
    grid-template-columns: minmax(0, 1fr) 236px;
    grid-template-rows: minmax(0, 1fr);
  }

  #stage-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    align-items: stretch;
  }

  .floating-pill-bar {
    position: static;
    transform: none;
    max-width: 100%;
    width: 100%;
    border-radius: 0;
    box-shadow: none;
    padding: 2px 6px;
  }

  #top-pill-bar {
    grid-row: 1;
    flex-wrap: nowrap;
    gap: 4px;
  }

  #ready-banner {
    position: absolute;
    top: 52px;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 20px);
    width: fit-content;
    border-radius: 999px;
    padding: 4px 6px 4px 12px;
    box-shadow: var(--shadow-pill);
    flex-wrap: nowrap;
  }

  #ready-banner .ready-banner-copy {
    display: none;
  }

  #scene-canvas {
    grid-row: 2;
    min-height: 0;
  }

  #nudge-dock {
    display: none;
  }

  #bottom-pill-bar.bottom-bar {
    grid-row: 3;
    position: static;
    transform: none;
    max-width: 100%;
    width: 100%;
    flex-wrap: nowrap;
    padding: 2px 6px;
    gap: 4px;
    justify-content: space-between;
  }

  #top-pill-bar .pill-chip,
  #bottom-pill-bar .pill-btn,
  #top-pill-bar .back-pill {
    min-height: 44px;
    padding: 0 7px;
    font-size: 0.72rem;
  }

  .bar-divider,
  .brand-sub,
  .back-text,
  #decisions-btn span:last-child,
  #audio-label {
    display: none;
  }

  #audio-btn {
    min-width: 44px;
    justify-content: center;
  }

  #telemetry-sidebar {
    border-top: none;
    border-left: 1px solid var(--border-strong);
    max-height: none;
    padding: 6px 8px 46px;
    gap: 5px;
  }

  .clock-readout {
    font-size: 1.32rem;
  }

  .model-view-card {
    display: none;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* High Contrast / Forced Colors */
@media (forced-colors: active) {
  .floating-pill-bar,
  .bench-card,
  #telemetry-sidebar,
  .lap-table-wrap,
  .pill-chip,
  .pill-btn,
  .primary-action-btn,
  .secondary-action-btn {
    border: 2px solid CanvasText;
  }

  .pill-btn.active,
  .primary-action-btn {
    background: Highlight;
    color: HighlightText;
  }
}
