:root {
  --bg: #f5f2ec;
  --card: #fffdf9;
  --soft: #efebe4;
  --text: #1c1c1e;
  --muted: #8a867f;
  --accent: #0a7aff;
  --ok: #248a3d;
  --bad: #d70015;
  --border: rgba(60, 50, 30, 0.12);
  --shadow: 0 1px 2px rgba(60, 50, 30, 0.06), 0 8px 28px rgba(60, 50, 30, 0.07);
  --surface: #ffffff;
  --hover: #f4f1ea;
  --chip-hover: #e7e2d9;
  --glass: rgba(255, 255, 255, 0.55);
  --glass-border: rgba(255, 255, 255, 0.6);
  --side-bg: rgba(255, 253, 249, 0.8);
  --warn-bg: rgba(255, 159, 10, 0.15);
  --warn-text: #7a4a00;
  --ok-text: #1f8a3d;
  --bad-text: #c8281f;
}

:root { color-scheme: light; }

/* Dark theme: follows the phone or computer setting, unless the toolbar switch picked a theme */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214; --card: #1c1c1f; --soft: #2a2a2e; --text: #f2f2f4; --muted: #9a9aa2;
    --accent: #3d95ff; --ok: #32d74b; --bad: #ff5a4f; --border: rgba(255, 255, 255, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.35);
    --surface: #242428; --hover: #2e2e33; --chip-hover: #3a3a40;
    --glass: rgba(28, 28, 31, 0.72); --glass-border: rgba(255, 255, 255, 0.1); --side-bg: rgba(28, 28, 31, 0.85);
    --warn-bg: rgba(255, 159, 10, 0.18); --warn-text: #ffc266; --ok-text: #4ade80; --bad-text: #ff7b72;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111214; --card: #1c1c1f; --soft: #2a2a2e; --text: #f2f2f4; --muted: #9a9aa2;
  --accent: #3d95ff; --ok: #32d74b; --bad: #ff5a4f; --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.35);
  --surface: #242428; --hover: #2e2e33; --chip-hover: #3a3a40;
  --glass: rgba(28, 28, 31, 0.72); --glass-border: rgba(255, 255, 255, 0.1); --side-bg: rgba(28, 28, 31, 0.85);
  --warn-bg: rgba(255, 159, 10, 0.18); --warn-text: #ffc266; --ok-text: #4ade80; --bad-text: #ff7b72;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* The aura canvas is wider than the card; it must never create a sideways scrollbar on phones */
html, body { overflow-x: hidden; max-width: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, Roboto, sans-serif;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.card {
  position: relative;
  z-index: 3;
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border-radius: 28px;
  padding: 24px;
  box-shadow: var(--shadow);
}

/* The home screen has no card: the head and the buttons sit straight on the ivory page */
.card[data-view="home"] { background: transparent; box-shadow: none; }

#home { text-align: center; }

.view[hidden] { display: none; }

h1 { font-size: 1.6rem; margin: 0 0 12px; }
h2 { font-size: 1.4rem; margin: 0 0 12px; }

.lead { color: var(--muted); line-height: 1.5; margin: 0 0 20px; }

.progress { color: var(--muted); font-size: 0.9rem; margin-bottom: 12px; }

.rule { color: var(--accent); font-size: 0.9rem; margin: 0 0 4px; }

.question { font-size: 1.1rem; margin: 0 0 16px; line-height: 1.4; }

.options { display: flex; flex-direction: column; gap: 10px; }

.option {
  text-align: left;
  padding: 14px 16px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 0 0 0.5px var(--border);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.option:hover:not(:disabled) { background: var(--hover); }
.option:active:not(:disabled) { transform: scale(0.99); }
.option:disabled { cursor: default; }
.option.correct { background: rgba(36, 138, 61, 0.12); color: var(--ok); animation: opt-bounce 0.55s ease; }
.option.wrong { background: rgba(215, 0, 21, 0.1); color: var(--bad); animation: opt-shake 0.5s ease; }

@keyframes opt-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-9px); }
  35% { transform: translateX(8px); }
  55% { transform: translateX(-6px); }
  75% { transform: translateX(4px); }
}

@keyframes opt-bounce {
  0% { transform: scale(1); }
  35% { transform: scale(1.04) translateY(-5px); }
  60% { transform: scale(0.99) translateY(1px); }
  100% { transform: scale(1); }
}

.domla-box {
  margin-top: 20px;
  padding: 14px 16px;
  background: var(--soft);
  border-radius: 18px;
}

.domla-name { font-weight: 600; margin-bottom: 4px; }
.domla-line { margin: 0; line-height: 1.5; min-height: 1.5em; }

.primary {
  margin-top: 16px;
  padding: 14px 22px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.primary:hover:not(:disabled) { filter: brightness(1.06); }
.primary:active:not(:disabled) { transform: scale(0.98); }

.primary:disabled { opacity: 0.5; cursor: default; }

.error { color: var(--bad); }

/* Domla mascot. It is a fixed element: on the home page it sits over an empty slot in the card, and when the
   exam starts it glides to the top-left corner and shrinks (left, top and width are animated). */
#df-hands [data-finger], #df-hands [data-thumb] { display: none; }
.mascot-slot { width: min(480px, 100%, 42vh); aspect-ratio: 372 / 450; margin: 0 auto 6px; }
body.exam-mode .mascot-slot { display: none; }

.mascot {
  position: fixed;
  z-index: 6;
  left: 0;
  top: 0;
  width: 480px;
  pointer-events: none;
  visibility: hidden;
  transition: left 1s cubic-bezier(0.65, 0, 0.2, 1), top 1s cubic-bezier(0.65, 0, 0.2, 1), width 1s cubic-bezier(0.65, 0, 0.2, 1), opacity 0.3s ease;
}
.mascot.placed { visibility: visible; }
.mascot.no-trans { transition: none; }

.mascot-face {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  /* Arms and signs may stick out above and to the sides, but are cut at the bottom edge. */
  clip-path: inset(-300px -300px 0 -300px);
}

/* Aura canvas reaches about 5 cm (200 px) past the head on every side, behind the card's content */
.mascot-aura {
  position: absolute;
  left: -200px;
  top: -200px;
  width: calc(100% + 400px);
  height: calc(100% + 400px);
  pointer-events: none;
  z-index: -1;
}

/* Phones: less room around the head for the aura, tighter card, smaller toolbar */
@media (max-width: 600px) {
  body { padding: 8px; }
  .card { padding: 14px; }
  .mascot-aura {
    left: -110px;
    top: -110px;
    width: calc(100% + 220px);
    height: calc(100% + 220px);
  }
  .toolbar { top: 8px; right: 8px; }
  .tb-btn { min-width: 36px; height: 34px; padding: 0 8px; }
}

/* The home card fades back in after the exam */
.card.home-in { animation: home-in 0.7s ease 0.35s both; }
@keyframes home-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* Exam mode: the city fills the screen, the card becomes a frosted-glass panel on the left
   (at the bottom on phones) and slides in once the head has started moving. */
body.exam-mode { overflow: hidden; height: 100vh; }

body.exam-mode .card {
  position: fixed;
  z-index: 3;
  left: 22px;
  top: 150px;
  bottom: auto;
  max-height: calc(100vh - 172px);
  width: min(470px, 42vw);
  max-width: none;
  margin: 0;
  padding: 20px;
  overflow-y: auto;
  background: var(--glass);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  border: 1px solid var(--glass-border);
  border-radius: 28px;
  box-shadow: 0 18px 50px rgba(20, 40, 80, 0.2);
  animation: panel-in 0.8s cubic-bezier(0.2, 0.9, 0.25, 1) 0.6s both;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateX(-40px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 760px) {
  body.exam-mode .card {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: 8px;
    width: auto;
    max-height: 60vh;
    padding: 14px;
  }
}

/* The face itself is animated by domla-face.js, the aura by domla-aura.js */

.bubble {
  min-height: 3.2em;
  margin: 0 auto 20px;
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--soft);
  line-height: 1.5;
  position: relative;
}

/* The isometric 3D city: the whole screen during the exam. It opens as a circle growing from the Start button. */
.city {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #e9f1fa;
}
.city[hidden] { display: none; }
.city-canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.city-canvas:active { cursor: grabbing; }

.city.reveal { animation: city-reveal 1.25s cubic-bezier(0.6, 0, 0.2, 1) both; }
.city.conceal { animation: city-conceal 0.8s cubic-bezier(0.55, 0, 0.45, 1) both; }

@keyframes city-reveal {
  from { clip-path: circle(0 at var(--rx, 50%) var(--ry, 60%)); }
  to { clip-path: circle(150vmax at var(--rx, 50%) var(--ry, 60%)); }
}

@keyframes city-conceal {
  from { clip-path: circle(150vmax at var(--rx, 50%) var(--ry, 60%)); }
  to { clip-path: circle(0 at var(--rx, 50%) var(--ry, 60%)); }
}

/* Road sign picture above the answers */
.sign-pic { display: flex; justify-content: center; margin: 4px 0 14px; }
.sign-pic svg { width: 150px; height: 150px; }
.sign-pic img { max-width: 100%; max-height: 220px; border-radius: 10px; object-fit: contain; }
.rv-sign { float: right; margin: 0 0 6px 10px; }
.rv-sign svg { width: 56px; height: 56px; display: block; }
@media (max-width: 600px) { .sign-pic svg { width: 120px; height: 120px; } }

/* Statistics, review of mistakes, share */
.stats { color: var(--muted); font-size: 0.9rem; margin: 12px 0 0; }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#result { text-align: center; }
.review { text-align: left; margin-top: 18px; }
.review h3 { font-size: 1.05rem; margin: 0 0 10px; }
.review-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.review-list li { padding: 14px 16px; border-radius: 16px; background: var(--surface); box-shadow: 0 0 0 0.5px var(--border); }
.rv-q { font-weight: 600; margin-bottom: 6px; line-height: 1.4; }
.rv-wrong { color: var(--bad); line-height: 1.4; }
.rv-right { color: var(--ok); line-height: 1.4; margin-top: 2px; }

/* Language and sound buttons */
.toolbar {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 6px;
  z-index: 30;
}

.tb-btn {
  min-width: 40px;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: var(--side-bg);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 0 0 0.5px var(--border);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tb-btn[hidden] { display: none; }
.tb-btn:hover { background: var(--surface); }
.tb-btn.active { background: var(--accent); color: #ffffff; }
.tb-icon .snd-mute { display: none; }
.tb-icon.muted .snd-mute { display: inline; }
.tb-icon.muted .snd-wave { display: none; }
.tb-icon.muted { color: var(--bad); }

/* Full-screen effects (confetti, fire, panic frame) */
.screenfx {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 20;
}

/* The question card flies in from Domla's direction */
.q-block.fly-in { animation: fly-in 0.55s cubic-bezier(0.2, 0.9, 0.25, 1.1); transform-origin: 50% 0; }

@keyframes fly-in {
  0% { opacity: 0; transform: translateY(-90px) scale(0.55); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* The panel's content jumps when Domla hits the table */
.view.bang { animation: card-bang 0.26s ease; }

@keyframes card-bang {
  0% { transform: translateY(0); }
  30% { transform: translateY(9px); }
  60% { transform: translateY(-4px); }
  100% { transform: translateY(0); }
}

/* Mistake counter flashes on every mistake and gets cracked at the limit */
.mistakes { display: inline-block; font-weight: 600; }
.mistakes.flash { animation: mist-flash 0.7s ease; }
.mistakes.danger { color: var(--bad); text-decoration: underline wavy var(--bad); text-underline-offset: 3px; }

@keyframes mist-flash {
  0% { transform: scale(1); background: transparent; }
  25% { transform: scale(1.7) rotate(-6deg); background: rgba(239, 68, 68, 0.28); color: var(--bad); }
  55% { transform: scale(0.9) rotate(4deg); }
  100% { transform: scale(1); background: transparent; }
}

/* Intersection scene */
.scene { margin: 0 0 14px; }
.scene-svg { display: block; width: 100%; max-width: 360px; margin: 0 auto; height: auto; }

/* Emotion test panel */
.emo-panel {
  position: fixed;
  top: 24px;
  right: 24px;
  width: 240px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 14px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.06);
}

.emo-panel h2 { font-size: 1rem; margin: 0 0 10px; }

.emo-list { display: flex; flex-direction: column; gap: 6px; }

.emo-btn {
  display: flex;
  gap: 8px;
  align-items: center;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.emo-btn:hover { border-color: var(--accent); }
.emo-btn.active { background: var(--accent); border-color: var(--accent); color: #ffffff; }
.emo-num { opacity: 0.6; min-width: 1.4em; }
.emo-btn.active .emo-num { opacity: 0.85; }

.emo-play { margin-top: 10px; width: 100%; }

@media (max-width: 900px) {
  .emo-panel {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: 150px;
  }
  .emo-list { flex-direction: row; flex-wrap: wrap; }
}

/* Home: one row of three buttons: the exam, the chat with Domla, and a small square for support */
.home-actions { display: flex; gap: 10px; align-items: stretch; max-width: 520px; margin: 16px auto 0; }
.home-actions .primary { margin-top: 0; min-height: 56px; padding: 12px 14px; border-radius: 18px; line-height: 1.2; }
.home-actions #start { flex: 1.25 1 0; font-size: 1.02rem; }
.home-actions #open-chat { flex: 1 1 0; }
.home-actions .square { flex: none; width: 56px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }

/* The exam and the chat are both blue, a little see-through; every button lights up on hover */
.home-actions .primary {
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease, color 0.2s ease;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.home-actions #start, .home-actions #open-chat { background: rgba(10, 122, 255, 0.82); color: #ffffff; }
.home-actions .primary.square { background: rgba(10, 122, 255, 0.12); color: var(--accent); }
.home-actions .primary.square:hover:not(:disabled),
.home-actions #start:hover:not(:disabled),
.home-actions #open-chat:hover:not(:disabled) {
  filter: none;
  background: rgba(10, 122, 255, 1);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 0 0 3px rgba(10, 122, 255, 0.18), 0 6px 22px rgba(10, 122, 255, 0.5);
}
.home-actions .primary:active:not(:disabled) { transform: scale(0.98); box-shadow: 0 0 0 3px rgba(10, 122, 255, 0.18), 0 2px 10px rgba(10, 122, 255, 0.4); }
.home-actions .primary:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(10, 122, 255, 0.35); }
.primary.secondary { background: rgba(10, 122, 255, 0.1); color: var(--accent); }
.primary.secondary:hover:not(:disabled) { filter: none; background: rgba(10, 122, 255, 0.16); }
@media (max-width: 600px) {
  .home-actions { gap: 8px; }
  .home-actions .primary { font-size: 0.9rem; padding: 10px 8px; }
  .home-actions .square { width: 48px; }
}

/* Chat with Domla and the support desk */
body.chat-mode .mascot-slot { width: min(150px, 100%); }
body.support-mode .mascot-slot { display: none; }
body.support-mode .mascot { opacity: 0; }
@media (max-width: 600px) { body.chat-mode .mascot-slot { width: min(110px, 100%); } }

.talk { text-align: left; }
.talk-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.talk-head h2 { margin: 0; }
.talk-back, .link-btn { border: 0; background: transparent; color: var(--accent); font: inherit; cursor: pointer; padding: 6px 0; }
.talk-back:hover, .link-btn:hover { opacity: 0.7; }
.link-btn[hidden] { display: none; }
.link-btn.hint { font-weight: 600; animation: hint-pulse 1.4s ease 3; }
@keyframes hint-pulse { 50% { transform: scale(1.06); } }
.talk-note { color: var(--muted); font-size: 0.8rem; line-height: 1.4; margin: 0 0 10px; }

.talk-log { display: flex; flex-direction: column; gap: 6px; height: min(46vh, 380px); overflow-y: auto; padding: 4px 2px; }
.msg { max-width: 82%; padding: 9px 14px; border-radius: 20px; line-height: 1.4; overflow-wrap: anywhere; }
.msg.bot { align-self: flex-start; background: var(--soft); border-bottom-left-radius: 6px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #ffffff; border-bottom-right-radius: 6px; }
.msg.status .msg-text { color: var(--muted); }
.msg-listen { display: block; margin-top: 4px; padding: 0; border: 0; background: none; font-size: 15px; line-height: 1; cursor: pointer; opacity: .6; }
.msg-listen:hover { opacity: 1; }

.talk-form { display: flex; gap: 8px; margin-top: 10px; }
.talk-form .primary { margin-top: 0; padding: 10px 18px; border-radius: 20px; }
.talk-form.busy { opacity: 0.7; }
.talk-input, .ticket textarea, .ticket input {
  flex: 1;
  min-width: 0;
  padding: 11px 16px;
  border: 0;
  border-radius: 20px;
  background: var(--soft);
  color: var(--text);
  font: inherit;
}
.ticket textarea { border-radius: 16px; }
.talk-input:focus, .ticket textarea:focus, .ticket input:focus { outline: 2px solid rgba(10, 122, 255, 0.5); outline-offset: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { padding: 7px 12px; border: 0; border-radius: 999px; background: var(--soft); color: var(--text); font: inherit; font-size: 0.82rem; cursor: pointer; transition: background 0.15s ease; }
.chip:hover { background: var(--chip-hover); }

.ticket { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; padding: 14px; border-radius: 20px; background: var(--surface); box-shadow: 0 0 0 0.5px var(--border); }
.ticket[hidden] { display: none; }
.ticket h3 { margin: 0; font-size: 1rem; }
.ticket textarea { resize: vertical; width: 100%; }
.ticket-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ticket-actions .primary { margin-top: 0; padding: 10px 18px; }
.ticket .stats { margin: 0; min-height: 1.2em; }

/* Side menu: a frosted panel on the left (a bar at the bottom on narrow screens), shown on the home and study screens */
.side {
  position: fixed;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 8;
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--side-bg);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-radius: 24px;
  box-shadow: var(--shadow), 0 0 0 0.5px var(--border);
}
body[data-view="home"] .side, body[data-view="tickets"] .side, body[data-view="topics"] .side, body[data-view="rules"] .side, body[data-view="mistakes"] .side { display: flex; }
.side-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 70px;
  padding: 11px 4px 9px;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}
.side-item:hover { background: rgba(10, 122, 255, 0.1); color: var(--accent); }
.side-item:active { transform: scale(0.95); }
.side-item.active { background: var(--accent); color: #ffffff; box-shadow: 0 6px 18px rgba(10, 122, 255, 0.35); }
.side-badge {
  position: absolute;
  top: 4px;
  right: 9px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ff3b30;
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}
.side-badge[hidden] { display: none; }
@media (max-width: 1000px) {
  .side { top: auto; bottom: 10px; left: 50%; transform: translateX(-50%); flex-direction: row; gap: 2px; padding: 6px; border-radius: 22px; }
  .side-item { width: min(74px, 18vw); padding: 8px 2px 6px; font-size: 0.68rem; }
  body[data-view="home"], body[data-view="tickets"], body[data-view="topics"], body[data-view="rules"], body[data-view="mistakes"] { padding-bottom: 96px; }
}

/* Study screens sit on top of the page, the head steps aside */
body.sec-mode { align-items: flex-start; padding-top: 28px; }
body.sec-mode .mascot-slot { display: none; }
body.sec-mode .mascot { opacity: 0; }
.card[data-view="tickets"], .card[data-view="topics"], .card[data-view="rules"], .card[data-view="mistakes"] { max-width: 760px; }
.study h2 { font-size: 1.7rem; margin: 0 0 4px; letter-spacing: -0.02em; }
.study { text-align: left; }

.bar { height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 4px; background: #c4c0b8; transition: width 0.6s cubic-bezier(0.2, 0.9, 0.25, 1); }
.bar span.good { background: #34c759; }
.bar span.mid { background: #ff9f0a; }
.bar span.bad { background: #ff453a; }

/* Tickets: big tiles that rise in one after another */
.tk-head { margin: 10px 0 14px; }
.tk-count { font-weight: 600; margin-bottom: 8px; }
.tk-continue { width: 100%; margin: 0 0 16px; }
.tk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.tile {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px;
  border: 0;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 0 0 0.5px var(--border), 0 1px 3px rgba(60, 50, 30, 0.06);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  animation: tile-in 0.5s cubic-bezier(0.2, 0.9, 0.25, 1.1) backwards;
  animation-delay: var(--d, 0ms);
  transition: transform 0.18s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.tile-label { font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.tile-no { font-size: 2.1rem; font-weight: 700; line-height: 1; letter-spacing: -0.03em; }
.tile-sub { font-size: 0.72rem; color: var(--muted); }
.tile:hover:not(:disabled) { transform: translateY(-4px) scale(1.04); box-shadow: 0 0 0 2px rgba(10, 122, 255, 0.5), 0 14px 28px rgba(10, 122, 255, 0.22); }
.tile:active:not(:disabled) { transform: scale(0.95); }
.tile.passed { background: rgba(52, 199, 89, 0.15); }
.tile.passed .tile-no, .tile.passed .tile-sub { color: var(--ok-text); }
.tile.passed::after { content: "✓"; position: absolute; top: 9px; right: 13px; color: var(--ok-text); font-weight: 700; }
.tile.failed { background: rgba(255, 69, 58, 0.1); }
.tile.failed .tile-no, .tile.failed .tile-sub { color: var(--bad-text); }
.tile.locked { background: transparent; box-shadow: none; border: 1.5px dashed rgba(60, 50, 30, 0.22); cursor: default; opacity: 0.75; }
@keyframes tile-in { from { opacity: 0; transform: translateY(16px) scale(0.84); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .tile { animation: none; } }
@media (max-width: 600px) { .tk-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; } .tile-no { font-size: 1.7rem; } }

/* Mistakes and statistics */
.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 8px 0 0; }
@media (min-width: 640px) { .metrics { grid-template-columns: repeat(4, 1fr); } }
.metric { background: var(--surface); border-radius: 18px; padding: 14px; box-shadow: 0 0 0 0.5px var(--border); }
.metric-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; }
.metric-label { color: var(--muted); font-size: 0.78rem; }
.st-avg { margin: 8px 0 0; }
.st-section { margin-top: 24px; }
.st-section h3 { font-size: 1.05rem; margin: 0 0 10px; }
.st-insight { background: var(--warn-bg); color: var(--warn-text); border-radius: 14px; padding: 10px 14px; margin: 0 0 12px; font-weight: 500; line-height: 1.4; }
.type-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; margin-bottom: 14px; }
.type-top { grid-column: 1; display: flex; justify-content: space-between; gap: 8px; }
.type-name { font-weight: 500; }
.type-pct { font-weight: 600; }
.type-row .bar { grid-column: 1; }
.type-row .chip { grid-column: 2; grid-row: 1 / 3; background: rgba(10, 122, 255, 0.1); color: var(--accent); font-weight: 600; padding: 9px 16px; }
.type-row .chip:hover { background: rgba(10, 122, 255, 0.18); }
.chap-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; box-shadow: inset 0 -0.5px 0 var(--border); font-size: 0.9rem; }
.chap-pct { font-weight: 600; flex: none; }
.chap-pct.bad { color: var(--bad); }
.chap-pct.mid { color: #b86e00; }
.chap-pct.good { color: var(--ok); }
.spark { display: flex; align-items: flex-end; gap: 6px; height: 84px; }
.spark span { flex: 1; max-width: 30px; border-radius: 7px; background: #34c759; }
.spark span.bad { background: #ff453a; }
.st-section .primary { width: 100%; margin-top: 0; }
.miss-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.miss-list li { background: var(--surface); border-radius: 16px; padding: 12px 14px; box-shadow: 0 0 0 0.5px var(--border); overflow: hidden; }
.miss-sign { float: right; margin: 0 0 4px 10px; }
.miss-sign svg { width: 52px; height: 52px; display: block; }
.miss-q { font-weight: 600; line-height: 1.4; margin-bottom: 4px; }
.miss-ok { color: var(--ok); font-size: 0.9rem; line-height: 1.4; }
.miss-n { color: var(--bad); font-size: 0.8rem; margin-top: 2px; }
.st-empty { color: var(--muted); line-height: 1.5; }
.st-reset { margin-top: 24px; color: var(--muted); }
.miss-photo { margin: 0 0 8px; }
.miss-photo img { display: block; max-width: 100%; max-height: 150px; border-radius: 10px; object-fit: contain; }

/* The exam clock next to the progress line; red in the last minute */
.exam-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.exam-top .progress { margin-bottom: 0; }
.timer { flex: none; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.9rem; color: var(--muted); padding: 3px 10px; border-radius: 999px; background: var(--soft); }
.timer[hidden] { display: none; }
.timer.low { color: #ffffff; background: var(--bad); animation: timer-pulse 1s ease-in-out infinite; }
@keyframes timer-pulse { 50% { opacity: 0.65; } }

/* The rule behind the answer, under Domla's remark */
.explain { margin-top: 12px; }
.explain[hidden], .explain [hidden] { display: none; }
#explain-body { padding: 12px 14px; border-radius: 16px; background: var(--surface); box-shadow: 0 0 0 0.5px var(--border); }
.explain-title { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin-bottom: 4px; }
.explain-text { margin: 0 0 10px; line-height: 1.5; font-size: 0.92rem; }
.explain-domla, .rv-domla { margin: 8px 0 0; line-height: 1.5; font-size: 0.92rem; font-style: italic; }
.explain-domla:empty, .rv-domla:empty { display: none; }
.explain .chip, .review-list .chip, .miss-list .chip { background: rgba(10, 122, 255, 0.1); color: var(--accent); font-weight: 600; margin-top: 8px; }
.explain .chip:hover, .review-list .chip:hover, .miss-list .chip:hover { background: rgba(10, 122, 255, 0.18); }
.explain .chip:disabled, .review-list .chip:disabled, .miss-list .chip:disabled { opacity: 0.6; cursor: default; }
.rv-explain { margin-top: 8px; padding-top: 8px; box-shadow: inset 0 0.5px 0 var(--border); color: var(--muted); font-size: 0.86rem; line-height: 1.45; }

/* On phones the Next button stays in sight at the bottom of the question panel */
@media (max-width: 760px) {
  body.exam-mode #next { position: sticky; bottom: 0; width: 100%; box-shadow: 0 -10px 18px var(--glass); }
}

/* Topics: one card per topic with its accuracy and the level buttons */
.topic-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin-top: 10px; }
.topic-card { padding: 14px 16px; border-radius: 20px; background: var(--surface); box-shadow: 0 0 0 0.5px var(--border); animation: tile-in 0.45s cubic-bezier(0.2, 0.9, 0.25, 1.1) backwards; animation-delay: var(--d, 0ms); }
.topic-card .type-top { margin-bottom: 8px; }
.topic-open { color: var(--bad); font-size: 0.8rem; font-weight: 600; }
.topic-line { margin: 6px 0 0; font-size: 0.8rem; }
.topic-card .chips { margin-top: 8px; }
.topic-card .chip { font-weight: 600; }
.chip.lvl-1 { color: var(--ok); }
.chip.lvl-3 { color: #b86e00; }
.chip.lvl-4 { color: var(--bad); }
.topic-row { width: 100%; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 0.9rem; text-align: left; cursor: pointer; }
.topic-row:hover .chap-name { color: var(--accent); }
@media (prefers-reduced-motion: reduce) { .topic-card { animation: none; } }

/* The theme switch in the toolbar shows the moon in light mode and the sun in dark mode */
#theme-btn .sun { display: none; }
:root[data-theme="dark"] #theme-btn .sun { display: inline; }
:root[data-theme="dark"] #theme-btn .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-btn .sun { display: inline; }
  :root:not([data-theme="light"]) #theme-btn .moon { display: none; }
}

/* Home: today's streak and goal, with the review waiting */
.home-today { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 14px auto 0; color: var(--muted); font-size: 0.9rem; }
.home-today[hidden], .home-today [hidden] { display: none; }
.chip.strong, .home-today .chip { background: rgba(10, 122, 255, 0.1); color: var(--accent); font-weight: 600; }
.chip.strong:hover, .home-today .chip:hover { background: rgba(10, 122, 255, 0.18); }
.chip:disabled { cursor: default; }
.chip.locked { opacity: 0.5; }

/* Statistics: the pass forecast ring */
.ready-card { display: flex; align-items: center; gap: 18px; margin-top: 8px; padding: 16px 18px; border-radius: 22px; background: var(--surface); box-shadow: 0 0 0 0.5px var(--border); }
.ready-ring { width: 104px; height: 104px; flex: none; }
.ring-track { fill: none; stroke: var(--soft); stroke-width: 10; }
.ring-fill { fill: none; stroke-width: 10; stroke-linecap: round; transition: stroke-dasharray 0.8s ease; }
.ring-fill.good { stroke: #34c759; }
.ring-fill.mid { stroke: #ff9f0a; }
.ring-fill.bad { stroke: #ff453a; }
.ring-num { font-size: 22px; font-weight: 700; fill: var(--text); }
.ready-title { font-weight: 700; font-size: 1.05rem; }
.ready-level { font-weight: 600; margin: 2px 0; }
.ready-level::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.ready-level.good::before { background: #34c759; }
.ready-level.mid::before { background: #ff9f0a; }
.ready-level.bad::before { background: #ff453a; }
.ready-text .stats { margin: 2px 0 0; }
.ready-hint { font-size: 0.8rem; }
@media (max-width: 480px) { .ready-card { flex-direction: column; text-align: center; } }
.metric-bar { margin-top: 8px; height: 6px; }
.metrics { margin-top: 12px; }
.due-lead { margin: 0 0 10px; }

/* Charts: thin marks, recessive grid, one hit column per day for the tooltip */
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 12px; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.chart-bar { fill: var(--accent); }
.chart-hit { fill: transparent; }
.chart-hit:hover { fill: rgba(10, 122, 255, 0.07); }
.chart-tip { position: fixed; z-index: 40; pointer-events: none; padding: 6px 10px; border-radius: 10px; background: var(--text); color: var(--card); font-size: 0.8rem; white-space: nowrap; box-shadow: var(--shadow); }
.chart-tip[hidden] { display: none; }

/* Activity calendar: weeks as columns, Monday on top, one hue from light to dark */
.cal-wrap { overflow-x: auto; }
.cal { display: grid; grid-template-rows: repeat(7, 14px); grid-auto-flow: column; grid-auto-columns: 14px; gap: 3px; }
.cal-cell { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--soft); }
.cal-cell.blank { background: transparent; }
.cal-cell.lv1 { background: rgba(10, 122, 255, 0.25); }
.cal-cell.lv2 { background: rgba(10, 122, 255, 0.45); }
.cal-cell.lv3 { background: rgba(10, 122, 255, 0.7); }
.cal-cell.lv4 { background: var(--accent); }
.cal-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cal-legend { display: flex; align-items: center; gap: 4px; margin-top: 8px; color: var(--muted); font-size: 0.75rem; }
.cal-legend span:first-child { margin-right: 4px; }
.cal-legend span:last-child { margin-left: 4px; }

/* Topic map: every topic as a tile, coloured by how it goes, with the number in words */
.topic-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.tmap { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 12px; border: 0; border-left: 5px solid #c4c0b8; border-radius: 16px; background: var(--surface); box-shadow: 0 0 0 0.5px var(--border); color: var(--text); font: inherit; cursor: pointer; transition: transform 0.15s ease; }
.tmap:hover { transform: translateY(-2px); }
.tmap.good { border-left-color: #34c759; }
.tmap.mid { border-left-color: #ff9f0a; }
.tmap.bad { border-left-color: #ff453a; }
.tmap-name { font-size: 0.85rem; font-weight: 600; line-height: 1.25; }
.tmap-pct { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.02em; }
.tmap.none .tmap-pct { font-size: 0.85rem; font-weight: 500; color: var(--muted); }
.tmap-sub { font-size: 0.72rem; color: var(--muted); }
.map-note { margin: 0 0 10px; }
.st-empty-box { text-align: center; padding: 24px 8px 8px; }
.st-empty-box .chips { justify-content: center; }
.st-empty-icon { font-size: 2.4rem; }

/* Topics screen: the marathon and the bookmarks above the topics */
.extra-card .type-name { font-weight: 700; margin-bottom: 8px; display: block; }
.topic-list + .topic-list { margin-top: 12px; }

/* Rules handbook */
.rules-search { width: 100%; margin: 4px 0 12px; }
.rule-topic { margin-top: 8px; border-radius: 18px; background: var(--surface); box-shadow: 0 0 0 0.5px var(--border); padding: 0 16px; }
.rule-topic > summary { display: flex; align-items: baseline; gap: 10px; padding: 14px 0; cursor: pointer; list-style: none; }
.rule-topic > summary::-webkit-details-marker { display: none; }
.rule-topic > summary::after { content: "›"; color: var(--muted); font-size: 1.2rem; transition: transform 0.2s ease; }
.rule-topic[open] > summary::after { transform: rotate(90deg); }
.rule-topic > summary .stats { margin: 0 0 0 auto; }
.rule-topic[open] { padding-bottom: 14px; }
.rule-list { list-style: none; margin: 0; padding: 0; }
.rule-chapter { margin: 12px 0 4px; font-size: 0.78rem; font-weight: 600; color: var(--accent); }
.rule-text { padding: 8px 0; line-height: 1.5; font-size: 0.92rem; box-shadow: inset 0 -0.5px 0 var(--border); }
.rule-topic .chip { margin-top: 12px; }
.sign-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.sign-item { display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; padding: 8px 4px; border-radius: 12px; background: var(--soft); }
.sign-item-pic { width: 64px; height: 64px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 600; }
.sign-item-pic svg { width: 64px; height: 64px; }
.sign-item-no { font-size: 0.72rem; font-weight: 700; color: var(--muted); }
.sign-item-name { font-size: 0.75rem; line-height: 1.25; }

/* Exam: the bookmark star and the marathon stop button next to the clock */
.exam-tools { display: flex; align-items: center; gap: 6px; flex: none; }
.mark-btn { width: 32px; height: 32px; border: 0; border-radius: 50%; background: var(--soft); color: var(--muted); font-size: 1.1rem; line-height: 1; cursor: pointer; }
.mark-btn.on { color: #ff9f0a; }
.mark-btn:hover { background: var(--chip-hover); }
.stop-btn[hidden] { display: none; }

/* Result: this attempt by topic */
.result-topics { margin-top: 14px; }
.result-topics[hidden], #compare-line[hidden] { display: none; }
.result-topics h3 { font-size: 0.95rem; margin: 0 0 8px; }
.rt-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.rt-chip { padding: 5px 10px; border-radius: 999px; background: var(--soft); font-size: 0.8rem; }
.rt-chip::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #c4c0b8; }
.rt-chip.good::before { background: #34c759; }
.rt-chip.mid::before { background: #ff9f0a; }
.rt-chip.bad::before { background: #ff453a; }
