:root {
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #efede7;
  --ink: #17171a;
  --ink-2: #52514e;
  --muted: #8a887f;
  --line: #dddad1;
  --accent: #2a78d6;
  --accent-ink: #fff;
  --ready: #138a4b;
  --warn: #b86e00;
  --danger: #c4372f;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --radius: 10px;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8d8b82;
    --line: #34332f; --accent: #3987e5; --ready: #2fbf71; --warn: #e0a030; --danger: #e66767;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8d8b82;
  --line: #34332f; --accent: #3987e5; --ready: #2fbf71; --warn: #e0a030; --danger: #e66767;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--sans); min-height: 100vh; }
h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
kbd { font: 12px var(--mono); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface); }
.muted { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }

.topbar { display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 10px; letter-spacing: -.01em; }
.logo { width: 22px; height: 22px; border-radius: 5px; background:
  conic-gradient(from 45deg, #00a651 0 25%, #c41e3a 0 50%, #0051ba 0 75%, #ffd500 0); box-shadow: inset 0 0 0 2px #111; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: none; border: 0; padding: 8px 14px; border-radius: 8px; color: var(--ink-2); font: inherit; font-weight: 500; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--ink); }
.pill { margin-left: auto; font-size: 12px; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.pill.ready { color: var(--ready); }

main { max-width: 1280px; margin: 0 auto; padding: 16px 20px 40px; }
.tab { display: none; }
.tab.active { display: block; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar label { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 14px; }
.spacer { flex: 1; }
select, input[type="text"], .alg-input { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.alg-input { flex: 1; min-width: 240px; font-family: var(--mono); font-size: 14px; }
button, .button { font: inherit; font-size: 14px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer; font-weight: 500; }
button.ghost, .button.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
button:hover:not(:disabled), .button:hover { filter: brightness(1.05); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.notice { padding: 8px 12px; border-radius: 8px; background: var(--surface-2); margin-bottom: 12px; font-size: 14px; }
.notice.error { color: var(--danger); }

.timer-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; }
.timer-side { display: flex; flex-direction: column; gap: 12px; }
.scramble-row { display: flex; gap: 10px; align-items: flex-start; }
.scramble { flex: 1; font: 22px/1.5 var(--mono); padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); word-spacing: .25em; min-height: 64px; }
.timer-pad { margin-top: 14px; min-height: 340px; display: flex; flex-direction: column; justify-content: center; align-items: center; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); user-select: none; touch-action: none; outline: none; cursor: pointer; }
.timer-display { font: 600 clamp(64px, 12vw, 132px)/1 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.timer-display.holding { color: var(--danger); }
.timer-display.ready { color: var(--ready); }
.timer-display.inspecting { color: var(--warn); }
.timer-hint { color: var(--muted); margin-top: 12px; font-size: 14px; min-height: 20px; }
.last-solve { margin-top: 10px; display: flex; gap: 8px; align-items: center; min-height: 36px; }
.running-mode .scramble-row, .running-mode .timer-side, .running-mode .topbar, .running-mode .toolbar, .running-mode .last-solve { visibility: hidden; }

.preview svg, .net svg { width: 100%; height: auto; display: block; }
.quick-stats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.quick-stats td { padding: 3px 0; }
.quick-stats td:nth-child(2), .quick-stats td:nth-child(3) { text-align: right; font-family: var(--mono); }
.quick-stats th { text-align: right; font-weight: 500; color: var(--muted); font-size: 12px; }
.solves-card { flex: 1; min-height: 0; }
.solve-list { margin: 0; padding: 0; max-height: 300px; overflow: auto; font-family: var(--mono); font-size: 14px; }
.solve-list li { padding: 3px 0; border-bottom: 1px solid var(--line); display: flex; gap: 6px; align-items: center; }
.solve-list li .t { flex: 1; }
.solve-list li .n { width: 36px; color: var(--muted); font-size: 12px; }
.solve-list button, .last-solve button { padding: 1px 7px; font-size: 12px; }
.penalty-on { background: var(--surface-2) !important; border-color: var(--ink-2) !important; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.tile .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile .v { font: 600 24px var(--mono); font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--ink-2); font-family: var(--mono); }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
figure { margin: 0; }
figcaption { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin-bottom: 8px; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .axis text { fill: var(--muted); font: 11px var(--sans); }
.chart .grid line { stroke: var(--line); }
.chart .empty { color: var(--muted); padding: 40px 0; text-align: center; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; z-index: 2; color: var(--ink); }
.tooltip b { font-family: var(--mono); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.data th { text-align: left; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line); padding: 5px 6px; font-size: 12px; }
table.data td { padding: 5px 6px; border-bottom: 1px solid var(--line); }
table.data td.num { text-align: right; font-family: var(--mono); }

.solver-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; }
.solver-side { display: flex; flex-direction: column; gap: 12px; }
.cube3d { height: 380px; perspective: 1100px; display: flex; align-items: center; justify-content: center; cursor: grab; touch-action: none; }
.cube3d .cube { position: relative; width: 0; height: 0; transform-style: preserve-3d; }
.cube3d .sticker { position: absolute; width: 56px; height: 56px; left: -28px; top: -28px; background: #111; padding: 3px; backface-visibility: hidden; }
.cube3d .sticker i { display: block; width: 100%; height: 100%; border-radius: 6px; }
.playback { display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.playback label { font-size: 13px; color: var(--ink-2); display: flex; gap: 6px; align-items: center; margin-left: 10px; }
.move-strip { margin-top: 10px; font-family: var(--mono); display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; min-height: 28px; }
.move-strip span { padding: 2px 6px; border-radius: 5px; background: var(--surface-2); font-size: 13px; }
.move-strip span.done { color: var(--muted); }
.move-strip span.current { background: var(--accent); color: var(--accent-ink); }
.move-strip span.sep { background: none; color: var(--muted); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.solution { font-family: var(--mono); font-size: 15px; }
.solution .meta { font-family: var(--sans); font-size: 13px; color: var(--muted); margin-top: 4px; }
.steps { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.steps li { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.steps li.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.steps .title { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.steps .title span { color: var(--muted); font-weight: 400; font-size: 12px; }
.steps .moves { font-family: var(--mono); font-size: 13px; margin: 3px 0; }
.steps .why { font-size: 13px; color: var(--ink-2); }

.trainer-layout { display: grid; grid-template-columns: 420px minmax(0, 1fr); gap: 16px; }
.trainer-card { display: flex; flex-direction: column; align-items: center; }
.ll-view svg { width: 240px; height: 240px; }
.setup { font-family: var(--mono); font-size: 13px; color: var(--ink-2); text-align: center; margin-top: 6px; }
.trainer-timer { min-height: 120px; width: 100%; font: 600 56px var(--mono); font-variant-numeric: tabular-nums; }
.reveal { margin-top: 10px; text-align: center; min-height: 48px; }
.reveal .name { font-weight: 600; }
.reveal .alg { font-family: var(--mono); }
.bar { height: 6px; border-radius: 3px; background: var(--series-2); }

@media (max-width: 900px) {
  .timer-layout, .solver-layout, .trainer-layout, .chart-grid { grid-template-columns: minmax(0, 1fr); }
  main { padding: 12px 16px 32px; }
  .scramble { font-size: 17px; }
  .cube3d { height: 300px; }
}
