/* Doppelganger Keep: pixel fantasy UI. Panels look like parchment and iron; text uses pixel fonts. */
:root {
  --ink: #120c1c;
  --night: #1b1428;
  --stone: #3a3246;
  --stone-hi: #6e6278;
  --parch: #ead7a8;
  --parch-dk: #c9ae78;
  --brown: #3a2614;
  --gold: #f2c94c;
  --gold-dk: #b8860b;
  --red: #d63a3a;
  --red-dk: #7d1430;
  --blue: #3a6ee0;
  --green: #4cc06a;
  --text: #f4ead5;
  --mute: #b7a9c9;
  --title: "Jacquard 12", "Pixelify Sans", serif;
  --ui: "Pixelify Sans", ui-monospace, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--text); font-family: var(--ui); }
body { touch-action: none; -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
#view { position: fixed; inset: 0; display: block; }
#touch { position: fixed; inset: 0; z-index: 1; }
#hud { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
#hud > * { pointer-events: auto; }
#screens { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#screens > * { pointer-events: auto; }
#home { position: fixed; inset: 0; z-index: 8; }
#toast { position: fixed; left: 50%; top: calc(84px + var(--safe-t)); transform: translateX(-50%); z-index: 20; pointer-events: none; display: flex; flex-direction: column; gap: 6px; align-items: center; width: min(92vw, 520px); }
.hidden { display: none !important; }
button { font-family: var(--ui); }
input, textarea, select { font-family: var(--ui); -webkit-user-select: text; user-select: text; }

/* ---------- pixel panels and buttons ---------- */
.panel {
  background: var(--night); color: var(--text);
  border: 4px solid var(--ink);
  box-shadow: inset 0 0 0 3px var(--stone-hi), inset 0 0 0 6px var(--stone), 0 6px 0 rgba(0,0,0,0.45);
  padding: 16px;
}
.parch {
  background: var(--parch); color: var(--brown);
  border: 4px solid var(--brown);
  box-shadow: inset 0 0 0 3px var(--parch-dk), 0 6px 0 rgba(0,0,0,0.45);
  padding: 16px;
}
.btn {
  appearance: none; cursor: pointer; border: 0; font-size: 18px; font-weight: 600; letter-spacing: 0.5px;
  padding: 12px 18px; color: var(--ink); background: var(--gold);
  box-shadow: inset -3px -4px 0 var(--gold-dk), inset 3px 3px 0 #fff0a8, 0 0 0 3px var(--ink), 0 5px 0 3px rgba(0,0,0,0.45);
  margin: 4px; min-height: 48px; text-shadow: none;
}
.btn:active { transform: translateY(3px); box-shadow: inset -3px -4px 0 var(--gold-dk), inset 3px 3px 0 #fff0a8, 0 0 0 3px var(--ink), 0 2px 0 3px rgba(0,0,0,0.45); }
.btn.red { background: var(--red); color: #fff; box-shadow: inset -3px -4px 0 var(--red-dk), inset 3px 3px 0 #ff8a8a, 0 0 0 3px var(--ink), 0 5px 0 3px rgba(0,0,0,0.45); }
.btn.blue { background: var(--blue); color: #fff; box-shadow: inset -3px -4px 0 #1a2a8a, inset 3px 3px 0 #8ab0ff, 0 0 0 3px var(--ink), 0 5px 0 3px rgba(0,0,0,0.45); }
.btn.dark { background: var(--stone); color: var(--text); box-shadow: inset -3px -4px 0 #221c2a, inset 3px 3px 0 var(--stone-hi), 0 0 0 3px var(--ink), 0 5px 0 3px rgba(0,0,0,0.45); }
.btn.green { background: var(--green); color: var(--ink); box-shadow: inset -3px -4px 0 #2a7a40, inset 3px 3px 0 #a0f0b0, 0 0 0 3px var(--ink), 0 5px 0 3px rgba(0,0,0,0.45); }
.btn:disabled { filter: grayscale(0.9) brightness(0.6); cursor: default; transform: none; }
.btn.small { font-size: 15px; padding: 8px 12px; min-height: 40px; }
.title { font-family: var(--title); font-weight: 400; line-height: 0.9; margin: 0; color: var(--gold); text-shadow: 3px 3px 0 var(--red-dk), 6px 6px 0 rgba(0,0,0,0.5); }
.spr { image-rendering: pixelated; display: block; }
.icon { image-rendering: pixelated; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.field label { font-size: 14px; color: var(--mute); letter-spacing: 1px; text-transform: uppercase; }
.input {
  font-size: 20px; padding: 10px 12px; border: 0; outline: 0; color: var(--ink); background: var(--parch);
  box-shadow: inset 3px 3px 0 var(--parch-dk), 0 0 0 3px var(--ink); width: 100%;
}
.input.code { text-transform: uppercase; letter-spacing: 8px; text-align: center; font-size: 28px; font-weight: 700; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.center { display: flex; align-items: center; justify-content: center; }
.mute { color: var(--mute); }
a { color: var(--gold); }

/* ---------- home ---------- */
#home {
  overflow-y: auto; touch-action: pan-y; padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
  background: radial-gradient(ellipse at 50% 20%, #2a1f40 0%, #120c1c 70%);
}
#home .wrap { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
#home .hero { text-align: center; padding-top: 8px; }
#home .hero .title { font-size: clamp(54px, 15vw, 92px); }
#home .hero .sub { font-size: 16px; color: var(--mute); margin-top: 8px; letter-spacing: 1px; }
#home .lineup { display: flex; justify-content: center; gap: 4px; margin: 12px 0 0; min-height: 84px; align-items: flex-end; }
#home .lineup .spr { animation: hop 1.6s ease-in-out infinite; }
#home .lineup .spr:nth-child(2n) { animation-delay: -0.4s; }
#home .lineup .spr:nth-child(3n) { animation-delay: -0.8s; }
@keyframes hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.lobbylist { display: flex; flex-direction: column; gap: 8px; }
.lobbylist .btn { display: flex; justify-content: space-between; width: 100%; margin: 4px 0; }
.howto { font-size: 15px; line-height: 1.5; color: var(--text); }
.howto b { color: var(--gold); }
.howto ul { padding-left: 20px; margin: 6px 0; }

/* ---------- in-game HUD ---------- */
.hud-tl { position: absolute; left: calc(10px + var(--safe-l)); top: calc(10px + var(--safe-t)); width: min(300px, 46vw); display: flex; flex-direction: column; gap: 8px; }
.taskbar { height: 22px; background: #2a2433; box-shadow: 0 0 0 3px var(--ink), inset 0 0 0 2px var(--stone-hi); position: relative; }
.taskbar i { position: absolute; left: 2px; top: 2px; bottom: 2px; background: linear-gradient(#6ae08a, #2a9a4a); transition: width .4s; }
.taskbar span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; letter-spacing: 1px; color: #fff; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; }
.tasklist { background: rgba(18,12,28,0.82); box-shadow: 0 0 0 3px var(--ink), inset 0 0 0 2px var(--stone); padding: 8px 10px; font-size: 14px; line-height: 1.35; cursor: pointer; }
.tasklist h4 { margin: 0 0 4px; font-size: 13px; letter-spacing: 1px; color: var(--gold); text-transform: uppercase; display: flex; justify-content: space-between; }
.tasklist .t { color: var(--text); }
.tasklist .t.done { color: #6ae08a; }
.tasklist .t.part { color: #f2e27a; }
.tasklist .t.sab { color: #ff6a6a; font-weight: 700; }
.tasklist.collapsed .t { display: none; }
.hud-tr { position: absolute; right: calc(10px + var(--safe-r)); top: calc(10px + var(--safe-t)); display: flex; gap: 10px; }
.sq { width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; padding: 0; margin: 0; }
.sq img, .sq canvas { width: 32px; height: auto; image-rendering: pixelated; }
.roomname { position: absolute; left: 50%; transform: translateX(-50%); top: calc(12px + var(--safe-t)); font-size: 18px; font-weight: 700; color: #fff; text-shadow: 2px 2px 0 #000; letter-spacing: 1px; pointer-events: none !important; white-space: nowrap; }
.sabbanner { position: absolute; left: 50%; transform: translateX(-50%); top: calc(44px + var(--safe-t)); background: var(--red); color: #fff; font-weight: 700; padding: 6px 14px; box-shadow: 0 0 0 3px var(--ink); font-size: 16px; animation: flash 0.8s steps(2) infinite; white-space: nowrap; pointer-events: none !important; max-width: 70vw; overflow: hidden; text-overflow: ellipsis; }
@keyframes flash { 50% { background: var(--red-dk); } }
.actions { position: absolute; right: calc(12px + var(--safe-r)); bottom: calc(12px + var(--safe-b)); display: grid; grid-template-columns: repeat(3, auto); gap: 10px; direction: rtl; align-items: end; }
.act {
  direction: ltr; position: relative; width: 84px; height: 84px; border: 0; cursor: pointer; padding: 4px 0 0;
  background: rgba(30,22,44,0.85); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 0 0 0 3px var(--ink), inset 0 0 0 3px var(--stone-hi), 0 5px 0 2px rgba(0,0,0,0.5);
  font-size: 13px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
}
.act img { width: 48px; height: auto; image-rendering: pixelated; }
.act.off { opacity: 0.38; filter: grayscale(1); }
.act.kill { background: rgba(90,20,30,0.9); }
.act.report { background: rgba(110,80,10,0.9); }
.act .cd { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 38px; color: #fff; text-shadow: 3px 3px 0 #000; }
.act .key { position: absolute; top: 3px; right: 6px; font-size: 11px; color: var(--mute); }
.act:active:not(.off) { transform: translateY(3px); }
.ventarrow .arr { display: block; }
.ventarrow .vlabel { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: 13px; color: #fff; text-shadow: 2px 2px 0 #000; }
.ventarrow { position: absolute; width: 56px; height: 56px; margin: -28px 0 0 -28px; border: 0; background: rgba(242,201,76,0.9); color: var(--ink); font-size: 28px; font-weight: 700; box-shadow: 0 0 0 3px var(--ink); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.lobbybar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(10px + var(--safe-b)); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; width: max-content; max-width: 96vw; }
.codebox { background: rgba(18,12,28,0.9); box-shadow: 0 0 0 3px var(--ink), inset 0 0 0 2px var(--stone-hi); padding: 6px 12px; text-align: center; cursor: pointer; }
.codebox b { font-size: 26px; letter-spacing: 6px; color: var(--gold); display: block; }
.codebox small { font-size: 11px; color: var(--mute); letter-spacing: 1px; }
.playercount { font-size: 14px; color: var(--mute); }
.stick { position: fixed; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(255,255,255,0.08); box-shadow: inset 0 0 0 3px rgba(255,255,255,0.25); z-index: 3; pointer-events: none; display: none; }
.stick.on { display: block; }
.knob { position: absolute; left: 34px; top: 34px; width: 52px; height: 52px; border-radius: 50%; background: rgba(242,201,76,0.7); box-shadow: 0 0 0 3px rgba(18,12,28,0.6); }
.pingdot { position: absolute; left: 50%; bottom: calc(46px + var(--safe-b)); transform: translateX(-50%); font-size: 12px; color: #ff9a9a; pointer-events: none !important; }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(6,4,12,0.7); padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l)); }
.overlay.clear { background: transparent; pointer-events: none; }
.overlay.solid { background: #0b0812; }
.closex { position: absolute; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); z-index: 3; }
.gamebox { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.gamebox .gtitle { font-size: 18px; font-weight: 700; color: var(--gold); letter-spacing: 1px; text-shadow: 2px 2px 0 #000; }
.gamebox canvas { box-shadow: 0 0 0 4px var(--ink), 0 0 0 7px var(--stone-hi), 0 10px 0 4px rgba(0,0,0,0.5); touch-action: none; }
.scroll { overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; }

/* meeting */
.meeting { width: min(980px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 8px; }
.meeting .mhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.meeting .mhead h2 { font-family: var(--title); font-weight: 400; font-size: clamp(30px, 6vw, 46px); margin: 0; color: var(--brown); }
.meeting .timer { font-size: 16px; font-weight: 700; color: var(--brown); white-space: nowrap; }
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 44vw), 1fr)); gap: 8px; }
.card { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: #f6e8c4; box-shadow: 0 0 0 3px var(--brown); position: relative; min-height: 64px; cursor: pointer; color: var(--brown); }
.card.dead { background: #b8a684; cursor: default; }
.card.dead .spr { opacity: 0.6; }
.card.sel { box-shadow: 0 0 0 3px var(--brown), 0 0 0 6px var(--gold); }
.card .nm { font-weight: 700; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .badge { position: absolute; top: -8px; right: -6px; background: var(--green); color: var(--ink); font-size: 11px; font-weight: 700; padding: 2px 6px; box-shadow: 0 0 0 2px var(--ink); }
.card .caller { position: absolute; top: -10px; left: -8px; }
.card .x { position: absolute; left: 4px; top: 50%; transform: translateY(-50%); font-size: 46px; color: var(--red); font-weight: 700; text-shadow: 2px 2px 0 #000; line-height: 1; }
.card .chips { display: flex; flex-wrap: wrap; gap: 2px; max-width: 70px; }
.card .chip { width: 14px; height: 14px; box-shadow: 0 0 0 2px var(--ink); }
.card .confirm { display: flex; gap: 4px; }
.card .confirm button { width: 40px; height: 40px; border: 0; font-size: 22px; font-weight: 700; cursor: pointer; box-shadow: 0 0 0 3px var(--ink); }
.mfoot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.skipline { display: flex; align-items: center; gap: 8px; }
.chatpanel { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.chatlog { background: #f6e8c4; box-shadow: 0 0 0 3px var(--brown); padding: 8px; height: min(26vh, 200px); overflow-y: auto; touch-action: pan-y; font-size: 15px; color: var(--brown); }
.chatlog .line { margin: 3px 0; display: flex; gap: 6px; align-items: flex-start; }
.chatlog .line.ghost { opacity: 0.6; font-style: italic; }
.chatlog .who { font-weight: 700; white-space: nowrap; }
.quick { display: flex; flex-wrap: wrap; gap: 4px; }
.quick button { font-size: 13px; padding: 6px 8px; min-height: 34px; margin: 2px; }

/* splash screens */
.splash { flex-direction: column; text-align: center; gap: 14px; }
.splash .big { font-family: var(--title); font-size: clamp(48px, 13vw, 110px); line-height: 0.9; }
.splash .line2 { font-size: clamp(16px, 4vw, 24px); letter-spacing: 1px; }
.lineup2 { display: flex; gap: 6px; justify-content: center; align-items: flex-end; flex-wrap: wrap; }
.shh { font-family: var(--title); font-size: clamp(70px, 20vw, 160px); color: var(--gold); text-shadow: 4px 4px 0 var(--red-dk); }
.eject { background: radial-gradient(ellipse at center, #2a1840 0%, #07040d 70%); overflow: hidden; }
.eject .faller { position: absolute; left: -20%; top: 40%; animation: fall 5s linear forwards; }
@keyframes fall { from { transform: translateX(0) rotate(0deg); left: -15%; } to { transform: translateX(0) rotate(900deg); left: 110%; } }
.eject .txt { position: relative; z-index: 2; font-size: clamp(20px, 5vw, 34px); font-weight: 700; color: #fff; text-shadow: 2px 2px 0 #000; min-height: 1.3em; }
.eject .sub { position: relative; z-index: 2; font-size: clamp(16px, 4vw, 22px); color: var(--mute); }
.stars { position: absolute; inset: 0; background-image: radial-gradient(1px 1px at 20% 30%, #fff, transparent), radial-gradient(1px 1px at 70% 60%, #fff, transparent), radial-gradient(2px 2px at 40% 80%, #c9a0ff, transparent), radial-gradient(1px 1px at 85% 20%, #fff, transparent), radial-gradient(1px 1px at 10% 70%, #9ab0ff, transparent), radial-gradient(2px 2px at 55% 15%, #fff, transparent); background-size: 300px 300px; animation: drift 12s linear infinite; opacity: 0.8; }
@keyframes drift { to { background-position: -300px 0; } }
.slain { background: rgba(60,0,10,0.85); flex-direction: column; gap: 10px; }
.slain .claw { position: absolute; inset: 0; pointer-events: none; animation: claw 0.9s ease-out forwards; }
@keyframes claw { 0% { opacity: 0; transform: translate(-30px, -30px); } 15% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.toast { background: rgba(18,12,28,0.95); color: var(--text); padding: 10px 14px; box-shadow: 0 0 0 3px var(--ink), inset 0 0 0 2px var(--gold-dk); font-size: 16px; text-align: center; animation: pop .2s ease-out; }
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }

/* map scroll */
.mapbox { position: relative; }
.mapbox canvas.base { display: block; width: min(94vw, calc((100vh - 110px) * 1.786)); height: auto; box-shadow: 0 0 0 4px var(--brown), 0 0 0 7px var(--parch-dk); background: #c9ae78; }
.mapbox .pin { position: absolute; transform: translate(-50%, -50%); pointer-events: none; }
.mapbox .lbl { position: absolute; transform: translate(-50%, -50%); font-size: clamp(9px, 1.5vw, 13px); font-weight: 700; color: var(--brown); white-space: nowrap; pointer-events: none; text-shadow: 0 1px 0 #f6e8c4; }
.mapbox .sabbtn { position: absolute; transform: translate(-50%, -50%); width: max(26px, 3.6%); height: auto; aspect-ratio: 1; border: 0; padding: 0; cursor: pointer; background: var(--red); box-shadow: 0 0 0 3px var(--ink); display: flex; align-items: center; justify-content: center; }
.mapbox .sabbtn img { width: 66%; image-rendering: pixelated; }
.mapbox .sabbtn.door { background: #6e6a78; width: max(22px, 2.8%); }
.mapbox .sabbtn.door img { width: 66%; }
.mapbox .sabbtn:disabled { filter: grayscale(1) brightness(0.6); }
.mapbox .count { position: absolute; transform: translate(-50%, -50%); display: flex; gap: 2px; flex-wrap: wrap; max-width: 80px; justify-content: center; pointer-events: none; }
.mapbox .count i { width: 10px; height: 12px; background: #3a6ee0; box-shadow: 0 0 0 2px var(--ink); border-radius: 5px 5px 2px 2px; }
.mapbox .count i.b { background: var(--red); }
.cams { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.cams .cam { position: relative; }
.cams .cam canvas { width: min(44vw, 380px); height: auto; display: block; box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px #5b3fbf; }
.cams .cam span { position: absolute; left: 6px; bottom: 4px; font-size: 13px; font-weight: 700; text-shadow: 1px 1px 0 #000; }

/* customize + settings */
.sheet { width: min(640px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 10px; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatches button { aspect-ratio: 1; border: 0; cursor: pointer; box-shadow: 0 0 0 3px var(--ink); position: relative; }
.swatches button.on { box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--gold); }
.swatches button.taken::after { content: ""; position: absolute; inset: 30%; background: rgba(0,0,0,0.6); }
.hats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.hats button { background: var(--stone); border: 0; cursor: pointer; box-shadow: 0 0 0 3px var(--ink); padding: 2px; display: flex; flex-direction: column; align-items: center; font-size: 10px; color: var(--mute); }
.hats button.on { box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--gold); }
.hats .spr { width: 44px; height: auto; }
.setrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 2px solid rgba(255,255,255,0.08); font-size: 16px; }
.setrow .ctl { display: flex; align-items: center; gap: 6px; }
.setrow .ctl button { width: 38px; height: 38px; min-height: 38px; padding: 0; margin: 0; font-size: 20px; }
.setrow .val { min-width: 64px; text-align: center; font-weight: 700; color: var(--gold); }
.seg { display: flex; gap: 0; }
.seg button { margin: 0 2px; }
.seg button.on { background: var(--gold); color: var(--ink); }
.qr { background: #fff; padding: 10px; box-shadow: 0 0 0 4px var(--ink); }
.qr img { display: block; width: min(60vw, 260px); image-rendering: pixelated; }

@media (max-width: 640px), (max-height: 480px) {
  .act { width: 70px; height: 70px; font-size: 11px; }
  .act img { width: 40px; }
  .act .key { display: none; }
  .sq { width: 46px; height: 46px; }
  .tasklist { font-size: 12px; }
  .roomname { font-size: 14px; left: auto; right: calc(12px + var(--safe-r)); transform: none; top: calc(64px + var(--safe-t)); }
  .codebox b { font-size: 20px; }
}
@media (max-height: 420px) {
  .meeting .mhead h2 { font-size: 26px; }
  .card { min-height: 52px; }
  .chatlog { height: 22vh; }
}
