* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #0d1110; color: #dfe7e2; font: 15px/1.35 system-ui, sans-serif; overscroll-behavior: none; }
button, input { font: inherit; color: inherit; }
button { background: #222b28; border: 1px solid #34413c; border-radius: 10px; padding: 10px 12px; cursor: pointer; }
button:active { background: #2c3833; }
button.go { background: #1f5a3c; border-color: #2f8a5c; font-weight: 600; }
input { background: #0d1110; border: 1px solid #34413c; border-radius: 10px; padding: 10px 12px; width: 100%; }
small, .dim { color: #8b9a93; }
h2, h3 { margin: 0 0 8px; }
p { margin: 6px 0; }

#app { height: 100dvh; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; position: relative; overflow: hidden; }
header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: calc(6px + env(safe-area-inset-top)) 10px 6px; background: #131917; border-bottom: 1px solid #25302c; }
#res { display: flex; gap: 10px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
#clock { padding: 4px 8px; font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
#quest { padding: 7px 12px; background: #1b2a22; border-bottom: 1px solid #2f8a5c; color: #a8f0c6; font-size: 14px; }
#quest:empty { display: none; }
main { flex: 1; position: relative; min-height: 0; }
#dom { position: absolute; inset: 0; overflow-y: auto; padding: 12px; }
#stage { position: absolute; inset: 0; touch-action: none; }
#cv { width: 100%; height: 100%; display: block; }
#chips { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
#chips span { align-self: flex-start; background: #131917dd; border: 1px solid #34413c; border-radius: 8px; padding: 3px 8px; font-size: 13px; }
#cap { position: absolute; left: 10px; right: 10px; top: calc(12px + env(safe-area-inset-top)); background: #0d1110e6; border: 1px solid #34413c; border-radius: 12px; padding: 12px; text-align: center; }
#cap:empty { display: none; }
#cap button { display: block; width: 100%; margin-top: 10px; }
nav { display: grid; grid-template-columns: repeat(6, 1fr); background: #131917; border-top: 1px solid #25302c; padding-bottom: env(safe-area-inset-bottom); }
nav button { border: 0; border-radius: 0; background: none; padding: 8px 0 7px; font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav button b { font-size: 19px; font-weight: 400; }
nav button.on { color: #7dffb0; box-shadow: inset 0 2px #7dffb0; }
nav button.locked { opacity: .45; }
#chatBtn { position: absolute; right: 10px; bottom: calc(70px + env(safe-area-inset-bottom)); border-radius: 50%; width: 46px; height: 46px; padding: 0; font-size: 20px; z-index: 3; }
#badge { position: absolute; top: -4px; right: -4px; background: #e2553f; border-radius: 9px; font: 600 11px system-ui; padding: 1px 5px; }
#badge:empty { display: none; }
body.intro nav, body.intro #chatBtn, body.intro header { display: none; }

.surface { text-align: center; padding: 10px; border-bottom: 3px solid #5b4a37; color: #c9a877; letter-spacing: 2px; font-size: 12px; }
.surface b { display: block; letter-spacing: 0; font-size: 16px; color: #dfe7e2; }
.floor { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 6px; padding: 6px 0; border-bottom: 1px solid #25302c; }
.depth { display: grid; place-items: center; color: #8b9a93; font-size: 12px; }
.slot { min-height: 74px; text-align: left; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.slot.wide { grid-column: 2 / 4; text-align: center; align-items: center; }
.slot.empty { border-style: dashed; color: #8b9a93; align-items: center; }
.slot.Economy { border-left: 4px solid #ffb454; }
.slot.Military { border-left: 4px solid #e2553f; }
.slot.Defensive { border-left: 4px solid #58a6ff; }
.slot.Milestone { border-left: 4px solid #7dffb0; background: #16221d; }
.slot.busy { background: repeating-linear-gradient(45deg, #1a211f, #1a211f 8px, #202926 8px, #202926 16px); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin-top: 14px; padding: 10px; background: #131917; border-radius: 10px; font-size: 13px; }
.stats h3 { grid-column: 1 / 3; font-size: 13px; color: #8b9a93; font-weight: 500; }
.bar { background: #0d1110; border-radius: 6px; height: 10px; overflow: hidden; margin: 4px 0 2px; }
.bar i { display: block; height: 100%; background: #7dffb0; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid #25302c; }
.card { background: #131917; border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.locked-view { text-align: center; padding: 60px 20px; }
.locked-view b { font-size: 44px; display: block; }

#sheet, #chat { position: absolute; inset: 0; background: #000a; z-index: 5; display: flex; flex-direction: column; justify-content: flex-end; }
#sheet[hidden], #chat[hidden] { display: none; }
#sheet > div, #chat > div { background: #171d1b; border-radius: 16px 16px 0 0; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); max-height: 82%; overflow-y: auto; }
#sheet button { display: block; width: 100%; text-align: left; margin-top: 6px; }
#sheet button small { display: block; }
#chat > div { height: 75%; display: flex; flex-direction: column; overflow: hidden; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tabs button { flex: 1; padding: 7px; }
.tabs button.on { border-color: #7dffb0; color: #7dffb0; }
#log { flex: 1; overflow-y: auto; font-size: 14px; }
#log p b { color: #a8f0c6; font-weight: 600; }
.say { display: flex; gap: 6px; margin-top: 8px; }
#toast { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); background: #e2553f; border-radius: 10px; padding: 8px 14px; z-index: 9; transition: opacity .3s; opacity: 0; pointer-events: none; max-width: 90%; text-align: center; }
.welcome { padding: 28px 22px; overflow-y: auto; }
.welcome h1 { letter-spacing: 4px; font-size: 26px; margin: 0 0 4px; }
.welcome blockquote { margin: 18px 0; padding-left: 12px; border-left: 2px solid #2f8a5c; color: #a9b6b0; font-size: 14px; }
.welcome button { width: 100%; margin-top: 10px; }

/* sign-in and character select */
.welcome { text-align: center; }
.welcome img { width: min(70%, 260px); margin: 10px auto 8px; display: block; }
.welcome form { display: flex; flex-direction: column; gap: 8px; margin: 18px 0 8px; }
.welcome .note { background: #5a2a22; border-radius: 10px; padding: 8px; }
.welcome .quiet { background: none; border: 0; color: #8b9a93; }

/* world canvases */
#gl, #cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#gl[hidden], #cv[hidden] { display: none; }

/* the Haven as a tower cut open */
#dom.tower { padding: 0; background: linear-gradient(#6b5138 0, #4a3725 150px, #2a2019 150px, #17120e 100%); }
.top { height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 6px; background: linear-gradient(#27323a, #6b5138 75%); border-bottom: 5px solid #3a2c20; }
.top .hut { font-size: 54px; line-height: 1; }
.top small { color: #e9c58f; letter-spacing: 2px; font-size: 11px; }
.tfloor { display: grid; grid-template-columns: 1fr 34px 1fr; height: 104px; margin: 0 10px; border-bottom: 5px solid #0d0a08; }
.room { position: relative; overflow: hidden; border: 0; border-radius: 0; padding: 0; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: #3b4750; box-shadow: inset 0 -12px #0003, inset 0 0 0 3px #0004; }
.room.wide { grid-column: 1 / 4; }
.room.rock { background: repeating-linear-gradient(135deg, #241b14, #241b14 10px, #2b2018 10px, #2b2018 20px); color: #c9a877; }
.room.rock b { font-size: 18px; }
.room.busy { background: repeating-linear-gradient(45deg, #3a3320, #3a3320 10px, #2b2618 10px, #2b2618 20px); color: #ffd98a; }
.room.Economy { background: linear-gradient(#6a5330, #4d3c22); }
.room.Military { background: linear-gradient(#6a3530, #4a2420); }
.room.Defensive { background: linear-gradient(#30506a, #22384a); }
.room.Milestone { background: linear-gradient(#2a5a48, #1c3d31); }
.room em { position: absolute; top: 5px; left: 0; right: 0; font-style: normal; font-size: 12px; font-weight: 600; text-shadow: 0 1px 2px #000; }
.room .props { position: absolute; bottom: 12px; left: 0; right: 0; font-size: 34px; letter-spacing: 14px; text-indent: 14px; }
.bit { position: absolute; bottom: 10px; font-style: normal; font-size: 20px; animation: walk 6s linear infinite alternate; }
@keyframes walk { from { left: 4%; } to { left: 78%; } }
.shaft { position: relative; background: #0d0a08; box-shadow: inset 3px 0 #1c1612, inset -3px 0 #1c1612; }
.shaft u { position: absolute; top: 4px; left: 0; right: 0; text-align: center; text-decoration: none; font-size: 10px; color: #8b9a93; }
.car { position: absolute; left: 5px; right: 5px; height: 30px; background: #ffd98a; border-radius: 3px; box-shadow: 0 0 10px #ffd98a88; animation: lift 5s ease-in-out infinite alternate; }
@keyframes lift { from { top: 62px; opacity: 1; } 45% { top: 62px; opacity: 1; } 55% { top: 62px; opacity: 0; } to { top: 62px; opacity: 0; } }
#dom.tower .stats { margin: 14px 10px; }
#hud { position: absolute; left: 10px; right: 66px; bottom: 12px; text-align: center; pointer-events: none; }
#hud button { pointer-events: auto; width: 100%; }
#hud button small { display: block; }
#hud p { margin: 6px 0 0; font-size: 12px; color: #c9d4ce; text-shadow: 0 1px 3px #000; }
#hud:empty { display: none; }
