/* Two worlds: anything from the story sits on cream paper in a book serif;
   anything from the spaceship is loud, chunky Karantina on grape. */
:root {
  --grape: #2a1b5e;
  --grape-2: #3b2787;
  --ink: #170d38;
  --paper: #fff4d6;
  --pink: #ff6fb5;
  --mint: #3ddc97;
  --tomato: #ff5a5f;
  --sun: #ffc93c;
  --sky: #8fdcff;
  --display: 'Karantina', 'Arial Narrow', 'Arial Hebrew', sans-serif;
  --book: 'Frank Ruhl Libre', 'David', 'Times New Roman', serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--grape);
  background-image:
    radial-gradient(circle at 12% 18%, #fff 0 1.5px, transparent 2px),
    radial-gradient(circle at 78% 9%, var(--sun) 0 2px, transparent 2.5px),
    radial-gradient(circle at 64% 72%, #fff 0 1.5px, transparent 2px),
    radial-gradient(circle at 30% 84%, var(--sky) 0 2px, transparent 2.5px),
    radial-gradient(circle at 90% 50%, #fff 0 1px, transparent 1.5px);
  background-size: 340px 340px, 420px 420px, 380px 380px, 460px 460px, 260px 260px;
  color: #fff;
  font-family: var(--book);
  font-weight: 500;
  font-size: 18px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.screen { display: none; min-height: 100dvh; padding: 24px 16px 32px; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; position: relative; }
.screen.active { display: flex; }

h1, h2, h3 { font-family: var(--display); font-weight: 700; margin: 0; line-height: 1; }
h2 { font-size: clamp(2.6rem, 9vw, 4rem); }
h3 { font-size: 1.9rem; }
p { margin: 0; }

.logo { font-size: clamp(4.2rem, 19vw, 8.5rem); color: var(--sun); text-shadow: 0 6px 0 var(--ink), 0 0 0 var(--ink); letter-spacing: .01em; margin-top: -18px; transform: rotate(-2deg); }
.tagline { font-size: 1.2rem; color: var(--sky); max-width: 26ch; }
#mascot { width: 220px; height: 150px; }
.note { color: #d9d0ff; max-width: 34ch; }
.err { color: var(--sun); min-height: 1.5em; max-width: 34ch; }
.err:empty { display: none; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.btn {
  font-family: var(--display); font-weight: 700; font-size: 2.1rem; line-height: 1;
  color: var(--ink); background: var(--mint);
  border: 4px solid var(--ink); border-radius: 20px;
  padding: 14px 30px 16px; min-width: 240px; cursor: pointer;
  box-shadow: 0 7px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--ink); }
.btn.pink { background: var(--pink); }
.btn.small { font-size: 1.6rem; min-width: 0; padding: 8px 20px 10px; box-shadow: 0 5px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: default; }

.chip {
  font-family: var(--book); font-weight: 700; font-size: 1rem;
  color: #fff; background: var(--grape-2);
  border: 2px solid #7a63d6; border-radius: 999px; padding: 8px 16px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--sun); color: var(--ink); border-color: var(--ink); }
.chip.corner { position: absolute; top: 14px; inset-inline-end: 14px; }
.chip.tiny { padding: 4px 10px; }

:is(.btn, .chip, .gun, input, .emoji-grid button, .tabs button):focus-visible { outline: 4px solid var(--sky); outline-offset: 3px; }

.stack { display: flex; flex-direction: column; gap: 18px; align-items: center; }
.row { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; }

.panel { background: var(--grape-2); border: 4px solid var(--ink); border-radius: 24px; padding: 18px; width: min(100%, 400px); display: flex; flex-direction: column; gap: 12px; align-items: center; box-shadow: 0 7px 0 var(--ink); }
.panel label, .panel .lbl { font-weight: 700; }
.panel .btn { min-width: 0; width: 100%; }
.panel .row { flex-wrap: nowrap; width: 100%; }
.panel .row .btn { width: auto; }

input {
  font-family: var(--book); font-weight: 700; font-size: 1.5rem; text-align: center;
  width: 100%; padding: 10px 12px; color: var(--ink); background: var(--paper);
  border: 4px solid var(--ink); border-radius: 14px;
}
#room-code { letter-spacing: .3em; font-size: 1.8rem; }

.tabs { display: flex; width: 100%; background: var(--ink); border-radius: 14px; padding: 4px; gap: 4px; }
.tabs button { flex: 1; font-family: var(--book); font-weight: 700; font-size: 1rem; padding: 8px 6px; border: 0; border-radius: 10px; background: transparent; color: #cfc4ff; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--sun); color: var(--ink); }

.slots { display: flex; gap: 10px; justify-content: center; direction: ltr; }
.slots span { width: 56px; height: 56px; border-radius: 14px; background: var(--ink); border: 3px dashed #7a63d6; font-size: 2rem; display: grid; place-items: center; }
.slots span.full { border-style: solid; border-color: var(--sun); cursor: pointer; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 10px; direction: ltr; }
.emoji-grid button { font-size: 1.5rem; aspect-ratio: 1; padding: 0; border: 0; border-radius: 10px; background: #4b35a3; cursor: pointer; }
.emoji-grid button:active { background: var(--sun); }

.key-show { direction: ltr; font-size: clamp(3.4rem, 18vw, 6rem); background: var(--paper); border: 5px solid var(--ink); border-radius: 28px; padding: 6px 26px; box-shadow: 0 8px 0 var(--ink); transform: rotate(-2deg); letter-spacing: .08em; }
.room-code { font-family: var(--display); font-weight: 700; font-size: clamp(5rem, 26vw, 9rem); line-height: 1; color: var(--sun); text-shadow: 0 6px 0 var(--ink); letter-spacing: .08em; }

.board { margin-top: 8px; }
.board h3 { color: var(--sky); }
.board ol { list-style: none; margin: 8px 0 0; padding: 0; min-width: 220px; }
.board li { display: flex; justify-content: space-between; gap: 24px; padding: 3px 0; border-bottom: 2px dotted #5b45b8; }

/* ---------- reading ---------- */
#s-read { justify-content: flex-start; padding-top: 18px; }
.timer { display: flex; align-items: center; gap: 12px; width: min(100%, 640px); }
.timer-bar { flex: 1; height: 16px; background: var(--ink); border-radius: 999px; overflow: hidden; }
.timer-bar i { display: block; height: 100%; width: 100%; background: var(--sun); border-radius: 999px; }
#timer-num { font-family: var(--display); font-weight: 700; font-size: 2rem; line-height: 1; min-width: 2ch; color: var(--sun); }
.page {
  background: var(--paper); color: var(--ink); text-align: start;
  width: min(100%, 640px); padding: 22px 24px 26px;
  border: 4px solid var(--ink); border-radius: 6px 22px 22px 6px;
  box-shadow: 0 8px 0 var(--ink), inset 10px 0 0 #f0dfb0;
}
[dir="rtl"] .page { border-radius: 22px 6px 6px 22px; box-shadow: 0 8px 0 var(--ink), inset -10px 0 0 #f0dfb0; }
.page h2 { font-family: var(--book); font-size: 1.7rem; line-height: 1.3; margin-bottom: 10px; }
.page p { font-size: clamp(1.25rem, 3.6vw, 1.55rem); line-height: 1.75; }
[dir="rtl"] .page p { line-height: 2; }

/* ---------- battle ---------- */
#s-battle { padding: 0; }
.stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; background: var(--ink); }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.label {
  position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform;
  width: max-content; max-width: 12.5em;
  background: var(--paper); color: var(--ink);
  font-family: var(--book); font-weight: 700; font-size: clamp(17px, 2.7vmin, 25px); line-height: 1.35; text-align: center;
  padding: 6px 12px 7px; border: 3px solid var(--ink); border-radius: 14px;
  box-shadow: 0 4px 0 rgba(23, 13, 56, .55);
  transition: opacity .25s;
}
[dir="rtl"] .label { line-height: 1.6; }
.label.gone { opacity: 0; }
.label.target { border-color: #fff; box-shadow: 0 0 0 4px var(--sky); }
.label.shake .tx { display: inline-block; animation: shake .35s; }
@keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(4px); } }
.label .tried { display: flex; gap: 4px; justify-content: center; }
.label .tried i { font-style: normal; font-size: .7em; line-height: 1; padding: 3px 7px; border-radius: 999px; color: var(--ink); text-decoration: line-through; opacity: .75; }

.hud { position: absolute; top: 0; left: 0; right: 0; height: 56px; padding: 8px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; pointer-events: none; font-family: var(--display); font-size: 1.9rem; line-height: 1; }
.hud > * { pointer-events: auto; display: flex; align-items: center; gap: 8px; }
.hud b { color: var(--sun); font-weight: 700; }
.shields { direction: ltr; display: inline-flex; gap: 3px; }
.shields i { width: 20px; height: 24px; background: var(--sky); border: 2.5px solid var(--ink); border-radius: 4px 4px 12px 12px; }
.shields i.off { background: #4a3a8a; opacity: .6; }
.hud-opp { color: var(--pink); }
.hud-opp .shields i { width: 14px; height: 17px; background: var(--pink); }
.hud-opp .shields i.off { background: #4a3a8a; }

.hint { position: absolute; left: 0; right: 0; bottom: 150px; text-align: center; padding: 0 16px; font-weight: 700; color: #fff; text-shadow: 0 2px 0 var(--ink), 0 0 12px var(--ink); pointer-events: none; }
.hint:empty { display: none; }

.guns { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 3vw max(10px, env(safe-area-inset-bottom)); display: flex; justify-content: space-around; align-items: flex-end; gap: 8px; direction: ltr; pointer-events: none; }
.gun {
  pointer-events: auto; position: relative; cursor: grab; touch-action: none;
  width: clamp(98px, 28vw, 180px); padding: 8px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 0;
  font-family: var(--display); font-weight: 700; font-size: clamp(1.5rem, 5.6vw, 2.1rem); line-height: 1; color: var(--ink);
  border: 4px solid var(--ink); border-radius: 26px 26px 12px 12px;
  box-shadow: inset 0 -10px 0 rgba(23, 13, 56, .22);
  transition: transform .12s;
}
.gun::before { content: ''; position: absolute; top: -26px; left: 50%; width: 30px; height: 26px; margin-left: -15px; background: inherit; border: 4px solid var(--ink); border-bottom: 0; border-radius: 12px 12px 0 0; }
.gun i { font-style: normal; font-family: var(--book); font-size: 1.5em; line-height: 1; }
.gun span { white-space: nowrap; }
.gun[data-gun="T"] { background: var(--mint); }
.gun[data-gun="F"] { background: var(--tomato); }
.gun[data-gun="U"] { background: var(--sun); }
.gun.armed { transform: translateY(-12px); box-shadow: inset 0 -10px 0 rgba(23, 13, 56, .22), 0 0 0 5px #fff; }

/* ---------- game over ---------- */
#s-over { justify-content: flex-start; padding-top: 36px; }
.big-score { font-family: var(--display); font-weight: 700; font-size: clamp(2.2rem, 8vw, 3.2rem); line-height: 1.1; color: var(--sun); }
.badge { font-family: var(--display); font-weight: 700; font-size: 1.8rem; line-height: 1; background: var(--pink); color: var(--ink); padding: 4px 16px 6px; border: 3px solid var(--ink); border-radius: 999px; transform: rotate(-3deg); }
.review { width: min(100%, 560px); margin-top: 12px; }
.review h3 { color: var(--sky); margin-bottom: 10px; }
.review ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.review li { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; padding: 8px 12px; display: flex; align-items: center; gap: 10px; text-align: start; font-weight: 700; }
.review li .tx { flex: 1; }
.review li .mark { font-size: 1.3rem; width: 1.2em; text-align: center; }
.review li .ans { font-family: var(--display); font-size: 1.4rem; line-height: 1; padding: 3px 10px 5px; border: 2.5px solid var(--ink); border-radius: 999px; white-space: nowrap; }
.ans.T { background: var(--mint); } .ans.F { background: var(--tomato); } .ans.U { background: var(--sun); }
.review li.bad { background: #ffe1d6; }

@media (prefers-reduced-motion: reduce) {
  .pulse, .label.shake .tx { animation: none; }
  .btn, .gun { transition: none; }
}
