/* Passatore Coach — design tokens + mobile-first layout */
:root {
  --bg: #0b0d10;
  --bg-2: #11151a;
  --bg-3: #1a1f25;
  --border: #1f262e;
  --border-2: #2a3038;
  --text: #e7eaee;
  --text-muted: #98a3ad;
  --text-faint: #4a5560;
  --accent: #2563eb;
  --accent-2: #60a5fa;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 14px;
  --topbar-h: 64px;
  --bottomnav-h: 64px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif; -webkit-font-smoothing: antialiased; min-height: 100dvh; }
body { overflow-x: hidden; }
button { font-family: inherit; }

/* App layout */
#app { display: flex; flex-direction: column; min-height: 100dvh; }
#topbar {
  position: fixed; top: 0; left: 0; right: 0;
  background: rgba(11,13,16,0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) 1rem 0.5rem 1rem;
  z-index: 10;
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; padding-top: 0.5rem; }
.topbar-title { font-size: 1.1rem; font-weight: 700; }
.topbar-actions { display: flex; gap: 0.4rem; }
.countdown { font-size: 0.78rem; color: var(--text-muted); padding-top: 0.15rem; }

main#view {
  flex: 1; padding: calc(var(--topbar-h) + 0.5rem) 1rem calc(var(--bottomnav-h) + 1rem);
  max-width: 720px; margin: 0 auto; width: 100%;
}

#bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: rgba(11,13,16,0.92); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.nav-item { display: flex; flex-direction: column; align-items: center; padding: 0.55rem 0.2rem; color: var(--text-faint); text-decoration: none; gap: 0.15rem; transition: color 0.15s; }
.nav-item.active { color: var(--accent-2); }
.nav-icon { font-size: 1.05rem; line-height: 1; }
.nav-label { font-size: 0.65rem; font-weight: 600; letter-spacing: 0.02em; }

/* Cards + components */
.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 0.7rem 0; }
.card-tight { padding: 0.7rem 0.85rem; }
.card-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 0.5rem; }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 0.7rem; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1rem; }
.kv { display: flex; flex-direction: column; }
.kv-key { font-size: 0.72rem; color: var(--text-muted); }
.kv-val { font-size: 1.05rem; font-weight: 600; }
.big { font-size: 2rem; font-weight: 700; line-height: 1.05; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.ok { color: var(--ok); } .warn { color: var(--warn); } .err { color: var(--err); }
.tag { display: inline-block; background: var(--bg-3); border: 1px solid var(--border-2); padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.72rem; color: var(--text-muted); }
.tag.ok { color: var(--ok); border-color: rgba(74,222,128,0.3); }
.tag.warn { color: var(--warn); border-color: rgba(251,191,36,0.3); }
.tag.err { color: var(--err); border-color: rgba(248,113,113,0.3); }

/* Buttons */
.btn, button.btn, a.btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: white; border: 0; border-radius: 12px;
  padding: 0.85rem 1rem; font-size: 1rem; font-weight: 600; width: 100%;
  text-decoration: none; cursor: pointer; transition: opacity 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn.secondary { background: var(--bg-3); color: var(--text); border: 1px solid var(--border-2); }
.btn.danger { background: #b91c1c; }
.btn.ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border-2); }
.btn.icon { width: 36px; height: 36px; padding: 0; font-size: 1rem; border-radius: 10px; background: var(--bg-3); border: 1px solid var(--border-2); color: var(--text-muted); }
button.icon, a.icon { display: inline-flex; align-items: center; justify-content: center; }

.icon.avatar {
  width: 36px; height: 36px; padding: 0; border-radius: 50%; overflow: hidden;
  background: var(--bg-3); border: 1px solid var(--border-2);
  color: var(--text-muted); text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon.avatar img { width: 100%; height: 100%; object-fit: cover; }
.topbar-actions { display: flex; gap: 0.4rem; align-items: center; }

.btn-row { display: flex; gap: 0.5rem; margin: 0.6rem 0; }
.btn-row .btn { flex: 1; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 0.4rem; }
.list-item { display: flex; align-items: center; gap: 0.7rem; padding: 0.7rem 0.85rem; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: inherit; }
.list-item:active { background: var(--bg-3); }
.list-item .left { font-size: 1.6rem; line-height: 1; min-width: 32px; text-align: center; }
.list-item .body { flex: 1; min-width: 0; }
.list-item .body .t1 { font-size: 0.95rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .body .t2 { font-size: 0.75rem; color: var(--text-muted); display: flex; gap: 0.6rem; flex-wrap: wrap; }
.list-item .right { font-size: 0.95rem; color: var(--text-muted); }

/* Forms */
label { display: block; font-size: 0.78rem; color: var(--text-muted); margin-top: 0.7rem; margin-bottom: 0.3rem; }
input[type=text], input[type=number], input[type=email], textarea, select {
  width: 100%; background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border-2); border-radius: 10px;
  padding: 0.7rem 0.85rem; font-size: 1rem;
}
textarea { min-height: 90px; resize: vertical; }
input[type=range] { width: 100%; }
.scale { display: flex; gap: 0.4rem; }
.scale > button {
  flex: 1; aspect-ratio: 1; border-radius: 10px;
  background: var(--bg-3); color: var(--text-muted);
  border: 1px solid var(--border-2); font-weight: 600; font-size: 1.1rem;
}
.scale > button.selected { background: var(--accent); color: white; border-color: var(--accent); }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 0.6rem; padding-bottom: 1rem; }
.bubble { max-width: 85%; padding: 0.65rem 0.85rem; border-radius: 14px; font-size: 0.95rem; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: white; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--bg-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.system { align-self: center; color: var(--text-muted); font-size: 0.78rem; font-style: italic; }
.chat-input {
  display: flex; gap: 0.4rem;
  position: sticky; bottom: calc(var(--bottomnav-h) + 0.5rem);
  background: var(--bg); padding: 0.5rem 0;
}
.chat-input textarea { min-height: 44px; flex: 1; }
.chat-input .btn { width: auto; padding: 0 1rem; }
.thinking { font-size: 0.85rem; color: var(--text-muted); padding: 0.5rem 0.85rem; }
.thinking::after { content: ''; display: inline-block; width: 1px; height: 1em; }
.thinking .dot { display: inline-block; animation: blink 1.4s infinite; }
.thinking .dot:nth-child(2) { animation-delay: 0.2s; }
.thinking .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80% { opacity: 0.2; } 40% { opacity: 1; } }

/* Login splash */
.splash { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 70vh; text-align: center; padding: 0 1rem; }
.splash h1 { font-size: 2rem; margin: 0.5rem 0; }
.splash p { color: var(--text-muted); margin-bottom: 1.5rem; max-width: 26rem; }

/* Charts */
.chart { width: 100%; height: 180px; }
.chart-axis { fill: var(--text-faint); font-size: 9px; }

/* Toast */
#toast { position: fixed; bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 1rem); left: 50%; transform: translateX(-50%); background: var(--bg-2); border: 1px solid var(--border); padding: 0.7rem 1.1rem; border-radius: 12px; opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 100; max-width: 90vw; font-size: 0.9rem; }
#toast.show { opacity: 1; }
#toast.err { color: var(--err); border-color: rgba(248,113,113,0.4); }
#toast.ok { color: var(--ok); border-color: rgba(74,222,128,0.4); }

/* Skeleton */
.skel { background: linear-gradient(90deg, var(--bg-2) 0%, var(--bg-3) 50%, var(--bg-2) 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; height: 1.1em; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Build stamp footer (settings only) */
.build { color: var(--text-faint); font-size: 0.72rem; text-align: center; margin: 1rem 0; }

/* ---- Live mode (race) ---- */
body.live-mode {
  background: #050608;
  color: #f7f7f5;
}
body.live-mode #topbar { background: #050608; border-bottom-color: #1a1d22; }
body.live-mode #bottomnav { display: none; }
body.live-mode main#view { padding: 0.6rem; }
.live-banner {
  background: #f15555; color: #fff; padding: 0.6rem 0.8rem; border-radius: 8px; font-weight: 600; margin-bottom: 0.5rem;
}
.live-root .label {
  display: block; font-size: 0.75rem; color: #9aa0a6; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.15rem;
}
.live-root .big {
  font-size: 3.4rem; font-weight: 700; line-height: 1.0; font-variant-numeric: tabular-nums;
}
.live-root .med { font-size: 1.4rem; font-weight: 600; }
.live-root .unit { font-size: 1.4rem; color: #9aa0a6; margin-left: 0.3rem; }
.live-root > div { padding: 0.7rem 0.6rem; border-bottom: 1px solid #15181c; }
.live-root .tabular { font-variant-numeric: tabular-nums; }
.live-actions { display: flex; flex-direction: column; gap: 0.4rem; padding-top: 0.8rem; }
.btn-live {
  width: 100%; padding: 1rem; font-size: 1.05rem; font-weight: 600; border-radius: 10px;
  border: 1px solid #2a2f36; background: #15181c; color: #f7f7f5;
}
.btn-live.primary { background: #ffce4d; color: #000; border-color: #ffce4d; }
.btn-live.ghost { background: transparent; color: #9aa0a6; }
.btn-live:disabled { opacity: 0.55; }
.live-cta .btn.primary.block { display: block; padding: 0.8rem 1rem; text-align: center; background: #ffce4d; color: #000; border-radius: 10px; font-weight: 600; text-decoration: none; }
.live-cta .btn.primary.block:hover { filter: brightness(1.05); }

/* ---- Welcome tour modal ---- */
.welcome-overlay {
  position: fixed; inset: 0; background: rgba(5,6,8,0.92); z-index: 9999;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0; animation: fadein 0.2s ease;
}
@keyframes fadein { from {opacity:0} to {opacity:1} }
.welcome-card {
  background: #15181c; color: #f7f7f5; width: 100%;
  max-width: 520px; max-height: 92vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 1.4rem 1.2rem 1rem;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.6);
  font-size: 0.95rem;
}
.welcome-card h2 { margin: 0.2rem 0 0.7rem; font-size: 1.3rem; }
.welcome-card p, .welcome-card ul, .welcome-card ol { margin: 0.4rem 0; }
.welcome-card em { font-style: italic; color: #ffce4d; }
.welcome-progress {
  display: flex; gap: 0.4rem; justify-content: center; margin-bottom: 0.6rem;
}
.welcome-progress .dot {
  width: 6px; height: 6px; background: #2a2f36; border-radius: 50%;
}
.welcome-progress .dot.on { background: #ffce4d; transform: scale(1.4); }
.welcome-nav {
  display: flex; gap: 0.4rem; align-items: center; margin-top: 1rem; padding-top: 0.6rem;
  border-top: 1px solid #2a2f36;
}
.welcome-nav .btn { padding: 0.6rem 1rem; }
.welcome-nav .btn.primary { background: #ffce4d; color: #000; }
.welcome-nav .btn.secondary { background: #2a2f36; color: #f7f7f5; }
.welcome-nav .btn.ghost { background: transparent; color: #9aa0a6; }

/* ---- Onboard welcome cards ---- */
.card.welcome { border-left: 3px solid #ffce4d; }
.card.welcome ul li, .card.welcome ol li { margin: 0.3rem 0; }

/* ---- Plan settings card + modify modal ---- */
.card.plan-settings { border-left: 3px solid #ffce4d; }
.card.plan-settings .kv-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.4rem; }
.card.plan-settings .kv {
  display: flex; flex-direction: column; align-items: center;
  background: #15181c; border-radius: 8px; padding: 0.6rem 0.4rem;
}
.card.plan-settings .kv-key { font-size: 0.72rem; color: #9aa0a6; text-transform: uppercase; letter-spacing: 0.04em; }
.card.plan-settings .kv-val { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; color: #f7f7f5; }
.plan-rationale strong { color: #ffce4d; }

/* ---- Evidence-first card (PR-D, P-2.14) ---- */
.card.evidence-card { border-left: 3px solid #33d17a; }
.card.evidence-card .ev-bullets li { color: #f7f7f5; }
.card.evidence-card details summary::-webkit-details-marker { display: none; }
.card.evidence-card .tag { font-size: 0.72rem; padding: 0.2rem 0.5rem; border-radius: 6px; font-weight: 600; }
.cite-ev {
  display: inline-block; padding: 0 0.3rem; border-radius: 4px;
  background: #1f242a; color: #9aa0a6; text-decoration: none;
  font-size: 0.78rem; font-weight: 600;
}

/* ---- Coach quick-action chips (PR-F) ---- */
.quick-chips {
  display: flex; gap: 0.4rem; flex-wrap: nowrap;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding: 0.4rem 0; margin: 0.2rem 0 0.4rem;
  scrollbar-width: none;
}
.quick-chips::-webkit-scrollbar { display: none; }
.quick-chips .chip {
  flex: 0 0 auto;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border-2); border-radius: 999px;
  padding: 0.45rem 0.85rem; font-size: 0.82rem; font-weight: 500;
  white-space: nowrap; cursor: pointer; transition: background 0.15s;
}
.quick-chips .chip:active { background: var(--accent); color: white; border-color: var(--accent); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(5,6,8,0.75); z-index: 9000;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  background: #15181c; color: #f7f7f5; width: 100%;
  max-width: 520px; padding: 1.2rem 1.1rem; border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.6);
}
.modal-card label { display: block; font-size: 0.85rem; }
.modal-card input[type=range] { -webkit-appearance: none; appearance: none; height: 6px; background: #2a2f36; border-radius: 4px; outline: none; }
.modal-card input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%; background: #ffce4d; cursor: pointer; border: 0;
}
.modal-card input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; background: #ffce4d; cursor: pointer; border: 0;
}
.modal-card .btn.primary { background: #ffce4d; color: #000; }

/* Citation rendering — clickable refs in coach replies */
.cite-obs { border-bottom: 1px dashed currentColor; padding: 0 0.1em; }
.cite-act { border-bottom: 1px dashed currentColor; padding: 0 0.1em; }
.cite-obs:hover, .cite-act:hover { background: rgba(255, 206, 77, 0.15); border-radius: 3px; }
