/* ============================================================================
   Avalon Circuit — presentation.
   Light theme page, dark arena. The frame is parchment and brass; the game is
   night water and ley light. No external fonts: the stack is native so the page
   renders identically offline.
   ========================================================================== */
:root {
  --ink: #171426;
  --ink-soft: #4b4660;
  --parch: #f6f1e6;
  --parch-2: #efe7d7;
  --brass: #b8863b;
  --brass-lit: #e8bd6a;
  --night: #0a0d1c;
  --night-2: #141a33;
  --line: #d8cdb6;
  --good: #2f8f5b;
  --bad: #c0392b;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 620px at 12% -10%, #fffdf7 0%, rgba(255, 253, 247, 0) 60%),
    radial-gradient(900px 540px at 100% 0%, #f0e9d8 0%, rgba(240, 233, 216, 0) 55%),
    linear-gradient(180deg, var(--parch) 0%, var(--parch-2) 100%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------- shell */
.shell { max-width: 1180px; margin: 0 auto; padding: 18px 18px 40px; }
.topbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand b {
  font-family: var(--serif); font-size: 25px; letter-spacing: .3px;
  background: linear-gradient(180deg, #3b2f18, #7a5b1f); -webkit-background-clip: text;
  background-clip: text; color: transparent;
}
.brand span { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-soft); }
.topbar .spacer { flex: 1 1 auto; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: #fffdf8;
  font-size: 12.5px; color: var(--ink-soft); box-shadow: 0 1px 0 #fff inset;
}
.chip b { color: var(--ink); }
.btn {
  appearance: none; border: 1px solid var(--line); background: linear-gradient(180deg, #fffdf8, #f3ecdd);
  color: var(--ink); border-radius: 10px; padding: 10px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit; box-shadow: 0 1px 0 #fff inset, 0 2px 0 rgba(0, 0, 0, .05);
  transition: transform .10s ease, box-shadow .16s ease, background .16s ease;
}
.btn:hover { background: linear-gradient(180deg, #fff, #f7f1e4); box-shadow: 0 2px 10px rgba(120, 96, 40, .15), 0 1px 0 #fff inset; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  border-color: #9c6f24; color: #fffef9;
  background: linear-gradient(180deg, #d4a349, #a9741f);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .35) inset, 0 6px 18px rgba(150, 106, 30, .28);
}
.btn.primary:hover { background: linear-gradient(180deg, #e0b158, #b8801f); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* -------------------------------------------------------------------- stage */
.stage {
  position: relative; border-radius: 18px; overflow: hidden;
  background: var(--night);
  border: 1px solid #2a2f52;
  box-shadow: 0 26px 60px -22px rgba(24, 20, 48, .6), 0 0 0 1px rgba(255, 255, 255, .5);
  aspect-ratio: 16 / 10; min-height: 380px;
}
.stage canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

/* HUD */
.hud {
  position: absolute; inset: 10px 10px auto 10px; display: flex; gap: 10px; align-items: flex-start;
  pointer-events: none; transition: opacity .25s ease, filter .25s ease;
}
.hud[data-dim="1"] { opacity: .35; filter: saturate(.4); }
.hud > * { pointer-events: auto; }
.panel {
  background: linear-gradient(180deg, rgba(17, 21, 42, .92), rgba(9, 12, 26, .92));
  border: 1px solid rgba(138, 156, 224, .28); border-radius: 12px;
  padding: 8px 12px; color: #eae6f6; backdrop-filter: blur(7px);
  box-shadow: 0 8px 26px -14px rgba(0, 0, 0, .9);
}
.hud .left { display: flex; flex-direction: column; gap: 3px; min-width: 168px; }
.hud .left .act { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: #9fb0e6; }
.hud .left .ch { font-size: 13.5px; font-weight: 600; }
.clock {
  font-family: var(--serif); font-size: 30px; line-height: 1; letter-spacing: 1px;
  min-width: 108px; text-align: center; color: #fff6e2;
  text-shadow: 0 0 18px rgba(255, 214, 130, .35);
}
.clock[data-urgent="1"] { color: #ff9aa8; text-shadow: 0 0 20px rgba(255, 90, 120, .55); animation: pulse .9s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.right { margin-left: auto; display: flex; gap: 8px; align-items: flex-start; }
.lives { display: flex; gap: 5px; align-items: center; }
.lives i {
  width: 15px; height: 15px; display: block; border-radius: 3px;
  background: linear-gradient(180deg, #ffe8ab, #d9a63f);
  box-shadow: 0 0 9px rgba(255, 206, 110, .55);
  transform: rotate(45deg);
}
.lives.pop i { animation: pop .34s ease; }
@keyframes pop { from { transform: rotate(45deg) scale(.3); opacity: 0; } to { transform: rotate(45deg) scale(1); opacity: 1; } }
.iconbtn {
  appearance: none; border: 1px solid rgba(138, 156, 224, .28); border-radius: 10px;
  background: linear-gradient(180deg, rgba(17, 21, 42, .92), rgba(9, 12, 26, .92));
  color: #eae6f6; width: 38px; height: 34px; cursor: pointer; font-size: 15px; line-height: 1;
}
.iconbtn:hover { border-color: rgba(180, 200, 255, .6); }

/* progress */
.trackwrap {
  position: absolute; left: 12px; right: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 12px; pointer-events: none;
}
.track {
  position: relative; flex: 1 1 auto; height: 13px; border-radius: 999px;
  background: rgba(8, 11, 24, .82); border: 1px solid rgba(138, 156, 224, .28); overflow: hidden;
}
.track .fill {
  position: absolute; inset: 0 auto 0 0; width: 0%;
  background: linear-gradient(90deg, #6f4bd8, #d9a63f 70%, #ffe6a8);
  box-shadow: 0 0 16px rgba(255, 205, 120, .5); transition: width .12s linear;
}
.track .goal { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #fff; opacity: .8; }
.sharenum { font-size: 12.5px; color: #e7e2f4; min-width: 118px; text-align: right; font-variant-numeric: tabular-nums; }
.boost { width: 96px; height: 7px; border-radius: 999px; background: rgba(8, 11, 24, .82); border: 1px solid rgba(138, 156, 224, .25); overflow: hidden; }
.boost .fill { height: 100%; width: 100%; background: #5566a8; transition: width .1s linear; }
.boost .fill[data-ready="1"] { background: linear-gradient(90deg, #8fd6ff, #fff0c4); box-shadow: 0 0 12px rgba(160, 220, 255, .6); }

/* census */
.census { position: absolute; right: 12px; top: 62px; display: flex; flex-direction: column; gap: 5px; pointer-events: none; }
.pip {
  font-size: 11px; color: #dfe4f7; background: rgba(9, 12, 26, .8); border-left: 3px solid var(--c);
  padding: 3px 9px 3px 7px; border-radius: 5px; font-variant-numeric: tabular-nums; min-width: 44px; text-align: right;
}
.pip.down { opacity: .38; text-decoration: line-through; }
.hint {
  position: absolute; left: 50%; bottom: 46px; transform: translateX(-50%);
  color: #cfd6f4; font-size: 12.5px; background: rgba(9, 12, 26, .78);
  border: 1px solid rgba(138, 156, 224, .25); padding: 7px 14px; border-radius: 999px;
  transition: opacity .6s ease; pointer-events: none;
}
.hint.gone { opacity: 0; }
.fpsbadge { position: absolute; left: 12px; bottom: 34px; font-size: 10.5px; color: #6d78a8; }

/* touch controls */
.touchpad { position: absolute; inset: 0; display: none; pointer-events: none; }
.touchpad .tbtn {
  position: absolute; bottom: 44px; width: 92px; height: 92px; border-radius: 50%;
  border: 1px solid rgba(160, 180, 255, .35); background: rgba(14, 18, 38, .6);
  color: #e6e9fb; font-size: 30px; line-height: 1; pointer-events: auto;
  display: flex; align-items: center; justify-content: center; user-select: none; touch-action: none;
}
.touchpad .tbtn.left { left: 16px; }
.touchpad .tbtn.right { left: 122px; }
.touchpad .tbtn.boost { right: 16px; width: 108px; font-size: 13px; letter-spacing: .1em; font-weight: 700; }
.touchpad .tbtn:active { background: rgba(60, 76, 150, .7); }
@media (pointer: coarse) { .touchpad { display: block; } }

/* ------------------------------------------------------------------ toasts */
.toasts { position: absolute; left: 50%; top: 76px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 7px; align-items: center; pointer-events: none; }
.toast {
  font-size: 13px; padding: 8px 15px; border-radius: 999px; color: #f4f1ff;
  background: rgba(12, 16, 34, .9); border: 1px solid rgba(140, 158, 226, .3);
  animation: rise .3s ease; max-width: 76vw; text-align: center;
}
.toast.out { opacity: 0; transform: translateY(-8px); transition: all .6s ease; }
.toast.good { border-color: #4fbd85; color: #d8ffe9; }
.toast.bad { border-color: #e0645c; color: #ffe2df; }
.toast.steal { border-color: #d9a63f; color: #fff0cd; }
.toast.story { border-color: #9d8bea; color: #ece6ff; font-style: italic; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* --------------------------------------------------------------- overlays */
.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 22px; background: radial-gradient(70% 70% at 50% 40%, rgba(10, 13, 30, .78), rgba(5, 7, 16, .95));
  backdrop-filter: blur(3px); z-index: 5;
}
.card-wrap {
  width: min(760px, 100%); max-height: 100%; overflow: auto; border-radius: 16px;
  background: linear-gradient(180deg, #fdfaf2, #f2ead9); border: 1px solid #e0d5bd;
  box-shadow: 0 30px 70px -26px rgba(0, 0, 0, .75); padding: 26px 26px 22px;
}
.card-wrap h2 { font-family: var(--serif); font-size: 30px; margin: 0 0 6px; letter-spacing: .2px; }
.card-wrap p { color: #4a4358; line-height: 1.62; font-size: 14.6px; margin: 0 0 10px; }
.kicker { font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--brass); font-weight: 700; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.muted { color: #6d6579; font-size: 12.6px; }

/* story art plate */
.art {
  height: 168px; border-radius: 12px; margin: 4px 0 16px; position: relative; overflow: hidden;
  border: 1px solid #ded2b8; background: linear-gradient(180deg, #1b2140, #0a0d1c);
}
.art::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(58% 78% at 50% 52%, rgba(255, 226, 160, .28), rgba(0, 0, 0, 0) 70%);
}
.art::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: 120px; height: 120px;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 2px solid rgba(255, 226, 160, .55); border-radius: 16px;
  box-shadow: 0 0 44px rgba(255, 210, 120, .35), 0 0 0 16px rgba(255, 226, 160, .07) inset;
}
.art-mist { background: linear-gradient(180deg, #2b3358, #0b0f1f 70%); }
.art-chariot { background: linear-gradient(180deg, #43331a, #100c1c 72%); }
.art-cage { background: linear-gradient(180deg, #2a2340, #0b0a16 72%); }
.art-keep { background: linear-gradient(180deg, #221f36, #07070f 72%); }
.art-crown { background: linear-gradient(180deg, #4a3a17, #120d1f 72%); }
.art-glass { background: linear-gradient(180deg, #1d3a46, #0a1218 72%); }

/* chapter grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); gap: 10px; margin-top: 8px; }
.card {
  text-align: left; cursor: pointer; font-family: inherit;
  border: 1px solid #e2d8c2; background: linear-gradient(180deg, #fffdf7, #f5efe1);
  border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px;
  transition: transform .12s ease, box-shadow .16s ease;
  border-left: 4px solid var(--tint, var(--brass));
}
.card:hover:not(.locked) { transform: translateY(-2px); box-shadow: 0 12px 26px -16px rgba(80, 60, 20, .5); }
.card.locked { opacity: .45; cursor: not-allowed; }
.card-n { font-family: var(--serif); font-size: 12px; color: var(--brass); letter-spacing: .1em; }
.card-name { font-size: 14.4px; font-weight: 600; }
.card-stars i { color: #d6cdb8; font-style: normal; font-size: 15px; }
.card-stars i.on { color: #d9a63f; text-shadow: 0 0 10px rgba(217, 166, 63, .4); }
.card-meta { font-size: 11.5px; color: #7b7387; }

/* results */
.stars { font-size: 40px; letter-spacing: 10px; color: #ded4bd; margin: 4px 0 10px; }
.stars i { font-style: normal; }
.stars i.on { color: #d9a63f; text-shadow: 0 0 22px rgba(217, 166, 63, .5); animation: pop .45s ease backwards; }
.rrow { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed #e3dac6; font-size: 14px; }
.rrow b { font-variant-numeric: tabular-nums; }
.sub { color: #6d6579; font-size: 13.5px; margin-bottom: 6px; }

/* footer notes */
footer { margin-top: 26px; display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
footer .note { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; background: #fffdf8; }
footer .note h3 { font-family: var(--serif); margin: 0 0 6px; font-size: 16.5px; }
footer .note p, footer .note li { color: #57506a; font-size: 13.4px; line-height: 1.6; }
footer .note ul { margin: 6px 0 0 18px; padding: 0; }

@media (max-width: 780px) {
  .stage { aspect-ratio: 3 / 4; min-height: 460px; }
  .clock { font-size: 25px; min-width: 84px; }
  .hud .left { min-width: 132px; }
  .census { top: 56px; }
  .sharenum { min-width: 92px; font-size: 11.5px; }
  .boost { width: 62px; }
  .card-wrap { padding: 20px 18px; }
  .card-wrap h2 { font-size: 24px; }
}
