/* Patrick Hand (SIL Open Font License), hosted with the game so it works offline */
@font-face { font-family: "Patrick Hand"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(fonts/patrickhand-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Patrick Hand"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(fonts/patrickhand-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
:root {
  --paper: #fbfaf5;
  --paper-line: #dfe8f1;
  --ink: #1f2328;
  --ink-soft: #5b6470;
  --card: #ffffff;
  --border: #d5d9de;
  --p1: #2f6fdb;
  --p2: #e0582b;
  --hp: #2fa65a;
  --hp-low: #d93a3a;
  --ep: #f0b429;
  --beam1: #59b7ff;
  --beam2: #ff8a3d;
  --ok: #1f9d55;
  --bad: #d64545;
  --accent: #7a4fe0;
  --shadow: 0 2px 0 rgba(0,0,0,.08), 0 6px 18px rgba(0,0,0,.06);
  --hand: "Patrick Hand", "Comic Sans MS", "Chalkboard SE", "PingFang SC", "Microsoft YaHei", sans-serif;
  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1d2420; --paper-line: #26302a; --ink: #eef2ee; --ink-soft: #a9b4ac;
    --card: #252d28; --border: #3a453e; --p1: #6ea4ff; --p2: #ff8a5c;
    --shadow: 0 2px 0 rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1d2420; --paper-line: #26302a; --ink: #eef2ee; --ink-soft: #a9b4ac;
  --card: #252d28; --border: #3a453e; --p1: #6ea4ff; --p2: #ff8a5c;
  --shadow: 0 2px 0 rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background-color: var(--paper);
  background-image: linear-gradient(var(--paper-line) 1px, transparent 1px);
  background-size: 100% 32px;
  color: var(--ink);
  font-family: var(--sans);
  min-height: 100vh;
  overflow-x: hidden;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; color: inherit; }
button:disabled { cursor: not-allowed; opacity: .4; }
input, select { font: inherit; color: var(--ink); background: var(--card); border: 1.5px solid var(--border); border-radius: 8px; padding: 6px 8px; }

.screen { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- setup ---------- */
.logo { font-family: var(--hand); font-size: clamp(40px, 8vw, 72px); text-align: center; margin: 20px 0 4px; letter-spacing: 1px; }
.logo span { display: block; font-size: .45em; color: var(--ink-soft); }
.tagline { text-align: center; color: var(--ink-soft); margin: 0 0 24px; line-height: 1.6; }
.setup-players { display: flex; gap: 16px; align-items: stretch; justify-content: center; flex-wrap: wrap; }
.pcard { background: var(--card); border: 2px solid var(--border); border-radius: 16px; padding: 16px; flex: 1 1 260px; max-width: 360px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.pcard.p1 { border-color: var(--p1); } .pcard.p2 { border-color: var(--p2); }
.pcard-head { font-family: var(--hand); font-size: 22px; display: flex; align-items: center; gap: 8px; }
.pcard label { display: grid; gap: 4px; font-size: 14px; color: var(--ink-soft); }
.pcard input { font-size: 18px; width: 100%; }
.range { display: flex; gap: 8px; align-items: center; }
.vs { font-family: var(--hand); font-size: 40px; align-self: center; }
.mini { width: 32px; height: 32px; flex: none; }
.mini circle { fill: none; stroke: currentColor; stroke-width: 2.5; }
.mini path { fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linejoin: round; }
.p1 .mini { color: var(--p1); } .p2 .mini { color: var(--p2); }

details.settings, details.rules { max-width: 760px; margin: 20px auto 0; background: var(--card); border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 16px; }
details summary { cursor: pointer; font-weight: 600; }
.settings .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 12px 0; }
.settings label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.rules ul { line-height: 1.7; padding-left: 20px; }
.link { background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline; }

.big { display: block; margin: 24px auto 0; font-size: 22px; font-family: var(--hand); padding: 10px 32px; border-radius: 999px; border: 2.5px solid var(--ink); background: var(--ep); color: #1f2328; box-shadow: 0 4px 0 var(--ink); transition: transform .08s; }
.big:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.ghost { background: transparent; border: 1.5px solid var(--border); border-radius: 999px; padding: 8px 14px; }
.ghost:hover:not(:disabled) { border-color: var(--ink-soft); }

/* ---------- battle ---------- */
.turnbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.turn-badge { display: flex; align-items: center; gap: 10px; font-family: var(--hand); font-size: 24px; padding: 6px 16px 6px 8px; border: 2.5px solid currentColor; border-radius: 0 0 24px 0; border-top: none; border-left: none; color: var(--p1); }
.turn-badge.p2 { color: var(--p2); }
.turn-badge span { color: var(--ink); }
.turn-badge.pop { animation: pop .4s; }
@keyframes pop { 50% { transform: scale(1.08); } }

.arena-wrap { position: relative; margin-top: 8px; }
#arena { width: 100%; height: auto; display: block; overflow: visible; }
.arena-wrap.shake { animation: shake .5s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }

.hud { position: absolute; top: 0; width: min(34%, 300px); font-size: 13px; }
.hud1 { left: 0; } .hud2 { right: 0; text-align: right; }
.hud .nm { font-family: var(--hand); font-size: 24px; line-height: 1; }
.hud1 .nm { color: var(--p1); } .hud2 .nm { color: var(--p2); }
.hud.active .nm::after { content: " ◀"; font-size: 16px; }
.hud2.active .nm::after { content: ""; } .hud2.active .nm::before { content: "▶ "; font-size: 16px; }
.bar { position: relative; height: 16px; border: 2px solid var(--ink); border-radius: 8px; background: var(--card); overflow: hidden; margin-top: 4px; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--hp); transition: width .6s ease, background .3s; }
.hud2 .bar > i { inset: 0 0 0 auto; }
.bar.ep > i { background: var(--ep); }
.bar.low > i { background: var(--hp-low); }
.bar > b { position: relative; display: block; font-size: 11px; line-height: 12px; padding: 0 6px; font-weight: 700; color: var(--ink); }
.bar.ep .tick { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: .5; }
.hud .lvl { font-size: 12px; color: var(--ink-soft); margin-top: 2px; min-height: 16px; }

.ground { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; }
.fig { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; transition: transform .5s; }
.fig .face { stroke-width: 3.5; }
.fig.p1 .head { stroke: var(--p1); } .fig.p2 .head { stroke: var(--p2); }
.fig.hit { animation: hit .5s; }
@keyframes hit { 0%,100% { opacity: 1; } 20%,60% { opacity: .2; } }
.fig .arm-up { display: none; } .fig.casting .arm-up { display: inline; } .fig.casting .arm-down { display: none; }
.fig.active .shadow { fill: currentColor; opacity: .18; }
.fig.p1 { color: var(--p1); } .fig.p2 { color: var(--p2); }
.fig .shadow { stroke: none; fill: var(--ink); opacity: .08; }

.fxtext { font-family: var(--hand); fill: var(--ink); font-size: 22px; paint-order: stroke; stroke: var(--paper); stroke-width: 4px; }
.dmg { font-family: var(--hand); font-size: 46px; fill: var(--bad); stroke: var(--paper); stroke-width: 5px; paint-order: stroke; font-weight: 700; }
.dmg-sub { font-family: var(--sans); font-size: 16px; fill: var(--ink-soft); }

.panel { display: grid; grid-template-columns: 1fr 260px; gap: 16px; margin-top: 8px; }
@media (max-width: 820px) { .panel { grid-template-columns: 1fr; } }
.qcard { background: var(--card); border: 2px solid var(--border); border-radius: 18px; padding: 16px 18px; box-shadow: var(--shadow); border-top: 6px solid var(--p1); }
.qcard.p2 { border-top-color: var(--p2); }
.qmeta { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--paper); border: 1px solid var(--border); }
.tag.diff { background: var(--ep); color: #1f2328; border-color: transparent; font-weight: 700; }
.tag.passed { background: var(--accent); color: #fff; border-color: transparent; }
.qtext { font-size: clamp(20px, 3vw, 28px); font-weight: 600; margin: 14px 0 4px; line-height: 1.35; }
.qzh { font-size: 17px; color: var(--ink-soft); margin-bottom: 4px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
@media (max-width: 480px) { .opts { grid-template-columns: 1fr; } }
.opt { text-align: left; font-size: 20px; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--border); background: var(--paper); display: flex; gap: 10px; align-items: center; min-height: 54px; }
.opt kbd { font-family: var(--sans); font-size: 12px; border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; color: var(--ink-soft); background: var(--card); }
.opt:hover:not(:disabled) { border-color: var(--ink-soft); }
.opt.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, var(--card)); opacity: 1; }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 15%, var(--card)); opacity: 1; }
.feedback { margin-top: 12px; padding: 10px 14px; border-radius: 10px; font-size: 17px; }
.feedback.ok { background: color-mix(in srgb, var(--ok) 14%, var(--card)); }
.feedback.bad { background: color-mix(in srgb, var(--bad) 14%, var(--card)); }
.feedback small { display: block; color: var(--ink-soft); margin-top: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: center; }
/* Next sits in the arena between the two players, so a long answer in the card can't push it around */
.arena-wrap .next { position: absolute; left: 50%; top: 60%; transform: translate(-50%, -50%); z-index: 5; font-size: 20px; padding: 8px 26px; white-space: nowrap; animation: nextIn .3s ease-out; }
.arena-wrap .next:active { transform: translate(-50%, calc(-50% + 3px)); }
@keyframes nextIn { from { opacity: 0; transform: translate(-50%, -30%); } }
@media (max-width: 600px) { .arena-wrap .next { font-size: 16px; padding: 6px 16px; top: 66%; } }
.attack { margin-left: auto; font-weight: 700; border-radius: 999px; padding: 8px 18px; border: 2px solid var(--ink); background: var(--card); }
.attack.ready { background: var(--ep); color: #1f2328; animation: glow 1.2s infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--ep) 35%, transparent); } }

.log { list-style: none; margin: 0; padding: 12px; background: var(--card); border: 1.5px solid var(--border); border-radius: 14px; max-height: 320px; overflow-y: auto; font-size: 13px; display: flex; flex-direction: column-reverse; gap: 6px; }
.log li { line-height: 1.4; }
.log .c1 { color: var(--p1); font-weight: 700; } .log .c2 { color: var(--p2); font-weight: 700; }

/* ---------- KO ---------- */
.overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--paper) 80%, transparent); display: grid; place-items: center; z-index: 10; padding: 16px; backdrop-filter: blur(3px); }
.ko-box { text-align: center; }
.ko-text { font-family: var(--hand); font-size: clamp(120px, 28vw, 240px); line-height: 1; letter-spacing: 20px; color: var(--ink); -webkit-text-stroke: 2px var(--ink); animation: slam .6s cubic-bezier(.2,1.6,.4,1); }
@keyframes slam { from { transform: scale(3); opacity: 0; } }
.ko-win { font-family: var(--hand); font-size: clamp(32px, 7vw, 56px); margin-top: 4px; }
.ko-stats { margin: 16px auto 0; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.ko-stats td, .ko-stats th { padding: 6px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.ko-btns { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }
.ko-btns .ghost { margin-top: 24px; }

.topbtns { display: flex; gap: 8px; }

@media (max-width: 600px) {
  .turn-badge { font-size: 18px; }
  .arena-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
  .hud { position: static; width: auto; }
  #arena { grid-column: 1 / -1; margin-top: 4px; }
  .hud .lvl { font-size: 11px; }
}

/* energy gain: "+N ⚡" flies from the question into the energy bar */
.ep-fly { position: fixed; z-index: 20; pointer-events: none; font-family: var(--hand); font-size: 34px; font-weight: 700;
  color: #1f2328; background: var(--ep); border: 2.5px solid var(--ink); border-radius: 999px; padding: 0 14px; white-space: nowrap;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--ep) 35%, transparent); }
.hud .bar.ep.gain { animation: epGlow .9s ease-out; }
@keyframes epGlow { 0% { box-shadow: 0 0 0 0 var(--ep); } 30% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--ep) 60%, transparent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.ep-pop { position: absolute; top: 40px; font-family: var(--hand); font-size: 26px; font-weight: 700; color: #b7791f; pointer-events: none; animation: epPop 1.2s ease-out forwards; }
.hud1 .ep-pop { right: -44px; } .hud2 .ep-pop { left: -44px; }
@keyframes epPop { from { transform: translateY(6px); opacity: 0; } 20% { opacity: 1; } to { transform: translateY(-22px); opacity: 0; } }
@media (max-width: 600px) { .hud { position: relative; } .hud1 .ep-pop { right: 0; } .hud2 .ep-pop { left: 0; } }

/* translation language */
.tr { color: var(--ink-soft); font-weight: 400; }
.big .tr, .attack.ready .tr, .tag.diff .tr { color: inherit; opacity: .75; }
.tag.passed .tr { color: #fff; opacity: .85; }
.rules li .tr, .tagline .tr { display: block; }
.ko-win .tr { display: block; font-size: .5em; color: var(--ink-soft); }
.langbar { display: flex; justify-content: flex-end; }
.langpick { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-soft); }
.langpick select { padding: 4px 6px; font-size: 14px; }
@media (max-width: 600px) {
  .turnbar { flex-wrap: wrap; row-gap: 6px; }
  .turn-badge { white-space: nowrap; }
  .topbtns { margin-left: auto; }
  .langpick select { max-width: 150px; }
}

/* language picker (custom, always opens downwards) */
.langSel { position: relative; display: inline-block; }
.ls-btn { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; padding: 5px 10px; border: 1.5px solid var(--border); border-radius: 8px; background: var(--card); color: var(--ink); white-space: nowrap; }
.ls-btn:hover { border-color: var(--ink-soft); }
.ls-btn i { font-style: normal; font-size: 11px; color: var(--ink-soft); }
.ls-list { position: absolute; top: calc(100% + 4px); right: 0; z-index: 30; min-width: 100%; margin: 0; padding: 4px; list-style: none;
  background: var(--card); border: 1.5px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); overflow-y: auto; }
.ls-list li { padding: 7px 12px; border-radius: 6px; font-size: 14px; white-space: nowrap; cursor: pointer; color: var(--ink); }
.ls-list li:hover, .ls-list li:focus { background: var(--paper); outline: none; }
.ls-list li[aria-selected="true"] { font-weight: 700; color: var(--accent); }
.ls-list li[aria-selected="true"]::after { content: " ✓"; }
@media (max-width: 600px) { .ls-btn { max-width: 160px; overflow: hidden; } }

/* whose turn: spotlight the current player, fade the other one */
.fig .turn-mark { display: none; }
.fig.active .turn-mark { display: inline; }
.turn-mark .halo { fill: currentColor; fill-opacity: .12; stroke: currentColor; stroke-width: 3; stroke-opacity: .5; transform-box: fill-box; transform-origin: center; animation: halo 1.6s ease-in-out infinite; }
.turn-mark .arrow { fill: currentColor; stroke: none; transform-box: fill-box; animation: bob .8s ease-in-out infinite alternate; }
@keyframes halo { 50% { transform: scale(1.12); fill-opacity: .2; } }
@keyframes bob { to { transform: translateY(10px); } }
.fig, .hud { transition: opacity .35s, filter .35s; }
.spot .fig:not(.active) { opacity: .3; }
.spot .hud:not(.active) { opacity: .4; filter: grayscale(1); }
.hud.active .nm { font-size: 28px; }
@media (prefers-reduced-motion: reduce) { .turn-mark .halo, .turn-mark .arrow { animation: none; } }

/* phones and tablets */
button, .opt, .ls-list li { touch-action: manipulation; } /* no double-tap zoom on quick taps */
@media (pointer: coarse) {
  input, select { font-size: 16px; } /* smaller text makes iPhone zoom in when the box is tapped */
  .ls-btn { min-height: 40px; }
  .ls-list li { padding: 10px 14px; }
}
/* phone turned sideways: battle on the left, question on the right */
@media (orientation: landscape) and (max-height: 500px) {
  .screen { padding: 8px 12px; max-width: none; }
  #battle:not(.hidden) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); grid-template-rows: auto 1fr; gap: 6px 14px; min-height: 100vh; }
  #battle .turnbar { grid-column: 1 / -1; }
  #battle .turn-badge { font-size: 16px; padding: 2px 12px 2px 4px; }
  #battle .arena-wrap { grid-column: 1; grid-row: 2; align-self: start; margin-top: 0; }
  #battle .panel { grid-column: 2; grid-row: 2; display: block; margin-top: 0; }
  #battle .log { display: none; }
  .hud { width: 46%; } .hud .nm { font-size: 18px; } .hud.active .nm { font-size: 20px; }
  #arena { margin-top: 64px; }
  .qcard { padding: 10px 12px; }
  .qtext { font-size: 18px; margin: 8px 0 2px; }
  .opts { gap: 6px; margin-top: 8px; }
  .opt { font-size: 17px; min-height: 42px; padding: 6px 10px; }
  .actions { margin-top: 8px; }
  .arena-wrap .next { top: 72%; font-size: 15px; padding: 6px 14px; }
  .hud { position: absolute; } .hud1 .ep-pop { right: 0; } .hud2 .ep-pop { left: 0; }
}
