/* Same font and background as the home page, so every site feels like one world. */
@font-face {
  font-family: "Display";
  src: url("assets/display-font.woff") format("woff");
  font-weight: 700;
  font-display: swap;
}

:root {
  --ink: #000;
  --shadow: #acb4bf;
  --white: #fff;
  --panel: rgba(15, 23, 42, 0.85);
  --edge: rgba(255, 255, 255, 0.25);
  --good: #4ade80;
  --bad: #ef4444;
  --gold: #fde047;
  --cell: 2.4rem;                 /* size of one digit square on the paper */
}

html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: #000 url("assets/background.jpg") center / cover no-repeat fixed;
  color: var(--white);
  font-family: "Display", "Arial Black", system-ui, sans-serif;
  font-weight: 700;
}

header { padding: 1.5rem; }

.brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  font-size: clamp(1.6rem, 6vw, 3.5rem);
  transition: transform 0.1s;
}
.brand:hover { transform: translateY(-2px); }
.emoji { font-size: 0.4em; margin: 0 0.15em; }

/* The "splice" effect from the home page: hollow outline over an offset grey copy. */
.splice {
  position: relative;
  z-index: 0;
  display: inline-block;
  color: transparent;
  -webkit-text-stroke: 0.04em var(--ink);
  line-height: 1.39;
  white-space: nowrap;
}
.splice::before {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  transform: translate(0.045em, 0.045em);
  color: var(--shadow);
  -webkit-text-stroke: 0;
  z-index: -1;
}

/* Game + leaderboard side by side; stacked on phones. */
main {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 1.5rem;
  padding: 1rem;
}
.game { text-align: center; width: min(520px, 100%); }
.status { margin: 0.75rem 0 0; font-family: system-ui, sans-serif; font-weight: 400; }
.status small { opacity: 0.7; }

/* Mode + level pickers */
.modes { display: flex; justify-content: center; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.pill.on { background: var(--good); }
.level-pick { font: 700 0.95rem system-ui, sans-serif; }
.level-pick select { font: inherit; padding: 0.25rem 0.4rem; border-radius: 8px; border: 2px solid var(--ink); }

/* The dragon */
.arena { display: grid; justify-items: center; gap: 0.3rem; margin-bottom: 0.4rem; }
.dragon-box { position: relative; height: 5.5rem; display: grid; place-items: center; }
.dragon {
  font-size: 4.5rem; line-height: 1; display: inline-block;
  transition: transform 0.3s, opacity 0.3s, filter 0.3s;
}
.dragon.hit { animation: shake 0.3s; }
.dragon.fly { transform: translate(200px, -160px) scale(0.3); opacity: 0; }
.dragon.enter { animation: land 0.6s ease-out; }
@keyframes land {
  0%   { transform: translate(-200px, -120px) scale(0.3); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
.fire {
  position: absolute; left: 50%; top: 10%; font-size: 3rem; line-height: 1;
  opacity: 0; transform: translateX(-50%) scale(0.2); pointer-events: none;
}
.fire.on { animation: breathe 0.7s ease-out; }
@keyframes breathe {
  0%   { opacity: 0; transform: translateX(-50%) scale(0.2); }
  30%  { opacity: 1; transform: translateX(-50%) translateY(30px) scale(1.4); }
  100% { opacity: 0; transform: translateX(-50%) translateY(70px) scale(1.8); }
}
/* Dragon skins are just colour filters on the same emoji. */
.dragon.ice    { filter: hue-rotate(180deg) saturate(1.4); }
.dragon.gold   { filter: sepia(1) saturate(4) hue-rotate(-10deg); }
.dragon.shadow { filter: brightness(0.25) contrast(1.4); }
.dragon.ruby   { filter: hue-rotate(250deg) saturate(1.6); }
.dragon-hp { width: min(240px, 80%); height: 12px; background: rgba(0,0,0,0.5); border: 2px solid var(--edge); border-radius: 100vw; overflow: hidden; }
#hp { height: 100%; width: 100%; background: var(--good); transition: width 0.3s, background 0.3s; }
.run-bar { margin: 0; font-family: system-ui, sans-serif; font-size: 1.1rem; display: flex; gap: 1rem; justify-content: center; min-height: 1.5rem; }
.combo { color: var(--gold); }

/* The prompt: what to do next. */
.prompt {
  margin: 0.3rem 0 0.6rem; min-height: 2.6rem;
  font-family: system-ui, sans-serif; font-weight: 600; font-size: 1.15rem;
  display: grid; place-items: center;
}
.prompt.explain { color: var(--gold); font-size: 1rem; }

/* ---- The paper ---------------------------------------------------------------- */
.paper {
  display: inline-grid;               /* columns and rows are set from game.js */
  padding: 1rem 1.25rem;
  border-radius: 6px;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.5);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.62);
  max-width: 100%;
  overflow-x: auto;
  user-select: none;
  --paper-ink: #1f2a44;               /* pencil colour, set by the pencil skin */
  --paper-rule: #b9c9e6;              /* the lines on the paper */
}
.cell {
  width: var(--cell); height: var(--cell);
  display: grid; place-items: center;
  color: var(--paper-ink);
  position: relative;
  border-radius: 4px;
}
.cell.narrow { width: calc(var(--cell) * 0.35); }
.cell.divisor { opacity: 0.9; }
.cell.top { border-top: 3px solid var(--paper-ink); }           /* the line over the dividend */
.cell.left { border-left: 3px solid var(--paper-ink); border-top-left-radius: 8px; }
.cell.under { border-bottom: 2px solid var(--paper-ink); }    /* line under a product */
.cell.minus::before { content: "−"; position: absolute; right: 100%; top: 0; width: var(--cell); height: var(--cell); display: grid; place-items: center; opacity: 0.7; }
.cell.active { background: rgba(250, 204, 21, 0.35); outline: 2px dashed rgba(250, 204, 21, 0.9); }
.cell.active.empty::after { content: ""; width: 2px; height: 55%; background: var(--paper-ink); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cell.good { color: var(--paper-ink); }
.cell.shown { color: #b45309; }                                 /* answers the game had to show */
.cell.wrong { animation: shake 0.35s; background: rgba(239, 68, 68, 0.35); }
.cell.bring { cursor: pointer; outline: 2px dashed rgba(74, 222, 128, 0.9); background: rgba(74, 222, 128, 0.25); animation: bounce 0.8s infinite; }
.cell.fall { animation: fall 0.35s ease-in; }
.cell.rem { width: auto; padding: 0 0.4rem; white-space: nowrap; justify-self: start; }
.cell.quotient { font-size: 1.1em; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes bounce { 0%,100% { transform: none; } 50% { transform: translateY(-4px); } }
@keyframes fall { 0% { transform: translateY(calc(var(--cell) * -1)); opacity: 0; } 100% { transform: none; opacity: 1; } }

/* Paper skins */
.paper-plain { background: #fffdf7 repeating-linear-gradient(transparent 0 calc(var(--cell) - 1px), var(--paper-rule) calc(var(--cell) - 1px) var(--cell)); background-position: 0 1rem; }
.paper-graph {
  background: #f8fafc;
  background-image: linear-gradient(#cbd5e1 1px, transparent 1px), linear-gradient(90deg, #cbd5e1 1px, transparent 1px);
  background-size: var(--cell) var(--cell); background-position: 1.25rem 1rem;
}
.paper-parchment { background: #f1e2b6; --paper-rule: #d6c48f; box-shadow: 4px 4px 0 #6b4f1d; border: 3px double #a9884b; }
.paper-chalk { background: #1e4d3a; --paper-ink: #f8fafc; --paper-rule: #2f6b52; border: 8px solid #7c5a3a; }
.paper-neon { background: #0b0b12; --paper-ink: #22d3ee; --paper-rule: #1f2937; box-shadow: 0 0 20px #22d3ee88; }
.paper-neon .cell { text-shadow: 0 0 6px currentColor; }

/* Pencil skins: the colour of the numbers. */
.pencil-blue    { --paper-ink: #1d4ed8; }
.pencil-red     { --paper-ink: #b91c1c; }
.pencil-purple  { --paper-ink: #7e22ce; }
.pencil-green   { --paper-ink: #15803d; }
.pencil-rainbow .cell.good, .pencil-rainbow .cell.quotient { background-image: linear-gradient(90deg, #ef4444, #f59e0b, #22c55e, #3b82f6, #a855f7); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* Hint strip: the divisor's times table. */
.hint-strip { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.3rem; margin: 0.6rem 0 0; }
.hint-strip[hidden] { display: none; }
.hint-strip span { font: 700 0.9rem ui-monospace, Menlo, monospace; padding: 0.2rem 0.5rem; background: var(--panel); border: 1px solid var(--edge); border-radius: 6px; }

.controls { display: flex; justify-content: center; gap: 0.5rem; margin-top: 0.7rem; flex-wrap: wrap; }

/* Number pad for touch screens. Hidden when a mouse/keyboard is likely. */
.numpad { display: grid; grid-template-columns: repeat(3, 4rem); gap: 0.35rem; justify-content: center; margin-top: 0.7rem; }
.numpad button {
  font: 700 1.3rem system-ui, sans-serif; height: 2.8rem; border-radius: 10px;
  border: 2px solid var(--ink); background: linear-gradient(180deg, var(--white), var(--shadow)); color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink); cursor: pointer;
}
.numpad button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.numpad .go { background: var(--good); font-size: 1rem; }
@media (hover: hover) and (pointer: fine) { .numpad { display: none; } }

.volume { display: flex; justify-content: center; align-items: center; gap: 0.5rem; margin-top: 0.75rem; }
#mute { font-size: 1.3rem; background: none; border: none; cursor: pointer; padding: 0.2rem; }
.volume input { width: 140px; accent-color: var(--good); }

.leaderboard {
  width: min(280px, 100%);
  padding: 1rem 1.25rem;
  background: var(--panel);
  border: 2px solid var(--edge);
  border-radius: 8px;
}
.leaderboard h2 { margin: 0 0 0.5rem; font-size: 1.4rem; }
.leaderboard ol { margin: 0; padding-left: 1.6rem; font-family: system-ui, sans-serif; font-weight: 400; }
.leaderboard li { display: flex; justify-content: space-between; padding: 0.15rem 0; }
.leaderboard li.me { color: var(--good); font-weight: 700; }
.leaderboard .muted { opacity: 0.6; }
.leaderboard li[title] { cursor: help; }
.totals {
  margin: 1rem 0 0; padding-top: 0.75rem; border-top: 1px solid var(--edge);
  font-family: system-ui, sans-serif; font-weight: 400; line-height: 1.6;
}
.totals.small { font-size: 0.8rem; opacity: 0.7; border: none; padding-top: 0.3rem; margin-top: 0.4rem; }
.leaderboard h3 { margin: 1rem 0 0.4rem; font-size: 1.1rem; }
.unlocks { list-style: none; margin: 0; padding: 0; font-family: system-ui, sans-serif; font-weight: 400; font-size: 0.9rem; }
.unlocks li { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.15rem 0; }
.unlocks .locked { opacity: 0.55; }
.unlocks .unlocked span:last-child { color: var(--good); font-weight: 700; }

/* Small pill button. */
.pill {
  font: 700 0.95rem system-ui, sans-serif;
  padding: 0.3rem 0.9rem;
  color: var(--ink);
  background: linear-gradient(180deg, var(--white), var(--shadow));
  border: 2px solid var(--ink);
  border-radius: 100vw;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
}
.pill:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.pill:disabled { opacity: 0.5; cursor: default; transform: none; }
.account { display: flex; justify-content: center; gap: 0.5rem; margin-top: 0.6rem; flex-wrap: wrap; }

/* Shop and run-over panels */
.shop {
  width: min(560px, 92vw); max-height: 88vh; overflow-y: auto;
  padding: 1.25rem 1.5rem; background: var(--panel); border: 2px solid var(--edge); border-radius: 12px;
}
.shop-head { display: flex; align-items: center; gap: 1rem; }
.shop-head h2 { margin: 0; font-size: 1.8rem; flex: 1; }
.shop-wallet { font-size: 1.1rem; color: var(--gold); }
.shop-head button { font-size: 1.2rem; background: none; border: 2px solid var(--edge); border-radius: 50%; color: var(--white); width: 2rem; height: 2rem; cursor: pointer; }
.shop h3 { margin: 1.25rem 0 0.25rem; font-size: 1.2rem; }
.shop-hint { margin: 0 0 0.5rem; font-family: system-ui, sans-serif; font-weight: 400; font-size: 0.85rem; opacity: 0.7; }
.shop-row { display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 1rem; align-items: center; padding: 0.5rem 0; border-top: 1px solid var(--edge); }
.shop-row .buy { grid-column: 2; grid-row: 1 / span 2; }
.shop-label { font-size: 1.05rem; }
.shop-detail { font-family: system-ui, sans-serif; font-weight: 400; font-size: 0.85rem; opacity: 0.75; }
.buy { font: inherit; font-size: 0.9rem; padding: 0.35rem 0.8rem; border-radius: 100vw; border: 2px solid var(--white); background: var(--good); color: #000; cursor: pointer; white-space: nowrap; }
.buy:disabled { background: #475569; color: #cbd5e1; border-color: var(--edge); cursor: default; }
.skins { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.75rem; }
.skin-card { display: grid; justify-items: center; gap: 0.4rem; padding: 0.75rem; background: rgba(0,0,0,0.3); border: 2px solid var(--edge); border-radius: 8px; }
.skin-card.equipped { border-color: var(--good); }
.skin-card .preview { width: 64px; height: 44px; display: grid; place-items: center; border-radius: 4px; font-family: ui-monospace, monospace; font-size: 1.2rem; }
.skin-card .preview.dragon { font-size: 2.2rem; background: none; }
.run-over { text-align: center; }
.run-over h2 { margin: 0; font-size: 2.2rem; }
.run-over .big { font-size: 3rem; margin: 0.5rem 0; color: var(--gold); }
.run-over p { font-family: system-ui, sans-serif; font-weight: 400; }

/* A fixed-height strip above the game so notifications never push things around. */
.notice-bar { height: 3.2rem; display: flex; justify-content: center; align-items: center; margin-bottom: 0.3rem; }
#banner {
  padding: 0.35rem 1.2rem; font-size: 1.4rem; color: var(--ink);
  background: linear-gradient(180deg, var(--white), var(--shadow));
  border: 3px solid var(--ink); border-radius: 100vw; box-shadow: 4px 4px 0 var(--ink);
  opacity: 0; transform: translateY(6px); transition: opacity 0.2s, transform 0.2s;
}
#banner.show { opacity: 1; transform: translateY(0); }

#countdown span { font-size: clamp(6rem, 25vw, 12rem); color: var(--white); -webkit-text-stroke: 4px var(--ink); animation: pop 1s ease-out; }
@keyframes pop { 0% { transform: scale(0.4); opacity: 0; } 20% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); opacity: 0.9; } }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(4px); z-index: 10; }
.overlay[hidden] { display: none; }
.overlay form { display: grid; gap: 1rem; padding: 2rem; background: var(--panel); border: 2px solid var(--edge); border-radius: 12px; text-align: center; }
.overlay h2 { margin: 0; font-size: 2rem; }

/* Fire flash: the whole screen glows orange, then fades. */
#flash { position: fixed; inset: 0; background: #f97316; opacity: 0; pointer-events: none; z-index: 5; }
#flash.on { animation: flash 0.9s ease-out; }
@keyframes flash { 0% { opacity: 0.7; } 100% { opacity: 0; } }

footer { padding: 1rem; text-align: center; font-family: system-ui, sans-serif; font-weight: 400; font-size: 0.8rem; opacity: 0.7; }
footer a { color: inherit; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
@media (max-width: 480px) { :root { --cell: 2rem; } }
