/* ==========================================================================
   Elixir Sort: The Bifröst Legend — shell styling.
   Aurora-dark glass, rune gold hairlines, serif display type. All chrome lives
   in the DOM so the canvas stays purely the game.
   ========================================================================== */
:root {
  --ink: #eef3ff;
  --dim: #9fb0cc;
  --gold: #e6c67c;
  --gold-2: #ffefc6;
  --night: #070b18;
  --panel: rgba(10, 15, 30, 0.92);
  --line: rgba(230, 198, 124, 0.28);
  --glass: rgba(255, 255, 255, 0.05);
  --good: #7fe3a5;
  --bad: #ff7d8f;
  --frost: #9fe6ff;
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100%;
  background:
    radial-gradient(1200px 700px at 50% -10%, #1b2a55 0%, rgba(7, 11, 24, 0) 60%),
    radial-gradient(900px 700px at 8% 110%, #23294f 0%, rgba(7, 11, 24, 0) 58%),
    radial-gradient(900px 600px at 96% 92%, #17324a 0%, rgba(7, 11, 24, 0) 60%),
    linear-gradient(180deg, #05070f 0%, #080d1c 45%, #04060d 100%);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 16px 30px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(22, 32, 62, 0.85), rgba(8, 12, 24, 0.92));
  box-shadow: var(--shadow);
}
.brand {
  font: 700 20px/1 Georgia, "Times New Roman", serif;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--gold-2);
  text-shadow: 0 0 18px rgba(230, 198, 124, 0.45);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.brand span {
  font: 600 10.5px/1 -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: 0.22em;
  color: var(--frost);
  text-transform: uppercase;
  opacity: 0.85;
}
.hud { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.metric {
  display: flex; flex-direction: column; align-items: flex-end; gap: 1px;
  min-width: 54px; padding: 2px 8px;
  border-left: 1px solid var(--line);
}
.metric b { font-size: 19px; color: var(--gold-2); font-variant-numeric: tabular-nums; }
.metric span { font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim); }
.metric.small b { font-size: 15px; color: var(--ink); }
.stars-mini { display: flex; gap: 2px; font-size: 15px; color: rgba(255, 255, 255, 0.22); }
.stars-mini .on { color: var(--gold); text-shadow: 0 0 10px rgba(230, 198, 124, 0.7); }
.stars-mini .dim { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.icobtn {
  position: relative;
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--gold-2); font-size: 15px; cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.icobtn:hover { background: rgba(230, 198, 124, 0.16); }
.icobtn:active { transform: translateY(1px); }
.icobtn:disabled { opacity: 0.38; cursor: default; }
.icobtn .badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 16px; height: 16px; border-radius: 8px;
  background: var(--gold); color: #241a05;
  font: 700 10px/16px -apple-system, sans-serif; font-style: normal;
  padding: 0 4px;
}

/* ------------------------------------------------------------------- stage */
.stage {
  position: relative;
  flex: 0 0 auto;
  height: min(72vh, 760px);
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 0%, #101a35 0%, #06090f 70%);
  box-shadow: var(--shadow);
  touch-action: manipulation;
}
#cv { display: block; position: absolute; inset: 0; }
.stage.dim #cv { filter: saturate(0.7) brightness(0.72); }

.stagehud {
  position: absolute; inset: 10px 12px auto 12px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  pointer-events: none;
}
.chapterlabel {
  font: 600 11.5px/1 -apple-system, sans-serif;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--gold-2);
  background: rgba(6, 10, 20, 0.62);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
}
.actname {
  font: 400 12px/1 Georgia, serif; font-style: italic;
  color: var(--frost); opacity: 0.9;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}
.strip { margin-left: auto; display: flex; gap: 5px; }
.strip .dot {
  width: 12px; height: 12px; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22) inset, 0 0 10px rgba(0, 0, 0, 0.5);
  opacity: 0.42; transition: opacity 0.3s, transform 0.3s;
}
.strip .dot.done {
  opacity: 1; transform: scale(1.22);
  box-shadow: 0 0 0 1px rgba(255, 240, 200, 0.85) inset, 0 0 14px rgba(255, 235, 190, 0.7);
}
.tapbar {
  position: absolute; left: 0; right: 0; bottom: 10px;
  text-align: center; pointer-events: none;
}
.tapbar span {
  display: inline-block;
  font: 500 12px/1 -apple-system, sans-serif; letter-spacing: 0.08em;
  color: var(--dim);
  background: rgba(5, 9, 18, 0.66);
  border-radius: 999px; padding: 7px 14px;
}
.toasts {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 46px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; width: min(94%, 520px);
}
.toast {
  font: 600 12.5px/1.35 -apple-system, sans-serif;
  color: var(--ink);
  background: rgba(9, 14, 28, 0.9);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  animation: toastIn 0.24s ease-out;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5);
}
.toast.good { color: #d8ffe8; border-color: rgba(127, 227, 165, 0.5); }
.toast.bad { color: #ffdfe4; border-color: rgba(255, 125, 143, 0.5); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.5s, transform 0.5s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; } }

/* ---------------------------------------------------------------- overlays */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: radial-gradient(120% 100% at 50% 0%, rgba(9, 14, 30, 0.72), rgba(3, 5, 11, 0.9));
  backdrop-filter: blur(3px);
  overflow-y: auto;
  z-index: 5;
}
.panel {
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(18, 26, 50, 0.96), rgba(8, 12, 24, 0.97));
  box-shadow: var(--shadow);
  padding: 22px 22px 20px;
  text-align: left;
  animation: panelIn 0.26s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.panel.wide { width: min(880px, 100%); }
@keyframes panelIn { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; } }
.eyebrow {
  display: block; font: 600 10.5px/1 -apple-system, sans-serif;
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--frost);
  margin-bottom: 8px;
}
.panel h1 {
  font: 700 27px/1.18 Georgia, serif; margin: 0 0 10px; color: var(--gold-2);
  text-shadow: 0 0 26px rgba(230, 198, 124, 0.28);
}
.panel h2 { font: 700 22px/1.2 Georgia, serif; margin: 0 0 10px; color: var(--gold-2); }
.panel h3.eyebrow { margin-top: 16px; }
.lede { color: #d6dcec; font-size: 14.2px; margin: 0 0 12px; }
.note { color: var(--dim); font-size: 12.4px; margin: 12px 0 0; }
.btncol { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; align-items: center; }
.btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font: 600 14.5px/1 -apple-system, sans-serif;
  padding: 12px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.16s, transform 0.1s, border-color 0.16s;
  text-align: center;
}
.btn:hover { background: rgba(230, 198, 124, 0.14); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, #ffe6a9, #e0b95f);
  color: #2a1f05; border-color: rgba(255, 240, 200, 0.8);
  box-shadow: 0 10px 26px rgba(224, 185, 95, 0.24);
}
.btn.primary:hover { background: linear-gradient(180deg, #fff0c4, #e8c571); }
.btn.ghost { background: transparent; color: var(--dim); }
.btn.small { padding: 10px 13px; font-size: 13.2px; }
.pill {
  align-self: flex-start;
  border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 12px; font: 600 12px/1 -apple-system, sans-serif; color: var(--gold-2);
  white-space: nowrap;
}
.briefhead { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.goals { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.goals li {
  position: relative; padding-left: 18px; color: #d6dcec; font-size: 13.6px;
}
.goals li::before {
  content: '\25C6'; position: absolute; left: 2px; top: 0; color: var(--gold); font-size: 10px;
}
.statline { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; color: var(--dim); font-size: 12.6px; }
.statline b { color: var(--gold-2); }
.howto { display: flex; flex-direction: column; gap: 9px; margin-top: 6px; }
.howto div { font-size: 13.6px; color: #d6dcec; }
.howto b { color: var(--gold-2); }
.scorebig { font-size: 15px; color: var(--dim); margin: 6px 0 12px; }
.scorebig b { font-size: 24px; color: var(--gold-2); font-variant-numeric: tabular-nums; }
.starrow { display: flex; gap: 8px; font-size: 40px; color: rgba(255, 255, 255, 0.16); margin: 4px 0 6px; }
.starrow .starrow-item { display: inline-block; }
.starrow .starrow-item.on {
  color: var(--gold);
  text-shadow: 0 0 22px rgba(230, 198, 124, 0.75);
  animation: starPop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
@keyframes starPop { from { transform: scale(0.3) rotate(-25deg); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* --------------------------------------------------------------- chapter cards */
#levelGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 10px;
  margin: 12px 0 4px;
  max-height: min(52vh, 460px);
  overflow-y: auto;
  padding-right: 4px;
}
.chcard {
  display: flex; flex-direction: column; gap: 3px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  padding: 10px 11px;
  color: var(--ink); cursor: pointer;
  transition: background 0.16s, transform 0.12s, border-color 0.16s;
}
.chcard:hover { background: rgba(230, 198, 124, 0.14); transform: translateY(-2px); }
.chcard.locked { opacity: 0.42; cursor: not-allowed; }
.chact { font: 600 9.5px/1 -apple-system, sans-serif; letter-spacing: 0.18em; text-transform: uppercase; color: var(--frost); }
.chnum { font: 700 22px/1 Georgia, serif; color: var(--gold-2); }
.chtitle { font: 600 12.6px/1.3 Georgia, serif; color: var(--ink); }
.chmeta { font-size: 10.8px; color: var(--dim); }
.chstars { display: flex; gap: 3px; font-size: 13px; margin-top: 2px; }
.chstars i { font-style: normal; color: rgba(255, 255, 255, 0.18); }
.chstars i.on { color: var(--gold); text-shadow: 0 0 8px rgba(230, 198, 124, 0.6); }
.chnote { font-size: 10.4px; color: var(--dim); opacity: 0.85; }

/* ------------------------------------------------------------------ article */
.foot { max-width: 1180px; margin: 10px auto 30px; padding: 0 4px; color: var(--dim); font-size: 13px; }
.foot strong { color: var(--gold-2); }
.article { max-width: 1180px; margin: 14px auto 0; padding: 0 18px 44px; }
.article h2 { font-family: Georgia, serif; color: var(--gold-2); font-size: 22px; margin: 26px 0 8px; }
.article h3 { font-family: Georgia, serif; color: var(--ink); font-size: 17px; margin: 18px 0 6px; }
.article p, .article li { color: #cfd6e6; font-size: 15px; }
.article table { width: 100%; border-collapse: collapse; margin: 12px 0 6px; font-size: 14px; }
.article th, .article td { border: 1px solid rgba(230, 198, 124, 0.2); padding: 8px 10px; text-align: left; vertical-align: top; }
.article th { background: rgba(230, 198, 124, 0.1); color: var(--gold-2); font-weight: 700; }
.article code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: rgba(255, 255, 255, 0.06); padding: 1px 5px; border-radius: 5px; }
.faq details { border: 1px solid rgba(230, 198, 124, 0.2); border-radius: 11px; padding: 11px 13px; margin: 8px 0; background: rgba(255, 255, 255, 0.03); }
.faq summary { cursor: pointer; font-weight: 600; color: var(--gold-2); }
.faq p { margin: 8px 0 0; }
.crumb { color: var(--dim); font-size: 13px; margin: 0 0 10px; }
.crumb a { color: var(--gold); text-decoration: none; }
.crumb a:hover { text-decoration: underline; }

@media (max-width: 780px) {
  .shell { padding: 10px 10px 22px; }
  .stage { height: min(66vh, 620px); min-height: 380px; }
  .brand { font-size: 15px; }
  .brand span { font-size: 9px; letter-spacing: 0.14em; }
  .metric { min-width: 40px; padding: 2px 6px; }
  .metric b { font-size: 16px; }
  .metric.small { display: none; }
  .icobtn { width: 32px; height: 32px; font-size: 13px; border-radius: 9px; }
  .panel { padding: 17px 15px; }
  .panel h1 { font-size: 22px; }
  .panel h2 { font-size: 19px; }
  .starrow { font-size: 32px; }
  .strip .dot { width: 10px; height: 10px; }
  #levelGrid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); max-height: 48vh; }
  .article { padding: 0 12px 34px; }
  .article h2 { font-size: 19px; }
  .article table { font-size: 13px; }
  .toasts { bottom: 40px; }
}
@media (max-width: 420px) {
  .hud { gap: 6px; }
  .metric.small { display: none; }
  .stars-mini { display: none; }
  .tapbar span { font-size: 11px; }
}
