/* Design polish layer: loaded last. Refines buttons, tabs, cards, inputs, tables and the app rail. */
:root {
  --r-sm: 9px; --r-md: 12px; --r-lg: 16px; --r-xl: 20px;
  --ring: 0 0 0 3px color-mix(in oklch, var(--brand) 28%, transparent);
  --hair: color-mix(in oklch, var(--text-primary) 9%, transparent);
  --card-bg: linear-gradient(180deg, color-mix(in oklch, var(--surface) 100%, white 2.5%), var(--surface));
  --shadow-1: 0 1px 0 oklch(100% 0 0 / .045) inset, 0 1px 2px oklch(0% 0 0 / .25);
  --shadow-2: 0 1px 0 oklch(100% 0 0 / .06) inset, 0 12px 28px -14px oklch(0% 0 0 / .55);
}
:root[data-theme="light"] { --hair: color-mix(in oklch, var(--text-primary) 10%, transparent); --card-bg: var(--surface); --shadow-1: 0 1px 2px oklch(0% 0 0 / .06); --shadow-2: 0 10px 28px -14px oklch(0% 0 0 / .22); }
body { font-feature-settings: "cv11", "ss01"; }
.ic { flex-shrink: 0; }

/* ---------- buttons ---------- */
.btn {
  height: 40px; padding: 0 18px; gap: 8px; border-radius: var(--r-md); font-weight: 600; font-size: .875rem; letter-spacing: -.005em;
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease, filter .2s ease;
}
.btn:active { transform: translateY(0) scale(.985); }
.btn-primary {
  background: linear-gradient(180deg, color-mix(in oklch, var(--brand) 86%, white), var(--brand));
  color: var(--brand-fg); border-color: color-mix(in oklch, var(--brand) 70%, black);
  box-shadow: 0 1px 0 oklch(100% 0 0 / .4) inset, 0 8px 18px -8px color-mix(in oklch, var(--brand) 70%, transparent);
}
.btn-primary:hover { filter: none; transform: translateY(-1px); box-shadow: 0 1px 0 oklch(100% 0 0 / .45) inset, 0 12px 24px -8px color-mix(in oklch, var(--brand) 80%, transparent); }
.btn-primary:disabled { opacity: .45; box-shadow: none; transform: none; }
.btn-ghost { background: color-mix(in oklch, var(--surface) 80%, transparent); border: 1px solid var(--hair); color: var(--text-primary); box-shadow: var(--shadow-1); }
.btn-ghost:hover { background: var(--surface-hover); border-color: color-mix(in oklch, var(--brand) 40%, var(--hair)); color: var(--text-primary); transform: translateY(-1px); }
.btn-ghost:disabled { opacity: .45; transform: none; }
.btn-sm { height: 32px; padding: 0 13px; font-size: .8125rem; border-radius: var(--r-sm); }
.btn-lg { height: 50px; padding: 0 24px; font-size: .9375rem; border-radius: 14px; }
.btn:focus-visible, .chip:focus-visible, .tab:focus-visible, .period:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---------- chips & segmented controls ---------- */
.chip {
  padding: 6px 13px; border-radius: 999px; font-size: .8125rem; font-weight: 500; color: var(--text-secondary);
  background: color-mix(in oklch, var(--surface) 70%, transparent); border: 1px solid var(--hair);
  transition: background .18s, border-color .18s, color .18s, box-shadow .18s;
}
.chip:hover { color: var(--text-primary); border-color: color-mix(in oklch, var(--brand) 40%, var(--hair)); background: var(--surface-hover); }
.chip[aria-pressed="true"], .chip.active {
  color: var(--brand); border-color: color-mix(in oklch, var(--brand) 55%, transparent);
  background: color-mix(in oklch, var(--brand) 14%, transparent); font-weight: 600;
}
.chip.lg { padding: 10px 18px; font-size: .9375rem; border-radius: 14px; }
.analyze-form .chip { border-radius: 10px; }
.period-tabs { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: color-mix(in oklch, var(--background) 60%, var(--surface)); border: 1px solid var(--hair); }
.period { height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--text-secondary); font-weight: 500; font-size: .875rem; transition: background .18s, color .18s; }
.period:hover { color: var(--text-primary); background: color-mix(in oklch, var(--surface-hover) 70%, transparent); }
.period.active { background: var(--surface); color: var(--text-primary); font-weight: 600; box-shadow: 0 1px 0 oklch(100% 0 0 / .06) inset, 0 2px 8px oklch(0% 0 0 / .3); border: 1px solid var(--hair); }

/* ---------- tabs ---------- */
.tabs { gap: 6px; padding: 5px; margin: 18px 0; border-radius: 16px; background: color-mix(in oklch, var(--background) 55%, var(--surface)); border: 1px solid var(--hair); overflow-x: auto; }
.tab {
  height: 42px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent; background: transparent; font-weight: 500; color: var(--text-secondary); gap: 8px;
  transition: background .18s, color .18s, box-shadow .18s;
}
.tab:hover { background: color-mix(in oklch, var(--surface-hover) 80%, transparent); color: var(--text-primary); }
.tab.active { background: var(--surface); color: var(--text-primary); font-weight: 600; border-color: var(--hair); box-shadow: 0 1px 0 oklch(100% 0 0 / .06) inset, 0 4px 12px -4px oklch(0% 0 0 / .45); }
.tab .tic { display: grid; place-items: center; color: var(--text-muted); } .tab.active .tic { color: var(--brand); }
.tab .count { background: var(--brand); color: var(--brand-fg); font-weight: 700; padding: 1px 7px; }

/* ---------- app rail ---------- */
@media (min-width: 761px) { .app { grid-template-columns: 88px 1fr; } }
.rail { background: color-mix(in oklch, var(--background) 82%, #000); border-right: 1px solid var(--hair); }
@media (min-width: 761px) { .rail { padding: 14px 10px; gap: 6px; } }
.rail .logo-mark { width: 40px; height: 40px; margin-bottom: 14px; border-radius: 13px; box-shadow: 0 8px 20px -8px color-mix(in oklch, var(--brand) 70%, transparent); }
.rail-btn { position: relative; width: 66px; padding: 9px 2px 7px; border-radius: 14px; gap: 5px; font-size: .6875rem; font-weight: 500; transition: background .18s, color .18s; }
.rail-btn .ri { display: grid; place-items: center; font-size: 0; color: var(--text-muted); transition: color .18s; }
.rail-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.rail-btn:hover .ri { color: var(--text-primary); }
.rail-btn.active { background: color-mix(in oklch, var(--brand) 13%, transparent); color: var(--text-primary); }
.rail-btn.active .ri { color: var(--brand); }
.rail-btn.active::before { content: ""; position: absolute; left: -10px; top: 18%; bottom: 18%; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }

/* ---------- cards & surfaces ---------- */
.card, .panel, .tile, .metric, .feature-card, .tool-link, .pz-card, .mode-card, .hub a { background: var(--card-bg); border-color: var(--hair); box-shadow: var(--shadow-1); }
.card { border-radius: var(--r-lg); } .card.pad, .pad { padding: 20px; }
.tile { border-radius: 14px; padding: 14px 16px; }
.hub a, .pz-card, .mode-card, .feature-card { transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease; }
.hub a:hover, .pz-card:hover, .mode-card:hover, .feature-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-2); border-color: color-mix(in oklch, var(--brand) 45%, var(--hair)); }
.hub .hi, .pz-ic, .feature-card .fi, .spot-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: var(--brand); background: color-mix(in oklch, var(--brand) 13%, transparent); border: 1px solid color-mix(in oklch, var(--brand) 25%, transparent); font-size: 0; }
.feature-card .fi { margin-bottom: 12px; }
.card-h { margin-bottom: 14px; }
.card-h b { font-size: .9375rem; font-weight: 700; letter-spacing: -.01em; }
.tile .tl, .metric .tl { font-size: .6875rem; letter-spacing: .09em; }
.tile b { font-size: 1.5rem; letter-spacing: -.03em; }
.panel-head { margin-bottom: 16px; }
.panel-head h2 { font-size: 1.375rem; font-weight: 800; letter-spacing: -.025em; }
.panel-head p { margin-top: 2px; }
.section-title { letter-spacing: -.02em; }
.stack { gap: 16px; }
.wdl { height: 8px; } .meter { height: 7px; }

/* ---------- profile header & banners ---------- */
.profile { padding: 20px 22px; border-radius: var(--r-xl); }
.profile h1 { font-size: 1.625rem; letter-spacing: -.03em; }
.avatar { width: 58px; height: 58px; border-radius: 16px; font-size: 0; background: linear-gradient(135deg, color-mix(in oklch, var(--brand) 85%, white), var(--brand-deep)); color: var(--brand-fg); border: 0; box-shadow: 0 10px 24px -10px color-mix(in oklch, var(--brand) 70%, transparent); }
.avatar::after { content: "♞"; font-size: 30px; line-height: 1; color: var(--brand-fg); font-family: "Apple Symbols", "Segoe UI Symbol", serif; }
.badge { padding: 3px 9px; border-radius: 999px; }
.deep { border-radius: 14px; padding: 12px 16px; margin-top: 14px; border-color: color-mix(in oklch, var(--brand) 28%, transparent); background: linear-gradient(90deg, color-mix(in oklch, var(--brand) 9%, transparent), transparent 70%); }
.toolrow { margin: 14px 0 0; }
.cmdk .input { border-radius: 12px; height: 40px; }

/* ---------- inputs ---------- */
.input, .select { border-radius: var(--r-md); border: 1px solid var(--hair); background: color-mix(in oklch, var(--background) 70%, var(--surface)); transition: border-color .18s, box-shadow .18s, background .18s; }
.input:hover, .select:hover { border-color: color-mix(in oklch, var(--text-primary) 22%, transparent); }
.input:focus, .select:focus { border-color: var(--brand); box-shadow: var(--ring); outline: none; background: var(--surface); }
.select { appearance: none; -webkit-appearance: none; padding: 0 30px 0 12px; height: 36px; font-size: .8125rem; font-weight: 500; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239AA1AE' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; }
input[type="range"] { accent-color: var(--brand); }
input[type="checkbox"] { accent-color: var(--brand); width: 15px; height: 15px; vertical-align: -3px; }

/* ---------- tables ---------- */
.table-wrap { border-radius: var(--r-lg); border-color: var(--hair); background: var(--card-bg); box-shadow: var(--shadow-1); }
.tbl th { font-size: .6875rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; padding: 12px 14px; background: color-mix(in oklch, var(--background) 40%, var(--surface)); position: sticky; top: 0; }
.tbl td { padding: 12px 14px; border-top-color: var(--hair); }
.tbl tbody tr { transition: background .15s; } .tbl tbody tr:hover td { background: color-mix(in oklch, var(--brand) 6%, var(--surface-hover)); }
.tbl td.win b, .tbl td.loss b, .tbl td.draw b { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; }
.tbl td.win b { background: color-mix(in oklch, var(--win) 16%, transparent); } .tbl td.loss b { background: color-mix(in oklch, var(--loss) 16%, transparent); } .tbl td.draw b { background: var(--surface-strong); }
.sortbar, .filterbar { gap: 4px 6px; margin-top: 12px; }
.sortchip { padding: 5px 11px; border-radius: 999px; font-size: .8125rem; border: 1px solid transparent; }
.sortchip:hover { background: var(--surface-hover); }
.sortchip[aria-pressed="true"] { border-color: color-mix(in oklch, var(--brand) 45%, transparent); }

/* ---------- report bits ---------- */
.grade-card { padding: 22px; border-radius: var(--r-xl); }
.grade { width: 60px; height: 60px; font-size: 1.625rem; }
.wdl-big { font-size: 2.25rem; }
.blown, .goal { border-radius: 12px; border-color: var(--hair); background: color-mix(in oklch, var(--background) 55%, var(--surface)); transition: background .15s, border-color .15s; }
.blown:hover, .goal:hover { background: var(--surface-hover); border-color: color-mix(in oklch, var(--brand) 35%, var(--hair)); }
.kv { padding: 9px 0; border-top-color: var(--hair); }
.empty-state { padding: 64px 24px; }

/* ---------- review ---------- */
.review .movelist, .rv-explain, .rv-lines, .rv-summary { border-radius: var(--r-lg); }
.movelist { border-color: var(--hair); }
.rv-nav .btn { min-width: 46px; }
.player-row { padding: 10px 2px; }
.player-row .clock, .player-row .acc { border-radius: 8px; }
.board { border-radius: 10px; box-shadow: 0 18px 40px -22px oklch(0% 0 0 / .7); }
.lines .line { border-radius: 10px; }

/* ---------- home + shared pages ---------- */
.analyze-form { border-radius: 22px; padding: 18px; }
.analyze-form .input { height: 50px; font-size: 1rem; }
.nav-pill { height: 36px; border-radius: 11px; }
.counter { padding: 11px 24px; }
.faq { border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.spotlight { border-radius: var(--r-xl); }
.tool-link { border-radius: 14px; }
.page-head h1 { letter-spacing: -.045em; }
.help-face { box-shadow: 0 14px 34px -10px color-mix(in oklch, var(--brand) 60%, transparent), 0 0 0 1px oklch(100% 0 0 / .08) inset; }
.help-hint { border-radius: 14px; }

/* smooth theme + scrollbars */
* { scrollbar-width: thin; scrollbar-color: color-mix(in oklch, var(--text-primary) 22%, transparent) transparent; }
@media (max-width: 760px) {
  .rail { padding: 6px 4px; gap: 0; } .rail-btn { width: auto; padding: 6px 2px; } .rail-btn.active::before { display: none; }
  .period-tabs { grid-template-columns: repeat(4, 1fr); }
  .tabs { margin: 14px 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

@media (max-width: 760px) {
  .rail { border-right: 0; border-top: 1px solid var(--hair); background: color-mix(in oklch, var(--background) 92%, #000); backdrop-filter: blur(12px); }
  .rail-btn { font-size: .625rem; }
  .app { grid-template-columns: 1fr; }
}

/* keep wide scrollers (tabs, tables) inside the viewport */
.main, #view, #panel, .app > div { min-width: 0; max-width: 100%; }
.tabs, .demo-tabs, .table-wrap { max-width: 100%; }
.tabs { scrollbar-width: none; } .tabs::-webkit-scrollbar { display: none; }
@media (max-width: 760px) { .main { overflow-x: clip; } .tab { flex: 0 0 auto; } }
@media (max-width: 760px) { body:has(.rail) .help-face { bottom: 78px; right: 12px; width: 52px; height: 52px; font-size: 26px; } body:has(.rail) .help-close { bottom: 128px; right: 8px; } body:has(.rail) .help-panel { bottom: 140px; } }
