/* Khối rubic — giao diện cho trẻ: chữ ≥ 24px trên máy tính bảng, vùng chạm ≥ 56px, mỗi màn một việc. */
:root {
  --bg: #f4f1ea; --ink: #1f2430; --muted: #5b6372; --card: #ffffff; --line: #d9d3c7;
  --pri: #24456b; --pri-ink: #ffffff; --ok: #1f8a4c; --bad: #b3261e; --hint: #8a5a00; --pink: #ff2d95;
  --touch: 56px; --fs: 24px; --radius: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font: 500 var(--fs)/1.35 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; -webkit-tap-highlight-color: transparent; }
@media (max-width: 600px) { :root { --fs: 20px; } }
#app { min-height: 100%; }
.loading { padding: 2rem; text-align: center; color: var(--muted); }
button, input, a.btn { font: inherit; }
.small { font-size: 0.75em; color: var(--muted); }
h1, h2, h3 { margin: 0.3em 0; line-height: 1.2; }
h2 { font-size: 1.1em; } h3 { font-size: 1em; }

/* nút */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.35em; min-height: var(--touch); min-width: var(--touch);
  padding: 0.25em 0.8em; border: 2px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink);
  text-decoration: none; cursor: pointer; user-select: none; touch-action: manipulation; }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 4px solid #4a90e2; outline-offset: 2px; }
.btn.primary { background: var(--pri); color: var(--pri-ink); border-color: var(--pri); }
.btn.danger { color: var(--bad); border-color: #e3b5b1; }
.btn.big { font-size: 1.15em; padding: 0.4em 1.2em; }
.btn.icon { padding: 0; width: var(--touch); font-size: 1.1em; }
.btn.on { background: #e6eef8; border-color: var(--pri); }
.row { display: flex; flex-wrap: wrap; gap: 0.5em; align-items: center; }

/* thanh trên */
.topbar { display: flex; align-items: center; gap: 0.5em; padding: 0.4em 0.6em; background: var(--pri); color: #fff; position: sticky; top: 0; z-index: 5; }
.topbar .title { flex: 1; font-size: 1.05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .btn { background: rgba(255, 255, 255, 0.14); color: #fff; border-color: rgba(255, 255, 255, 0.3); }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: var(--touch); height: var(--touch); border-radius: 50%; background: #fff; font-size: 1.4em; text-decoration: none; }
.notice { margin: 0.4em 0.8em; padding: 0.5em 0.8em; background: #fff4d6; border: 2px solid #f0d58a; border-radius: 12px; font-size: 0.7em; color: #6b4e00; }

/* hồ sơ */
.profiles .profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1em; padding: 1em; }
.profile-card { display: flex; flex-direction: column; align-items: center; gap: 0.2em; padding: 0.8em; border: 3px solid var(--line); border-radius: 22px; background: var(--card); cursor: pointer; min-height: 150px; justify-content: center; font: inherit; }
.profile-card .animal { font-size: 3.2em; line-height: 1; }
.profile-card.new { border-style: dashed; }
.animal-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.4em; }
.animal-btn { font-size: 2em; min-height: 64px; border: 3px solid var(--line); border-radius: 14px; background: #fff; cursor: pointer; }
.animal-btn.on { border-color: var(--pri); background: #e6eef8; }
.field { display: flex; flex-direction: column; gap: 0.2em; margin-top: 0.6em; }
.nick-input, .gate-input, .alg-input { font: inherit; min-height: var(--touch); padding: 0.2em 0.6em; border: 2px solid var(--line); border-radius: 12px; width: 100%; }

/* màn chính */
.home .say-row, .say-row { display: flex; align-items: center; gap: 0.4em; }
.home .say-row { padding: 0.4em 0.8em 0; }
.say { flex: 1; margin: 0.2em 0; font-size: 1.05em; font-weight: 650; }
.btn.continue { display: flex; flex-wrap: wrap; margin: 0.6em 0.8em; min-height: 96px; font-size: 1.5em; background: var(--ok); border-color: var(--ok); color: #fff; border-radius: 26px; }
.btn.continue .play-ico { font-size: 1.1em; }
.btn.continue small { flex-basis: 100%; text-align: center; font-size: 0.55em; opacity: 0.95; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6em; padding: 0 0.8em; }
@media (max-width: 700px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 130px; border-radius: 24px; text-decoration: none; color: var(--ink); background: var(--card); border: 3px solid var(--line); }
.tile-icon { font-size: 2.6em; line-height: 1.1; }
.tile-label { font-weight: 750; font-size: 1.1em; }
.tile.learn { border-color: #7fb0e0; } .tile.practice { border-color: #e0b36f; } .tile.play { border-color: #8fd0a4; } .tile.time { border-color: #e39a9a; }
.map-title { padding: 0 0.8em; margin-top: 0.8em; }
.roadmap { display: flex; flex-direction: column; gap: 0.4em; padding: 0 0.8em 1.2em; }
.road-group { background: var(--card); border: 2px solid var(--line); border-radius: 18px; padding: 0.4em 0.6em; }
.road-title { font-size: 0.8em; font-weight: 700; color: var(--muted); }
.road-nodes { display: flex; flex-wrap: wrap; gap: 0.4em; margin-top: 0.2em; }
.node { display: flex; flex-direction: column; align-items: center; min-width: var(--touch); min-height: var(--touch); padding: 0.15em 0.3em; border-radius: 14px; border: 2px solid var(--line); text-decoration: none; color: inherit; background: #fbfaf7; }
.node.practice { border-style: dashed; }
.node.here { border: 3px solid var(--pink); box-shadow: 0 0 0 3px #ffd1e6; animation: here 1.2s ease-in-out infinite alternate; }
@keyframes here { to { box-shadow: 0 0 0 7px #ffd1e6; } }
.node.locked { opacity: 0.45; }
.node-icon { font-size: 1.2em; }
.stars { font-size: 0.6em; letter-spacing: -0.05em; white-space: nowrap; }
.star { color: #c9c2b4; } .star.on { color: #f2a900; }

/* danh sách bài */
.list-group { padding: 0.2em 0.8em; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.6em; }
.card { display: flex; align-items: center; gap: 0.5em; min-height: 76px; padding: 0.4em 0.7em; border-radius: 18px; background: var(--card); border: 2px solid var(--line); text-decoration: none; color: inherit; cursor: pointer; }
.card.here { border: 3px solid var(--pink); }
.card.locked { opacity: 0.5; }
.card-icon { font-size: 1.6em; }
.card-title { flex: 1; font-size: 0.85em; font-weight: 650; }

/* màn có khối: ngang → khối trái, bảng phải; dọc → khối trên, bảng dưới */
.stage-wrap { display: flex; gap: 0.6em; padding: 0.5em; height: calc(100dvh - 72px); }
.cube-area { position: relative; flex: 1.25; min-height: 260px; background: radial-gradient(circle at 45% 40%, #ffffff 0%, #e8e3d8 75%); border-radius: 22px; overflow: hidden; touch-action: none; }
.cube-canvas { display: block; width: 100%; height: 100%; }
.panel { flex: 1; display: flex; flex-direction: column; gap: 0.35em; overflow-y: auto; min-width: 300px; max-width: 560px; }
@media (orientation: portrait), (max-width: 760px) {
  .stage-wrap { flex-direction: column; height: auto; }
  .cube-area { flex: none; height: 48vh; min-height: 260px; }
  .panel { max-width: none; min-width: 0; overflow: visible; }
}
.intro { margin: 0; font-size: 0.8em; color: var(--muted); }
.intro:empty, .feedback:empty, .stage-label:empty { display: none; }
.cue { display: flex; gap: 0.4em; align-items: center; flex-wrap: wrap; }
.swatch { display: inline-block; width: 48px; height: 48px; border-radius: 10px; border: 3px solid #15171c; }
.swatch.big { width: 72px; height: 72px; }
.big-move { font-size: 3em; font-weight: 800; color: var(--pri); line-height: 1; }
.big-face { font-size: 2em; font-weight: 800; color: var(--pri); }
.stage-label { margin: 0; font-weight: 700; color: var(--pri); font-size: 0.85em; }
.feedback { margin: 0; padding: 0.3em 0.6em; border-radius: 12px; font-weight: 650; }
.feedback.ok { background: #e3f5e9; color: var(--ok); }
.feedback.bad { background: #fde8e6; color: var(--bad); }
.feedback.hint { background: #fff4d6; color: var(--hint); }
.actions { display: flex; flex-wrap: wrap; gap: 0.4em; align-items: center; }
.btn.hint { background: #fff4d6; border-color: #f0d58a; }
.bulb { font-size: 1.15em; }
.hint-dots { display: inline-flex; gap: 3px; }
.hint-dots .dot { width: 10px; height: 10px; border-radius: 50%; background: #e5d9b8; }
.hint-dots .dot.on { background: #e39b00; }
.progress { margin-left: auto; color: var(--muted); font-size: 0.8em; }
.algo-name { margin: 0; font-weight: 750; }
.alg-chips { display: flex; flex-wrap: wrap; gap: 0.5em; }
.alg-chunk { display: inline-flex; gap: 0.2em; padding: 0.1em; border-radius: 12px; background: #ece6da; }
.chip { min-width: 52px; min-height: 52px; display: inline-flex; align-items: center; justify-content: center; padding: 0 0.3em; border-radius: 10px; background: #fff; font-weight: 800; font-size: 1.05em; border: 2px solid var(--line); }
.chip.done { background: #e3f5e9; color: var(--ok); border-color: #b9e2c7; }
.chip.cur { background: var(--pink); color: #fff; border-color: #c0006b; animation: pulse 0.8s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }
.step-count { margin: 0; color: var(--muted); font-size: 0.8em; }
.dont-worry { margin: 0; padding: 0.3em 0.6em; background: #e6eef8; border-radius: 12px; font-weight: 650; }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.5em; }
.choices:empty { display: none; }
.btn.choice { min-height: 96px; border: 4px solid #15171c; }
.choice-name { background: rgba(255, 255, 255, 0.85); color: #15171c; border-radius: 8px; padding: 0 0.3em; font-size: 0.8em; }
.btn.choice.dim { opacity: 0.25; }
.btn.choice.right { outline: 6px solid var(--ok); }
.btn.choice.nope { opacity: 0.4; }
.result { display: flex; flex-direction: column; align-items: flex-start; gap: 0.3em; padding: 0.6em; background: #e3f5e9; border-radius: 18px; }
.result .stars { font-size: 2em; }
.result-big { margin: 0; font-size: 1.4em; font-weight: 800; color: var(--ok); }

/* bàn nút xoay */
.movepad { display: flex; flex-direction: column; gap: 0.4em; }
.pad-grid { display: grid; grid-template-columns: repeat(6, minmax(var(--touch), 1fr)); gap: 0.3em; }
@media (max-width: 460px) { .pad-grid { grid-template-columns: repeat(4, 1fr); } }
.btn.mv { flex-direction: column; gap: 0; padding: 0.1em; min-height: 64px; }
.mv-svg { width: 34px; height: 30px; }
.mv-face { fill: #dfe7f1; stroke: #24456b; stroke-width: 2.5; }
.mv-arrow { fill: none; stroke: var(--pink); stroke-width: 4; stroke-linecap: round; }
.mv-two { font: 800 15px system-ui, sans-serif; fill: #24456b; text-anchor: middle; }
.mv-txt { font-size: 0.8em; line-height: 1; }
.pad-rot { display: flex; flex-wrap: wrap; gap: 0.3em; align-items: center; }
.pad-rot-label { font-size: 0.7em; color: var(--muted); width: 100%; }
.btn.mv.rot { flex-direction: row; min-height: var(--touch); }
.rot-ico { font-size: 1.2em; }

/* chọn đoạn */
.seg-row { display: flex; align-items: center; gap: 0.5em; flex-wrap: wrap; }
.seg-label { font-size: 0.8em; color: var(--muted); font-weight: 700; }
.seg { display: inline-flex; gap: 0.3em; flex-wrap: wrap; }
.seg-btn.on { background: var(--pri); color: #fff; border-color: var(--pri); }
.alg-box summary { cursor: pointer; min-height: var(--touch); display: flex; align-items: center; font-size: 0.85em; }

/* Thi */
.time-wrap { display: flex; gap: 0.8em; padding: 0.5em; }
.time-left { flex: 1; display: flex; flex-direction: column; gap: 0.4em; min-width: 0; }
.time-right { flex: 1.1; display: flex; flex-direction: column; gap: 0.5em; min-width: 0; }
/* Dọc / màn nhỏ: ô đồng hồ ngay dưới đề xáo, hình khối và số liệu xuống dưới. */
@media (orientation: portrait), (max-width: 760px) {
  .time-wrap { flex-direction: column; }
  .time-left, .time-right { display: contents; }
  .time-wrap .timer-pad { order: 3; min-height: 200px; }
  .time-wrap .last-acts { order: 4; }
  .time-wrap .time-left > .small, .time-wrap .preview { order: 5; }
  .time-wrap .stats { order: 6; }
  .time-wrap .time-right > h3, .time-wrap .history { order: 7; }
  .cube-area.preview { height: 240px; }
}
.scramble-box { background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 0.4em 0.6em; }
.scramble-text { margin: 0.2em 0; font: 800 1.35em/1.35 ui-monospace, "Cascadia Mono", Consolas, monospace; word-spacing: 0.25em; }
.cube-area.preview { flex: none; height: 300px; }
.timer-pad { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 260px; border-radius: 26px; background: #20242e; color: #fff; user-select: none; touch-action: none; cursor: pointer; }
.timer-pad.holding .clock { color: #ff5a5a; }
.timer-pad.ready .clock { color: #3ee07a; }
.timer-pad.inspecting { background: #3b2f12; }
.clock { font: 800 4.2em/1 ui-monospace, "Cascadia Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.clock-tip { margin: 0.4em; font-size: 0.75em; text-align: center; opacity: 0.85; }
.pen-note { margin: 0; color: #ffcf5a; font-weight: 700; min-height: 1.2em; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.4em; }
.stat { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 0.3em 0.6em; display: flex; flex-direction: column; }
.stat-label { font-size: 0.7em; color: var(--muted); font-weight: 700; }
.stat-val { font-size: 1.2em; font-variant-numeric: tabular-nums; }
.history { margin: 0; padding-left: 2.2em; max-height: 40vh; overflow: auto; font-variant-numeric: tabular-nums; }
.history li { padding: 0.1em 0; }
.screen.time.running .time-left, .screen.time.running .stats, .screen.time.running .history, .screen.time.running h3, .screen.time.running .last-acts { display: none; }
.screen.time.running .timer-pad { min-height: 70vh; }

/* hộp thoại */
.modal-wrap { position: fixed; inset: 0; background: rgba(20, 24, 32, 0.45); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 1em; }
.modal { background: var(--bg); border-radius: 22px; padding: 1em; max-width: 640px; width: 100%; max-height: 92vh; overflow: auto; display: flex; flex-direction: column; gap: 0.5em; }
.gate-q { font-size: 2em; font-weight: 800; margin: 0.2em 0; }
.gate-msg { color: var(--bad); min-height: 1.2em; margin: 0; }
.settings { display: flex; flex-direction: column; gap: 0.6em; }
.toast { position: fixed; left: 50%; bottom: 1.2em; transform: translate(-50%, 30px); opacity: 0; transition: all 0.3s; background: #1f2430; color: #fff; padding: 0.5em 1em; border-radius: 14px; z-index: 30; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); }
.no-webgl-msg { padding: 1em; text-align: center; }
