/* =========================================================
   The Midnight Murder — STEMFEST Escape Room
   Animations use only transform/opacity for smooth 60fps on tablets.
   ========================================================= */
:root {
  --bg: #0a0507;
  --bg-2: #140a0d;
  --panel: rgba(22, 10, 14, 0.78);
  --blood: #c1121f;
  --blood-dark: #6a040f;
  --blood-glow: rgba(193, 18, 31, 0.55);
  --pumpkin: #ff7518;
  --pumpkin-glow: rgba(255, 117, 24, 0.45);
  --bone: #eadfc8;
  --bone-dim: #a89a85;
  --tape: #f5c400;
  --ok: #3ddc84;
  --radius: 14px;
  --f-horror: "Creepster", "Chiller", "Impact", fantasy;
  --f-type: "Special Elite", "Courier New", monospace;
  --f-ui: "Oswald", "Arial Narrow", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at 50% -10%, #2a0f16 0%, transparent 60%),
    radial-gradient(ellipse at 100% 100%, #1d0a05 0%, transparent 50%),
    var(--bg);
  color: var(--bone);
  font-family: var(--f-type);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
input { -webkit-user-select: text; user-select: text; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }

/* ---------------- Atmosphere ---------------- */
.atmos { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; contain: strict; }
.moon {
  position: absolute; top: 6vh; right: 8vw; width: 14vmin; height: 14vmin; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3d6, #e8c98a 55%, #b8924a);
  box-shadow: 0 0 60px 10px rgba(255, 220, 150, 0.18);
  opacity: 0.35;
}
.fog {
  position: absolute; left: -50%; width: 200%; height: 60%;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(160, 140, 150, 0.10), transparent 60%),
    radial-gradient(ellipse at 60% 40%, rgba(140, 120, 130, 0.08), transparent 55%),
    radial-gradient(ellipse at 85% 60%, rgba(160, 140, 150, 0.10), transparent 60%);
  will-change: transform;
}
.fog-a { bottom: -10%; animation: drift 38s linear infinite; }
.fog-b { bottom: 10%; opacity: 0.7; animation: drift 55s linear infinite reverse; }
@keyframes drift { from { transform: translate3d(0,0,0); } to { transform: translate3d(25%,0,0); } }

.chalk {
  position: absolute; bottom: -14vh; right: 6vw; height: 55vh; width: auto;
  fill: none; stroke: rgba(234, 223, 200, 0.06); stroke-width: 3; stroke-dasharray: 8 6;
  transform: rotate(-18deg);
}
.vignette { position: absolute; inset: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,0.75) 100%); }

.bat { position: absolute; top: 0; left: 0; width: 46px; height: 22px; will-change: transform; animation: fly 22s linear infinite; }
.bat::before {
  content: ""; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 30'%3E%3Cpath fill='%23000' d='M32 8c-2 0-3 2-3 4-4-6-12-9-20-8 4 2 6 5 6 8-5-2-11-1-15 2 6 1 10 4 12 8 3-3 8-4 12-2 2-3 5-4 8-4s6 1 8 4c4-2 9-1 12 2 2-4 6-7 12-8-4-3-10-4-15-2 0-3 2-6 6-8-8-1-16 2-20 8 0-2-1-4-3-4z'/%3E%3C/svg%3E") center/contain no-repeat;
  animation: flap 0.28s ease-in-out infinite alternate;
  filter: drop-shadow(0 0 2px rgba(255,117,24,0.25));
}
.bat-1 { animation-duration: 24s; }
.bat-2 { animation-duration: 31s; animation-delay: -12s; transform: scale(0.7); }
.bat-3 { animation-duration: 27s; animation-delay: -20s; }
@keyframes flap { from { transform: scaleY(1); } to { transform: scaleY(0.35); } }
@keyframes fly {
  0%   { transform: translate3d(-10vw, 30vh, 0) scale(.8); }
  25%  { transform: translate3d(25vw, 12vh, 0) scale(.9); }
  50%  { transform: translate3d(55vw, 26vh, 0) scale(.7); }
  75%  { transform: translate3d(80vw, 8vh, 0) scale(.85); }
  100% { transform: translate3d(112vw, 20vh, 0) scale(.8); }
}

/* ---------------- Crime tape ---------------- */
.tape {
  position: relative; z-index: 2; overflow: hidden; white-space: nowrap;
  background: repeating-linear-gradient(-45deg, var(--tape) 0 22px, #e0b300 22px 26px);
  color: #111; font-family: var(--f-ui); font-weight: 700; letter-spacing: .18em;
  font-size: clamp(11px, 1.4vw, 15px); padding: 6px 0;
  box-shadow: 0 4px 18px rgba(0,0,0,0.6);
}
.tape-top { transform: rotate(-0.6deg); margin: 0 -10px; }
.tape-track { display: inline-flex; animation: tape 30s linear infinite; will-change: transform; }
.tape-track span { padding-right: 0; }
@keyframes tape { from { transform: translate3d(0,0,0); } to { transform: translate3d(-50%,0,0); } }

/* ---------------- Header ---------------- */
.brand { position: relative; z-index: 2; text-align: center; padding: clamp(8px, 2vh, 20px) 16px 0; }
.kicker { margin: 0; font-family: var(--f-ui); letter-spacing: .3em; text-transform: uppercase; font-size: clamp(10px, 1.2vw, 13px); color: var(--pumpkin); opacity: .85; }
.title {
  position: relative; display: inline-block; margin: 2px 0 0;
  font-family: var(--f-horror); font-weight: 400; letter-spacing: .04em;
  font-size: clamp(34px, 6vw, 70px); line-height: 1.05;
  color: var(--blood);
  text-shadow: 0 0 18px var(--blood-glow), 0 3px 0 #2a0005;
  animation: flicker 6s infinite steps(1);
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  41% { opacity: 1; } 42% { opacity: .35; } 43% { opacity: 1; } 45% { opacity: .55; } 46% { opacity: 1; }
  78% { opacity: 1; } 79% { opacity: .4; } 80% { opacity: 1; }
}
/* blood drips under the title */
.title::after {
  content: ""; position: absolute; left: 8%; right: 8%; top: 82%; height: 26px;
  background:
    radial-gradient(circle at 10% 0, var(--blood) 3px, transparent 4px),
    radial-gradient(circle at 37% 0, var(--blood) 3px, transparent 4px),
    radial-gradient(circle at 63% 0, var(--blood) 2.5px, transparent 3.5px),
    radial-gradient(circle at 88% 0, var(--blood) 3px, transparent 4px);
  transform-origin: top; animation: drip 4.5s ease-in infinite;
}
@keyframes drip { 0% { transform: scaleY(.1); opacity: 1; } 80% { transform: scaleY(1) translateY(16px); opacity: 1; } 100% { transform: scaleY(1) translateY(24px); opacity: 0; } }

/* ---------------- Layout ----------------
   .screen is exactly one viewport tall; the game fills what's left
   under the header and the keypad stretches to fit any device. */
.screen {
  position: relative; z-index: 2; display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; min-height: 600px;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
.screen > .view { flex: 1 1 auto; min-height: 0; }
.view { position: relative; z-index: 2; width: min(1180px, 100%); margin: 0 auto; padding: clamp(10px, 2.2vh, 24px) clamp(12px, 3vw, 32px) clamp(12px, 2.4vh, 24px); animation: viewIn .6s cubic-bezier(.2,.8,.2,1) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.game { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: clamp(14px, 3vw, 36px); }

.left { display: flex; flex-direction: column; gap: clamp(10px, 2vh, 20px); min-height: 0; }

/* ---------------- Team row ---------------- */
.team-row { display: flex; align-items: center; gap: 10px; }
.team-row .btn-start { flex: 0 0 auto; padding: 0 18px; }
.team-label { font-family: var(--f-horror); font-size: clamp(30px, 4vw, 44px); color: var(--pumpkin); text-shadow: 0 0 14px var(--pumpkin-glow); }
.team-input {
  flex: 1 1 0; min-width: 0; height: 58px; padding: 0 14px; font-size: 20px;
  border: 2px solid rgba(234,223,200,0.25); border-radius: var(--radius);
  background: rgba(0,0,0,0.45); color: var(--bone); outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.team-input:focus { border-color: var(--pumpkin); box-shadow: 0 0 0 4px rgba(255,117,24,0.18); }
.team-input:disabled { opacity: 1; border-color: var(--blood); color: #fff; -webkit-text-fill-color: #fff; background: rgba(106,4,15,0.25); }
.team-input.shake { animation: shake .4s; border-color: var(--blood); }

/* ---------------- Buttons ---------------- */
.btn {
  position: relative; border: 0; border-radius: var(--radius); padding: 0 22px; height: 58px;
  font-family: var(--f-ui); font-weight: 700; font-size: 20px; letter-spacing: .14em; text-transform: uppercase;
  transition: transform .12s, filter .2s, opacity .2s; overflow: hidden;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn-start { background: linear-gradient(180deg, #ff8a33, #d4520a); color: #1a0700; box-shadow: 0 6px 22px var(--pumpkin-glow), inset 0 -3px 0 rgba(0,0,0,0.25); }
.btn-start:not(:disabled)::after {
  content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,0.45) 50%, transparent 70%);
  transform: translateX(-120%); animation: sheen 3.2s ease-in-out infinite;
}
@keyframes sheen { 0%, 60% { transform: translateX(-120%); } 100% { transform: translateX(120%); } }
.btn-danger { background: linear-gradient(180deg, #e01e2e, #7a0610); color: #fff; box-shadow: 0 6px 22px var(--blood-glow); }
.btn-ghost { background: rgba(234,223,200,0.08); color: var(--bone); border: 1px solid rgba(234,223,200,0.25); }
.btn-sm { height: 40px; font-size: 14px; padding: 0 14px; letter-spacing: .08em; }

/* ---------------- Code display ---------------- */
.code-wrap {
  border: 2px solid rgba(234,223,200,0.2); border-radius: var(--radius); background: var(--panel);
  padding: 16px 18px 12px; box-shadow: inset 0 0 30px rgba(0,0,0,0.6);
}
.code-display { display: flex; justify-content: center; gap: clamp(10px, 2vw, 18px); min-height: 70px; align-items: flex-end; }
.slot {
  width: clamp(44px, 6.5vw, 64px); height: 66px; display: grid; place-items: center;
  border-bottom: 4px solid var(--bone-dim); font-family: var(--f-ui); font-size: 44px; font-weight: 700; color: #fff;
  transition: border-color .2s;
}
.slot.filled { border-color: var(--pumpkin); }
.slot.filled span { display: inline-block; animation: pop .22s cubic-bezier(.3,1.6,.5,1); }
.slot.next { border-color: var(--bone); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { border-color: transparent; } }
@keyframes pop { from { transform: scale(.3) translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.code-wrap.wrong { animation: shake .45s; border-color: var(--blood); box-shadow: 0 0 30px var(--blood-glow), inset 0 0 30px rgba(193,18,31,0.35); }
.code-wrap.wrong .slot { border-color: var(--blood); color: var(--blood); }
.code-wrap.right { border-color: var(--ok); box-shadow: 0 0 30px rgba(61,220,132,0.5); }
.code-hint { margin: 8px 0 0; text-align: center; font-size: 14px; color: var(--bone-dim); min-height: 1.3em; }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(5px); } 30%, 50%, 70% { transform: translateX(-9px); } 40%, 60% { transform: translateX(9px); } }

/* ---------------- Numpad ---------------- */
.numpad {
  flex: 1 1 auto; min-height: 220px; max-height: 540px;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 1fr; gap: clamp(8px, 1.4vw, 14px);
  padding-bottom: 5px; /* room for the key "depth" shadow */
}
.key {
  min-height: 0; border-radius: var(--radius);
  border: 1px solid rgba(234,223,200,0.18);
  background: linear-gradient(180deg, #2a1418, #170a0d);
  box-shadow: 0 5px 0 #050203, 0 8px 18px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
  font-family: var(--f-ui); font-size: clamp(26px, min(4vw, 4.6vh), 44px); font-weight: 700; color: var(--bone);
  transition: transform .08s, box-shadow .08s, background .2s, opacity .3s;
}
.key:active, .key.pressed { transform: translateY(4px); box-shadow: 0 1px 0 #050203, 0 2px 8px rgba(0,0,0,0.5), 0 0 22px var(--pumpkin-glow); background: linear-gradient(180deg, #3a1a14, #22100c); color: var(--pumpkin); }
.key-clear { color: #ff6b6b; }
.key-enter { color: var(--ok); }
.numpad.locked .key { opacity: .32; pointer-events: none; }

/* ---------------- Case file (right column) ---------------- */
.case-file {
  position: relative; border-radius: var(--radius); background: var(--panel);
  border: 2px solid rgba(234,223,200,0.18);
  box-shadow: 0 18px 50px rgba(0,0,0,0.6);
  display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
.timer-box { position: relative; padding: clamp(8px, 1.6vh, 14px) 20px clamp(10px, 1.8vh, 16px); background: linear-gradient(180deg, rgba(106,4,15,0.45), rgba(0,0,0,0.2)); border-bottom: 2px dashed rgba(234,223,200,0.2); display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.timer-label { font-family: var(--f-horror); font-size: clamp(30px, 3.6vw, 42px); color: var(--bone); }
.timer { display: inline-block; font-family: var(--f-ui); font-weight: 700; font-size: clamp(46px, 6vw, 72px); color: #fff; font-variant-numeric: tabular-nums; letter-spacing: .04em; text-shadow: 0 0 16px rgba(255,255,255,0.25); }
.timer.warn { color: var(--pumpkin); text-shadow: 0 0 18px var(--pumpkin-glow); }
.timer.danger { color: var(--blood); text-shadow: 0 0 22px var(--blood-glow); animation: heartbeat 1s ease-in-out infinite; }
@keyframes heartbeat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.08); } 30% { transform: scale(1); } 45% { transform: scale(1.05); } }
.timer-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0,0,0,0.5); }
.timer-bar > div { height: 100%; width: 100%; background: linear-gradient(90deg, var(--blood), var(--pumpkin)); transform-origin: left; transform: scaleX(1); }

.clues { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--blood-dark) transparent; }
.clue {
  position: relative; padding: clamp(10px, 1.7vh, 16px) 20px clamp(10px, 1.7vh, 16px) 22px; border-bottom: 1px solid rgba(234,223,200,0.12);
  animation: clueIn .6s cubic-bezier(.2,.8,.2,1) both; animation-delay: calc(var(--i) * 0.12s + .2s);
}
.clue:last-child { border-bottom: 0; }
.clue::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 2px; background: linear-gradient(var(--blood), var(--blood-dark)); }
.clue-tag { display: inline-block; font-family: var(--f-ui); font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--pumpkin); border: 1px solid rgba(255,117,24,0.4); border-radius: 4px; padding: 2px 7px; }
.clue h3 { margin: 6px 0 4px; font-family: var(--f-ui); font-weight: 700; letter-spacing: .06em; font-size: clamp(18px, 2vw, 22px); color: #fff; }
.clue p { margin: 0; font-size: clamp(15px, 1.6vw, 17px); line-height: 1.45; color: var(--bone); white-space: pre-line; }
@keyframes clueIn { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }

/* ---------------- Below the fold: TERMINATE ---------------- */
.below-fold { position: relative; z-index: 2; margin-top: 60vh; padding-bottom: 60px; text-align: center; }
.tape-bottom { transform: rotate(0.8deg); margin: 0 -10px 40px; }
.tape-bottom .tape-track { animation-direction: reverse; }
.staff-controls { display: flex; flex-direction: column; align-items: center; gap: 14px; padding-bottom: env(safe-area-inset-bottom); }
.btn-terminate { background: #1a0005; color: var(--blood); border: 2px solid var(--blood); letter-spacing: .3em; height: 52px; font-size: 16px; }

/* ---------------- Result overlay ---------------- */
.result {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(ellipse at center, rgba(14,20,14,0.93), rgba(0,0,0,0.98));
  animation: fadeIn .4s both; overflow: hidden;
}
.result-inner { text-align: center; max-width: 820px; }
.result-title { margin: 10px 0; font-family: var(--f-horror); font-weight: 400; font-size: clamp(38px, min(9vw, 13vh), 110px); line-height: 1; animation: slam .8s cubic-bezier(.2,1.4,.4,1) .15s both; }
.result-sub { font-size: clamp(16px, min(2.4vw, 4vh), 26px); color: var(--bone); margin: 8px 0 clamp(14px, 4vh, 28px); animation: fadeIn .5s .7s both; }
.result-inner .btn { animation: fadeIn .5s 1s both; }
.result-icon { font-size: clamp(44px, min(10vw, 14vh), 110px); line-height: 1; animation: float 3s ease-in-out infinite; }
.result.win .result-title { color: var(--ok); text-shadow: 0 0 30px rgba(61,220,132,0.55), 0 4px 0 #04210f; }
.result.lose .result-title { color: var(--blood); text-shadow: 0 0 34px var(--blood-glow), 0 4px 0 #2a0005; }
.result.lose { background: radial-gradient(ellipse at center, rgba(60,0,8,0.93), rgba(0,0,0,0.98)); }
.result.lose::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 15% 20%, rgba(193,18,31,0.55) 0 40px, transparent 41px),
    radial-gradient(circle at 18% 26%, rgba(193,18,31,0.55) 0 14px, transparent 15px),
    radial-gradient(circle at 85% 75%, rgba(193,18,31,0.5) 0 60px, transparent 61px),
    radial-gradient(circle at 80% 68%, rgba(193,18,31,0.5) 0 18px, transparent 19px),
    radial-gradient(circle at 78% 15%, rgba(193,18,31,0.35) 0 22px, transparent 23px);
  animation: splat .5s cubic-bezier(.2,1.6,.4,1) both;
}
.result.win::before {
  content: ""; position: absolute; inset: -20%; pointer-events: none;
  background: repeating-conic-gradient(from 0deg, rgba(61,220,132,0.07) 0 6deg, transparent 6deg 20deg);
  -webkit-mask: radial-gradient(circle, #000 0, transparent 60%);
  mask: radial-gradient(circle, #000 0, transparent 60%);
  animation: spin 24s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes splat { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slam { from { transform: scale(2.6); opacity: 0; filter: blur(8px); } to { transform: none; opacity: 1; filter: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

/* ---------------- Leaderboard ---------------- */
.lb { max-width: 900px; display: flex; flex-direction: column; }
.lb-head { text-align: center; margin-bottom: 14px; }
.lb-title { margin: 0; font-family: var(--f-horror); font-weight: 400; font-size: clamp(38px, 6vw, 64px); color: var(--pumpkin); text-shadow: 0 0 20px var(--pumpkin-glow); }
.lb-sub { margin: 0; color: var(--bone-dim); letter-spacing: .2em; text-transform: uppercase; font-size: 13px; font-family: var(--f-ui); }
.lb-table-wrap { border-radius: var(--radius); background: var(--panel); border: 2px solid rgba(234,223,200,0.18); flex: 1 1 auto; min-height: 120px; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.lb-table { width: 100%; border-collapse: collapse; }
.lb-table th { position: sticky; top: 0; z-index: 1; background: #1e0c10; text-align: left; font-family: var(--f-ui); letter-spacing: .18em; text-transform: uppercase; font-size: 13px; color: var(--bone-dim); padding: 12px 16px; }
.lb-table td { padding: 12px 16px; border-top: 1px solid rgba(234,223,200,0.08); font-size: 18px; }
.lb-table td:first-child { width: 64px; font-family: var(--f-ui); font-weight: 700; color: var(--bone-dim); }
.lb-table td:nth-child(2) { word-break: break-word; }
.lb-table td:nth-child(3) { font-family: var(--f-ui); font-variant-numeric: tabular-nums; font-weight: 700; color: #fff; white-space: nowrap; }
.lb-table tbody tr { animation: rowIn .45s cubic-bezier(.2,.8,.2,1) both; animation-delay: calc(min(var(--r, 0), 15) * 0.04s); }
@keyframes rowIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.lb-table tr.r1 td:first-child { color: #ffd166; }
.lb-table tr.r2 td:first-child { color: #d8d8e0; }
.lb-table tr.r3 td:first-child { color: #e0915a; }
.lb-table tr.r1 td { font-size: 21px; background: rgba(255,209,102,0.06); }
.lb-table tr.me td { background: rgba(255,117,24,0.16); }
.lb-table tr.me td:nth-child(2)::after { content: " ← you"; color: var(--pumpkin); font-size: 14px; }
.medal { margin-right: 4px; }
.admin-col { display: none; }
.lb.admin .admin-col { display: table-cell; }
.lb.admin .lb-table td.admin-col { white-space: nowrap; text-align: right; }
.lb.admin .lb-table td.admin-col .btn { margin-left: 6px; }
.lb-empty { text-align: center; padding: 28px 16px; color: var(--bone-dim); margin: 0; }
.lb-status { text-align: center; font-size: 12px; color: var(--bone-dim); margin: 0; padding: 0 12px; min-height: 0; }
.lb-status:not(:empty) { padding: 8px 12px; }
.lb-actions { display: flex; gap: 12px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.admin-bar { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; padding: 10px; border-radius: var(--radius); border: 1px dashed var(--blood); background: rgba(106,4,15,0.2); }
.admin-badge { font-family: var(--f-ui); letter-spacing: .14em; color: var(--blood); text-transform: uppercase; font-weight: 700; }

/* ---------------- Modal ---------------- */
.modal { position: fixed; inset: 0; z-index: 80; display: flex; padding: 16px; overflow-y: auto; overscroll-behavior: contain; background: rgba(0,0,0,0.78); animation: fadeIn .2s both; }
.modal-card {
  width: min(460px, 100%); margin: auto; border-radius: 18px; padding: clamp(16px, 4vw, 24px); background: linear-gradient(180deg, #1f0c10, #110608);
  border: 2px solid var(--blood); box-shadow: 0 0 50px var(--blood-glow);
  animation: modalIn .28s cubic-bezier(.2,1.3,.4,1) both;
}
@keyframes modalIn { from { transform: scale(.88); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-card h3 { margin: 0 0 8px; font-family: var(--f-horror); font-weight: 400; font-size: 34px; color: var(--blood); }
.modal-card p { margin: 0 0 14px; line-height: 1.45; }
.modal-fields { display: flex; flex-direction: column; gap: 10px; }
.modal-fields label { font-family: var(--f-ui); font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--bone-dim); }
.modal-fields input { width: 100%; height: 50px; padding: 0 14px; font-size: 18px; border-radius: 10px; border: 2px solid rgba(234,223,200,0.25); background: rgba(0,0,0,0.5); color: var(--bone); outline: none; }
.modal-fields input:focus { border-color: var(--pumpkin); }
.modal-error { color: #ff6b6b; min-height: 1.2em; margin: 8px 0 0 !important; font-size: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; }
.modal-actions .btn { height: 50px; font-size: 16px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 90; transform: translate(-50%, 30px); opacity: 0;
  background: #1e0c10; border: 1px solid var(--pumpkin); color: var(--bone); padding: 12px 18px; border-radius: 12px;
  transition: transform .3s, opacity .3s; pointer-events: none; max-width: 90vw; text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------------- Running state ---------------- */
body.running .title { animation-duration: 3s; }
body.running .case-file { border-color: rgba(193,18,31,0.45); }

/* =========================================================
   PHONE PORTRAIT — single column: timer, team, code, keypad, clues
   ========================================================= */
@media (max-width: 680px) {
  .screen { height: auto; min-height: 100dvh; }
  .brand { padding-top: 6px; }
  .kicker { font-size: 9px; letter-spacing: .22em; }
  .title { font-size: clamp(28px, 9vw, 40px); }
  .title::after { display: none; }
  .moon { width: 18vmin; height: 18vmin; top: 4vh; right: 4vw; }

  .game { display: flex; flex-direction: column; gap: 12px; }
  .left, .case-file { display: contents; }
  .timer-box {
    order: 0; position: sticky; top: max(6px, env(safe-area-inset-top)); z-index: 5;
    padding: 8px 14px 10px; border-radius: var(--radius); align-items: center;
    background: linear-gradient(180deg, #3a0810, #1a080b); border: 2px solid rgba(193,18,31,0.45);
    box-shadow: 0 8px 24px rgba(0,0,0,0.7); overflow: hidden;
  }
  .timer-label { font-size: 26px; }
  .timer { font-size: 44px; margin-left: auto; }
  .team-row { order: 1; }
  .team-label { font-size: 26px; }
  .team-input, .team-row .btn-start { height: 52px; }
  .team-input { font-size: 18px; }
  .team-row .btn-start { font-size: 17px; padding: 0 14px; }
  .code-wrap { order: 2; padding: 10px 12px 8px; }
  .code-display { min-height: 54px; }
  .slot { height: 52px; font-size: 36px; }
  .numpad { order: 3; flex: none; min-height: 0; max-height: none; grid-auto-rows: clamp(56px, 8.6dvh, 78px); }
  .clues { order: 4; overflow: visible; border-radius: var(--radius); background: var(--panel); border: 2px solid rgba(234,223,200,0.18); }

  .lb-table th, .lb-table td { padding: 10px 10px; }
  .lb-table td { font-size: 16px; }
  .lb-table td:first-child { width: 44px; }
  .lb-table tr.r1 td { font-size: 17px; }
  .lb.admin .lb-table td.admin-col .btn { display: block; width: 100%; margin: 3px 0; height: 34px; }
  .lb-actions .btn { flex: 1; }
  .modal-actions .btn { flex: 1; padding: 0 10px; }
}

/* =========================================================
   SHORT LANDSCAPE (phones sideways) — compact everything
   ========================================================= */
@media (max-height: 540px) and (orientation: landscape) {
  .screen { min-height: 0; }
  .brand, .moon, .chalk { display: none; }
  .tape { font-size: 10px; padding: 3px 0; }
  .view { padding: 8px 14px 8px; }
  .game { gap: 14px; }
  .left { gap: 8px; }
  .team-label { font-size: 24px; }
  .team-input, .btn, .team-row .btn-start { height: 42px; font-size: 16px; }
  .code-wrap { padding: 4px 10px 4px; }
  .code-display { min-height: 40px; }
  .slot { height: 38px; font-size: 26px; border-bottom-width: 3px; }
  .code-hint { font-size: 11px; margin-top: 2px; }
  .numpad { min-height: 0; gap: 6px; }
  .key { font-size: 22px; box-shadow: 0 3px 0 #050203, 0 4px 10px rgba(0,0,0,0.5); }
  .key:active, .key.pressed { transform: translateY(2px); }
  .timer-box { padding: 6px 14px 8px; gap: 10px; }
  .timer-label { font-size: 24px; }
  .timer { font-size: 38px; }
  .clue { padding: 8px 14px 8px 18px; }
  .clue h3 { font-size: 15px; margin: 4px 0 2px; }
  .clue p { font-size: 13px; }
  .lb-head { margin-bottom: 6px; }
  .lb-title { font-size: 30px; }
  .lb-actions { margin-top: 8px; }
  .result-inner .btn { height: 46px; }
}

/* =========================================================
   TABLET PORTRAIT — two columns, bigger code display
   ========================================================= */
@media (min-width: 681px) and (orientation: portrait) {
  .slot { height: 76px; font-size: 52px; }
  .code-display { min-height: 80px; }
  .team-label { font-size: 32px; }
}

/* ---------------- Reduced motion / low power ---------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .bat, .fog { display: none; }
}
