/* ============================================================
 * Bird Sort: Song of Yggdrasil — page & overlay styles
 * Direction: organic storybook · parchment + ink + gold accent
 * ============================================================ */
:root {
  --parchment: #f6efe3;
  --parchment-2: #efe4cf;
  --ink: #2a2136;
  --ink-soft: #5c5266;
  --gold: #c9973a;
  --gold-deep: #a3742a;
  --moss: #1d4d33;
  --radius: 18px;
  --shadow-1: 0 2px 6px rgba(42, 33, 54, 0.10);
  --shadow-2: 0 8px 24px rgba(42, 33, 54, 0.16);
  --shadow-3: 0 24px 60px rgba(20, 12, 34, 0.32);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

body {
  font-family: Georgia, 'Times New Roman', serif;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(201, 151, 58, 0.10), transparent 60%),
    var(--parchment);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---------- header / footer ---------- */
.site-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px;
}
.logo {
  font-weight: 700; font-size: 22px; color: var(--ink); text-decoration: none;
  letter-spacing: -0.02em;
}
.logo span { color: var(--gold-deep); font-style: italic; }
.logo-mark { font-size: 20px; }
.site-nav { font-size: 14px; color: var(--ink-soft); }
.site-nav a { color: var(--ink-soft); text-decoration: none; }
.site-nav a:hover { color: var(--gold-deep); }
.site-foot { text-align: center; padding: 26px; color: var(--ink-soft); font-size: 14px; }
.site-foot a { color: var(--gold-deep); }

/* ---------- hero ---------- */
.main { max-width: 1080px; margin: 0 auto; padding: 8px 20px 40px; }
h1 {
  font-size: clamp(34px, 5vw, 52px);
  letter-spacing: -0.03em; line-height: 1.04;
  text-align: center;
}
.tagline {
  text-align: center; color: var(--ink-soft); font-style: italic;
  margin: 8px 0 22px; font-size: 17px;
}

/* ---------- stage ---------- */
.stage-wrap { display: flex; justify-content: center; }
.stage {
  position: relative;
  width: min(100%, 980px);
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-2), 0 0 0 1px rgba(42, 33, 54, 0.08);
  background: #12291d;
}
#gameCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }

/* ---------- HUD ---------- */
.hud {
  position: absolute; top: 10px; right: 10px;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end;
  z-index: 5;
}
.hud-chip {
  background: rgba(16, 12, 24, 0.55); color: #f6efe3;
  font-size: 13px; padding: 5px 12px; border-radius: 999px;
  backdrop-filter: blur(4px);
}
.hud-btn {
  background: rgba(16, 12, 24, 0.55); color: #f6efe3;
  border: 1px solid rgba(255, 255, 255, 0.25);
  font-family: inherit; font-size: 13px;
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
  transition: transform 0.15s var(--ease-out), background 0.15s;
  min-height: 30px;
}
.hud-btn:hover:not(:disabled) { background: rgba(201, 151, 58, 0.75); transform: translateY(-1px); }
.hud-btn:disabled { opacity: 0.4; cursor: default; }

.stuck-bar {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: rgba(60, 16, 24, 0.85); color: #ffe9e4;
  padding: 10px 18px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow-2); z-index: 6; font-style: italic;
  animation: rise 0.35s var(--ease-out);
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(18, 12, 28, 0.42);
  backdrop-filter: blur(3px);
}
.overlay.dark { background: rgba(10, 7, 16, 0.72); }
.panel {
  background: linear-gradient(160deg, #fdf8ee, #f1e6cf);
  border-radius: var(--radius);
  box-shadow: var(--shadow-3), inset 0 0 0 1px rgba(201, 151, 58, 0.35);
  padding: 30px 36px;
  text-align: center;
  max-width: min(88%, 460px);
  max-height: 88%;
  overflow: auto;
  animation: pop 0.45s var(--ease-out);
}
@keyframes pop { from { opacity: 0; transform: scale(0.92) translateY(14px); } }

.crest { font-size: 34px; margin-bottom: 4px; }
.game-logo { font-size: 44px; letter-spacing: -0.02em; line-height: 1; }
.game-logo em { color: var(--gold-deep); }
.subtitle {
  color: var(--gold-deep); font-style: italic; font-size: 17px; margin: 4px 0 12px;
}
.menu-blurb { font-size: 14px; color: var(--ink-soft); margin-bottom: 18px; }
.hint { font-size: 12px; color: var(--ink-soft); margin-top: 14px; font-style: italic; }

/* ---------- buttons ---------- */
.btn {
  display: block; width: 100%;
  font-family: inherit; font-size: 17px;
  padding: 12px 20px; margin: 8px 0;
  border-radius: 12px; border: 1.5px solid rgba(42, 33, 54, 0.25);
  background: #fff; color: var(--ink); cursor: pointer;
  transition: transform 0.18s var(--ease-out), box-shadow 0.18s, background 0.18s;
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(160deg, #d9a845, #a3742a);
  border-color: #8a6120; color: #fff8ea; font-weight: 700;
}
.btn-ghost { background: transparent; border-style: dashed; color: var(--ink-soft); font-size: 14px; }
.btn-small { display: inline-block; width: auto; padding: 6px 14px; font-size: 14px; margin: 0 0 0 10px; }
.btn:focus-visible, .hud-btn:focus-visible, .lv-btn:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px;
}

/* ---------- level select ---------- */
.level-panel { text-align: left; max-width: min(92%, 560px); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2 { font-size: 24px; }
.panel-close {
  border: none; background: none; font-size: 20px; cursor: pointer; color: var(--ink-soft);
  width: 40px; height: 40px; border-radius: 10px;
}
.panel-close:hover { background: rgba(42, 33, 54, 0.08); }
.lv-scroll { max-height: 52vh; overflow-y: auto; padding-right: 4px; }
.act-head {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--gold-deep); margin: 14px 0 8px; font-weight: 700;
}
.lv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.lv-btn {
  border: 1.5px solid rgba(42, 33, 54, 0.2); border-radius: 12px;
  background: #fffdf7; cursor: pointer; padding: 8px 4px 6px;
  font-family: inherit; text-align: center;
  transition: transform 0.15s var(--ease-out), border-color 0.15s;
}
.lv-btn:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--gold); }
.lv-btn b { display: block; font-size: 17px; }
.lv-btn.locked { opacity: 0.42; cursor: not-allowed; filter: grayscale(0.7); }
.stars { display: block; font-size: 9px; letter-spacing: 1px; }
.stars i { font-style: normal; color: #d8ccb4; }
.stars i.on { color: var(--gold); }
.lv-foot { font-size: 12px; color: var(--ink-soft); margin-top: 12px; font-style: italic; }

/* ---------- story ---------- */
.story-panel {
  max-width: min(88%, 560px); text-align: center; color: #f2ead8;
  animation: fadeIn 0.6s var(--ease-out);
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(16px); } }
.story-act { text-transform: uppercase; letter-spacing: 0.2em; font-size: 12px; color: var(--gold); }
.story-title { font-size: clamp(24px, 4vw, 34px); margin: 8px 0 18px; letter-spacing: -0.02em; }
.story-page {
  font-size: clamp(16px, 2.4vw, 19px); font-style: italic; line-height: 1.75;
  min-height: 5.5em; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
.story-dots { margin: 18px 0 14px; }
.story-dots .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.3); margin: 0 4px;
  transition: background 0.2s, transform 0.2s;
}
.story-dots .dot.on { background: var(--gold); transform: scale(1.25); }
.story-panel .btn { width: auto; display: inline-block; padding: 12px 34px; }

/* ---------- win ---------- */
.win-panel { min-width: min(80%, 340px); }
.win-stars { font-size: 46px; letter-spacing: 6px; margin-bottom: 6px; }
.win-stars .star { display: inline-block; color: #d8ccb4; animation: starPop 0.5s var(--ease-out) backwards; }
.win-stars .star.on { color: var(--gold); text-shadow: 0 2px 14px rgba(201, 151, 58, 0.55); }
.win-stars .star:nth-child(1) { animation-delay: 0.1s; }
.win-stars .star:nth-child(2) { animation-delay: 0.35s; }
.win-stars .star:nth-child(3) { animation-delay: 0.6s; }
@keyframes starPop { from { opacity: 0; transform: scale(0.2) rotate(-30deg); } }
.win-panel h2 { font-size: 26px; margin-bottom: 4px; }
.win-panel p { color: var(--ink-soft); font-size: 15px; margin-bottom: 14px; }

/* ---------- prose / SEO article ---------- */
.prose { margin-top: 46px; max-width: 760px; margin-left: auto; margin-right: auto; }
.prose h2 {
  font-size: 26px; letter-spacing: -0.02em; margin: 34px 0 12px;
  border-left: 4px solid var(--gold); padding-left: 14px;
}
.prose p { color: #3d3448; margin-bottom: 12px; }
.steps { padding-left: 22px; margin-bottom: 12px; }
.steps li { margin-bottom: 8px; color: #3d3448; }
.rules {
  width: 100%; border-collapse: collapse; margin: 14px 0 20px; font-size: 15px;
  box-shadow: var(--shadow-1); border-radius: 12px; overflow: hidden;
}
.rules th {
  background: var(--moss); color: #f2ead8; text-align: left; padding: 10px 14px;
  font-weight: 700; font-size: 14px;
}
.rules td { padding: 10px 14px; border-bottom: 1px solid rgba(42, 33, 54, 0.09); background: #fffdf7; }
.rules tr:nth-child(even) td { background: var(--parchment-2); }
.faq h3 { font-size: 18px; margin: 18px 0 6px; color: var(--ink); }
.faq p { font-size: 15px; }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .site-head { padding: 10px 14px; }
  .site-nav { display: none; }
  .main { padding: 4px 10px 30px; }
  .stage { border-radius: 12px; }
  .panel { padding: 20px 20px; }
  .game-logo { font-size: 34px; }
  .hud { gap: 5px; }
  .hud-chip { font-size: 11px; padding: 4px 9px; }
  .hud-btn { font-size: 11px; padding: 4px 9px; }
  .prose h2 { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
