:root {
  --bg: #1a0f08; --wood: #2e1b0e; --wood2: #43280f; --wood3: #6b4423; --parch: #ecdcb4; --parch2: #d6c08a;
  --ink: #2a170c; --gold: #ffd35a; --white: #f1e9d2; --brown: #8a5a2e; --red: #d6523f; --green: #7dff8a;
  --font: 'Press Start 2P', 'Courier New', monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg) repeating-linear-gradient(90deg, #1a0f08 0 38px, #1e120a 38px 40px);
  color: var(--parch); font-family: var(--font); font-size: 10px; line-height: 1.6; overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100vh; padding: 8px 12px; gap: 8px; }
header { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
h1 { margin: 0; font-size: 15px; color: var(--white); text-shadow: 2px 2px 0 #000; letter-spacing: 1px; }
h1 span { color: var(--gold); }
h2 { margin: 0 0 6px; font-size: 10px; color: var(--gold); text-shadow: 1px 1px 0 #000; }
h2 small { color: var(--parch2); font-size: 8px; margin-left: 6px; }
.badge { padding: 6px 10px; border: 3px solid #000; background: var(--white); color: var(--ink); font-size: 10px; box-shadow: 3px 3px 0 #000; }
.badge.b { background: var(--brown); color: #fff; }
.controls { margin-left: auto; display: flex; align-items: center; gap: 8px; }
input[type=range] { width: 80px; accent-color: var(--gold); }

button {
  font-family: var(--font); font-size: 10px; color: var(--ink); background: var(--parch); border: 3px solid #000; padding: 7px 10px; cursor: pointer;
  box-shadow: inset -3px -3px 0 var(--parch2), 3px 3px 0 #000; text-transform: uppercase;
}
button:hover:not(:disabled) { background: #fff3cf; }
button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: inset -3px -3px 0 var(--parch2), 1px 1px 0 #000; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.big { padding: 10px 14px; font-size: 11px; background: var(--gold); box-shadow: inset -3px -3px 0 #c9962e, 3px 3px 0 #000; }
button.big.brown { background: #b07a45; color: #fff; box-shadow: inset -3px -3px 0 #7a4f27, 3px 3px 0 #000; }
button.big.agreed { background: var(--green); color: var(--ink); }
button.mini { padding: 5px 8px; font-size: 8px; }
button.off { opacity: .55; text-decoration: line-through; }

main { flex: 1; display: flex; gap: 12px; min-height: 0; }
#stage { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
#boardWrap { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
canvas#board { image-rendering: pixelated; image-rendering: crisp-edges; border: 4px solid #000; box-shadow: 0 0 0 4px var(--wood3), 8px 8px 0 4px #000; cursor: pointer; background: #000; max-width: 100%; max-height: 100%; }
#info { min-height: 22px; font-size: 9px; color: var(--parch2); text-align: center; }
#abilityBar { min-height: 38px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
#abilityBar button { background: #cdb4ff; box-shadow: inset -3px -3px 0 #9a7fd0, 3px 3px 0 #000; }
#abilityBar button.active { background: #fff; outline: 3px solid var(--gold); }

#side { width: 340px; flex: none; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.panel { background: var(--wood); border: 3px solid #000; box-shadow: inset 0 0 0 3px var(--wood3), 4px 4px 0 #000; padding: 12px; }
.panel.grow { flex: 1; min-height: 80px; display: flex; flex-direction: column; }
textarea, input[type=text], #npcInput {
  width: 100%; font-family: var(--font); font-size: 9px; line-height: 1.7; background: var(--parch); color: var(--ink); border: 3px solid #000; padding: 8px; resize: none; outline: none;
}
textarea:focus, #npcInput:focus { border-color: var(--gold); }
textarea:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
#wishNote { font-size: 7px; color: var(--parch2); flex: 1; min-width: 100px; }
#wishStatus { margin-top: 8px; font-size: 8px; min-height: 12px; color: var(--green); }
#wishStatus.err { color: #ff8a7a; }
#wishStatus.busy::before { content: ''; display: inline-block; width: 8px; height: 8px; background: var(--gold); margin-right: 6px; animation: spin 0.6s steps(4) infinite; }
@keyframes spin { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } }
#winList { list-style: none; margin: 0 0 8px; padding: 0; font-size: 8px; }
#winList li { padding: 3px 0 3px 12px; position: relative; }
#winList li::before { content: ''; position: absolute; left: 0; top: 5px; width: 6px; height: 6px; background: #ffd94d; box-shadow: 0 0 0 2px var(--wood3); }
#winList li b { color: #ffd94d; }
#winList li span { display: block; color: var(--parch2); font-size: 7px; }
#modList { list-style: none; margin: 0; padding: 0; max-height: 150px; overflow: auto; font-size: 8px; }
#modList li { padding: 4px 0; border-bottom: 2px dotted var(--wood3); }
#modList li b { color: var(--white); } #modList li.b b { color: #d89a5a; }
#modList li span { display: block; color: var(--parch2); font-size: 7px; }
#modList .empty { color: var(--parch2); }
#log { flex: 1; overflow: auto; font-size: 8px; line-height: 1.7; }
#log div { padding: 2px 0; } #log .w { color: var(--white); } #log .b { color: #d89a5a; } #log .sys { color: var(--parch2); } #log .err { color: #ff8a7a; }

.overlay { position: fixed; inset: 0; background: rgba(10, 5, 2, .82); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 12px; }
.overlay.hidden { display: none; }
.card { background: var(--wood); border: 4px solid #000; box-shadow: inset 0 0 0 4px var(--wood3), 8px 8px 0 #000; padding: 22px; max-width: 520px; width: 100%; text-align: center; }
.card.chat { text-align: left; max-width: 560px; }
.card h1 { font-size: 18px; margin-bottom: 14px; }
.card p { margin: 10px 0; }
.lead { color: var(--parch); font-size: 9px; line-height: 2; }
.small { font-size: 7px; color: var(--parch2); }
.modes { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; text-align: left; font-size: 9px; }
.modes label { background: var(--wood2); padding: 8px; border: 2px solid #000; cursor: pointer; }
#npcLog { height: 220px; overflow: auto; background: var(--wood2); border: 3px solid #000; padding: 8px; font-size: 9px; line-height: 1.8; margin-bottom: 8px; }
#npcLog .me { color: var(--white); } #npcLog .npc { color: var(--gold); } #npcLog .act { color: var(--green); } #npcLog .wait { color: var(--parch2); }
#npcInput { flex: 1; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #000; color: var(--gold); padding: 10px 14px; border: 3px solid var(--gold); font-size: 9px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 40; max-width: 90vw; }
#toast.show { opacity: 1; }
@media (max-width: 900px) { #boardWrap { flex: none; min-height: 70vw; height: 70vw; } main { flex-direction: column; overflow: auto; } #side { width: 100%; } body { overflow: auto; } #app { height: auto; } }

#hud { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; }
#hud .headline { flex-basis: 100%; text-align: center; font-size: 12px; color: var(--gold); text-shadow: 2px 2px 0 #000; }
#hud .chip { border: 3px solid var(--gold); background: var(--wood); padding: 3px 8px; font-size: 9px; box-shadow: 2px 2px 0 #000; }
#hud .chip.w { background: var(--white); color: var(--ink); } #hud .chip.b { background: var(--brown); color: #fff; }
#buttonBar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: 0; }
#buttonBar button { color: var(--ink); } #buttonBar button.bw { outline: 3px solid var(--white); } #buttonBar button.bb { outline: 3px solid var(--brown); }
#buttonBar button.active { outline: 3px solid #fff; }

.hidden { display: none !important; }
.lobby { margin-top: 14px; border-top: 3px dotted var(--wood3); padding-top: 8px; }
.lobby input { font-family: var(--font); font-size: 9px; padding: 6px; border: 3px solid #000; background: var(--parch); color: var(--ink); }
#joinCode { width: 120px; text-transform: lowercase; } #apiBase { width: 210px; } #chatInput { width: 100%; }
#log .chat { color: #9fe8ff; }

#view3d { image-rendering: pixelated; border: 4px solid var(--wood3, #6b4423); box-shadow: 0 0 0 4px #1b0f06, 0 10px 30px rgba(0,0,0,.6); background: #000; outline: none; cursor: crosshair; }

/* ---------- the astral plane: a different world, not pixel art ---------- */
#astralSky { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0; display: none; }
#app { position: relative; z-index: 1; }
#astral { position: absolute; inset: 0; z-index: 3; cursor: crosshair; display: none; }
body.astral { background: #04030c !important; font-family: 'Cormorant Garamond', Georgia, serif; font-size: 15px; line-height: 1.35; color: #e9e2ff; transition: color .8s; }
body.astral h1, body.astral h2, body.astral button, body.astral .badge, body.astral #info { font-family: 'Cinzel', Georgia, serif; }
body.astral h1 { font-size: 22px; letter-spacing: .22em; color: #fff4dc; text-shadow: 0 0 22px rgba(255, 214, 140, .65); font-weight: 600; }
body.astral h1 span { color: #ffd98a; }
body.astral h2 { font-size: 12px; letter-spacing: .2em; color: #ffd98a; text-shadow: 0 0 14px rgba(255, 214, 140, .45); text-transform: uppercase; }
body.astral h2 small { font-size: 10px; color: #b9b0e8; letter-spacing: .08em; }
body.astral .panel { background: rgba(9, 8, 28, .56); border: 1px solid rgba(176, 156, 255, .38); box-shadow: 0 0 0 1px rgba(255, 255, 255, .04) inset, 0 18px 50px rgba(0, 0, 0, .55); backdrop-filter: blur(10px) saturate(1.2); -webkit-backdrop-filter: blur(10px) saturate(1.2); border-radius: 3px; }
body.astral button { background: rgba(255, 236, 190, .08); color: #ffe9be; border: 1px solid rgba(255, 236, 190, .5); box-shadow: 0 0 18px rgba(255, 214, 140, .12) inset; letter-spacing: .14em; font-size: 11px; border-radius: 2px; }
body.astral button:hover:not(:disabled) { background: rgba(255, 236, 190, .2); box-shadow: 0 0 22px rgba(255, 214, 140, .35); }
body.astral button:active:not(:disabled) { transform: none; box-shadow: 0 0 10px rgba(255, 214, 140, .5); }
body.astral button.big { background: rgba(255, 214, 140, .2); box-shadow: 0 0 24px rgba(255, 214, 140, .25); font-size: 12px; }
body.astral .badge { background: rgba(255, 244, 220, .92); color: #150c2e; border: 1px solid #fff; box-shadow: 0 0 22px rgba(255, 214, 140, .5); letter-spacing: .16em; font-size: 11px; }
body.astral .badge.b { background: rgba(60, 22, 96, .9); color: #f6c8ff; border-color: #f08cff; box-shadow: 0 0 22px rgba(240, 140, 255, .5); }
body.astral textarea, body.astral input[type=text], body.astral #npcInput { background: rgba(4, 4, 18, .6); color: #f3ecff; border: 1px solid rgba(176, 156, 255, .45); font-family: 'Cormorant Garamond', Georgia, serif; font-size: 15px; box-shadow: none; }
body.astral #log, body.astral #modList, body.astral #winList, body.astral #modList li span, body.astral #winList li span, body.astral #wishNote, body.astral #wishStatus { font-size: 13px; line-height: 1.35; }
body.astral #log .w { color: #fff4dc; } body.astral #log .b { color: #f0a8ff; } body.astral #log .sys { color: #b9b0e8; }
body.astral #winList li b, body.astral #modList li b { color: #ffd98a; font-family: 'Cinzel', Georgia, serif; font-size: 11px; letter-spacing: .12em; }
body.astral #modList li.b b { color: #f0a8ff; }
body.astral #modList li { border-bottom: 1px solid rgba(176, 156, 255, .2); }
body.astral #winList li::before { background: #ffd98a; box-shadow: 0 0 10px #ffd98a; border-radius: 50%; }
body.astral #info { font-size: 12px; letter-spacing: .12em; color: #b9b0e8; }
body.astral #hud .chip, body.astral #hud .headline { font-family: 'Cinzel', Georgia, serif; font-size: 11px; letter-spacing: .12em; background: rgba(9, 8, 28, .6); border: 1px solid rgba(176, 156, 255, .5); color: #ffe9be; box-shadow: none; }
