:root {
  --bg: #0b0d12;
  --panel: #14181f;
  --line: #2a3242;
  --accent: #ff8a1f;
  --accent2: #ffd166;
  --green: #6ee7a8;
  --red: #ff5d5d;
  --text: #d7dde8;
  --dim: #8b95a7;
}

* { box-sizing: border-box; }

/* 手机上长按不要选中文字/弹菜单；输入框仍可正常选中 */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
/* 画布长按会弹「保存图片/复制链接」，一起关掉 */
.canvas-wrap, .canvas-wrap canvas, .hud, .hud * {
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -10%, #1a2233 0%, #0b0d12 55%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 3px);
  color: var(--text);
  font-family: "Consolas", "Courier New", ui-monospace, monospace;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 18px 14px 40vh;
}

.wrap { width: 100%; max-width: 980px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.logo {
  font-size: 20px;
  letter-spacing: 2px;
  font-weight: 700;
  color: var(--accent2);
  text-shadow: 0 0 12px rgba(255, 138, 31, .35);
}
.logo span { color: var(--accent); margin-left: 8px; }
.logo em {
  font-style: normal;
  font-size: 12px;
  color: var(--dim);
  margin-left: 10px;
  letter-spacing: 1px;
}

.status {
  font-size: 12px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--dim);
}
.status.ok { color: var(--green); border-color: rgba(110, 231, 168, .35); }
.status.bad { color: var(--red); border-color: rgba(255, 93, 93, .4); }

.screen { display: none; }
.screen.active { display: block; }

.panel {
  background: linear-gradient(180deg, #161b24, #10141a);
  border: 1px solid var(--line);
  box-shadow: 0 0 0 1px #0a0c10, 0 18px 50px rgba(0, 0, 0, .6);
  padding: 26px 24px;
  border-radius: 4px;
  position: relative;
}
.panel::before, .panel::after {
  content: "";
  position: absolute;
  width: 10px; height: 10px;
  border: 2px solid var(--accent);
  opacity: .55;
}
.panel::before { top: 6px; left: 6px; border-right: 0; border-bottom: 0; }
.panel::after { bottom: 6px; right: 6px; border-left: 0; border-top: 0; }

h1 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: 1px;
  color: #fff;
}
.sub { margin: 0 0 22px; font-size: 12px; color: var(--dim); letter-spacing: .5px; }

.field { margin-bottom: 18px; }
.field label { display: block; font-size: 12px; color: var(--dim); margin-bottom: 6px; }

input {
  width: 100%;
  background: #0a0d12;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 13px;
  font-family: inherit;
  font-size: 14px;
  border-radius: 3px;
  outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 138, 31, .15); }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.mode-btn {
  text-align: left;
  background: #0d1117;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 13px 14px;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  transition: .15s;
}
.mode-btn b { display: block; font-size: 14px; margin-bottom: 3px; }
.mode-btn small { color: var(--dim); font-size: 11px; }
.mode-btn:hover { border-color: #3c4658; }
.mode-btn.active { border-color: var(--accent); background: #1d1409; }
.mode-btn.active b { color: var(--accent2); }

button { font-family: inherit; cursor: pointer; }

.primary {
  width: 100%;
  padding: 13px;
  font-size: 15px;
  letter-spacing: 2px;
  color: #170d02;
  background: linear-gradient(180deg, #ffb256, #ff8a1f);
  border: 0;
  border-radius: 3px;
  font-weight: 700;
  box-shadow: 0 4px 0 #a54f04, 0 12px 24px rgba(255, 138, 31, .2);
  transition: .1s;
}
.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #a54f04; }
.primary:disabled { filter: grayscale(.7) brightness(.7); cursor: not-allowed; box-shadow: none; }

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  padding: 12px;
  border-radius: 3px;
  font-size: 13px;
}
.ghost:hover { color: var(--text); border-color: #46536b; }

.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0 14px;
  color: var(--dim); font-size: 11px;
}
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }

.join-row { display: flex; gap: 10px; }
.join-row input { text-transform: uppercase; letter-spacing: 6px; font-size: 18px; text-align: center; }
.join-row button {
  background: #1a1f29;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0 24px;
  border-radius: 3px;
  font-size: 14px;
  white-space: nowrap;
}
.join-row button:hover { border-color: var(--accent); color: var(--accent2); }

.tips { margin: 18px 0 0; font-size: 11px; line-height: 1.8; color: #6c7587; }

/* 大厅 */
.room-code {
  display: flex; align-items: center; gap: 12px;
  padding: 14px;
  background: #0a0d12;
  border: 1px dashed var(--line);
  border-radius: 3px;
  font-size: 12px; color: var(--dim);
}
.room-code strong {
  font-size: 30px; letter-spacing: 8px; color: var(--accent2);
  text-shadow: 0 0 14px rgba(255, 209, 102, .3);
}
.mini {
  margin-left: auto;
  background: #1a1f29; border: 1px solid var(--line); color: var(--text);
  font-size: 11px; padding: 6px 10px; border-radius: 3px;
}
.mini:hover { border-color: var(--accent); }

.players { margin: 20px 0; display: grid; gap: 8px; }
.player-slot {
  display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--line); background: #0d1117;
  padding: 12px 14px; border-radius: 3px; font-size: 13px;
}
.player-slot.me { border-color: rgba(255,138,31,.5); }
.player-slot .tag { font-size: 10px; color: var(--dim); border: 1px solid var(--line); padding: 2px 6px; border-radius: 2px; margin-left: 8px; }
.player-slot .empty { color: #55606f; }

.actions { display: grid; gap: 10px; }

/* 游戏 */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 760px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .hud { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
}

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: min(100%, 74vh);
  margin: 0 auto;
  background: #08090c;
  border: 2px solid #2b3446;
  border-radius: 3px;
  box-shadow: 0 0 0 6px #0d1117, 0 0 40px rgba(0,0,0,.8), inset 0 0 40px rgba(0,0,0,.6);
  overflow: hidden;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.scan {
  position: absolute; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.35) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
  opacity: .55;
}

.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  background: rgba(6, 8, 12, .88);
  backdrop-filter: blur(2px);
  text-align: center;
  padding: 20px;
}
.overlay.hidden { display: none; }
.overlay h2 { margin: 0; font-size: 26px; letter-spacing: 4px; color: var(--accent2); }
.overlay p { margin: 0; font-size: 12px; color: var(--dim); line-height: 1.7; }
.ov-actions { display: flex; gap: 10px; width: 100%; max-width: 300px; margin-top: 8px; }
.ov-actions .primary { flex: 1; padding: 11px; font-size: 13px; letter-spacing: 1px; }
.ov-actions .ghost { flex: 1; }

.hud { display: grid; gap: 8px; font-size: 12px; }
.hud-row {
  display: flex; justify-content: space-between; align-items: center;
  border: 1px solid var(--line); background: #0d1117;
  padding: 9px 11px; border-radius: 3px;
}
.hud-row span { color: var(--dim); }
.hud-row b { color: var(--text); font-weight: 600; }
.hud-row.goal b { color: var(--green); }

.player-card {
  border: 1px solid var(--line);
  background: #0d1117;
  padding: 10px 11px;
  border-radius: 3px;
}
.player-card.p1 { border-left: 3px solid #e8d24a; }
.player-card.p2 { border-left: 3px solid #5ab04a; }
.player-card.hidden { display: none; }
.p-name { font-size: 12px; color: #fff; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-lives { font-size: 12px; letter-spacing: 2px; color: var(--accent2); }
.p-kills { font-size: 10px; color: var(--dim); margin-top: 3px; }

/* 触屏 */
.touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .touch {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 14px; padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    position: sticky; bottom: 0; z-index: 10;
    background: linear-gradient(to top, rgba(11,13,18,.98) 55%, rgba(11,13,18,.72));
  }
  /* 手机上让棋盘和按键在一屏内：画布限制高度，HUD 压缩成两栏 */
  .canvas-wrap { max-height: 46vh; width: auto; max-width: 100%; margin: 0 auto; }
  .hud { font-size: 11px; }
  .hud-row { padding: 6px 9px; }
  .player-card { padding: 8px 9px; }
  .dpad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); }
  .fire { width: 84px; height: 84px; font-size: 13px; }
}
/* 手机长按不要弹「复制/选择」菜单，也不要触发滚动与缩放手势 */
.touch, .touch * {
  -webkit-user-select: none; -moz-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  -webkit-user-drag: none;
}
.dpad { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); gap: 4px; }
.dpad button {
  background: #161b24; border: 1px solid var(--line); color: var(--text);
  border-radius: 4px; font-size: 18px; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; touch-action: none;
}
.dpad button:active { background: #262e3d; }
.up { grid-area: 1 / 2; } .left { grid-area: 2 / 1; } .right { grid-area: 2 / 3; } .down { grid-area: 3 / 2; }
.fire {
  width: 96px; height: 96px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #ffb256, #e06b0c);
  border: 0; color: #1b0d00; font-weight: 800; letter-spacing: 2px;
  box-shadow: 0 6px 0 #94440a, 0 0 30px rgba(255, 138, 31, .25);
  -webkit-touch-callout: none; touch-action: none; user-select: none; -webkit-user-select: none;
}
.fire:active { transform: translateY(4px); box-shadow: 0 2px 0 #94440a; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: #1a202b; border: 1px solid var(--line); color: var(--text);
  padding: 11px 18px; border-radius: 3px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 99;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 480px) {
  body { padding: 12px 10px 24px; }
  .join-row button { padding: 0 18px; }
  .panel { padding: 20px 16px; }
  h1 { font-size: 18px; }
}
