/* SERPENT SPIRE — arcane parchment over a living board */
:root {
  --gold: #e8c979;
  --gold-dim: #a98d4f;
  --ivory: #f2ead8;
  --ink: #171310;
  --danger: #ff5a42;
  --good: #8affd4;
  --panel: rgba(16, 12, 9, 0.86);
  --panel-edge: rgba(232, 201, 121, 0.28);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, "Avenir Next", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background: #0a0806; }
body { font-family: var(--sans); color: var(--ivory); user-select: none; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#ui > * { pointer-events: auto; }

/* ---------- overlays ---------- */
.vignette { position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: radial-gradient(ellipse at 50% 42%, transparent 46%, rgba(5,3,2,0.55) 100%); }
.grain { position: fixed; inset: -50%; pointer-events: none; z-index: 6; opacity: 0.05;
  background-image: repeating-conic-gradient(rgba(255,255,255,0.7) 0 0.0006turn, transparent 0 0.0012turn);
  animation: grain 1.4s steps(4) infinite; }
@keyframes grain { 0% { transform: translate(0,0);} 25% { transform: translate(-2%,1%);} 50% { transform: translate(1%,-2%);} 75% { transform: translate(-1%,2%);} }
.dmg-flash { position: fixed; inset: 0; pointer-events: none; z-index: 7; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(255,40,20,0.5) 100%); transition: opacity 0.09s; }
.dmg-flash.on { opacity: 1; }
.heal-flash { position: fixed; inset: 0; pointer-events: none; z-index: 7; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(120,255,190,0.35) 100%); transition: opacity 0.3s; }
.heal-flash.on { opacity: 1; }

.letterbox { position: fixed; left: 0; right: 0; height: 0; background: #000; z-index: 8; transition: height 0.35s ease; pointer-events: none; }
.letterbox.top { top: 0; } .letterbox.bottom { bottom: 0; }
.letterbox.on { height: 9vh; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; display: none; }
#hud.on { display: block; }
.hud-top { position: absolute; top: 14px; left: 18px; right: 18px; display: flex; align-items: flex-start; gap: 14px; }
.level-plaque { background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 10px; padding: 10px 16px; min-width: 220px; }
.level-plaque .lv { font-family: var(--serif); font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--gold); }
.level-plaque .name { font-family: var(--serif); font-size: 19px; margin-top: 2px; }
.level-plaque .progress { margin-top: 8px; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.09); overflow: hidden; }
.level-plaque .progress i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold-dim), var(--gold)); border-radius: 3px; transition: width 0.4s ease; }
.level-plaque .tiles { font-size: 11px; color: rgba(242,234,216,0.6); margin-top: 5px; letter-spacing: 0.08em; }

.hearts { display: flex; gap: 5px; align-items: center; background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 10px; padding: 10px 12px; }
.hearts svg { width: 21px; height: 21px; filter: drop-shadow(0 0 5px rgba(255,60,40,0.5)); }
.hearts svg.empty { opacity: 0.22; filter: none; }
.hearts svg.pop { animation: heart-pop 0.45s ease; }
@keyframes heart-pop { 0% { transform: scale(1);} 35% { transform: scale(1.55) rotate(-8deg);} 100% { transform: scale(1);} }
.hearts svg.lost { animation: heart-lost 0.6s ease forwards; }
@keyframes heart-lost { 0% { transform: scale(1);} 30% { transform: scale(1.4) rotate(10deg);} 100% { transform: scale(0.6); opacity: 0.2; } }

.hud-buttons { margin-left: auto; display: flex; gap: 8px; }
.icon-btn { width: 38px; height: 38px; border-radius: 9px; background: var(--panel); border: 1px solid var(--panel-edge);
  color: var(--ivory); font-size: 16px; cursor: pointer; display: grid; place-items: center; transition: all 0.15s; }
.icon-btn:hover { border-color: var(--gold); color: var(--gold); transform: translateY(-1px); }

/* relic tray */
.relic-tray { position: absolute; left: 18px; bottom: 18px; display: flex; gap: 8px; flex-wrap: wrap; max-width: 40vw; }
.relic { position: relative; width: 46px; height: 46px; border-radius: 10px; background: var(--panel); border: 1px solid var(--panel-edge);
  display: grid; place-items: center; cursor: default; transition: transform 0.15s; animation: relic-in 0.4s ease; }
.relic:hover { transform: translateY(-3px) scale(1.06); border-color: var(--gold); }
.relic svg { width: 26px; height: 26px; }
.relic .tip { position: absolute; bottom: 56px; left: 0; width: 220px; background: var(--panel); border: 1px solid var(--panel-edge);
  border-radius: 8px; padding: 9px 11px; font-size: 12px; line-height: 1.45; opacity: 0; pointer-events: none; transition: opacity 0.15s; z-index: 20; }
.relic .tip b { color: var(--gold); font-family: var(--serif); font-size: 13px; display: block; margin-bottom: 3px; }
.relic:hover .tip { opacity: 1; }
@keyframes relic-in { from { transform: translateY(14px) scale(0.7); opacity: 0; } }

/* roll controls */
.roll-zone { position: absolute; right: 22px; bottom: 20px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.reroll-charges { font-size: 12px; letter-spacing: 0.12em; color: rgba(242,234,216,0.7); text-transform: uppercase; }
#roll-btn { position: relative; border: 1px solid var(--gold); color: var(--ink); background: linear-gradient(180deg, #f4dd9a, #d8b45f);
  font-family: var(--serif); font-size: 19px; letter-spacing: 0.2em; text-transform: uppercase; padding: 15px 34px; border-radius: 12px;
  cursor: pointer; transition: all 0.18s; box-shadow: 0 6px 22px rgba(232,201,121,0.28); }
#roll-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(232,201,121,0.4); }
#roll-btn:active:not(:disabled) { transform: translateY(1px); }
#roll-btn:disabled { opacity: 0.35; cursor: default; box-shadow: none; }
#roll-btn .sub { display: block; font-size: 10px; letter-spacing: 0.14em; color: rgba(23,19,16,0.72); margin-top: 2px; }
#roll-btn.pulse { animation: roll-pulse 1.6s ease infinite; }
@keyframes roll-pulse { 0%,100% { box-shadow: 0 6px 22px rgba(232,201,121,0.25);} 50% { box-shadow: 0 6px 34px rgba(232,201,121,0.65);} }
#reroll-btn { display: none; border: 1px solid var(--panel-edge); background: var(--panel); color: var(--ivory);
  font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; padding: 9px 18px; border-radius: 9px; cursor: pointer; transition: all 0.15s; }
#reroll-btn:hover { border-color: var(--gold); color: var(--gold); }
#reroll-btn.on { display: block; animation: relic-in 0.3s ease; }
.last-roll { font-family: var(--serif); font-size: 54px; color: var(--gold); text-shadow: 0 0 24px rgba(232,201,121,0.4); min-height: 60px; line-height: 1; }

/* toast */
#toast { position: absolute; top: 86px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast-item { background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 999px; padding: 8px 20px;
  font-family: var(--serif); font-size: 15px; letter-spacing: 0.06em; animation: toast-in 0.3s ease; white-space: nowrap; }
.toast-item.bad { border-color: rgba(255,90,66,0.5); color: #ffb4a6; }
.toast-item.good { border-color: rgba(138,255,212,0.5); color: #bfffe8; }
@keyframes toast-in { from { transform: translateY(-12px); opacity: 0; } }

/* ---------- full screens ---------- */
.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column;
  background: rgba(8,6,4,0.62); backdrop-filter: blur(3px); z-index: 30;
  overflow-y: auto; padding: 18px 0; }
.screen.on { display: flex; animation: fade-in 0.4s ease; }
/* margin-marginals centering that stays reachable when content overflows */
.screen.on::before, .screen.on::after { content: ""; margin: auto; flex: 0 0 auto; }
.screen.on > * { flex-shrink: 0; }
@keyframes fade-in { from { opacity: 0; } }
#screen-title { background: radial-gradient(ellipse at 50% 46%, rgba(10,7,5,0.55) 0%, rgba(6,4,3,0.88) 100%); }

.title-logo { text-align: center; margin-bottom: 26px; padding: 26px 44px 30px; border-radius: 20px;
  background: radial-gradient(ellipse at 50% 50%, rgba(10,7,5,0.5), rgba(10,7,5,0) 72%); }
.title-logo .over { font-size: 13px; letter-spacing: 0.5em; text-transform: uppercase; color: var(--gold-dim); margin-bottom: 14px; }
.title-logo h1 { font-family: var(--serif); font-size: clamp(40px, 8vw, 86px); line-height: 0.95; color: var(--ivory);
  text-shadow: 0 0 40px rgba(232,201,121,0.22), 0 4px 34px rgba(0,0,0,0.9); letter-spacing: 0.04em; }
.title-logo h1 em { font-style: normal; color: var(--gold); }
.title-logo .under { font-family: var(--serif); font-style: italic; font-size: 17px; color: rgba(242,234,216,0.75); margin-top: 14px; }
.title-logo .under2 { font-size: 12px; letter-spacing: 0.3em; text-transform: uppercase; color: rgba(242,234,216,0.45); margin-top: 6px; }

.menu { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.btn { font-family: var(--serif); font-size: 17px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ivory);
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 10px; padding: 14px 44px; cursor: pointer; transition: all 0.18s; }
.btn:hover { border-color: var(--gold); color: var(--gold); transform: translateY(-2px); box-shadow: 0 8px 26px rgba(0,0,0,0.5); }
.btn.primary { background: linear-gradient(180deg, #f4dd9a, #d8b45f); color: var(--ink); border-color: var(--gold); }
.btn.small { font-size: 13px; padding: 10px 22px; }
.best-line { margin-top: 26px; font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: rgba(242,234,216,0.5); }
.best-line b { color: var(--gold); }

/* oath / relic cards */
.pick-title { font-family: var(--serif); font-size: 30px; margin-bottom: 6px; color: var(--ivory); }
.pick-sub { font-size: 13px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold-dim); margin-bottom: 30px; }
.cards { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; padding: 0 20px; max-width: 1100px; }
.card { width: 240px; background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 14px; padding: 22px 20px 18px;
  cursor: pointer; transition: all 0.2s; position: relative; overflow: hidden; text-align: center; }
.card::before { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 0%, rgba(232,201,121,0.14), transparent 65%); opacity: 0; transition: opacity 0.2s; }
.card:hover { transform: translateY(-6px); border-color: var(--gold); box-shadow: 0 18px 44px rgba(0,0,0,0.55); }
.card:hover::before { opacity: 1; }
.card.picked { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold), 0 18px 44px rgba(0,0,0,0.55); }
.card svg { width: 44px; height: 44px; margin-bottom: 12px; }
.card h3 { font-family: var(--serif); font-size: 19px; color: var(--gold); margin-bottom: 8px; }
.card p { font-size: 12.5px; line-height: 1.55; color: rgba(242,234,216,0.82); }
.card .tag { position: absolute; top: 12px; right: 14px; font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase; color: rgba(242,234,216,0.4); }
.seed-line { margin-top: 26px; font-size: 12px; letter-spacing: 0.14em; color: rgba(242,234,216,0.55); display: flex; gap: 12px; align-items: center; }
.seed-line button { background: none; border: 1px solid var(--panel-edge); color: var(--ivory); border-radius: 7px; padding: 5px 12px; font-size: 11px; cursor: pointer; letter-spacing: 0.1em; text-transform: uppercase; }
.seed-line button:hover { border-color: var(--gold); color: var(--gold); }

/* level banner */
.banner { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; z-index: 25; pointer-events: none; }
.banner.on { display: flex; }
.banner .rule { width: 0; height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); transition: width 0.7s ease; }
.banner.on .rule { width: 60vw; }
.banner .lv { font-size: 13px; letter-spacing: 0.6em; text-transform: uppercase; color: var(--gold); margin: 16px 0 10px; }
.banner .nm { font-family: var(--serif); font-size: clamp(30px, 5.4vw, 58px); text-shadow: 0 4px 30px rgba(0,0,0,0.9); }
.banner .ep { font-family: var(--serif); font-style: italic; font-size: 17px; color: rgba(242,234,216,0.7); margin-top: 10px; }
.banner > * { opacity: 0; animation: banner-in 0.6s ease forwards; }
@keyframes banner-in { to { opacity: 1; } }

/* stats + end screens */
.end-frame { background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 18px; padding: 38px 46px; max-width: 640px; width: min(92vw, 640px); text-align: center; animation: relic-in 0.5s ease; }
.end-frame h2 { font-family: var(--serif); font-size: 42px; margin-bottom: 4px; }
.end-frame h2.win { color: var(--gold); }
.end-frame h2.lose { color: var(--danger); }
.end-frame .epitaph { font-family: var(--serif); font-style: italic; color: rgba(242,234,216,0.75); margin-bottom: 26px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 10px; margin-bottom: 28px; }
.stat .v { font-family: var(--serif); font-size: 26px; color: var(--ivory); }
.stat .k { font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase; color: rgba(242,234,216,0.5); margin-top: 3px; }
.end-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* pause */
.pause-frame { background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 16px; padding: 34px 40px; text-align: center; min-width: 320px; }
.pause-frame h2 { font-family: var(--serif); letter-spacing: 0.3em; text-transform: uppercase; font-size: 22px; margin-bottom: 24px; }
.pause-frame .menu { gap: 10px; }
.help-list { text-align: left; font-size: 13.5px; line-height: 1.8; color: rgba(242,234,216,0.85); max-width: 460px; margin: 18px auto 0; }
.help-list b { color: var(--gold); font-family: var(--serif); }

/* cache modal */
.cache-frame { background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 16px; padding: 30px 36px; text-align: center; }
.cache-frame h3 { font-family: var(--serif); font-size: 24px; color: var(--gold); margin-bottom: 6px; }
.cache-frame p { font-size: 13px; color: rgba(242,234,216,0.7); margin-bottom: 20px; }

/* loading / webgl fail */
#boot { position: fixed; inset: 0; display: grid; place-items: center; background: #0a0806; z-index: 100; transition: opacity 0.5s; }
#boot .t { font-family: var(--serif); letter-spacing: 0.4em; text-transform: uppercase; color: var(--gold-dim); animation: boot-pulse 1.6s ease infinite; }
@keyframes boot-pulse { 50% { opacity: 0.45; } }
#boot.done { opacity: 0; pointer-events: none; }
.webgl-fail { position: fixed; inset: 0; display: none; place-items: center; z-index: 200; background: #0a0806; color: var(--ivory); text-align: center; padding: 30px; line-height: 1.7; }

@media (max-width: 760px), (max-height: 780px) {
  .relic-tray { max-width: 60vw; bottom: 108px; }
  .roll-zone { bottom: 14px; right: 14px; }
  #roll-btn { font-size: 16px; padding: 13px 26px; }
  .level-plaque { min-width: 140px; padding: 8px 12px; }
  .level-plaque .name { font-size: 14px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .card { width: min(84vw, 300px); padding: 14px 14px 12px; }
  .cards { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch; max-width: 94vw; padding-bottom: 8px; }
  .cards .card { flex: 0 0 74vw; scroll-snap-align: center; }
  .cards .card:hover { transform: none; }
  .card svg { width: 34px; height: 34px; margin-bottom: 8px; }
  .pick-title { font-size: 24px; margin-top: 8px; }
  .pick-sub { margin-bottom: 16px; }
  .title-logo { margin-bottom: 16px; padding: 16px 20px 20px; }
  .title-logo h1 { font-size: clamp(34px, 10vw, 62px); }
  .title-logo .under { font-size: 14px; margin-top: 10px; }
  .seed-line { margin-top: 16px; flex-direction: column; gap: 8px; }
  .menu { margin-top: 14px; }
  .btn { font-size: 15px; padding: 12px 30px; }
  .end-frame { padding: 26px 22px; }
  .end-frame h2 { font-size: 32px; }
  .hud-top { gap: 8px; }
  .hearts svg { width: 17px; height: 17px; }
  .banner .nm { font-size: clamp(24px, 7vw, 40px); }
}
