:root {
  --teacher: #6fdc8c;
  --student: #4aa3ff;
  --leader: #ff5a4f;
  --thug: #ffb347;
  --parent: #e8916a;
  --ink: #f4f6f8;
  --muted: #a8b3bf;
  --panel: rgba(14, 18, 24, .78);
  --line: rgba(255, 255, 255, .12);
  --vvw: 100vw;
  --vvh: 100vh;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; overflow: hidden; background: #0b0e12; color: var(--ink);
  width: var(--vvw); height: var(--vvh);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
canvas#c { position: fixed; left: 0; top: 0; display: block; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#topbar {
  position: absolute; top: calc(env(safe-area-inset-top) + 12px); left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; align-items: stretch;
}
.score, #timer {
  display: flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(8px);
  font-size: 14px; font-weight: 600;
}
.score i { width: 10px; height: 10px; border-radius: 50%; background: var(--fc); box-shadow: 0 0 10px var(--fc); }
.score .n { color: var(--muted); }
.score b { font-size: 18px; font-variant-numeric: tabular-nums; min-width: 22px; text-align: right; }
.score.me { border-color: var(--fc); }
.score[data-f="teacher"] { --fc: var(--teacher); }
.score[data-f="student"] { --fc: var(--student); }
.score[data-f="leader"] { --fc: var(--leader); }
.score[data-f="thug"] { --fc: var(--thug); }
.score[data-f="parent"] { --fc: var(--parent); }
#timer { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; order: 0; }
#topbar .score[data-f="teacher"] { order: -1; }
#goal {
  position: absolute; top: calc(env(safe-area-inset-top) + 58px); left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--muted); text-shadow: 0 1px 4px rgba(0, 0, 0, .8);
}
#minimap {
  position: absolute; left: calc(env(safe-area-inset-left) + 14px); top: calc(env(safe-area-inset-top) + 14px);
  width: 170px; height: 170px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(10, 14, 18, .7);
}
#feed {
  position: absolute; right: calc(env(safe-area-inset-right) + 14px); top: calc(env(safe-area-inset-top) + 14px);
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end; max-width: 46vw;
}
.kf {
  padding: 5px 10px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);
  font-size: 13px; white-space: nowrap; animation: kfIn .2s ease-out;
}
.kf .a { font-weight: 700; }
.kf .w { color: var(--muted); margin: 0 6px; }
.kf.mine { border-color: rgba(255, 220, 120, .6); }
.kf.expel .w { color: #ff8a80; font-weight: 700; }
@keyframes kfIn { from { opacity: 0; transform: translateX(12px); } }

#cross {
  position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%);
}
#cross::before, #cross::after {
  content: ""; position: absolute; background: rgba(255, 255, 255, .92);
  box-shadow: 0 0 2px rgba(0, 0, 0, .8);
}
#cross::before { left: 10px; top: 2px; width: 2px; height: 18px; clip-path: polygon(0 0, 100% 0, 100% 33%, 0 33%, 0 67%, 100% 67%, 100% 100%, 0 100%); }
#cross::after { top: 10px; left: 2px; height: 2px; width: 18px; clip-path: polygon(0 0, 33% 0, 33% 100%, 0 100%, 0 0, 67% 0, 100% 0, 100% 100%, 67% 100%); }
#hitmark {
  position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; transform: translate(-50%, -50%) rotate(45deg);
  opacity: 0; transition: opacity .12s;
}
#hitmark::before, #hitmark::after { content: ""; position: absolute; background: #fff; }
#hitmark::before { left: 14px; top: 0; width: 2px; height: 30px; clip-path: polygon(0 0, 100% 0, 100% 30%, 0 30%, 0 70%, 100% 70%, 100% 100%, 0 100%); }
#hitmark::after { top: 14px; left: 0; height: 2px; width: 30px; clip-path: polygon(0 0, 30% 0, 30% 100%, 0 100%, 0 0, 70% 0, 100% 0, 100% 100%, 70% 100%); }
#hitmark.on { opacity: 1; }
#hitmark.kill::before, #hitmark.kill::after { background: #ff5a4f; }
#status {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 132px); transform: translateX(-50%);
  display: flex; gap: 8px;
}
#status span { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--panel); border: 1px solid var(--line); }
#dmgFlash {
  position: absolute; inset: 0; opacity: 0; transition: opacity .25s;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(200, 30, 20, .55) 100%);
}

#bottom {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#who { font-size: 13px; color: var(--muted); display: flex; gap: 8px; }
#whoFaction { font-weight: 700; color: var(--fc, #fff); }
#hpWrap {
  position: relative; width: 300px; height: 14px; border-radius: 999px; overflow: hidden;
  background: rgba(0, 0, 0, .55); border: 1px solid var(--line);
}
#hpFill { position: absolute; inset: 0; transform-origin: left; background: linear-gradient(90deg, #4fd27a, #8ef0a6); transition: transform .15s; }
#hpFill.low { background: linear-gradient(90deg, #e0483b, #ff8a6a); }
#hpText { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; text-shadow: 0 1px 2px #000; }
#weapons { display: flex; gap: 6px; pointer-events: auto; }
.wslot {
  position: relative; width: 74px; padding: 7px 6px 6px; border-radius: 10px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); text-align: center; cursor: pointer;
}
.wslot .k { position: absolute; left: 6px; top: 4px; font-size: 10px; color: var(--muted); }
.wslot .sw { width: 22px; height: 6px; margin: 6px auto 5px; border-radius: 3px; background: var(--wc, #ccc); box-shadow: 0 0 8px var(--wc, transparent); }
.wslot .nm { font-size: 12px; font-weight: 600; white-space: nowrap; }
.wslot .cdm { position: absolute; left: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, .7); }
.wslot .lock {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .6); font-size: 16px; font-weight: 800; color: #ffb4a8; font-variant-numeric: tabular-nums;
}
.wslot.locked .lock { display: flex; }
.fxpop {
  position: absolute; left: 50%; top: calc(50% - 46px); transform: translateX(-50%); font-size: 15px; font-weight: 800;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .9); animation: fxUp .9s ease-out forwards; pointer-events: none;
}
@keyframes fxUp { to { transform: translate(-50%, -22px); opacity: 0; } }
.wslot.on { border-color: rgba(255, 255, 255, .7); background: rgba(40, 48, 60, .9); }

#deathOv {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, .25), rgba(0, 0, 0, .7));
}
#deathOv h2 { margin: 14px 0 6px; font-size: 32px; letter-spacing: .08em; text-shadow: 0 2px 10px rgba(0, 0, 0, .8); }
#deathOv p { margin: 0; color: var(--muted); font-size: 14px; }
#deathOv .spectate-btn {
  margin-top: 18px; width: min(220px, 70vw); height: 48px; font-size: 16px; letter-spacing: .12em;
  background: linear-gradient(135deg, #4aa3ff, #2a6fd4); color: #041018; border: none; cursor: pointer;
  pointer-events: auto; position: relative; z-index: 5;
}
#spectateTag {
  position: absolute; top: 72px; left: 50%; transform: translateX(-50%);
  padding: 8px 14px; border-radius: 999px; font-size: 12px; letter-spacing: .06em;
  background: rgba(10, 16, 24, .72); border: 1px solid rgba(74, 163, 255, .35); color: #cfe6ff;
  pointer-events: none; z-index: 6;
}
.paper {
  width: 210px; height: 280px; background: #fbfaf5; color: #222; border-radius: 3px; padding: 18px 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .55); position: relative; transform: rotate(-4deg);
  animation: paperIn .35s cubic-bezier(.2, 1.4, .4, 1);
}
.paper .ph { text-align: center; color: #c62828; font-weight: 800; font-size: 22px; letter-spacing: .18em; border-bottom: 2px solid #c62828; padding-bottom: 8px; }
.paper .pb { margin-top: 18px; font-size: 13px; line-height: 2; background: repeating-linear-gradient(transparent 0 25px, #ddd 25px 26px); min-height: 120px; }
.paper .stamp {
  position: absolute; right: 18px; bottom: 22px; width: 78px; height: 78px; border-radius: 50%;
  border: 3px solid rgba(210, 30, 30, .85); color: rgba(210, 30, 30, .9); display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; transform: rotate(-16deg);
}
@keyframes paperIn { from { transform: scale(1.6) rotate(8deg); opacity: 0; } }

#board {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(760px, 92vw); padding: 18px; border-radius: 14px; background: rgba(12, 16, 22, .9); border: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px;
}
#board h4 { margin: 0 0 8px; font-size: 14px; display: flex; justify-content: space-between; color: var(--fc); }
#board .row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; border-top: 1px solid var(--line); }
#board .row.me { color: #ffe08a; font-weight: 700; }
#board .row.dead { opacity: .5; }
#board .col[data-f="teacher"] { --fc: var(--teacher); }
#board .col[data-f="student"] { --fc: var(--student); }
#board .col[data-f="leader"] { --fc: var(--leader); }
#board .col[data-f="thug"] { --fc: var(--thug); }
#board .col[data-f="parent"] { --fc: var(--parent); }
#lockHint {
  position: absolute; left: 50%; top: 62%; transform: translateX(-50%); padding: 10px 16px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); font-size: 13px; color: var(--muted); white-space: nowrap;
}

/* ---------- 触屏 ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 8; }
#joy {
  position: absolute; left: calc(env(safe-area-inset-left) + 18px); bottom: calc(env(safe-area-inset-bottom) + 18px);
  width: 148px; height: 148px; border-radius: 50%; background: rgba(255, 255, 255, .1); border: 2px solid rgba(255, 255, 255, .25);
  pointer-events: auto; touch-action: none;
}
#joyKnob { position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px; border-radius: 50%; background: rgba(255, 255, 255, .42); box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.tbtn {
  position: absolute; width: 66px; height: 66px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .14); border: 2px solid rgba(255, 255, 255, .3); color: #fff; font-weight: 700; font-size: 16px;
  pointer-events: auto; touch-action: none; user-select: none;
}
.tbtn.on { background: rgba(255, 255, 255, .35); transform: scale(.96); }
.tbtn.big { width: 92px; height: 92px; font-size: 18px; right: calc(env(safe-area-inset-right) + 22px); bottom: calc(env(safe-area-inset-bottom) + 28px); background: rgba(255, 90, 79, .28); border-color: rgba(255, 140, 120, .6); }
#tJump { right: calc(env(safe-area-inset-right) + 132px); bottom: calc(env(safe-area-inset-bottom) + 22px); }
#tSwap { right: calc(env(safe-area-inset-right) + 34px); bottom: calc(env(safe-area-inset-bottom) + 138px); }
.tbtn.small { width: 46px; height: 46px; font-size: 14px; right: calc(env(safe-area-inset-right) + 12px); top: calc(env(safe-area-inset-top) + 70px); border-radius: 12px; }
#tBoard { right: calc(env(safe-area-inset-right) + 66px); top: calc(env(safe-area-inset-top) + 70px); }
#tSettings { right: calc(env(safe-area-inset-right) + 120px); top: calc(env(safe-area-inset-top) + 70px); }
#layoutEditTip {
  position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + 10px); transform: translateX(-50%);
  padding: 8px 14px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .04em;
  background: rgba(10, 16, 24, .82); border: 1px solid rgba(255, 215, 106, .45); color: #ffe08a;
  pointer-events: none; z-index: 12; white-space: nowrap;
}
body.layout-edit .tctl { outline: 2px dashed rgba(255, 215, 106, .7); outline-offset: 2px; z-index: 11; }
body.layout-edit #layoutEditTip { display: block !important; }

#mobSettings {
  position: fixed; inset: 0; z-index: 55; display: flex; align-items: center; justify-content: center;
  background: rgba(6, 8, 12, .72); backdrop-filter: blur(6px); pointer-events: auto;
}
#mobSettings.hidden { display: none !important; }
.ms-panel {
  width: min(420px, 94vw); max-height: min(88vh, 640px); overflow: auto;
  border-radius: 16px; border: 1px solid var(--line); background: rgba(16, 21, 28, .96); padding: 16px;
  -webkit-overflow-scrolling: touch;
}
.ms-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.ms-head h2 { margin: 0; font-size: 20px; letter-spacing: .08em; }
.ms-x {
  height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; color: var(--ink); font: inherit; cursor: pointer;
}
.ms-body { display: flex; flex-direction: column; gap: 10px; }
.ms-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border-radius: 10px; background: rgba(0,0,0,.28); border: 1px solid var(--line);
  font-size: 14px; color: var(--muted);
}
.ms-row input[type="checkbox"] { width: 22px; height: 22px; }
.ms-row input[type="range"] { flex: 1; max-width: 160px; }
.ms-actions { justify-content: stretch; gap: 8px; }
.ms-actions .ms-btn { flex: 1; }
.ms-label { font-size: 12px; letter-spacing: .12em; color: #9ecbff; font-weight: 800; margin-top: 4px; }
.ms-presets { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.ms-btn {
  min-height: 40px; padding: 8px 10px; border-radius: 10px; border: 1px solid #4a5a70;
  background: #151c26; color: var(--ink); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
}
.ms-btn:hover { border-color: #6a8ab0; }
.ms-btn-gold {
  border-color: #b8943a; color: #1a1206;
  background: linear-gradient(180deg, #ffe08a, #f0b43c);
}
.ms-tip { margin: 4px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
@media (max-width: 420px) {
  .ms-presets { grid-template-columns: 1fr; }
}
#rotateTip {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(6, 8, 12, .78); backdrop-filter: blur(8px); pointer-events: none;
}
#rotateTip .rt-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 22px 26px; border-radius: 16px;
  background: rgba(16, 21, 28, .94); border: 1px solid var(--line); text-align: center; max-width: 80vw;
}
#rotateTip .rt-ico { font-size: 42px; line-height: 1; color: #ffd76a; animation: rtSpin 1.6s ease-in-out infinite; }
#rotateTip b { font-size: 20px; letter-spacing: .08em; }
#rotateTip span { font-size: 13px; color: var(--muted); }
@keyframes rtSpin { 0%, 100% { transform: rotate(-18deg); } 50% { transform: rotate(28deg); } }

body.touch #minimap { width: 108px; height: 108px; opacity: .9; }
body.touch #feed { top: calc(env(safe-area-inset-top) + 56px); max-width: 42vw; }
body.touch #weapons {
  pointer-events: auto; max-width: min(70vw, 420px); overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px;
}
body.touch #weapons::-webkit-scrollbar { display: none; }
body.touch .wslot { width: 56px; min-width: 56px; padding: 6px 4px; flex: 0 0 auto; }
body.touch .wslot .nm { font-size: 10px; }
body.touch .wslot .k { display: none; }
body.touch #hpWrap { width: min(240px, 56vw); height: 12px; }
body.touch #who { font-size: 12px; }
body.touch #bottom {
  bottom: auto; top: calc(env(safe-area-inset-top) + 48px);
  gap: 6px; z-index: 3;
}
body.touch #status { bottom: auto; top: calc(env(safe-area-inset-top) + 118px); }
body.touch #goal {
  display: block; top: auto; bottom: calc(env(safe-area-inset-bottom) + 8px);
  left: 50%; transform: translateX(-50%); max-width: 46vw; text-align: center;
  font-size: 11px; pointer-events: none; z-index: 2;
}
body.touch #topbar {
  flex-wrap: wrap; justify-content: center; gap: 4px; max-width: 92vw;
  top: calc(env(safe-area-inset-top) + 6px);
}
body.touch .score .n { display: none; }
body.touch .score, body.touch #timer { padding: 4px 8px; font-size: 11px; border-radius: 8px; }
body.touch .score b { font-size: 13px; min-width: 16px; }
body.touch #timer { font-size: 14px; }
body.touch #zoneBar { top: calc(env(safe-area-inset-top) + 44px); width: min(280px, 58vw); height: 14px; }
body.touch #floorTag { top: calc(env(safe-area-inset-top) + 150px); font-size: 11px; padding: 4px 8px; }
body.touch #spectateTag { top: calc(env(safe-area-inset-top) + 52px); font-size: 11px; max-width: 86vw; text-align: center; white-space: normal; }
body.touch #lockHint { white-space: normal; max-width: 86vw; text-align: center; font-size: 12px; }
body.touch #cross { transform: translate(-50%, -50%) scale(.85); opacity: .85; }
body.touch.portrait #rotateTip:not(.hidden) { display: flex; }
body.touch:not(.portrait) #rotateTip { display: none !important; }

@media (max-height: 460px), (orientation: landscape) and (max-height: 500px) {
  #topbar { top: 4px; }
  .score, #timer { padding: 3px 7px; font-size: 11px; }
  .score b { font-size: 12px; }
  #joy { width: 118px; height: 118px; left: calc(env(safe-area-inset-left) + 12px); bottom: calc(env(safe-area-inset-bottom) + 10px); }
  #joyKnob { width: 50px; height: 50px; margin: -25px; }
  .tbtn.big { width: 76px; height: 76px; bottom: calc(env(safe-area-inset-bottom) + 14px); right: calc(env(safe-area-inset-right) + 14px); }
  #tJump { right: calc(env(safe-area-inset-right) + 104px); bottom: calc(env(safe-area-inset-bottom) + 12px); width: 54px; height: 54px; }
  #tSwap { right: calc(env(safe-area-inset-right) + 20px); bottom: calc(env(safe-area-inset-bottom) + 104px); width: 54px; height: 54px; }
  .tbtn.small, #tBoard, #tSettings { width: 40px; height: 40px; top: calc(env(safe-area-inset-top) + 52px); font-size: 12px; }
  #tBoard { right: calc(env(safe-area-inset-right) + 58px); }
  #tSettings { right: calc(env(safe-area-inset-right) + 104px); }
  body.touch #minimap { width: 88px; height: 88px; }
  body.touch #bottom { top: calc(env(safe-area-inset-top) + 40px); }
  body.touch #status { top: calc(env(safe-area-inset-top) + 98px); }
  body.touch #goal { display: none; }
}

/* ---------- 菜单 ---------- */
#menu {
  position: fixed; inset: 0; overflow: auto; display: flex;
  background: linear-gradient(90deg, rgba(8, 11, 15, .88) 0%, rgba(8, 11, 15, .55) 55%, rgba(8, 11, 15, .25) 100%);
  touch-action: pan-y;
}
.menu-inner { width: min(1080px, 94vw); padding: 32px 0; margin: auto; }
.m-kicker { font-size: 12px; letter-spacing: .3em; color: var(--muted); }
.m-head h1 { margin: 8px 0 10px; font-size: clamp(40px, 7vw, 76px); letter-spacing: .06em; line-height: 1; font-weight: 800; }
.m-head h1 span { color: #ffd76a; margin-left: 6px; }
.m-head p { margin: 0 0 26px; color: #c9d2db; font-size: 15px; max-width: 560px; }
.modes {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 16px;
}
.modes .mode[data-m="revolt"].sel { border-color: #ff8a5c; box-shadow: 0 0 0 1px #ff8a5c inset; background: rgba(40, 22, 16, .9); }
.mode {
  text-align: left; cursor: pointer; color: var(--ink); font: inherit; padding: 10px 12px; border-radius: 10px;
  background: rgba(16, 21, 28, .72); border: 1px solid var(--line);
}
.mode b { display: block; font-size: 14px; margin-bottom: 3px; }
.mode span { display: block; font-size: 11px; color: var(--muted); line-height: 1.35; }
.mode:hover { border-color: rgba(255, 255, 255, .28); }
.mode.sel { border-color: #ffd76a; box-shadow: 0 0 0 1px #ffd76a inset; background: rgba(36, 32, 18, .88); }
/* ---------- 联机大厅（仿钢铁前线一） ---------- */
.lobby-panel {
  margin: 0 0 18px; padding: 16px 16px 12px; border-radius: 14px;
  border: 1px solid #334056; background: linear-gradient(180deg, rgba(22,30,42,.92), rgba(12,16,24,.92));
}
.lobby-head { text-align: center; margin-bottom: 12px; }
.lobby-title {
  margin: 0 0 6px; font-size: 28px; letter-spacing: .18em; font-weight: 800;
  background: linear-gradient(180deg, #d8ecff, #4aa3ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lobby-tip { color: var(--muted); font-size: 13px; }
.lobby-tip span { color: #8fe66e; font-weight: 700; }
.lobby-room-bar {
  display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px;
  margin-bottom: 12px;
}
.lobby-btn {
  height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid #4a5a70;
  background: #151c26; color: var(--ink); font: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer;
}
.lobby-btn:hover { border-color: #6a8ab0; }
.lobby-btn-gold {
  border-color: #b8943a; color: #1a1206;
  background: linear-gradient(180deg, #ffe08a, #f0b43c);
}
.room-code-input {
  width: min(160px, 42vw); height: 38px; padding: 0 12px; border-radius: 10px;
  border: 1px solid #4a5a70; background: #0f1620; color: #e8eef6;
  font-size: 16px; font-weight: 700; letter-spacing: .18em; outline: none; text-align: center;
  font-variant-numeric: tabular-nums;
}
.room-code-input:focus { border-color: #4aa3ff; }
.room-list-wrap {
  border: 1px solid #2f3d52; border-radius: 12px; padding: 12px 14px; background: rgba(8,12,18,.55);
}
.room-list-title { font-size: 13px; font-weight: 800; letter-spacing: .16em; color: #9ecbff; margin-bottom: 10px; }
.room-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow: auto; }
.friends-empty { color: var(--muted); font-size: 13px; padding: 10px 4px; }
.room-card {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #151c26; border: 1px solid #2f3d52; border-radius: 12px; padding: 12px 14px;
}
.room-card-info { flex: 1; min-width: 140px; }
.room-card-name { font-size: 15px; font-weight: 800; color: #e8eef6; }
.room-card-meta { font-size: 12px; color: #8b98a9; margin-top: 3px; }
.room-card-actions { display: flex; gap: 6px; }
.lobby-note { margin: 10px 0 0; font-size: 12px; color: var(--muted); text-align: center; }

.cw-lobby {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  background: #05070c; color: #d6dde8;
  pointer-events: auto;
}
.cw-lobby.hidden { display: none !important; }
.cw-lobby-bar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #1a2434, #0e141e);
  border-bottom: 2px solid #3a506e;
}
.cw-lobby-title { font-size: clamp(18px, 2.4vw, 24px); font-weight: 900; letter-spacing: .1em; color: #d8ecff; }
.cw-lobby-meta { margin-top: 2px; font-size: 13px; color: #8fb4d8; letter-spacing: .06em; }
.cw-lobby-bar-right { display: flex; gap: 10px; }
.cw-lbtn {
  min-width: 96px; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid #4a5a70; background: linear-gradient(180deg, #243044, #151c28);
  color: #e8eef6; font-size: 14px; font-weight: 800; letter-spacing: .06em; cursor: pointer;
}
.cw-lbtn:hover { filter: brightness(1.08); }
.cw-lbtn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.cw-lbtn-start {
  min-width: 120px; height: 40px; border-color: #b8943a; color: #1a1206;
  background: linear-gradient(180deg, #ffe08a, #f0b43c);
}
.cw-lbtn-sm { min-width: 72px; height: 32px; font-size: 12px; }
.cw-lobby-body {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, .9fr); gap: 0;
}
.cw-col { min-height: 0; min-width: 0; display: flex; flex-direction: column; border-left: 1px solid #1e2a3a; }
.cw-col-players { border-left: none; }
.cw-panel { display: flex; flex-direction: column; min-height: 0; background: #080c12; border-bottom: 1px solid #1e2a3a; }
.cw-panel-head {
  flex: none; padding: 8px 12px;
  background: linear-gradient(180deg, #182232, #0e141e);
  border-bottom: 1px solid #2a3a50;
  color: #9ecbff; font-size: 13px; font-weight: 900; letter-spacing: .16em;
}
.cw-players-panel { flex: 1.4; }
.cw-chat-panel { flex: 1; border-bottom: none; }
.cw-slot-head, .cw-slot {
  display: grid; grid-template-columns: 36px 1.2fr 1fr .8fr; gap: 8px;
  align-items: center; padding: 8px 12px; font-size: 13px;
}
.cw-slot-head { color: #7e8ea3; border-bottom: 1px solid #1e2a3a; font-size: 12px; letter-spacing: .08em; }
.cw-slots { overflow: auto; flex: 1; }
.cw-slot { border-bottom: 1px solid rgba(40,55,75,.55); }
.cw-slot .host { color: #ffd76a; font-weight: 800; }
.cw-slot .me { color: #8fe66e; }
.cw-chat-log {
  flex: 1; overflow: auto; padding: 10px 12px; font-size: 13px; line-height: 1.55; color: #c4cdd6;
}
.cw-chat-log .sys { color: #7e8ea3; }
.cw-chat-log .nm { color: #9ecbff; font-weight: 700; margin-right: 6px; }
.cw-chat-form { flex: none; display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid #1e2a3a; }
.cw-chat-form input {
  flex: 1; height: 34px; border-radius: 8px; border: 1px solid #334056; background: #0f1620;
  color: var(--ink); padding: 0 10px; font: inherit; outline: none;
}
.cw-opts { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.cw-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 13px; color: var(--muted);
}
.cw-opt input, .cw-opt select {
  min-width: 120px; height: 34px; border-radius: 8px; border: 1px solid #334056;
  background: #0f1620; color: var(--ink); padding: 0 8px; font: inherit; font-size: 13px;
}
.cw-opts-tip, .cw-help-list { margin: 0; padding: 0 12px 14px; font-size: 12px; color: var(--muted); line-height: 1.55; }
.cw-help-list { padding-left: 28px; }
@media (max-width: 760px) {
  .cw-lobby-body { grid-template-columns: 1fr; }
  .lobby-title { font-size: 22px; }
  .online-row, .lobby-room-bar { flex-direction: column; align-items: stretch; }
  .room-code-input, .lobby-btn { width: 100%; }
}
#floorTag {
  position: absolute; left: calc(env(safe-area-inset-left) + 14px); top: calc(env(safe-area-inset-top) + 196px);
  padding: 5px 10px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);
  font-size: 12px; font-weight: 700; color: #ffe08a;
}
#zoneBar {
  position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + 86px); transform: translateX(-50%);
  width: min(320px, 70vw); height: 18px; border-radius: 999px; overflow: hidden;
  background: rgba(0, 0, 0, .55); border: 1px solid var(--line);
}
#zoneFill { position: absolute; inset: 0; width: 0; background: linear-gradient(90deg, #4aa3ff, #6fdc8c); }
#zoneText { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; text-shadow: 0 1px 2px #000; }
body.night-mode canvas#c { filter: saturate(.85); }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; justify-content: flex-start;
  text-align: left; cursor: pointer; color: var(--ink); font: inherit; padding: 18px; border-radius: 14px;
  background: rgba(16, 21, 28, .82); border: 1px solid var(--line); backdrop-filter: blur(10px);
  transition: border-color .15s, transform .15s, background .15s;
}
.card:hover { transform: translateY(-2px); border-color: rgba(255, 255, 255, .28); }
.card.sel { border-color: var(--fc); background: rgba(24, 30, 40, .92); box-shadow: 0 0 0 1px var(--fc) inset, 0 14px 40px rgba(0, 0, 0, .35); }
.card.locked { opacity: .28; pointer-events: none; filter: grayscale(.7); }
.card.locked.sel { opacity: .28; }
.card[data-f="teacher"] { --fc: var(--teacher); }
.card[data-f="student"] { --fc: var(--student); }
.card[data-f="leader"] { --fc: var(--leader); }
.card[data-f="thug"] { --fc: var(--thug); }
.card[data-f="parent"] { --fc: var(--parent); }
.card[data-f="random"] { --fc: #c9a0ff; }
.modes .mode[data-m="bio"].sel { border-color: #7dcf4a; box-shadow: 0 0 0 1px #7dcf4a inset; background: rgba(18, 36, 16, .9); }
.c-top { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); letter-spacing: .1em; }
.c-top i { width: 10px; height: 10px; border-radius: 50%; background: var(--fc); box-shadow: 0 0 10px var(--fc); }
.card h3 { margin: 10px 0 6px; font-size: 28px; }
.c-desc { margin: 0 0 12px; color: #c4cdd6; font-size: 13px; line-height: 1.6; min-height: 42px; }
.card ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 5px; }
.card li { font-size: 13px; color: var(--muted); }
.card li b { color: var(--ink); margin-right: 8px; font-weight: 600; }
.card ul { margin-bottom: 14px; }
.c-stat { margin-top: auto; display: flex; gap: 12px; font-size: 12px; color: var(--muted); padding-top: 10px; border-top: 1px solid var(--line); }
.m-opts { display: flex; gap: 12px; margin: 18px 0; flex-wrap: wrap; }
.opt {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px;
  background: rgba(16, 21, 28, .82); border: 1px solid var(--line); font-size: 13px; color: var(--muted);
}
.opt input, .opt select {
  background: rgba(0, 0, 0, .35); color: var(--ink); border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 8px; font: inherit; font-size: 13px; outline: none;
}
.opt input { width: 110px; }
.m-start {
  display: inline-flex; align-items: center; justify-content: center; min-width: 240px; height: 54px; padding: 0 28px;
  border-radius: 12px; border: 0; cursor: pointer; font: inherit; font-size: 18px; font-weight: 800; letter-spacing: .12em;
  color: #1a1206; background: linear-gradient(180deg, #ffe08a, #f0b43c); box-shadow: 0 10px 30px rgba(240, 180, 60, .25);
}
.m-start:disabled { cursor: default; color: #8a8f96; background: #2a3039; box-shadow: none; }
.m-start:not(:disabled):hover { filter: brightness(1.05); }
.m-help { color: var(--muted); font-size: 12px; margin: 14px 0 0; }
.ghost {
  display: inline-flex; align-items: center; justify-content: center; height: 46px; padding: 0 22px; margin-top: 10px;
  border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; font: inherit; font-size: 15px;
}
.ghost:hover { background: rgba(255, 255, 255, .06); }

#pause, #result {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(6, 8, 12, .62);
  backdrop-filter: blur(6px);
}
.panel {
  width: min(520px, 92vw); padding: 26px; border-radius: 16px; background: rgba(16, 21, 28, .94); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: stretch; text-align: center;
}
.panel h2 { margin: 6px 0 18px; font-size: 30px; }
#resBody { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 18px; }
#resBody .rc { padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, .25); }
#resBody .rc b { display: block; font-size: 26px; margin-top: 4px; }
#resBody .rc.win { border-color: #ffd76a; }
#resBody .mvp { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
@media (max-height: 520px) {
  .menu-inner { padding: 14px 0; }
  .m-kicker { display: none; }
  .modes { margin-bottom: 8px; gap: 6px; }
  .mode { padding: 7px 9px; }
  .mode b { font-size: 12px; }
  .mode span { display: none; }
  .m-head h1 { font-size: 34px; margin: 0 0 4px; }
  .m-head p { margin-bottom: 10px; font-size: 13px; }
  .card { padding: 10px 12px; }
  .card h3 { font-size: 20px; margin: 4px 0 2px; }
  .c-desc { font-size: 12px; min-height: 0; margin-bottom: 6px; }
  .card ul { flex-direction: row; flex-wrap: wrap; gap: 2px 10px; margin-bottom: 8px; }
  .card li { font-size: 11px; }
  .card li b { margin-right: 4px; }
  .c-stat { padding-top: 6px; }
  .m-opts { margin: 10px 0; gap: 8px; }
  .opt { padding: 5px 9px; }
  .m-start { height: 44px; font-size: 16px; }
  .m-help { margin-top: 8px; }
}
@media (max-width: 760px) {
  .menu-inner { width: min(100vw - 20px, 720px); padding: 18px 0 calc(18px + env(safe-area-inset-bottom)); }
  .modes { grid-template-columns: 1fr 1fr; }
  .cards { grid-template-columns: 1fr 1fr; }
  .c-desc { min-height: 0; }
  .card { padding: 14px; min-height: 44px; }
  .card h3 { font-size: 22px; }
  .card ul { flex-direction: row; flex-wrap: wrap; gap: 4px 12px; }
  .m-start { width: 100%; min-height: 48px; }
  .ghost { min-height: 44px; width: 100%; }
  .online-row { flex-direction: column; align-items: stretch; }
  .online-row input { width: 100%; height: 44px; }
  .online-row .ghost { width: 100%; }
  .m-opts { flex-direction: column; align-items: stretch; }
  .opt { justify-content: space-between; min-height: 44px; }
  .opt input, .opt select { min-height: 36px; font-size: 16px; }
  #board { grid-template-columns: 1fr; max-height: 80vh; overflow: auto; }
  .panel { width: min(520px, 94vw); padding: 20px 16px; }
  .panel h2 { font-size: 24px; }
}
@media (max-width: 420px) {
  .modes { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  .m-head h1 { font-size: 36px; }
  .m-head p { font-size: 13px; }
}
