:root {
  --bg: #f3f4f7;
  --card: #ffffff;
  --ink: #1a1e24;
  --muted: #677080;
  --line: #e2e5ea;
  --soft: #f6f7f9;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --accent-ink: #ffffff;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --warn: #d99a00;
  --warn-soft: #fff6dc;
  --ok: #12965a;
  --ok-soft: #e6f6ee;
  --sticker-off: #c5cad3;
  --plastic: #16181c;
  --mv-on: #f5a524; --mv-off: #e6e9ee; --mv-arrow: #14171c;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .06);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --alg: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --card: #161a21; --ink: #e7eaef; --muted: #96a0ae; --line: #262c35; --soft: #1c212a;
    --accent: #5b8cff; --accent-soft: #1d2a48; --accent-ink: #0b1020;
    --danger: #ff6b5e; --danger-soft: #3a1d1b; --warn: #f2bd3a; --warn-soft: #3a3016; --ok: #3ccf8e; --ok-soft: #15322a;
    --sticker-off: #3b424d; --plastic: #0a0b0d; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
    --mv-on: #e8981d; --mv-off: #2d343e; --mv-arrow: #f4f6f9;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --card: #161a21; --ink: #e7eaef; --muted: #96a0ae; --line: #262c35; --soft: #1c212a;
  --accent: #5b8cff; --accent-soft: #1d2a48; --accent-ink: #0b1020;
  --danger: #ff6b5e; --danger-soft: #3a1d1b; --warn: #f2bd3a; --warn-soft: #3a3016; --ok: #3ccf8e; --ok-soft: #15322a;
  --sticker-off: #3b424d; --plastic: #0a0b0d; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  --mv-on: #e8981d; --mv-off: #2d343e; --mv-arrow: #f4f6f9;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 10px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; margin-top: 14px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { justify-content: center; text-align: center; }
.row { display: flex; align-items: center; }
.wrap { flex-wrap: wrap; }
.gap { gap: 8px; }
kbd { font: 11px var(--mono); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; opacity: .75; margin-left: 4px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  padding: 10px 20px; background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.logo {
  width: 26px; height: 26px; border-radius: 6px; display: inline-block;
  background:
    linear-gradient(90deg, transparent 31%, var(--plastic) 31% 35%, transparent 35% 65%, var(--plastic) 65% 69%, transparent 69%),
    linear-gradient(0deg, transparent 31%, var(--plastic) 31% 35%, transparent 35% 65%, var(--plastic) 65% 69%, transparent 69%),
    conic-gradient(#c8102e 0 25%, #ffd500 0 50%, #009b48 0 75%, #0046ad 0);
  border: 2px solid var(--plastic);
}
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tab {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 7px 12px; border-radius: 9px; cursor: pointer; white-space: nowrap;
}
.tab:hover { background: var(--soft); color: var(--ink); }
.tab.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1320px; margin: 0 auto; padding: 18px 20px 60px; }
.panel { display: none; }
.panel.active { display: block; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }

/* ---------- controls ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: 14px; color: var(--ink); background: var(--soft);
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 13px; cursor: pointer; line-height: 1.3;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.icon { min-width: 42px; padding: 7px 8px; }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn.bad { background: var(--danger); color: #fff; border-color: transparent; }
.select, .search, textarea {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 9px; padding: 6px 9px;
}
textarea { width: 100%; font-family: var(--mono); font-size: 12px; }
.search { min-width: 220px; flex: 1; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; user-select: none; }
details.more { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
details.more summary { cursor: pointer; font-weight: 600; font-size: 14px; }
details.more > * { margin-top: 8px; }
.seg { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: transparent; font: inherit; font-size: 14px; font-weight: 600; color: var(--muted); padding: 5px 12px; border-radius: 8px; cursor: pointer; }
.seg button.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- scan ---------- */
.scan-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
.cam-wrap { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 12px; overflow: hidden; }
.cam-wrap canvas { width: 100%; height: 100%; display: block; object-fit: contain; }
.cam-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: #e6e8eb; text-align: center; padding: 20px;
  background: radial-gradient(circle at 50% 40%, #2a2f38, #0b0c0f);
}
.cam-placeholder[hidden] { display: none; }
.cam-placeholder .muted { color: #a8b0bb; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .35s; }
.cam-flash.on { opacity: .55; transition: none; }
.cam-status {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); max-width: 92%;
  background: rgba(0, 0, 0, .65); color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cam-status:empty { display: none; }
.cam-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 12px; }
.quality { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.face-steps { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 12px; }
.face-chip {
  font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--soft);
  border: 1.5px solid var(--line); border-radius: 10px; padding: 6px 2px; cursor: pointer; text-align: center; line-height: 1.25;
}
.face-chip .dot { width: 16px; height: 16px; border-radius: 4px; display: block; margin: 0 auto 3px; border: 1px solid rgba(0,0,0,.25); background: var(--sticker-off); }
.face-chip.done { color: var(--ink); }
.face-chip.current { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.instruction { background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.instruction b { color: var(--accent); }
.instruction .step-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; color: var(--ink); }

.palette { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.swatch {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--ink);
  background: var(--card); border: 1.5px solid var(--line); border-radius: 9px; padding: 3px 8px 3px 4px; cursor: pointer;
}
.swatch i { width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgba(0, 0, 0, .25); display: block; }
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

/* ---------- net ---------- */
.net { --cell: 25px; display: grid; grid-template-columns: repeat(12, var(--cell)); grid-template-rows: repeat(9, var(--cell)); gap: 2px; margin: 6px 0 14px; max-width: 100%; }
.net-small { --cell: 13px; gap: 1px; margin: 0; }
.net-cell {
  border: 1px solid rgba(0, 0, 0, .28); border-radius: 4px; padding: 0; font: 700 10px/1 var(--mono); color: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center; background: var(--sticker-off);
}
button.net-cell { cursor: pointer; }
button.net-cell:hover { transform: scale(1.12); z-index: 1; }
.net-unknown { background: repeating-linear-gradient(45deg, var(--soft), var(--soft) 3px, var(--line) 3px, var(--line) 6px) !important; }
.net-mark { outline: 3px solid var(--danger); outline-offset: 1px; z-index: 2; }
.net-warn { outline: 2.5px dashed var(--warn); outline-offset: 1px; z-index: 1; }
@media (max-width: 420px) { .net { --cell: 20px; } }

/* ---------- diagnosis ---------- */
.diag-grid { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 16px; align-items: start; }
.checklist { list-style: none; padding: 0; margin: 6px 0 12px; }
.checklist li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); align-items: flex-start; }
.checklist li:last-child { border-bottom: 0; }
.ck { flex: none; width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; color: #fff; background: var(--ok); }
.ck.bad { background: var(--danger); }
.ck.warn { background: var(--warn); }
.verdict { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-weight: 600; }
.verdict.ok { background: var(--ok-soft); color: var(--ok); }
.verdict.bad { background: var(--danger-soft); color: var(--danger); }
.verdict .big { font-size: 17px; display: block; }
.verdict .muted { color: inherit; opacity: .8; font-weight: 500; }
.suggest { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 10px 0; }
.stat { background: var(--soft); border-radius: 12px; padding: 10px 12px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .k { font-size: 12.5px; color: var(--muted); }
.slots { display: flex; gap: 6px; }
.slot { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--danger-soft); color: var(--danger); }
.slot.on { background: var(--ok-soft); color: var(--ok); }
.case-inline { display: flex; gap: 12px; align-items: center; background: var(--soft); border-radius: 12px; padding: 10px; margin: 8px 0; }
.case-inline svg { width: 84px; height: 84px; flex: none; }

/* ---------- solve ---------- */
.solve-head { margin-bottom: 16px; }
.solve-head label { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; font-size: 14px; }
.hold { font-size: 14px; background: var(--warn-soft); color: var(--ink); padding: 6px 12px; border-radius: 10px; }
.methods { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.method {
  text-align: left; font: inherit; color: var(--ink); background: var(--soft); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 3px;
}
.method:hover { border-color: var(--muted); }
.method.active { border-color: var(--accent); background: var(--accent-soft); }
.method .mname { font-weight: 700; }
.method .mcount { font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
.method .mcount small { font-size: 13px; font-weight: 600; color: var(--muted); }
.method .mdesc { font-size: 12.5px; color: var(--muted); }
.solve-grid { display: grid; grid-template-columns: minmax(300px, 0.9fr) minmax(0, 1.3fr); gap: 16px; align-items: start; }
.player-card { position: sticky; top: 70px; }
.cube3d { height: 290px; }
.c3-scene { perspective: 1100px; display: flex; align-items: center; justify-content: center; touch-action: none; cursor: grab; user-select: none; }
.c3-scene:active { cursor: grabbing; }
.c3-cube { position: relative; width: 0; height: 0; transform-style: preserve-3d; }
.c3-cubie { position: absolute; width: var(--c3); height: var(--c3); left: calc(var(--c3) / -2); top: calc(var(--c3) / -2); transform-style: preserve-3d; }
.c3-face { position: absolute; inset: 0; background: var(--plastic); border-radius: 9%; backface-visibility: hidden; }
.c3-face > i { position: absolute; inset: 5%; border-radius: 13%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .18), inset 0 -3px 6px rgba(0, 0, 0, .12); }
.move-now { text-align: center; font: 800 46px/1.1 var(--alg); margin-top: 4px; letter-spacing: -1px; }
.move-sub { text-align: center; color: var(--muted); font-size: 13.5px; min-height: 20px; }
.player-controls { display: flex; justify-content: center; gap: 6px; margin: 12px 0 8px; flex-wrap: wrap; }
.progress { height: 6px; background: var(--soft); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.steps { list-style: none; padding: 0; margin: 0; }
.stage-head { font-size: 12.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 16px 0 6px; }
.stage-head:first-child { margin-top: 4px; }
.step { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; transition: border-color .15s, background .15s; }
.step.current { border-color: var(--accent); background: var(--accent-soft); }
.step.done { opacity: .62; }
.step-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; cursor: pointer; }
.step-title { font-weight: 700; }
.step-count { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.step-detail { font-size: 13.5px; color: var(--muted); white-space: pre-line; margin: 4px 0 6px; }
.step-body { display: flex; gap: 10px; align-items: flex-start; }
.step-body svg { width: 64px; height: 64px; flex: none; }
.mvs { display: flex; flex-wrap: wrap; gap: 4px; }
.mv {
  font: 700 14px/1 var(--alg); padding: 5px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); cursor: pointer; min-width: 30px;
}
.mv.past { color: var(--muted); background: transparent; }
.mv.now { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.mv { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 5px 5px; }
.mv .move-svg { width: 34px; height: 34px; }
.mv .mv-dir { font-size: 12px; margin-left: 3px; opacity: .75; }

/* dải hình các nước liên tiếp */
.move-strip { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center; gap: 6px; margin: 6px 0 4px; }
.ms-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 5px 5px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font: 700 13px/1 var(--alg); }
button.ms-cell { cursor: pointer; }
.ms-cell .move-svg { width: 46px; height: 46px; }
.ms-cell.now { border: 2px solid var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); font-size: 15px; }
.ms-cell.now .move-svg { width: 64px; height: 64px; }
.ms-sep { align-self: center; font-size: 12px; color: var(--muted); margin: 0 2px; }
.play-next .move-strip { justify-content: center; }

/* chiều xoay của từng nước */
.move-svg { display: block; }
.move-svg .mv-arrow { fill: none; stroke: var(--mv-arrow); stroke-width: 5.5; stroke-linecap: round; stroke-linejoin: round; }
.move-svg .mv-halo { fill: none; stroke: var(--mv-on); stroke-width: 10.5; stroke-linecap: round; stroke-linejoin: round; }
.move-svg .mv-head { fill: var(--mv-arrow); }
.move-svg .mv-x2 { font: 800 15px var(--alg); fill: var(--mv-arrow); }
.move-how { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 86px; margin: 2px 0 4px; }
.move-how .move-svg { width: 86px; height: 86px; flex: none; }
.move-how-txt { font-size: 15.5px; font-weight: 700; max-width: 240px; line-height: 1.35; }
.dir { color: var(--accent); font-weight: 800; margin: 0 6px 0 4px; }
.move-how-txt .dir { font-size: 22px; margin-left: 0; vertical-align: -2px; }
.how { margin-top: 8px; }
.how summary { font-size: 13px; font-weight: 700; color: var(--accent); cursor: pointer; }
.how-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.how-list li { display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 4px 8px 4px 4px; background: var(--card); cursor: pointer; font-size: 13px; line-height: 1.35; }
.how-list li.past { opacity: .55; }
.how-list li.now { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.how-list li b { font: 800 15px var(--alg); }
.how-list .move-svg { width: 50px; height: 50px; flex: none; }
.notation .move-svg { width: 52px; height: 52px; }
.summary { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }

/* ---------- algorithm library ---------- */
.subtabs { display: flex; flex-wrap: wrap; gap: 4px; }
.subtabs button { font: inherit; font-size: 13.5px; font-weight: 600; color: var(--muted); background: var(--soft); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.subtabs button.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.group-head { display: flex; align-items: baseline; gap: 10px; margin: 22px 0 10px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.group-head h3 { margin: 0; font-size: 16px; }
.alg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 10px; }
.alg-card { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; gap: 10px; background: var(--card); }
.alg-card svg { width: 92px; height: 92px; flex: none; }
.alg-card .info { min-width: 0; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.alg-card .nm { font-weight: 700; display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.alg-main { font: 700 14.5px/1.45 var(--alg); word-spacing: .12em; }
.alg-alt { font: 500 12.5px/1.4 var(--alg); word-spacing: .1em; color: var(--muted); }
.alg-card .acts { display: flex; gap: 6px; margin-top: auto; flex-wrap: wrap; }
.lvl { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.lvl.l1, .lvl.l2 { background: var(--warn-soft); color: var(--warn); }
.lvl.l3, .lvl.l4 { background: var(--accent-soft); color: var(--accent); }
.lvl.l5 { background: var(--ok-soft); color: var(--ok); }
.case-svg { display: block; }
.case-body { fill: var(--plastic); }
.case-svg .arrow { stroke: #111; stroke-width: 2.6; stroke-linecap: round; }
.case-svg .arrow-head { fill: #111; }
.iso-st { stroke: var(--plastic); stroke-width: 1.4; stroke-linejoin: round; }
.notation { width: 100%; border-collapse: collapse; }
.notation td, .notation th { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: middle; font-size: 14px; }
.notation td:first-child { font: 800 16px var(--alg); white-space: nowrap; }
.notation-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.notation-grid .cube3d { height: 260px; position: sticky; top: 80px; }

/* ---------- review ---------- */
.boxes { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.box { background: var(--soft); border-radius: 10px; padding: 6px 12px; font-size: 13px; }
.box b { font-size: 16px; margin-right: 4px; }
.review-area { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 10px 0 20px; text-align: center; }
.review-area svg.case-svg { width: 210px; height: 210px; }
.review-alg { font: 700 22px/1.5 var(--alg); word-spacing: .15em; max-width: 640px; }
.quiz-opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: min(720px, 100%); }
.quiz-opts button { font: 600 14.5px/1.4 var(--alg); word-spacing: .1em; text-align: left; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; }
.quiz-opts button.right { border-color: var(--ok); background: var(--ok-soft); }
.quiz-opts button.wrong { border-color: var(--danger); background: var(--danger-soft); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5, 8, 12, .55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { position: relative; background: var(--card); border-radius: 16px; padding: 18px; width: min(560px, 100%); max-height: 92vh; overflow: auto; box-shadow: var(--shadow); }
.modal-card svg.case-svg { width: 110px; height: 110px; flex: none; }
.modal-card .cube3d { height: 250px; }
.modal-x { position: absolute; right: 10px; top: 8px; border: 0; background: transparent; font-size: 26px; cursor: pointer; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--card); padding: 10px 18px; border-radius: 12px; font-weight: 600; z-index: 60; box-shadow: var(--shadow); max-width: 92vw; }


/* ---------- chơi & bấm giờ ---------- */
.play-head { margin-bottom: 16px; }
.lbl { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; font-size: 14px; }
#playerName { min-width: 200px; }
#playerName.attn { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.play-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 16px; align-items: start; margin-bottom: 16px; }
.play-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.play-timer { font: 800 52px/1 var(--alg); font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.play-timer.huge { font-size: clamp(64px, 11vw, 120px); text-align: center; }
.play-timer[data-phase="holding"] { color: var(--danger); }
.play-timer[data-phase="ready"] { color: var(--ok); }
.play-state { font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 6px; }
.play-state.run { color: var(--accent); }
.play-state.ok { color: var(--ok); }
.play-stage-row { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(0, 1.1fr); gap: 12px; align-items: center; margin: 8px 0; }
.play-cube { height: 270px; }
.play-cube.previewing::after { content: 'xem trước'; position: absolute; top: 6px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 700; color: var(--muted); }
.play-cube { position: relative; }
.play-now { text-align: center; min-width: 0; }
.play-move { font: 800 84px/1 var(--alg); letter-spacing: -2px; margin: 4px 0; }
.play-move-row { display: flex; align-items: center; justify-content: center; gap: 14px; }
.play-move-icon .move-svg { width: 108px; height: 108px; }
.play-move-txt { font-size: 17px; font-weight: 700; }
.play-step { color: var(--muted); font-size: 14px; margin-top: 8px; }
.play-next { color: var(--muted); font: 600 14px/1.4 var(--alg); word-spacing: .2em; margin-top: 6px; }
.stage-list { list-style: none; padding: 0; margin: 0 0 12px; }
.stage-list .stage { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; border-radius: 9px; font-size: 14px; color: var(--muted); }
.stage-list .stage.fin { color: var(--ink); }
.stage-list .stage.fin::before { content: '✓'; color: var(--ok); font-weight: 800; margin-right: 6px; }
.stage-list .stage.cur { background: var(--accent-soft); color: var(--ink); font-weight: 700; }
.stage-list .stage > span:first-child { flex: 1; }
.st-time { font-variant-numeric: tabular-nums; font-weight: 700; }
.play-side .cam-wrap { margin-bottom: 8px; }
.cam-status[data-level="ok"] { background: rgba(18, 150, 90, .85); }
.cam-status[data-level="warn"] { background: rgba(217, 154, 0, .92); color: #1a1300; }
.scramble-box { background: var(--soft); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.scramble { font: 700 20px/1.5 var(--alg); word-spacing: .25em; }
.timer-pad { margin: 18px 0; padding: 30px 10px; border-radius: 16px; border: 2px dashed var(--line); text-align: center; user-select: none; touch-action: none; cursor: pointer; }
.play-side svg.case-svg { width: 130px; height: 130px; }

/* biểu đồ thanh: thời gian theo giai đoạn */
.bars { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 14px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 210px) minmax(80px, 1fr) auto; gap: 10px; align-items: center; font-size: 13.5px; padding: 2px 4px; border-radius: 6px; }
.bar-row:hover { background: var(--soft); }
.bar-label { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; position: relative; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 0 4px 4px 0; }
.bar-row.slow .bar-fill { background: var(--warn); }
.bar-val { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); white-space: nowrap; }
.slow-tag { font-size: 12px; font-weight: 700; color: var(--warn); margin-left: 8px; }

/* bảng thành tích */
.table-wrap { overflow-x: auto; }
.table-wrap.tall { max-height: 420px; overflow-y: auto; }
.rec-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.rec-table th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 700; padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
.rec-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.rec-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.rec-table .strong { font-weight: 800; }
.rec-table td.scr { white-space: normal; font: 500 12px/1.35 var(--alg); color: var(--muted); min-width: 200px; }
.rec-table tr.me td:nth-child(2) { font-weight: 800; color: var(--accent); }
.rec-table tr.best td { background: var(--ok-soft); }
.rec-table tr.worst td { background: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }

/* khối 3D ở tab Quét / Chẩn đoán */
.view-head { justify-content: space-between; margin: 14px 0 8px; }
.view-head h3 { margin: 0; }
.scan3d { height: 300px; margin: 4px 0 6px; }
.diag3d { height: 250px; margin: 6px 0; }
.c3-face > i.c3-mark { box-shadow: 0 0 0 4px var(--danger), inset 0 0 0 1px rgba(0,0,0,.18); }
.c3-face > i.c3-warn { box-shadow: 0 0 0 3px var(--warn), inset 0 0 0 1px rgba(0,0,0,.18); }
.scan3d .c3-face > i { cursor: pointer; }

/* giải mù */
.bld-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 0 0 12px; background: var(--soft); }
.bld-card .hold { margin-bottom: 8px; }
.bld-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px; align-items: start; }
.bld-letters { font: 800 21px/1.5 var(--mono); letter-spacing: 1px; word-spacing: 6px; margin: 2px 0 10px; overflow-wrap: anywhere; }
.net-cell.bld-l { display: flex; align-items: center; justify-content: center; font: 800 11px/1 var(--alg); color: #111; text-shadow: 0 0 2px #fff, 0 0 3px #fff; }
.warn-note { background: var(--warn-soft); border-radius: 8px; padding: 6px 8px; }
@media (max-width: 700px) { .bld-grid { grid-template-columns: minmax(0, 1fr); } }

/* giải mù có gia sư */
.bld-howto { margin: 10px 0; padding-left: 20px; line-height: 1.6; }
.bld-exec { display: flex; gap: 18px; align-items: center; padding: 18px; border-radius: 14px; background: var(--soft); margin: 10px 0; }
.bld-eyes { font-size: 64px; line-height: 1; }
.bld-exec .big { font-size: 20px; font-weight: 800; }
.bld-log { list-style: none; padding: 0; margin: 0; max-height: 240px; overflow: auto; font-size: 13.5px; }
.bld-log li { padding: 5px 8px; border-bottom: 1px dashed var(--line); }
.bld-log li.warn { color: var(--danger); font-weight: 600; }
.bld-log li.ok { color: var(--ok); }
.bld-log li.hint { color: var(--accent); }
.col { display: flex; flex-direction: column; align-items: flex-start; }

/* xáo khối */
.scr-seq { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: baseline; margin: 10px 0 4px; font: 700 16px/1.6 var(--alg); }
.scr-seq .tok { padding: 0 4px; border-radius: 6px; }
.scr-seq .tok.past { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.scr-seq .tok.now { background: var(--accent); color: var(--accent-ink); }
.warn-text { color: var(--danger); }

/* chụp chéo góc */
.shot-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 8px 0; }
.shot-card { display: flex; gap: 8px; align-items: center; border: 1.5px solid var(--line); border-radius: 12px; padding: 6px 8px; background: var(--card); font-size: 13.5px; line-height: 1.35; }
.shot-card svg { width: 62px; height: 62px; flex: none; }
.shot-card.done { border-color: var(--ok); background: var(--ok-soft); }
div.face-chip { cursor: default; }
#scanModeSeg button { font-size: 13px; }

.print-only { display: none; }

@media (max-width: 1080px) {
  .methods { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .scan-grid, .diag-grid, .solve-grid, .notation-grid, .play-grid, .play-stage-row { grid-template-columns: minmax(0, 1fr); }
  .play-move { font-size: 64px; }
  .player-card { position: static; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  main { padding: 14px 16px 50px; }
}
@media (max-width: 520px) {
  .methods { grid-template-columns: minmax(0, 1fr); }
  .quiz-opts { grid-template-columns: minmax(0, 1fr); }
  .face-steps { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- print: bảng ôn công thức ---------- */
@media print {
  body { background: #fff; color: #000; font-size: 10px; }
  .topbar, main, .modal, .toast { display: none !important; }
  .print-only { display: block; }
  .print-only h2 { font-size: 15px; margin: 10px 0 6px; page-break-after: avoid; }
  .print-only h3 { font-size: 11px; margin: 6px 0 4px; color: #444; }
  .print-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .print-card { border: 1px solid #bbb; border-radius: 6px; padding: 4px; display: flex; gap: 5px; align-items: center; break-inside: avoid; }
  .print-card svg { width: 46px; height: 46px; flex: none; }
  .print-card .pn { font-weight: 700; font-size: 9.5px; }
  .print-card .pa { font: 600 9px/1.3 var(--alg); }
  :root { --sticker-off: #c8c8c8; --plastic: #222; }
}
