/* LAIR LORD: carved stone, torch gold, and blood red, over a dark dungeon. */
:root {
  --ink: #ecdfc6;
  --dim: #a8987c;
  --gold: #f0b43c;
  --gold-2: #ffd77a;
  --blood: #c8262e;
  --good: #63d36f;
  --bad: #ff5a4f;
  --warn: #f0b43c;
  --stone: rgba(22, 18, 16, 0.92);
  --stone-2: rgba(36, 29, 25, 0.95);
  --edge: #5a4734;
  --edge-hi: #8a6c45;
  --display: 'Cinzel', 'Trajan Pro', Georgia, serif;
  --body: 'Alegreya Sans', 'Segoe UI', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #050407; color: var(--ink); font-family: var(--body); font-size: 15px; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
#game { position: fixed; inset: 0; user-select: none; -webkit-user-select: none; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: none; }
#view.fp { cursor: none; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--display); font-size: 22px; letter-spacing: 0.08em; color: var(--dim); background: #050407; z-index: 50; }
#loading[hidden] { display: none; }

/* --- the panels look like dressed stone --- */
.slab, #top, #panel, #info, #tip, #handBox, #tooltip, .pane, #mapBox {
  background: linear-gradient(180deg, var(--stone-2), var(--stone));
  border: 1px solid var(--edge);
  box-shadow: inset 0 1px 0 rgba(255, 220, 160, 0.08), 0 8px 30px rgba(0, 0, 0, 0.55);
}

/* --- top bar --- */
#top { position: absolute; top: 10px; left: 10px; right: 222px; display: flex; align-items: center; gap: 18px; padding: 7px 12px; border-radius: 10px; z-index: 5; min-height: 46px; flex-wrap: wrap; }
.stat { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.stat b { font-size: 19px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat span, .stat small { color: var(--dim); font-size: 13px; }
.stat.gold b { color: var(--gold-2); }
.ico { width: 20px; height: 20px; fill: none; stroke: var(--gold); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; align-self: center; flex: none; }
.ico.heart { stroke: var(--blood); fill: rgba(200, 38, 46, 0.35); }
.heartbar { display: flex; align-items: center; gap: 6px; }
.heartbar .bar { width: 120px; height: 10px; border-radius: 5px; background: #1a0c0c; border: 1px solid #4a2020; overflow: hidden; }
.heartbar .bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #8a1020, #ff3a3a); transition: width 0.3s; }
.heartbar.hit .bar { box-shadow: 0 0 12px #ff2a2a; }
.obj { flex: 1; min-width: 200px; display: flex; flex-direction: column; line-height: 1.2; }
.obj b { font-family: var(--display); font-weight: 800; letter-spacing: 0.05em; color: var(--gold-2); font-size: 14px; }
.obj span { color: var(--dim); font-size: 13px; }
#raid { color: #ffb08a; }
.buttons { display: flex; gap: 6px; }
.buttons button { min-width: 38px; height: 34px; border-radius: 8px; background: #2a201a; border: 1px solid var(--edge); display: grid; place-items: center; font-weight: 700; }
.buttons button:hover { border-color: var(--edge-hi); background: #362a20; }
.buttons button svg { width: 18px; height: 18px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.buttons button.off svg { stroke: var(--dim); opacity: 0.5; }

/* --- minimap --- */
#mapBox { position: absolute; top: 10px; right: 10px; width: 202px; height: 202px; padding: 0; border-radius: 10px; overflow: hidden; z-index: 5; }
#minimap { width: 200px; height: 200px; display: block; cursor: pointer; image-rendering: pixelated; }

/* --- the build panel --- */
#panel { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); width: min(820px, calc(100vw - 20px)); border-radius: 12px; z-index: 5; padding: 0 10px 8px; }
#tabs { display: flex; gap: 2px; margin: 0 -10px 8px; border-bottom: 1px solid var(--edge); }
#tabs button { flex: 1; background: none; border: none; padding: 9px 4px 8px; font-family: var(--display); font-weight: 600; font-size: 13px; letter-spacing: 0.08em; color: var(--dim); border-bottom: 2px solid transparent; }
#tabs button:hover { color: var(--ink); }
#tabs button.on { color: var(--gold-2); border-bottom-color: var(--gold); }
#tabBody { display: flex; gap: 8px; flex-wrap: wrap; min-height: 84px; align-items: stretch; }
.tool { position: relative; width: 88px; height: 84px; border-radius: 9px; border: 1px solid var(--edge); background: #1c1612 center/cover no-repeat; display: flex; flex-direction: column; justify-content: flex-end; padding: 0; overflow: hidden; text-align: left; transition: transform 0.08s, border-color 0.12s; }
.tool::before { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0.05) 30%, rgba(0,0,0,0.85)); }
.tool .nm { position: relative; font-weight: 700; font-size: 13px; padding: 0 7px; line-height: 1.1; }
.tool .cost { position: relative; font-size: 12px; color: var(--gold-2); padding: 1px 7px 6px; font-variant-numeric: tabular-nums; }
.tool svg.glyph { position: absolute; top: 9px; left: 50%; transform: translateX(-50%); width: 34px; height: 34px; fill: none; stroke: var(--gold-2); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 6px rgba(255, 180, 60, 0.45)); }
.tool:hover { border-color: var(--edge-hi); transform: translateY(-2px); }
.tool.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 16px rgba(240, 180, 60, 0.45); }
.tool.locked { filter: grayscale(1) brightness(0.55); cursor: not-allowed; }
.tool.poor .cost { color: var(--bad); }
.tool kbd { position: absolute; top: 4px; right: 5px; font: 11px var(--body); color: var(--dim); background: rgba(0,0,0,0.5); border-radius: 3px; padding: 0 4px; }
.tool.sell { background: #2a1414; }
.tool.sell svg.glyph { stroke: #ff8a7a; }
.empty { color: var(--dim); font-size: 14px; padding: 18px 6px; }
.crow { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--edge); background: #1c1612; min-width: 150px; text-align: left; }
.crow:hover { border-color: var(--edge-hi); }
.crow .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.crow b { font-size: 18px; margin-left: auto; font-variant-numeric: tabular-nums; }
.crow small { color: var(--dim); display: block; font-size: 12px; }
#toolLine { color: var(--dim); font-size: 13px; padding-top: 6px; min-height: 22px; }
#toolLine b { color: var(--ink); }
#researchLine { color: #c9a8ff; }

/* --- hover info, log, tips --- */
#info { position: absolute; left: 10px; bottom: 200px; width: 230px; border-radius: 10px; padding: 9px 12px; z-index: 5; font-size: 13px; }
#info h4 { margin: 0 0 3px; font-family: var(--display); font-size: 14px; color: var(--gold-2); letter-spacing: 0.04em; }
#info .row { display: flex; justify-content: space-between; color: var(--dim); }
#info .row b { color: var(--ink); font-weight: 500; }
#info .hb { height: 6px; border-radius: 3px; background: #1a0c0c; margin: 4px 0 6px; overflow: hidden; }
#info .hb i { display: block; height: 100%; background: var(--good); }
#info.hero .hb i { background: var(--bad); }
#log { position: absolute; left: 10px; bottom: 10px; width: min(360px, 30vw); display: flex; flex-direction: column; gap: 4px; z-index: 4; pointer-events: none; }
#log div { background: rgba(14, 10, 9, 0.82); border-left: 3px solid var(--dim); padding: 5px 9px; border-radius: 0 6px 6px 0; font-size: 13.5px; line-height: 1.3; animation: in 0.25s ease-out; transition: opacity 0.6s; }
#log div.good { border-color: var(--good); }
#log div.bad { border-color: var(--bad); color: #ffd6cf; }
#log div.warn { border-color: var(--warn); }
#log div.fade { opacity: 0; }
@keyframes in { from { transform: translateX(-12px); opacity: 0; } }
#tip { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); width: min(560px, calc(100vw - 260px)); border-radius: 12px; padding: 12px 16px 12px; z-index: 6; border-color: var(--edge-hi); animation: drop 0.3s ease-out; }
#tip .tipHead { font-family: var(--display); font-size: 12px; letter-spacing: 0.18em; color: var(--blood); text-transform: uppercase; }
#tip p { margin: 4px 0 8px; font-size: 16px; line-height: 1.4; }
#tip button { float: right; background: #2a201a; border: 1px solid var(--edge-hi); border-radius: 7px; padding: 4px 14px; font-weight: 700; color: var(--gold-2); }
@keyframes drop { from { transform: translate(-50%, -10px); opacity: 0; } }
#nowPlaying { position: absolute; right: 10px; top: 222px; font-size: 12px; color: var(--dim); background: rgba(0,0,0,0.6); padding: 4px 9px; border-radius: 6px; z-index: 4; }
#handBox { position: absolute; right: 10px; bottom: 200px; border-radius: 10px; padding: 8px 10px; z-index: 5; font-size: 13px; width: 202px; }
#handBox h4 { margin: 0 0 4px; font-family: var(--display); font-size: 12px; letter-spacing: 0.12em; color: var(--dim); }
#handBox span { display: inline-block; margin: 2px 4px 2px 0; padding: 2px 7px; border-radius: 10px; background: #2a201a; border: 1px solid var(--edge); }
#tooltip { position: absolute; z-index: 20; border-radius: 8px; padding: 7px 10px; max-width: 260px; font-size: 13px; pointer-events: none; line-height: 1.35; }
#tooltip b { color: var(--gold-2); display: block; font-family: var(--display); font-size: 13px; }

/* --- first person --- */
#fpHud { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
#fpHud .cross { position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px; border: 2px solid rgba(255, 220, 160, 0.7); border-radius: 50%; }
#fpHud .fpName { position: absolute; left: 50%; bottom: 74px; transform: translateX(-50%); font-family: var(--display); color: var(--gold-2); letter-spacing: 0.08em; font-size: 18px; text-shadow: 0 2px 8px #000; }
#fpHud .fpBar { position: absolute; left: 50%; bottom: 56px; transform: translateX(-50%); width: 260px; height: 10px; border-radius: 5px; background: rgba(20, 8, 8, 0.8); border: 1px solid #4a2020; overflow: hidden; }
#fpHud .fpBar i { display: block; height: 100%; background: linear-gradient(90deg, #2a8a3a, #63d36f); }
#fpHud .fpHelp { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); color: var(--dim); font-size: 13px; text-shadow: 0 1px 4px #000; white-space: nowrap; }
#hud.fp > :not(#fpHud):not(#log):not(#top) { display: none; }

/* --- screens --- */
.screen { position: absolute; inset: 0; display: grid; place-items: center; z-index: 30; background: radial-gradient(ellipse at center, rgba(5, 4, 7, 0.25), rgba(5, 4, 7, 0.92)), url('assets/title.jpg') center/cover no-repeat, #050407; }
.screen.over { background: rgba(5, 4, 7, 0.72); }
.screen[hidden] { display: none; }
.pane { border-radius: 16px; padding: 30px 38px; max-width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; text-align: center; }
.pane[hidden] { display: none; }
#title { background: none; border: none; box-shadow: none; padding-top: 26vh; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1 { font-family: var(--display); font-weight: 800; font-size: clamp(52px, 9vw, 104px); letter-spacing: 0.08em; margin: 0; color: #ffcf7a; text-shadow: 0 0 30px rgba(255, 80, 30, 0.6), 0 4px 0 #3a1408, 0 8px 30px #000; }
h2 { font-family: var(--display); font-weight: 800; letter-spacing: 0.06em; color: var(--gold-2); margin: 0 0 16px; font-size: 28px; }
h3 { font-family: var(--display); color: var(--gold-2); font-size: 15px; letter-spacing: 0.06em; margin: 0 0 4px; }
.sub { font-size: 20px; color: var(--ink); margin: 6px 0 28px; text-shadow: 0 2px 8px #000; letter-spacing: 0.04em; }
.menu { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.menu button, .pane button.back { min-width: 240px; padding: 11px 22px; border-radius: 10px; background: linear-gradient(180deg, #3a2a1c, #241a12); border: 1px solid var(--edge-hi); font-family: var(--display); font-weight: 600; letter-spacing: 0.08em; font-size: 15px; color: var(--ink); }
.menu button.big { font-size: 18px; color: var(--gold-2); border-color: var(--gold); box-shadow: 0 0 20px rgba(240, 180, 60, 0.25); }
.menu button:hover, .pane button.back:hover { filter: brightness(1.2); }
.pane button.back { margin-top: 18px; min-width: 160px; }
.credit { margin-top: 30px; color: var(--dim); font-size: 13px; text-shadow: 0 1px 4px #000; }
.credit a { color: var(--gold); }
#levelList { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; text-align: left; }
.lvl { border-radius: 12px; border: 1px solid var(--edge); background: #1a1410; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.lvl:hover:not(.locked) { border-color: var(--gold); }
.lvl .n { font-family: var(--display); color: var(--blood); font-size: 12px; letter-spacing: 0.2em; }
.lvl b { font-family: var(--display); font-size: 18px; color: var(--gold-2); letter-spacing: 0.04em; }
.lvl p { margin: 0; color: var(--dim); font-size: 14px; line-height: 1.35; flex: 1; }
.lvl .done { color: var(--good); font-size: 13px; }
.lvl.locked { opacity: 0.45; cursor: not-allowed; }
.howGrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px 20px; text-align: left; }
.howGrid p { margin: 0; color: var(--dim); line-height: 1.45; }
.howGrid b { color: var(--ink); }
#endTitle.win { color: var(--gold-2); }
#endTitle.lose { color: var(--bad); }
#endText { font-size: 17px; max-width: 520px; margin: 0 auto 14px; line-height: 1.45; }
#endStats { display: grid; grid-template-columns: auto auto; gap: 4px 20px; justify-content: center; margin: 0 0 20px; }
#endStats dt { color: var(--dim); text-align: right; }
#endStats dd { margin: 0; text-align: left; font-weight: 700; }

@media (max-width: 900px) {
  #top { right: 10px; top: 10px; gap: 10px; }
  #mapBox { top: auto; bottom: 214px; width: 132px; height: 132px; }
  #minimap { width: 130px; height: 130px; }
  #info, #handBox { display: none; }
  .tool { width: 74px; height: 72px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
