* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 800px at 50% 12%, #242830, #0c0e12);
  color: #e8e0d4;
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  font-size: 18px;
}
.shell { height: 100%; min-height: 100vh; display: grid; grid-template-rows: auto 1fr; overflow: hidden; }
.hud {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 8px 12px;
  background: linear-gradient(#2a2e36, #16181c);
  border-bottom: 2px solid #d4b06a;
  box-shadow: 0 2px 0 #8a5a28, inset 0 1px 0 #4a5048;
}
.hud .hof { display: none !important; }
.hud .stat {
  color: #7dcea0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.hud .plate-mid { margin: 0 auto; }
.eqx-win { color: #7dcea0; font-size: 0.82rem; margin-left: 10px; white-space: nowrap; }
.plate-hud { display: none !important; }
.hud a.scores, .hud #btn-menu {
  display: inline-flex; align-items: center;
  background: #1e2228; color: #efe6d8; padding: 6px 14px;
  border: 1px solid #8a6a3e; border-radius: 8px; text-decoration: none;
  font: inherit; cursor: pointer;
}
.viewport { padding: 16px 20px 12px; max-width: 64rem; min-height: 0; overflow: auto; }
body[data-screen="play"] .viewport {
  max-width: none;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 36px 16px 16px;
}
#prefs[hidden],
#map[hidden],
#play[hidden] { display: none !important; }
body[data-screen="play"] #map,
body[data-screen="play"] #prefs,
body[data-screen="map"] #play,
body[data-screen="map"] #prefs,
body[data-screen="prefs"] #map,
body[data-screen="prefs"] #play { display: none !important; }
#play:not([hidden]) {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#play .plate-frame { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: 8px; }
#play .hint-row { flex: 0 0 auto; padding-bottom: 8px; }
.lede { color: #9aa0a8; font-size: 1.05rem; line-height: 1.45; }
.done { color: #7dcea0; font-weight: 700; }
.cats { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.cat {
  display: inline-flex; align-items: center; gap: 6px;
  background: #1e2228; color: #efe6d8; border: 1px solid #8a6a3e;
  border-radius: 999px; padding: 8px 12px; cursor: pointer;
}
.cat .mark-svg { width: 1.1rem; height: 1.1rem; }
.cat.on {
  background: linear-gradient(180deg, var(--cat-top, #c4a574), var(--cat, #8a6a3e));
  color: var(--ink, #1c1612);
  border-color: #f0d48a;
  font-weight: 700;
}
.modes { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
.modes button {
  font: inherit; background: #1e2228; color: #efe6d8; border: 1px solid #8a6a3e;
  border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
.modes button.on { background: #d4b06a; color: #1c1612; font-weight: 700; }
.q-timer {
  --t: 1;
  position: relative;
  margin: 0 0 12px;
  height: 1.4rem;
  border: 1px solid #8a6a3e;
  border-radius: 8px;
  overflow: hidden;
  color: #1c1612;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  line-height: 1.4rem;
  z-index: 1;
}
.q-timer::before {
  content: "";
  position: absolute; inset: 0 auto 0 0;
  width: calc(var(--t) * 100%);
  background: linear-gradient(90deg, #e23a2a, #e6c36a 55%, #d4b06a);
  z-index: -1;
}
body.fun #q-timer { display: none !important; }
.q-pay {
  margin: 0 0 10px;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
}
.q-pay.ok {
  background: linear-gradient(90deg, #146038, #2ecc71 55%, #7dcea0);
  color: #e8ffe8;
  box-shadow: 0 0 18px #2ecc7188, inset 0 1px 0 #c8ffe0;
}
.q-pay.bad {
  background: linear-gradient(90deg, #7a2818, #e07050);
  color: #fff4e8;
  box-shadow: 0 0 14px #e0705088;
}
.spine {
  position: relative;
  margin: 12px auto 8px;
  max-width: 44rem;
  height: min(240px, 34vh);
}
.spine-svg { display: block; width: 100%; height: 100%; }
.spine-nodes { position: absolute; inset: 0; pointer-events: none; }
.pearl {
  position: absolute;
  width: 2.7rem; height: 2.7rem; border-radius: 50%;
  font: 700 0.9rem Cinzel, Palatino, serif;
  color: #e8e0d4; cursor: pointer;
  border: 3px solid #d4b06a;
  background: radial-gradient(circle at 32% 28%, #3a4038, #16181c);
  transform: translate(-50%, -50%);
  pointer-events: auto;
  box-shadow: inset 0 1px 0 #6a7068, 0 3px 0 #0c0c0e;
}
.pearl.tone-copper { border-color: #e8b060; }
.pearl.tone-steel { border-color: #8a9098; }
.pearl.tone-verdigris { border-color: #3ecf9a; }
.pearl.closed {
  background: radial-gradient(circle at 35% 30%, #7dff9a, #1f8a4c);
  border-color: #f0d48a;
}
.pearl.open {
  background: radial-gradient(circle at 35% 30%, #ffe9a8, #d4b06a);
  box-shadow: 0 0 12px #d4b06aaa;
}
.pearl.next {
  background: radial-gradient(circle at 35% 30%, #6a7068, #2a2e36);
  color: #efe6d8; opacity: 0.85;
}
.pearl.locked {
  background: #16181c; color: #6a6258; border-color: #3a4038; cursor: default;
}
.pearl:disabled { cursor: default; }
.plate-frame {
  margin: 0 auto;
  padding: 10px 14px 16px;
  width: 100%; max-width: 100%;
  background:
    radial-gradient(ellipse at 50% 0%, #3a4a5888, transparent 55%),
    repeating-linear-gradient(90deg, #16181c 0 4px, #101218 4px 8px);
  border: 3px solid #d4b06a;
  border-radius: 24px;
  box-shadow:
    inset 0 0 40px #000a,
    0 0 0 1px #8a5a28,
    0 8px 0 #3a2410;
  overflow: hidden;
}
.plate-hud {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 2px 8px 10px;
  color: #7dcea0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 0 #000;
}
.plate { position: relative; margin: 0 auto; flex: 0 0 auto; }
.hex {
  position: absolute;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  filter: none;
  clip-path: none;
}
.hex .hex-svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.hex:hover:not(:disabled) .hex-svg { filter: brightness(1.1); }
.hex:disabled { cursor: default; }
.hex.ok, .hex.bad, .hex.skip {
  filter: grayscale(0.88) brightness(0.62);
}
.q-art, .topic-art {
  width: min(100%, 22rem); height: auto;
  border-radius: 10px; border: 1px solid #8a6a3e;
  display: block; margin: 8px 0 12px;
}
.topic-art { width: min(100%, 100%); max-height: 22rem; object-fit: cover; }
.q-cat {
  display: inline-block; margin: 0 0 8px; padding: 4px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--cat-top, #3a2c20), var(--cat, #3a2c20));
  color: var(--ink, #efe6d8); font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase;
}
.choices { display: grid; gap: 10px; margin: 14px 0; }
.choices button, .go, #fifty, #crowd, #again, #next-pearl, #btn-map,
#fifty-sheet, #crowd-sheet, #skip-mini, #read-btn, #type-btn, #type-close, #back-btn, #topic-close,
#btn-save-prefs, #btn-save-menu-prefs, #btn-resume {
  font: inherit; font-size: 1.12rem; background: #1e2228; color: #e8e0d4; border: 1px solid #8a6a3e;
  border-radius: 8px; padding: 12px 16px; cursor: pointer; text-align: left;
}
.go, #next-pearl { background: #d4b06a; color: #1c1612; font-weight: 700; }
.choices button.right {
  background: linear-gradient(90deg, #146038, #2ecc71 60%, #7dcea0);
  border-color: #7dcea0;
  color: #e8ffe8;
  font-weight: 700;
  box-shadow: 0 0 16px #2ecc7188, inset 0 1px 0 #c8ffe0;
}
.choices button.wrong {
  background: linear-gradient(90deg, #7a2818, #e07050);
  border-color: #e07050;
  color: #fff4e8;
}
button:disabled { opacity: 0.45; cursor: default; }
.hint-row { display: flex; flex-wrap: wrap; gap: 8px; }
.crowd-bar { display: grid; gap: 6px; margin: 8px 0 12px; }
.crowd-row { display: grid; grid-template-columns: 1fr minmax(3rem, 40%); gap: 8px; align-items: center; color: #9aa0a8; font-size: 0.85rem; }
.crowd-row b {
  display: block; background: #d4b06a; color: #1c1612;
  border-radius: 4px; padding: 2px 6px; font-weight: 700; min-width: 2.5rem;
}
.sheet {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: #080a0e;
  padding: 24px; overflow: auto;
}
.sheet[hidden] { display: none !important; }
.sheet-card {
  background: linear-gradient(#2a2e36, #16181c);
  border: 2px solid #d4b06a;
  border-radius: 12px;
  padding: 22px 24px;
  max-width: 36rem;
  width: min(36rem, 94vw);
  color: #efe6d8;
  box-shadow: 0 20px 60px #000a, inset 0 0 40px #0004, 0 0 0 1px #8a5a28;
}
.sheet-card.hit-ok { box-shadow: 0 0 28px #2ecc7188, 0 20px 60px #000a, 0 0 0 1px #7dcea0; }
.sheet-card.hit-bad { box-shadow: 0 0 22px #e0705088, 0 20px 60px #000a, 0 0 0 1px #e07050; }
.sheet-card h2 { font-family: Cinzel, Palatino, serif; color: #d4b06a; margin: 0 0 10px; font-size: 1.4rem; line-height: 1.3; }
.q-sheet .hint-row { position: sticky; bottom: 0; background: #16181c; padding-top: 8px; }
.topic-card { max-width: 42rem; width: min(42rem, 94vw); }
.topic-read { line-height: 1.55; color: #efe6d8; margin: 0 0 16px; }
#mini-canvas { width: 100%; max-width: 420px; height: auto; display: block; margin: 8px 0 12px; background: #101218; border: 1px solid #8a6a3e; border-radius: 8px; }
@media (min-width: 821px) {
  .q-sheet {
    display: grid;
    grid-template-columns: minmax(8.5rem, 14rem) 1fr;
    grid-template-rows: auto auto auto 1fr auto;
    column-gap: 16px;
    row-gap: 6px;
    max-width: min(52rem, 94vw);
    max-height: 86vh;
    width: min(52rem, 94vw);
    padding: 14px 16px 12px;
    overflow: hidden;
    align-items: stretch;
  }
  .q-sheet #q-cat { grid-column: 1 / -1; margin-bottom: 0; }
  .q-sheet #q-timer { grid-column: 1 / -1; margin: 0; height: 1.15rem; line-height: 1.15rem; }
  .q-sheet #q-pay { grid-column: 1 / -1; margin: 0; }
  .q-sheet #q-wrap {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(8.5rem, 14rem) 1fr;
    gap: 16px;
    min-height: 0;
    overflow: hidden;
  }
  .q-sheet #q-art {
    width: 100%;
    max-height: 38vh;
    margin: 0;
    object-fit: cover;
  }
  .q-sheet .q-copy { min-height: 0; overflow: auto; }
  .q-sheet #q { font-size: 1.35rem; margin: 0 0 10px; }
  .q-sheet #choices { margin: 0; }
  .q-sheet #crowd-bar { margin: 6px 0 0; }
  .q-sheet #mini-wrap { grid-column: 1 / -1; }
  .q-sheet .hint-row { grid-column: 1 / -1; margin: 8px 0 0; }
  .q-sheet #hint-cap-sheet { grid-column: 1 / -1; margin: 4px 0 0; }
  .q-sheet .choices button { padding: 7px 12px; }
}
@media (max-aspect-ratio: 4/3) {
  .hud { padding: 4px 8px; gap: 6px; }
  body[data-screen="play"] .viewport { padding: 4px 8px; }
  #play .hint-row { padding-bottom: 4px; }
  .plate-hud { padding-bottom: 4px; font-size: 0.92rem; }
}
@media (max-width: 640px) {
  .pearl { width: 2.2rem; height: 2.2rem; }
}
