:root {
  --bg: #0b0a10;
  --panel: rgba(18, 15, 22, 0.86);
  --panel-edge: #3b2f29;
  --ink: #efe6d8;
  --ink-dim: #a99f92;
  --ember: #ff8a3a;
  --ember-deep: #c2410c;
  --moss: #7ad35a;
  --frost: #9ee8ff;
  --blood: #e8503a;
  --mana: #5aa8ff;
  --pixel: 'Pixelify Sans', ui-monospace, monospace;
  --voice: 'Cormorant Garamond', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
body { font-family: var(--pixel); -webkit-font-smoothing: antialiased; user-select: none; }
button, input { font-family: inherit; }
.hidden { display: none !important; }

#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; cursor: crosshair; image-rendering: pixelated; }
#vignette {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(5, 3, 8, 0.55) 100%);
}

/* ------------------------------------------------------------------ menu */
#menu {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(8, 6, 12, 0.25), rgba(8, 6, 12, 0.7));
  overflow-y: auto;
}
.panel {
  width: min(560px, 100%); padding: 28px 30px 22px; border-radius: 6px;
  background: var(--panel); border: 2px solid var(--panel-edge);
  box-shadow: 0 0 0 2px #120e10, 0 18px 60px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 200, 150, 0.06);
  backdrop-filter: blur(3px);
  display: flex; flex-direction: column; gap: 16px;
}
.panel.wide { width: min(860px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; }
.logo { text-align: center; }
.logo h1 {
  margin: 0; font-size: clamp(40px, 9vw, 72px); font-weight: 700; letter-spacing: 6px; line-height: 1;
  background: linear-gradient(180deg, #ffe7a0 0%, #ffae4a 40%, #e2561a 75%, #7a2410 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 120, 40, 0.45)) drop-shadow(0 3px 0 #2a1208);
  animation: flicker 3.2s infinite;
}
@keyframes flicker {
  0%, 100% { filter: drop-shadow(0 0 18px rgba(255, 120, 40, 0.45)) drop-shadow(0 3px 0 #2a1208); }
  45% { filter: drop-shadow(0 0 26px rgba(255, 140, 50, 0.6)) drop-shadow(0 3px 0 #2a1208); }
  60% { filter: drop-shadow(0 0 14px rgba(255, 100, 30, 0.35)) drop-shadow(0 3px 0 #2a1208); }
}
.tagline { margin: 8px 0 0; font-family: var(--voice); font-style: italic; font-size: 20px; color: var(--ink-dim); }
.panel h2 { margin: 0; font-size: 26px; color: var(--ember); letter-spacing: 1px; }
.lede { margin: 0; font-family: var(--voice); font-style: italic; font-size: 19px; color: var(--ink-dim); }

.identity { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
input.name, input.code {
  flex: 1; min-width: 160px; padding: 10px 12px; font-size: 18px; color: var(--ink);
  background: #0e0c12; border: 2px solid #3a302c; border-radius: 4px; outline: none;
}
input.name:focus, input.code:focus { border-color: var(--ember); }
input.code { flex: 0 1 120px; min-width: 90px; text-transform: uppercase; letter-spacing: 4px; text-align: center; }
.swatches { display: flex; gap: 6px; }
.swatch { width: 26px; height: 26px; border-radius: 3px; border: 2px solid #120e10; cursor: pointer; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25); }
.swatch.on { outline: 2px solid var(--ink); outline-offset: 2px; }

.actions { display: grid; gap: 10px; }
.action { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.action small { color: var(--ink-dim); font-size: 13px; }
.action.join { gap: 8px; }
.btn {
  padding: 10px 18px; font-size: 17px; font-weight: 600; letter-spacing: 0.5px; cursor: pointer;
  color: var(--ink); background: #241c1c; border: 2px solid #4a3a32; border-radius: 4px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.35); transition: transform 0.06s, background 0.15s;
}
.btn:hover { background: #30241f; border-color: #6a5040; }
.btn:active { transform: translateY(1px); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.35); }
.btn.primary { background: linear-gradient(180deg, #ff9a48, #d9561c); border-color: #7a2a10; color: #1a0a04; }
.btn.primary:hover { background: linear-gradient(180deg, #ffb060, #e5642a); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.bots { display: flex; gap: 10px; align-items: center; color: var(--ink-dim); font-size: 14px; }
.bots input { accent-color: var(--ember); width: 130px; }
.links { display: flex; gap: 18px; justify-content: center; }
.link { background: none; border: none; color: var(--frost); cursor: pointer; font-size: 15px; text-decoration: underline dotted; }
.foot { margin: 0; text-align: center; font-size: 12px; color: #7d7468; line-height: 1.5; }
.error { margin: 0; min-height: 1em; color: #ff8a7a; font-size: 14px; }
.error:empty { display: none; }
.busy { text-align: center; color: var(--ink-dim); font-family: var(--voice); font-style: italic; font-size: 20px; margin: 8px 0; }

.room { text-align: center; display: grid; gap: 6px; justify-items: center; }
.room small { color: var(--ink-dim); letter-spacing: 2px; text-transform: uppercase; font-size: 12px; }
.room-code { font-size: 46px; font-weight: 700; letter-spacing: 10px; color: #ffd27a; text-shadow: 0 0 16px rgba(255, 170, 60, 0.4); user-select: text; }
.roster { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.roster li { display: flex; gap: 8px; align-items: center; padding: 7px 10px; background: rgba(255, 255, 255, 0.03); border: 1px solid #2c2420; border-radius: 3px; }
.roster li.empty { color: #5d554c; font-style: italic; font-family: var(--voice); }
.roster i, .scores i, .results i, .board i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; }
.roster em { margin-left: auto; color: var(--ink-dim); font-size: 12px; font-style: normal; }
.lobby-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.status-line { margin: 0; color: var(--ink-dim); font-size: 13px; text-align: center; }

.spell-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.spell-rule { display: grid; grid-template-columns: 30px 1fr; gap: 2px 10px; align-items: center; padding: 8px; background: rgba(255, 255, 255, 0.03); border-radius: 3px; }
.spell-rule img { grid-row: span 2; width: 30px; height: 30px; image-rendering: pixelated; }
.spell-rule span { font-size: 13px; color: var(--ink-dim); line-height: 1.35; }
.rules { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.rules dt { color: var(--ember); font-weight: 600; }
.rules dd { margin: 0; font-size: 14px; color: var(--ink); line-height: 1.45; }
.vol { display: grid; grid-template-columns: 200px 1fr; align-items: center; gap: 12px; }
.vol input { accent-color: var(--ember); }

/* ------------------------------------------------------------------ hud */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: none; }
.hud-top {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 14px; align-items: center; padding: 6px 14px;
  background: rgba(12, 10, 16, 0.72); border: 1px solid #3a2f29; border-radius: 4px; font-size: 16px;
}
.season { font-weight: 700; color: #ffd27a; min-width: 64px; }
#hud[data-season='spring'] .season { color: #9ee07a; }
#hud[data-season='autumn'] .season { color: #ff9a48; }
#hud[data-season='winter'] .season { color: #bfe8ff; }
.day-bar { position: relative; width: 120px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #1a2040 0%, #1a2040 22%, #e8a060 28%, #9fd0f0 40%, #9fd0f0 65%, #e88040 74%, #1a2040 80%, #1a2040 100%); }
.day-sun { position: absolute; top: 50%; transform: translate(-50%, -50%); font-size: 14px; color: #fff3c0; text-shadow: 0 0 6px #ffcc60; }
.time { min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; }
.time.urgent { color: var(--blood); animation: pulse 0.5s infinite alternate; }
@keyframes pulse { to { opacity: 0.5; } }
.weather { color: var(--frost); min-width: 76px; }
.wind { width: 18px; text-align: center; color: #cfe8e0; }
.wind-arrow { display: inline-block; transition: transform 0.4s; }

.mood { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); display: grid; justify-items: center; gap: 6px; font-size: 12px; color: var(--ink-dim); }
.mood-title { letter-spacing: 1px; }
.mood-gauge { position: relative; width: 10px; height: 160px; border-radius: 5px; border: 1px solid #3a2f29; background: linear-gradient(0deg, #b0301a 0%, #6a2a1a 30%, #3a3a2a 50%, #2a5a2a 70%, #6ddc5a 100%); }
.mood-mark { position: absolute; left: 50%; width: 18px; height: 4px; transform: translate(-50%, 50%); background: #fff; border-radius: 2px; box-shadow: 0 0 6px #fff; transition: bottom 0.6s; }
.mood-label { font-weight: 600; }
.mood[data-state='wrath'] .mood-label { color: #ff6a4a; }
.mood[data-state='bloom'] .mood-label { color: var(--moss); }

.scores { position: absolute; top: 10px; right: 12px; display: grid; gap: 3px; min-width: 170px; }
.score-row { display: flex; gap: 8px; align-items: center; padding: 3px 8px; background: rgba(12, 10, 16, 0.7); border-radius: 3px; font-size: 14px; }
.score-row.me { outline: 1px solid rgba(255, 210, 122, 0.5); }
.score-row .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-row b { color: #ffd27a; }
.feed { position: absolute; top: 190px; right: 12px; display: grid; gap: 4px; justify-items: end; max-width: 360px; }
.feed-item { padding: 4px 9px; font-size: 13px; background: rgba(12, 10, 16, 0.72); border-left: 3px solid #6a5a4a; border-radius: 2px; animation: slidein 0.25s ease-out; }
.feed-item.mine { border-left-color: var(--ember); color: #ffe0b0; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

.subtitle {
  position: fixed; left: 50%; bottom: 128px; transform: translateX(-50%); max-width: min(760px, 90vw);
  font-family: var(--voice); font-style: italic; font-size: clamp(18px, 2.2vw, 26px); color: #f3ead8; text-align: center;
  text-shadow: 0 0 12px #000, 0 2px 2px #000; opacity: 0; transition: opacity 0.6s; pointer-events: none; z-index: 5;
}
.subtitle.show { opacity: 1; }

.hud-bottom { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: grid; justify-items: center; gap: 6px; }
.status-row { display: flex; gap: 6px; min-height: 18px; }
.status { display: flex; gap: 4px; align-items: center; padding: 1px 6px; font-size: 12px; background: rgba(12, 10, 16, 0.75); border-radius: 3px; }
.status img { width: 14px; height: 14px; image-rendering: pixelated; }
.bars { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 400px; max-width: 90vw; }
.bar { position: relative; height: 14px; background: rgba(12, 10, 16, 0.85); border: 1px solid #3a2f29; border-radius: 3px; overflow: hidden; }
.bar .fill { position: absolute; inset: 0 auto 0 0; transition: width 0.12s; }
.bar.hp .fill { background: linear-gradient(180deg, #ff7a5a, #c2301a); }
.bar.mana .fill { background: linear-gradient(180deg, #8ac8ff, #2a6ad0); }
.bar span { position: relative; display: block; text-align: center; font-size: 11px; line-height: 14px; text-shadow: 0 1px 0 #000; }
.spells { display: flex; gap: 6px; }
.spell {
  position: relative; width: 52px; height: 52px; border-radius: 4px; overflow: hidden;
  background: rgba(12, 10, 16, 0.85); border: 2px solid #3a2f29; display: grid; place-items: center;
}
.spell img { width: 36px; height: 36px; image-rendering: pixelated; }
.spell.sel { border-color: var(--c); box-shadow: 0 0 12px var(--c), inset 0 0 10px color-mix(in srgb, var(--c) 30%, transparent); transform: translateY(-3px); }
.spell.poor img { opacity: 0.35; filter: grayscale(0.7); }
.spell .cd { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.62); }
.spell .key { position: absolute; top: 1px; left: 4px; font-size: 11px; color: var(--ink-dim); }
.spell .cost { position: absolute; bottom: 1px; right: 4px; font-size: 11px; color: #9fc8ff; }
.dash-pill { font-size: 11px; color: #6d655b; letter-spacing: 1px; }
.dash-pill.ready { color: var(--ink-dim); }

.center-msg {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%) scale(0.96); opacity: 0;
  min-width: 320px; max-width: 92vw; padding: 20px 28px; text-align: center;
  background: var(--panel); border: 2px solid var(--panel-edge); border-radius: 6px; transition: opacity 0.35s, transform 0.35s;
}
.center-msg.show { opacity: 1; transform: translate(-50%, -50%) scale(1); pointer-events: auto; }
.center-msg[data-kind='death'] { background: rgba(30, 8, 8, 0.7); border-color: #5a1a14; }
.center-msg h2 { margin: 0 0 6px; color: var(--ember); font-size: 28px; }
.center-msg p { margin: 6px 0; color: var(--ink-dim); font-family: var(--voice); font-style: italic; font-size: 19px; }
.champion b { font-family: var(--pixel); font-style: normal; font-size: 24px; }
.results { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 4px; text-align: left; }
.results li { display: grid; grid-template-columns: 12px 1fr auto 44px; gap: 10px; align-items: center; padding: 5px 10px; background: rgba(255, 255, 255, 0.04); border-radius: 3px; }
.results li:first-child { background: rgba(255, 200, 100, 0.1); }
.results em { color: var(--ink-dim); font-size: 13px; font-style: normal; }
.results b { text-align: right; color: #ffd27a; font-size: 18px; }
.grove-report { font-size: 16px !important; }
.center-msg .row { display: flex; gap: 10px; justify-content: center; margin-top: 12px; }

.board { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 16px 20px; background: var(--panel); border: 2px solid var(--panel-edge); border-radius: 6px; }
.board h3 { margin: 0 0 10px; color: var(--ember); }
.board table { border-collapse: collapse; font-size: 14px; }
.board th, .board td { padding: 4px 10px; text-align: center; }
.board th { color: var(--ink-dim); font-weight: 400; font-size: 12px; }
.board td:first-child { text-align: left; display: flex; gap: 8px; align-items: center; }
.board .total { color: #ffd27a; font-weight: 700; }

@media (max-width: 720px) {
  .mood, .feed, .dash-pill { display: none; }
  .spell { width: 42px; height: 42px; }
  .spell img { width: 28px; height: 28px; }
  .roster { grid-template-columns: 1fr; }
  .rules { grid-template-columns: 1fr; }
  .scores { min-width: 120px; font-size: 12px; }
  .hud-top { font-size: 13px; gap: 8px; }
  .day-bar { width: 70px; }
}

.banner { position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); text-align: center; animation: banner 3.6s ease-out forwards; }
.banner h1 { margin: 0; font-size: clamp(48px, 10vw, 96px); letter-spacing: 8px; color: #ffe2a0; text-shadow: 0 0 30px rgba(255, 150, 60, 0.6), 0 4px 0 #2a1208; }
#hud[data-season='spring'] .banner h1 { color: #c8f0a0; text-shadow: 0 0 30px rgba(120, 220, 90, 0.5), 0 4px 0 #10240a; }
#hud[data-season='autumn'] .banner h1 { color: #ffb070; }
#hud[data-season='winter'] .banner h1 { color: #e0f6ff; text-shadow: 0 0 30px rgba(150, 220, 255, 0.6), 0 4px 0 #0a1a2a; }
.banner p { margin: 4px 0 0; font-family: var(--voice); font-style: italic; font-size: 22px; color: var(--ink-dim); }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -40%); } 15%, 70% { opacity: 1; transform: translate(-50%, -50%); } 100% { opacity: 0; transform: translate(-50%, -55%); } }
