:root {
  --ink: #fdfbff;
  --muted: #b9b3d6;
  --panel: rgba(27, 20, 64, 0.92);
  --panel-edge: #4b3c9c;
  --pill: rgba(20, 14, 48, 0.72);
  --accent: #ffd23f;
  --accent-ink: #3a2600;
  --good: #7ed957;
  --bad: #ff5a5a;
  --radius: 14px;
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1b1440; color: var(--ink); font-family: var(--font); }
body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#view { position: fixed; inset: 0; display: block; image-rendering: pixelated; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
kbd { background: #2d2466; border: 1px solid #5b4cb0; border-bottom-width: 3px; border-radius: 6px; padding: 1px 6px; font-family: inherit; font-size: 0.9em; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 700; color: var(--ink); cursor: pointer;
  background: #3a2d86; border: 2px solid #6a58d0; border-bottom-width: 4px; border-radius: 12px;
  padding: 8px 14px; font-size: 1rem; line-height: 1.1;
  transition: transform 0.06s ease, background 0.15s;
}
.btn:hover { background: #4a3aa6; }
.btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: #c79a00; }
.btn.primary:hover { background: #ffe06e; }
.btn.huge { font-size: 1.5rem; padding: 14px 28px; width: 100%; margin-top: 12px; }
.btn.small { font-size: 0.8rem; padding: 4px 8px; border-bottom-width: 3px; }
.btn.duel { background: #d9342b; border-color: #8f1d17; }
.btn.duel:hover { background: #ee4a40; }

/* ---------- panels & modals ---------- */
.panel {
  background: var(--panel); border: 3px solid var(--panel-edge); border-radius: 20px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45); padding: 20px;
}
.screen, .modal {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: safe center;
  padding: 16px; z-index: 20; overflow-y: auto; touch-action: pan-y;
}
.screen { background: radial-gradient(ellipse at top, #6ec6ff 0%, #3f7fd8 45%, #1b1440 100%); }
.modal { background: rgba(10, 6, 30, 0.55); }
h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: 2.2rem; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }

/* ---------- lobby ---------- */
.lobby-panel { width: min(440px, 100%); }
.lobby-panel label, .lobby-panel .label { display: block; font-weight: 700; margin: 14px 0 6px; }
.lobby-panel small { color: var(--muted); font-weight: 400; }
.tagline { color: var(--muted); margin: -4px 0 8px; }
input {
  font: inherit; font-size: 1.2rem; width: 100%; margin-top: 6px; padding: 10px 12px; color: var(--ink);
  background: #120d33; border: 2px solid #5b4cb0; border-radius: 12px; outline: none;
  -webkit-user-select: text; user-select: text;
}
input:focus { border-color: var(--accent); }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.color-btn { width: 44px; height: 44px; border-radius: 50%; border: 4px solid transparent; cursor: pointer; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25); }
.color-btn.sel { border-color: #fff; transform: scale(1.12); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud button, #hud .hotbar { pointer-events: auto; }
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  gap: 10px; padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
}
.hud-left, .hud-right { display: flex; gap: 8px; }
.hud-left { flex-direction: column; align-items: flex-start; min-width: 0; }
.hud-right { flex-wrap: wrap; justify-content: flex-end; }
.hud-center { display: flex; flex-direction: column; align-items: center; gap: 6px; position: absolute; left: 50%; transform: translateX(-50%); top: 10px; }
.room-pill, .prow, .phase, .hot {
  background: var(--pill); border-radius: 999px; padding: 5px 12px; backdrop-filter: blur(4px);
  font-weight: 700; display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.players { display: flex; flex-direction: column; gap: 4px; }
.prow.me { outline: 2px solid rgba(255, 255, 255, 0.6); }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 2px solid rgba(255, 255, 255, 0.7); flex: none; }
.pname { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.chip { background: rgba(255, 255, 255, 0.12); border-radius: 999px; padding: 1px 8px; font-size: 0.9rem; }
.chip.star { color: var(--accent); }
.phase { font-size: 1.15rem; padding: 7px 16px; }
.phase[data-phase="hide"] { background: rgba(143, 90, 20, 0.85); }
.phase[data-phase="hunt"] { background: rgba(160, 30, 60, 0.85); }
.timer { font-variant-numeric: tabular-nums; background: rgba(0, 0, 0, 0.3); border-radius: 8px; padding: 1px 8px; }
.timer.urgent { color: #fff; background: var(--bad); animation: pulse 0.5s infinite alternate; }
.hot { flex-wrap: wrap; justify-content: center; width: 240px; }
.hot-track { flex: 1; height: 14px; border-radius: 999px; background: linear-gradient(90deg, #4fc3f7, #ffe14d, #ff5a1f); position: relative; overflow: hidden; }
.hot-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; border-right: 5px solid #fff; box-shadow: 3px 0 8px #fff; transition: width 0.3s; }
.hot-text { width: 100%; text-align: center; font-size: 0.95rem; }

.toasts { position: absolute; top: 120px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(92vw, 560px); }
.toast {
  background: rgba(20, 14, 48, 0.88); border: 2px solid var(--panel-edge); padding: 8px 16px; border-radius: 14px;
  font-weight: 700; text-align: center; animation: pop 0.25s ease-out; transition: opacity 0.4s, transform 0.4s;
}
.toast.big { font-size: 1.4rem; border-color: var(--accent); padding: 12px 20px; }
.toast.out { opacity: 0; transform: translateY(-10px); }

.hud-bottom { z-index: 2; position: absolute; bottom: max(10px, env(safe-area-inset-bottom)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
.hearts { font-size: 1.25rem; letter-spacing: 1px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6)); }
.hearts.bump { animation: pop 0.3s ease-out; }
#btn-zombies.off { opacity: 0.55; }
.hotbar { display: flex; gap: 5px; background: var(--pill); padding: 6px; border-radius: 16px; max-width: calc(100vw - 20px); overflow-x: auto; }
.slot {
  position: relative; width: 50px; height: 50px; flex: none; border-radius: 10px; border: 3px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.3); padding: 5px; cursor: pointer; color: var(--ink); font-size: 1.5rem;
}
.slot img { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.slot.sel { border-color: var(--accent); background: rgba(255, 210, 63, 0.25); transform: translateY(-3px); }
.slot-key { position: absolute; left: 3px; top: 1px; font-size: 0.7rem; font-weight: 700; text-shadow: 0 1px 2px #000; }
.slot.chest .slot-key { left: auto; right: 3px; font-size: 0.85rem; color: var(--accent); }
.slot-emoji { display: block; line-height: 34px; }
.slot.chest { border-color: #c79a00; }

/* touch controls: floating joystick bottom-left, jump bottom-right (like Minecraft on a phone) */
.touch {
  --cell: 64px; --stick: 132px;
  position: absolute; left: 0; right: 0; bottom: 78px; display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); pointer-events: none;
}
/* The joystick zone is the lower-left part of the screen; the stick jumps to wherever the thumb lands. */
.stick-zone {
  position: fixed; left: 0; bottom: 0; width: min(42vw, 360px); height: min(62vh, 420px);
  pointer-events: auto; touch-action: none; z-index: 1;
}
.stick-base {
  position: absolute; left: calc(max(14px, env(safe-area-inset-left)) + var(--stick) / 2); top: calc(100% - 78px - var(--stick) / 2);
  width: var(--stick); height: var(--stick); margin: calc(var(--stick) / -2) 0 0 calc(var(--stick) / -2);
  border-radius: 50%; background: rgba(20, 14, 48, 0.35); border: 3px solid rgba(255, 255, 255, 0.4);
  display: grid; place-items: center; opacity: 0.7; transition: opacity 0.15s;
}
.stick-zone.active .stick-base { opacity: 1; transition: none; }
.stick-knob {
  width: calc(var(--stick) * 0.46); height: calc(var(--stick) * 0.46); border-radius: 50%;
  background: rgba(255, 255, 255, 0.75); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.stick-zone.active .stick-knob { background: #fff; }
.tbtn {
  pointer-events: auto; touch-action: none; color: #fff; font-size: 1.7rem; padding: 0;
  background: rgba(20, 14, 48, 0.45); border: 3px solid rgba(255, 255, 255, 0.45); border-radius: 12px;
}
.tbtn.held { background: rgba(255, 255, 255, 0.45); }
.tbtn.sword { margin-left: auto; margin-bottom: calc(var(--cell) * 0.7); width: calc(var(--cell) * 1.15); height: calc(var(--cell) * 1.15); border-radius: 50%; font-size: 1.9rem; }
.tbtn.jump { margin-left: 12px; width: calc(var(--cell) * 1.4); height: calc(var(--cell) * 1.4); border-radius: 50%; font-size: 2.2rem; }

/* ---------- picker ---------- */
.picker-panel { width: min(720px, 100%); max-height: 86vh; overflow: auto; }
.ws-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.ws-head h2 { margin: 0; flex: 1; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.pick {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer;
  background: rgba(0, 0, 0, 0.25); border: 2px solid transparent; border-radius: 12px; padding: 8px; color: var(--ink); font: inherit; font-size: 0.85rem;
}
.pick:hover { border-color: var(--accent); }
.pick img { width: 48px; height: 48px; image-rendering: pixelated; }
.pick i { position: absolute; top: 2px; right: 4px; font-style: normal; }

/* ---------- workshop ---------- */
.ws-panel { width: min(860px, 100%); max-height: 94vh; overflow: auto; }
.ws-editing { color: var(--accent); font-weight: 700; }
.ws-body { display: flex; gap: 20px; flex-wrap: wrap; }
.ws-col { flex: 1 1 320px; display: flex; flex-direction: column; gap: 12px; }
.ws-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); width: min(340px, 100%); aspect-ratio: 1; touch-action: none;
  border: 3px solid #5b4cb0; border-radius: 8px; overflow: hidden; cursor: crosshair;
}
.ws-cell { border: 1px solid rgba(255, 255, 255, 0.08); }
.ws-cell.empty { background-image: linear-gradient(45deg, #2a2258 25%, transparent 25%, transparent 75%, #2a2258 75%), linear-gradient(45deg, #2a2258 25%, #1d1745 25%, #1d1745 75%, #2a2258 75%); background-size: 12px 12px; background-position: 0 0, 6px 6px; }
.ws-palette { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; width: min(340px, 100%); }
.ws-swatch { aspect-ratio: 1; border-radius: 8px; border: 3px solid rgba(255, 255, 255, 0.25); cursor: pointer; font-size: 1rem; padding: 0; }
.ws-swatch.eraser { background: #2a2258; }
.ws-swatch.active { border-color: #fff; transform: scale(1.15); box-shadow: 0 0 0 2px #000; }
.ws-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.ws-tools select { font: inherit; background: #120d33; color: var(--ink); border: 2px solid #5b4cb0; border-radius: 10px; padding: 6px; }
.ws-name { font-weight: 700; }
.ws-abilities { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.ability {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; cursor: pointer; color: var(--muted);
  background: rgba(0, 0, 0, 0.25); border: 3px solid transparent; border-radius: 12px; font: inherit; font-size: 0.85rem; font-weight: 700;
}
.ability .ab-icon { font-size: 1.6rem; filter: grayscale(1) opacity(0.5); }
.ability.on { color: var(--ink); border-color: var(--good); background: rgba(126, 217, 87, 0.18); }
.ability.on .ab-icon { filter: none; }
.ws-steppers { display: flex; gap: 12px; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; gap: 6px; background: rgba(0, 0, 0, 0.25); border-radius: 12px; padding: 4px 8px; font-weight: 700; }
.stepper b { min-width: 22px; text-align: center; font-size: 1.2rem; }
.stepper .btn { padding: 2px 10px; }
.ws-save-row { display: flex; align-items: center; gap: 14px; margin-top: auto; }
.ws-preview canvas { width: 72px; height: 72px; image-rendering: pixelated; border: 3px solid #5b4cb0; border-radius: 6px; background: #6ec6ff; }
.ws-save { flex: 1; font-size: 1.3rem; padding: 12px; }
.ws-mine-wrap { margin-top: 16px; border-top: 2px solid rgba(255, 255, 255, 0.1); padding-top: 12px; }
.ws-mine-title { font-weight: 700; margin-bottom: 8px; display: flex; gap: 10px; align-items: center; }
.ws-mine { display: flex; flex-wrap: wrap; gap: 8px; }
.mine-item { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 78px; background: rgba(0, 0, 0, 0.25); border: 2px solid transparent; border-radius: 10px; padding: 6px; cursor: pointer; color: var(--ink); font: inherit; font-size: 0.75rem; }
.mine-item:hover { border-color: var(--accent); }
.mine-item img { width: 40px; height: 40px; image-rendering: pixelated; }
.mine-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- result & help ---------- */
.result-panel { width: min(560px, 100%); text-align: center; }
.result-panel table { width: 100%; border-collapse: collapse; margin: 8px 0 12px; }
.result-panel th { color: var(--muted); font-size: 0.85rem; font-weight: 400; padding: 4px; }
.result-panel td { padding: 8px 6px; border-top: 1px solid rgba(255, 255, 255, 0.1); }
.result-panel td:first-child { text-align: left; font-weight: 700; }
.result-panel td.big { font-size: 1.5rem; font-weight: 800; color: var(--accent); }
.result-panel tr.me td { background: rgba(255, 255, 255, 0.06); }
.help-panel { width: min(820px, 100%); max-height: 90vh; overflow: auto; }
.help-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.help-cols p { margin: 6px 0; line-height: 1.4; }

@keyframes pop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.12); } }
.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

@media (max-width: 700px) {
  .hud-center { top: auto; bottom: 150px; }
  .pname { max-width: 70px; }
  .slot { width: 42px; height: 42px; padding: 4px; }
  .touch { --cell: 56px; --stick: 120px; bottom: 66px; }
  .btn { padding: 6px 10px; }
}

@media (max-height: 520px) {
  h1 { font-size: 1.5rem; margin-bottom: 4px; }
  .panel { padding: 14px; }
  .tagline { display: none; }
  .lobby-panel label, .lobby-panel .label { margin: 8px 0 4px; }
  input { padding: 7px 10px; font-size: 1rem; }
  .color-btn { width: 36px; height: 36px; }
  .btn.huge { font-size: 1.2rem; padding: 10px; }
  .slot { width: 40px; height: 40px; padding: 3px; }
  .touch { --cell: 48px; --stick: 104px; bottom: 58px; }
  .tbtn { font-size: 1.3rem; }
  .toasts { top: auto; bottom: 62px; width: min(52vw, 440px); flex-direction: column-reverse; }
  .toast { font-size: 0.9rem; padding: 6px 12px; }
  .toast.big { font-size: 1.05rem; padding: 8px 14px; }
}
