/* ============================================================================
   Celtic Merge: The Four Treasures — stylesheet
   ----------------------------------------------------------------------------
   Theme: "Celtic Grove" — Forest Canopy's deep emerald structure gilded with
   Golden Hour's mustard gold. Deep green field (#0b1a13) carries ~60% of the
   surface, ivory text ~30%, and a single gold accent (#f4a900) is reserved for
   anything the player is meant to touch.
   ========================================================================== */

:root {
  --ink: #08120d;
  --deep: #0b1a13;
  --panel: #12241b;
  --panel-2: #172e22;
  --line: rgba(244, 169, 0, .26);
  --line-soft: rgba(164, 172, 134, .18);
  --gold: #f4a900;
  --gold-pale: #ffe6a8;
  --gold-deep: #a86d05;
  --ivory: #faf9f6;
  --sage: #a4ac86;
  --olive: #7d8471;
  --danger: #c1666b;
  --jade: #8fd8b0;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, sans-serif;

  --r-s: 8px; --r-m: 14px; --r-l: 22px;
  --sh-1: 0 2px 6px rgba(0, 0, 0, .35);
  --sh-2: 0 8px 24px rgba(0, 0, 0, .45);
  --sh-3: 0 24px 64px rgba(0, 0, 0, .55);
  --ease: cubic-bezier(.16, 1, .3, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--ivory);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* deep-field backdrop with a cold light from above, so the page never reads flat */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(900px 520px at 50% -8%, rgba(120, 180, 140, .16), transparent 70%),
    radial-gradient(700px 700px at 88% 104%, rgba(244, 169, 0, .07), transparent 70%),
    linear-gradient(180deg, #08120d 0%, #0b1a13 55%, #07110c 100%);
}
body::after {
  content: "";
  position: fixed; inset: 0; z-index: -1; opacity: .05; pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3'/></filter><rect width='140' height='140' filter='url(%23n)'/></svg>");
}

/* ------------------------------------------------------------------- shell */
.shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px 18px 64px;
  display: grid;
  gap: 26px;
}
@media (min-width: 980px) {
  .shell {
    grid-template-columns: minmax(0, auto) minmax(380px, 1fr);
    align-items: start;
    gap: 34px;
    padding: 28px 26px 80px;
  }
}

/* the stage is a fixed 9:16 reliquary. Height is set explicitly — never with
   flex:1 — because a flex-basis of 0 collapses it on mobile. */
.stage {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  aspect-ratio: 9 / 16;
  border-radius: var(--r-l);
  overflow: hidden;
  box-shadow: var(--sh-3), 0 0 0 1px var(--line) inset;
  background: #08120d;
}
@media (min-width: 980px) {
  .stage {
    height: calc(100vh - 56px);
    max-height: 900px;
    width: auto;
    margin: 0;
    justify-self: start;
  }
}
.stage canvas {
  display: block;
  width: 100%; height: 100%;
  touch-action: none;
  cursor: pointer;
}

/* ----------------------------------------------------------------- overlay */
.overlay {
  position: absolute; inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: radial-gradient(120% 90% at 50% 20%, rgba(9, 20, 15, .82), rgba(5, 11, 8, .94));
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  z-index: 5;
  overflow-y: auto;
}
.overlay.show { display: flex; animation: fade .28s var(--ease) both; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.overlay > .panel { animation: rise .38s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(.985) } to { opacity: 1; transform: none } }

.panel {
  width: 100%;
  max-width: 430px;
  max-height: 100%;
  overflow-y: auto;
  background:
    linear-gradient(180deg, rgba(23, 46, 34, .96), rgba(9, 20, 15, .97));
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 24px 22px;
  box-shadow: var(--sh-2), 0 0 0 1px rgba(164, 172, 134, .07) inset;
  text-align: center;
}
.panel.wide { max-width: 520px; }
.panel-l { text-align: left; }

.eyebrow {
  margin: 0 0 6px;
  font: 700 11px/1 var(--sans);
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: .92;
}
h1.gtitle, .gtitle {
  margin: 0 0 4px;
  font: 700 clamp(26px, 5.4vw, 36px)/1.06 var(--serif);
  letter-spacing: -.015em;
  color: var(--ivory);
}
h1.gtitle em, .gtitle em {
  font-style: italic;
  color: var(--gold-pale);
}

/* always-available in-game buttons; sit above the canvas, below every overlay */
.hudbtn {
  position: absolute;
  top: 10px;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(9, 20, 15, .72);
  color: var(--gold-pale);
  font: 700 13px/1 var(--sans);
  cursor: pointer;
  z-index: 4;
  transition: border-color .2s, transform .15s var(--ease);
}
.hudbtn:hover { border-color: var(--gold); transform: translateY(-1px); }
.hudbtn:focus-visible { outline: 2px solid var(--gold-pale); outline-offset: 2px; }
#btnPause { right: 10px; }
#btnSound { right: 52px; }
.gsub {
  margin: 0 0 16px;
  font: 500 13.5px/1.55 var(--sans);
  color: var(--sage);
}
h2.ptitle {
  margin: 0 0 10px;
  font: 700 21px/1.15 var(--serif);
  color: var(--ivory);
}
.psub {
  margin: 0 0 14px;
  font: 500 13px/1.6 var(--sans);
  color: var(--sage);
}
.pmeta {
  margin: 12px 0 0;
  font: 600 11.5px/1.5 var(--sans);
  letter-spacing: .04em;
  color: var(--olive);
}

/* ------------------------------------------------------------------ buttons */
.btns { display: grid; gap: 9px; margin-top: 4px; }
.btns.two { grid-template-columns: 1fr 1fr; }
.btn {
  appearance: none;
  min-height: 46px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(30, 58, 42, .9), rgba(14, 28, 21, .95));
  color: var(--ivory);
  font: 700 14.5px/1.2 var(--sans);
  letter-spacing: .01em;
  cursor: pointer;
  transition: transform .16s var(--ease), box-shadow .2s var(--ease), border-color .2s;
}
.btn:hover { transform: translateY(-1px); border-color: rgba(244, 169, 0, .5); }
.btn:active { transform: translateY(0) scale(.99); }
.btn:focus-visible { outline: 2px solid var(--gold-pale); outline-offset: 2px; }
.btn.primary {
  background: linear-gradient(180deg, #ffe6a8, #f4a900 52%, #c98600);
  color: #241a02;
  border-color: rgba(255, 230, 168, .6);
  box-shadow: 0 6px 20px rgba(244, 169, 0, .28);
}
.btn.primary:hover { box-shadow: 0 10px 28px rgba(244, 169, 0, .42); }
.btn.ghost { background: rgba(12, 24, 18, .7); color: var(--sage); }
.btn.small { min-height: 38px; padding: 9px 14px; font-size: 13px; }

.kv { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin: 14px 0 0; }
.kv div { display: grid; gap: 2px; min-width: 62px; }
.kv b { font: 800 18px/1 var(--sans); color: var(--ivory); font-variant-numeric: tabular-nums; }
.kv span { font: 600 10px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--olive); }

/* --------------------------------------------------------- stars & goals   */
.starrow { display: flex; gap: 6px; justify-content: center; margin: 6px 0 12px; font-size: 30px; line-height: 1; }
.wstar, .bstar, .sstar { color: rgba(164, 172, 134, .3); transition: color .3s var(--ease), transform .3s var(--ease); }
.wstar.on, .bstar.on, .sstar.on { color: var(--gold); text-shadow: 0 0 14px rgba(244, 169, 0, .55); }
.wstar.on { animation: pop .5s var(--ease) both; }
.wstar.on:nth-child(2) { animation-delay: .12s; }
.wstar.on:nth-child(3) { animation-delay: .24s; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0 } 62% { transform: scale(1.2) } 100% { transform: scale(1); opacity: 1 } }

.goal-list { list-style: none; margin: 12px 0 4px; padding: 0; display: grid; gap: 8px; }
.goal-list li {
  display: grid;
  grid-template-columns: 56px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 0 12px;
  padding: 9px 12px;
  border-radius: var(--r-m);
  background: rgba(9, 20, 15, .6);
  border: 1px solid var(--line-soft);
  text-align: left;
}
.goal-list .bi { grid-row: 1 / span 2; display: block; line-height: 0; }
.goal-list b { font: 700 14px/1.2 var(--sans); color: var(--ivory); }
.goal-list em { font: 500 11.5px/1.3 var(--sans); font-style: normal; color: var(--olive); }

#winStats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 4px 0 14px; }
#winStats div { padding: 9px 4px; border-radius: var(--r-s); background: rgba(9, 20, 15, .6); border: 1px solid var(--line-soft); }
#winStats b { display: block; font: 800 17px/1.1 var(--sans); color: var(--gold-pale); font-variant-numeric: tabular-nums; }
#winStats span { font: 600 9.5px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--olive); }

.tips { margin: 0 0 14px; padding: 0; list-style: none; display: grid; gap: 7px; text-align: left; }
.tips li {
  font: 500 12.5px/1.5 var(--sans); color: var(--sage);
  padding: 8px 11px; border-left: 2px solid var(--line); background: rgba(9, 20, 15, .45);
  border-radius: 0 var(--r-s) var(--r-s) 0;
}
.tips b, .lore-p b { color: var(--gold-pale); }

/* ------------------------------------------------------- chapter select   */
.sel-act { margin: 0 0 16px; text-align: left; }
.sel-act h3 {
  margin: 0 0 8px; font: 700 12px/1 var(--sans);
  letter-spacing: .14em; text-transform: uppercase; color: var(--gold);
}
.sel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.sel-cell {
  appearance: none; cursor: pointer;
  display: grid; gap: 2px; padding: 9px 8px; min-height: 74px;
  border-radius: var(--r-m);
  border: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(23, 46, 34, .8), rgba(10, 22, 16, .9));
  color: var(--ivory); text-align: left;
  transition: transform .15s var(--ease), border-color .2s;
}
.sel-cell:hover:not(:disabled) { transform: translateY(-2px); border-color: rgba(244, 169, 0, .5); }
.sel-cell:focus-visible { outline: 2px solid var(--gold-pale); outline-offset: 2px; }
.sel-cell.locked { opacity: .42; cursor: not-allowed; }
.sel-n { font: 800 17px/1 var(--sans); color: var(--gold-pale); font-variant-numeric: tabular-nums; }
.sel-name { font: 600 11px/1.25 var(--sans); color: var(--sage); }
.sel-stars { font-size: 12px; line-height: 1; letter-spacing: 1px; }

/* --------------------------------------------------------------- lore     */
.lore-card {
  margin: 0 0 10px; padding: 11px 13px; text-align: left;
  border-radius: var(--r-m); border: 1px solid var(--line-soft);
  background: rgba(9, 20, 15, .55);
}
.lore-card h3 { margin: 0; font: 700 15px/1.2 var(--serif); color: var(--gold-pale); }
.lore-sub { margin: 2px 0 8px; font: 600 10.5px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--olive); }
.lore-card ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 3px; }
.lore-card li { display: flex; align-items: center; gap: 8px; font: 500 12px/1.2 var(--sans); color: var(--sage); }
.lore-card li b { color: var(--gold); font: 700 10px/1 var(--sans); min-width: 18px; }
.lore-i { line-height: 0; }
.lore-p { margin: 0 0 10px; font: 500 12.5px/1.6 var(--sans); color: var(--sage); text-align: left; }

/* ------------------------------------------------------ branch chooser    */
#ovBranch { background: rgba(5, 11, 8, .55); z-index: 8; }
.branch-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.branch-opt {
  appearance: none; cursor: pointer; min-height: 74px;
  border-radius: var(--r-m); border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(30, 58, 42, .92), rgba(12, 24, 18, .95));
  color: var(--ivory); font: 700 12px/1.2 var(--sans);
  transition: transform .15s var(--ease), border-color .2s;
}
.branch-opt:hover { transform: translateY(-2px); border-color: var(--gold); }
.branch-opt:focus-visible { outline: 2px solid var(--gold-pale); outline-offset: 2px; }

/* --------------------------------------------------------------- article  */
.article { max-width: 760px; }
.article h1 {
  margin: 0 0 10px;
  font: 700 clamp(24px, 3.4vw, 38px)/1.08 var(--serif);
  letter-spacing: -.02em;
  color: var(--ivory);
}
.article h1 em { font-style: italic; color: var(--gold-pale); }
.article .lede { margin: 0 0 22px; font: 500 16px/1.65 var(--sans); color: var(--sage); max-width: 62ch; }
.article h2 {
  margin: 30px 0 8px;
  font: 700 22px/1.2 var(--serif);
  color: var(--ivory);
}
.article h3 { margin: 20px 0 5px; font: 700 15.5px/1.3 var(--sans); color: var(--gold-pale); }
.article p { margin: 0 0 12px; font: 400 14.5px/1.7 var(--sans); color: #cfd8cf; max-width: 68ch; }
.article ul, .article ol { margin: 0 0 14px; padding-left: 20px; }
.article li { font: 400 14.5px/1.7 var(--sans); color: #cfd8cf; margin: 4px 0; }
.article strong { color: var(--ivory); }
.article code {
  font: 500 12.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(244, 169, 0, .1); color: var(--gold-pale);
  padding: 2px 6px; border-radius: 5px;
}
.article table {
  width: 100%; border-collapse: collapse; margin: 14px 0 18px;
  font: 400 13.5px/1.5 var(--sans); table-layout: fixed;
}
.article th, .article td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line-soft); color: #cfd8cf; overflow-wrap: break-word; }
.article th { font: 700 11px/1.2 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--gold); }
.article tbody tr:hover { background: rgba(244, 169, 0, .04); }
.tags { display: flex; flex-wrap: wrap; gap: 7px; margin: 20px 0 8px; }
.tag {
  font: 600 11px/1 var(--sans); letter-spacing: .06em; text-transform: uppercase;
  color: var(--sage); border: 1px solid var(--line-soft);
  padding: 6px 10px; border-radius: 999px; background: rgba(9, 20, 15, .5);
}
.site-foot { margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--line-soft); font: 500 12px/1.6 var(--sans); color: var(--olive); }

/* staggered, orchestrated page-load reveal for the article */
.reveal { opacity: 0; animation: revealUp .7s var(--ease) both; }
.reveal:nth-child(1) { animation-delay: .04s } .reveal:nth-child(2) { animation-delay: .10s }
.reveal:nth-child(3) { animation-delay: .16s } .reveal:nth-child(4) { animation-delay: .22s }
.reveal:nth-child(5) { animation-delay: .28s } .reveal:nth-child(6) { animation-delay: .34s }
@keyframes revealUp { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }

@media (max-width: 620px) {
  .shell { padding: 12px 12px 48px; gap: 20px; }
  .stage { border-radius: var(--r-m); }
  .panel { padding: 20px 16px; border-radius: var(--r-m); }
  .article h2 { font-size: 19px; }
  .article p, .article li { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .reveal { opacity: 1; }
}
