:root {
  --bg: #14100d; --panel: #1e1813; --panel2: #271f18; --edge: #3a2f26; --ink: #eadfcc; --muted: #a8977f;
  --accent: #d9a441; --danger: #d0505a; --good: #6fc08c; --info: #6aa7d8;
  --serif: Georgia, 'Palatino Linotype', Palatino, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: radial-gradient(1200px 700px at 50% -10%, #2a1f17 0%, var(--bg) 60%); color: var(--ink); font-family: var(--sans); font-size: 15px; line-height: 1.4; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: .02em; }
button { font: inherit; color: var(--ink); background: var(--panel2); border: 1px solid var(--edge); border-radius: 8px; padding: 9px 14px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: linear-gradient(#e0ae4d, #b9852a); color: #1a1208; border-color: #e8bd68; font-weight: 700; }
button.ghost { background: transparent; }
button.danger { background: #5a2128; border-color: var(--danger); }
button.icon { width: 34px; height: 34px; padding: 0; border-radius: 17px; font-weight: 700; }
input { font: inherit; color: var(--ink); background: #0f0c09; border: 1px solid var(--edge); border-radius: 8px; padding: 10px 12px; width: 100%; }
input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input { margin-top: 4px; }

.conn { position: fixed; top: 0; left: 0; right: 0; z-index: 50; background: #7a2f35; text-align: center; padding: 6px; font-size: 13px; }

.screen { min-height: 100%; }
.card { background: var(--panel); border: 1px solid var(--edge); border-radius: 14px; box-shadow: 0 10px 40px #0008; }

/* home */
#home { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.home-card { width: 100%; max-width: 400px; padding: 28px 24px; }
.home-card h1 { font-size: 44px; text-align: center; color: var(--accent); text-shadow: 0 2px 18px #d9a44140; }
.tag { text-align: center; color: var(--muted); margin: 6px 0 22px; }
.home-card button.primary { width: 100%; padding: 12px; }
.or { display: flex; align-items: center; gap: 10px; margin: 18px 0 12px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--edge); }
.row { display: flex; gap: 8px; }
#code { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; }
.msg { min-height: 20px; color: var(--danger); font-size: 13px; margin: 10px 0 0; text-align: center; }

/* lobby */
#lobby { display: flex; justify-content: center; padding: 20px 14px 40px; }
.lobby-card { width: 100%; max-width: 760px; padding: 22px; }
.lob-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.bigcode { font-family: var(--serif); font-size: 46px; letter-spacing: .18em; color: var(--accent); line-height: 1; }
.lob-share { display: flex; gap: 8px; }
.plist { list-style: none; margin: 16px 0; padding: 0; display: grid; gap: 6px; }
.plist li { background: var(--panel2); border: 1px solid var(--edge); border-radius: 8px; padding: 8px 12px; display: flex; align-items: center; gap: 10px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.lobby-card h2 { margin: 18px 0 10px; font-size: 20px; }
.chars { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.char { text-align: left; padding: 12px; border-left-width: 5px; }
.char.sel { outline: 2px solid var(--accent); background: #33281b; }
.char .nm { font-family: var(--serif); font-size: 16px; }
.char .tt { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.char .st { font-size: 12.5px; color: var(--ink); }
.char .taken { color: var(--danger); font-size: 12px; margin-top: 4px; }
.lob-foot { margin-top: 20px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* game layout */
#game { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: #0e0b08; border-bottom: 1px solid var(--edge); flex: none; flex-wrap: wrap; }
.bar-left, .bar-right { display: flex; align-items: center; gap: 8px; }
.brand { font-family: var(--serif); color: var(--accent); font-size: 18px; }
.chip { background: var(--panel2); border: 1px solid var(--edge); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; white-space: nowrap; }
.turn { flex: 1; text-align: center; font-family: var(--serif); font-size: 17px; min-width: 180px; }
.turn.mine { color: var(--accent); }
.turn .sub { font-family: var(--sans); font-size: 12.5px; color: var(--muted); margin-left: 6px; }
.hauntbar { padding: 7px 12px; background: #3a1519; border-bottom: 1px solid #7a2f35; font-size: 13.5px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; flex: none; }
.hauntbar b { color: #ff8b94; font-family: var(--serif); }
.hauntbar button { padding: 3px 10px; font-size: 12px; }
#main { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 340px; min-height: 0; }
#boardCol { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.boardtop { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px 0; gap: 8px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 8px 8px 0 0; background: var(--panel); font-size: 13.5px; }
.tab.on { background: #2e2318; border-color: var(--accent); color: var(--accent); }
.tab .pip { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-left: 3px; border: 1px solid #0007; vertical-align: middle; }
.zoom { display: flex; gap: 6px; }
#boardWrap { flex: 1; min-height: 0; overflow: auto; margin: 0 10px; background: #0b0806; border: 1px solid var(--edge); border-radius: 0 10px 10px 10px; position: relative; display: flex; }
#board { display: block; flex: none; margin: auto; touch-action: pan-x pan-y; cursor: default; }
.legend { padding: 6px 12px 8px; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; border: 2px solid; }
.lg-move { border-color: #6fe08a; } .lg-explore { border-color: #e6b84f; border-style: dashed; } .lg-secret { border-color: #b388eb; border-style: dashed; }
#side { overflow-y: auto; padding: 8px 10px 14px 0; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--edge); border-radius: 10px; padding: 10px 12px; }
.panel h3 { font-size: 14px; color: var(--accent); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .08em; }
#actions:empty, #mine:empty { display: none; }
#actions { display: flex; flex-direction: column; gap: 8px; border-color: var(--accent); }
#actions .btns { display: flex; flex-wrap: wrap; gap: 8px; }
#actions .note { font-size: 13px; color: var(--muted); }

.pl { padding: 8px; border-radius: 8px; border: 1px solid transparent; margin-bottom: 6px; background: var(--panel2); }
.pl.cur { border-color: var(--accent); background: #33281b; }
.pl.dead { opacity: .5; }
.pl.dead .pn { text-decoration: line-through; }
.pl .top { display: flex; align-items: center; gap: 8px; }
.pl .pn { font-weight: 600; }
.pl .cn { color: var(--muted); font-size: 12px; }
.badge { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; padding: 1px 6px; border-radius: 4px; background: #4a1c21; color: #ff9aa2; border: 1px solid #7a2f35; }
.badge.off { background: #333; color: #bbb; border-color: #555; }
.badge.me { background: #2b3a22; color: #b6e39a; border-color: #4f7a38; }
.hp { height: 7px; background: #0c0907; border-radius: 4px; overflow: hidden; margin: 6px 0 4px; border: 1px solid #0006; }
.hp i { display: block; height: 100%; background: linear-gradient(#7fd09a, #4f9c6a); }
.hp i.low { background: linear-gradient(#e0707a, #a83a44); }
.stats { font-size: 12.5px; display: flex; gap: 10px; flex-wrap: wrap; color: var(--ink); }
.items { margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.inv { display: flex; flex-direction: column; gap: 6px; }
.inv .it { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--panel2); padding: 6px 8px; border-radius: 8px; font-size: 13.5px; }
.inv .it small { color: var(--muted); display: block; }
.inv button { padding: 4px 10px; font-size: 12.5px; }
#log { max-height: 240px; overflow-y: auto; font-size: 12.5px; color: #cdbfa8; display: flex; flex-direction: column; gap: 3px; }
#log .sep { color: var(--accent); margin-top: 6px; font-family: var(--serif); }
#log .big { color: #ff9aa2; }

/* overlays */
.overlay { position: fixed; inset: 0; background: #000b; z-index: 40; display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.cardview { width: 100%; max-width: 440px; background: linear-gradient(#2a2017, #1b1510); border: 2px solid var(--accent); border-radius: 16px; padding: 22px; text-align: center; box-shadow: 0 20px 60px #000c; animation: pop .22s ease-out; }
.cardview.haunt { border-color: var(--danger); background: linear-gradient(#35151a, #1a0d0f); max-width: 520px; }
.cardview .kind { font-size: 11.5px; letter-spacing: .25em; text-transform: uppercase; color: var(--accent); }
.cardview.haunt .kind { color: #ff8b94; }
.cardview h2 { font-size: 26px; margin: 6px 0 4px; }
.cardview .who { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.cardview p { margin: 8px 0; }
.cardview .detail { color: var(--good); font-weight: 600; }
.cardview .detail.bad { color: var(--danger); }
.dice { display: flex; justify-content: center; gap: 6px; margin: 12px 0 4px; flex-wrap: wrap; }
.die { width: 30px; height: 30px; border-radius: 7px; background: #efe3c9; color: #20170d; display: grid; place-items: center; font-weight: 800; font-family: var(--serif); box-shadow: inset 0 -3px 0 #0003; }
.die.z { background: #8a7e6a; }
.rollline { font-size: 13.5px; color: var(--muted); }
.rollline b.ok { color: var(--good); } .rollline b.no { color: var(--danger); }
.goals { text-align: left; display: grid; gap: 8px; margin: 12px 0; }
.goal { border: 1px solid var(--edge); border-radius: 10px; padding: 8px 10px; background: #0003; font-size: 14px; }
.goal.you { border-color: var(--accent); background: #d9a44118; }
.goal b { display: block; font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.goal.t b { color: #ff8b94; }
.cardview .btns { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.rules { text-align: left; max-width: 560px; max-height: 86vh; overflow-y: auto; }
.rules h2 { text-align: center; } .rules h4 { margin: 14px 0 4px; color: var(--accent); font-family: var(--serif); font-size: 16px; }
.rules p, .rules li { font-size: 14px; margin: 4px 0; }
.rules ul { padding-left: 18px; margin: 4px 0; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; background: #0d0a07f2; border: 1px solid var(--accent); border-radius: 12px; padding: 10px 16px; z-index: 45; max-width: min(92vw, 460px); text-align: center; box-shadow: 0 10px 30px #000a; font-size: 14px; }
.toast.err { border-color: var(--danger); color: #ffb3b9; }
.toast .dice { margin: 6px 0 2px; }

/* phones */
@media (max-width: 860px) {
  #game { height: auto; min-height: 100dvh; }
  #main { display: flex; flex-direction: column; }
  #boardCol { height: 62dvh; min-height: 330px; }
  #side { padding: 4px 10px 20px 10px; overflow: visible; }
  #boardWrap { margin: 0 6px; }
  .turn { order: 3; flex-basis: 100%; }
  #log { max-height: 180px; }
  .brand { display: none; }
}
