:root {
  --bg: #070d18;
  --bg2: #0b1424;
  --panel: #0f1a2b;
  --panel2: #16233a;
  --line: #22334e;
  --cell-bg: #16233a;
  --text: #e2e8f0;
  --muted: #8ea0bd;
  --accent: #22d3ee;
  --accent-dim: #0e7490;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --dead: #dc2626;
  --dead-dark: #7f1d1d;
  --cell: 30px;
  --gap: 2px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #10233d 0%, var(--bg) 60%);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  min-height: 100%;
}

#app { max-width: 900px; margin: 0 auto; padding: 16px 14px 40px; }

.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg2) 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
}

/* ---------------- 首页 ---------------- */
.logo {
  margin: 4px 0 6px;
  font-size: 30px;
  letter-spacing: 6px;
  text-align: center;
  background: linear-gradient(90deg, #22d3ee, #60a5fa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { margin: 0 0 18px; text-align: center; color: var(--muted); font-size: 13px; }

.rule-card {
  display: flex; gap: 14px; align-items: center;
  background: rgba(34, 211, 238, .06);
  border: 1px solid rgba(34, 211, 238, .18);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 18px;
}
.rule-shape { display: grid; grid-template-columns: repeat(5, 14px); grid-template-rows: repeat(4, 14px); gap: 2px; flex-shrink: 0; }
.rule-shape i { border-radius: 2px; background: var(--panel2); }
.rule-shape i.on { background: var(--accent-dim); }
.rule-shape i.head { background: var(--accent); }
.rule-text { font-size: 12.5px; line-height: 1.9; color: var(--muted); }
.rule-text b { color: var(--text); font-weight: 600; }
.rule-text em { font-style: normal; }
.rule-text .bad { color: var(--bad); }
.rule-text .warn { color: var(--warn); }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
input {
  width: 100%; padding: 11px 13px; font-size: 15px;
  background: #0a1424; color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; outline: none;
  font-family: inherit;
}
input:focus { border-color: var(--accent); }
#inpRoom { text-transform: uppercase; letter-spacing: 3px; text-align: center; font-weight: 700; }

.home-actions { display: flex; flex-direction: column; gap: 12px; }
.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; }

.btn {
  padding: 10px 16px; font-size: 14px; font-family: inherit; font-weight: 600;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; cursor: pointer;
  transition: transform .08s ease, background .15s ease, opacity .15s;
}
.btn:hover:not(:disabled) { background: #1d2c46; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #06b6d4, #0891b2); border-color: transparent; color: #04222b; }
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #22d3ee, #06b6d4); }
.btn.danger { background: rgba(220, 38, 38, .16); border-color: rgba(220, 38, 38, .4); color: #fca5a5; }
.btn.danger:hover:not(:disabled) { background: rgba(220, 38, 38, .28); }
.btn.ghost { background: transparent; }
.btn.big { padding: 13px 18px; font-size: 15px; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.full { width: 100%; margin-top: 14px; }

.msg { min-height: 20px; margin-top: 10px; text-align: center; font-size: 13px; color: var(--bad); }
.msg.ok { color: var(--ok); }

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13px;
}
.room-tag { color: var(--muted); }
.room-tag b { color: var(--accent); letter-spacing: 2px; }
.opp-tag { color: var(--muted); }
.turn-tag { font-weight: 700; }
.turn-tag.mine { color: var(--ok); }
.turn-tag.theirs { color: var(--warn); }
.timer-tag { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 40px; text-align: right; }
.timer-tag.urgent { color: var(--bad); font-weight: 700; }

/* ---------------- 棋盘 ---------------- */
.board-wrap { display: flex; justify-content: center; margin: 8px 0 14px; }
.board {
  display: grid;
  grid-template-columns: 18px repeat(10, var(--cell));
  grid-template-rows: 18px repeat(10, var(--cell));
  gap: var(--gap);
  touch-action: none;
  user-select: none;
}
#deployBoard { cursor: pointer; }
.enemy-board { cursor: crosshair; }

.cell {
  background: var(--cell-bg);
  border: 1px solid #1e2e48;
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: var(--muted);
  position: relative;
}
.cell.axis { background: transparent; border: none; font-size: 9px; color: #5b7196; }

/* 我方飞机（布防 / 我方视角） */
.cell.plane { background: #155e75; border-color: #22d3ee55; }
.cell.head { background: var(--accent); border-color: #a5f3fc; }
.cell.head::after { content: "▲"; font-size: 8px; color: #083344; }

/* 落点状态 */
.cell.miss::after { content: "·"; font-size: 18px; color: #7f93b3; line-height: 0; }
.cell.hit { background: var(--warn); border-color: #fde68a; }
.cell.hit::after { content: "✦"; font-size: 10px; color: #422006; }
.cell.dead { background: var(--dead); border-color: #fca5a5; }
.cell.dead::after { content: "✸"; font-size: 11px; color: #450a0a; }
.cell.sunk-plane { background: var(--dead-dark); border-color: #b91c1c; }
.cell.sunk-plane::after { content: ""; }

/* 我方被击中的飞机格 */
.cell.plane.hit { background: #b45309; border-color: #fcd34d; }
.cell.plane.dead, .cell.head.dead { background: var(--dead); }

/* 选中 & 拖拽预览 */
.cell.sel { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 2; }
.cell.ghost-ok { background: rgba(34, 211, 238, .35); border-color: var(--accent); }
.cell.ghost-bad { background: rgba(220, 38, 38, .35); border-color: var(--bad); }

/* 开火反馈动画 */
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
.cell.just-fired { animation: pop .35s ease; }

/* ---------------- 布防页 ---------------- */
.sec-title { margin: 0 0 6px; font-size: 17px; text-align: center; }
.hint { margin: 0 0 14px; text-align: center; font-size: 12px; color: var(--muted); }
.hint kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 11px; }
.toolbar { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.toolbar .btn { flex: 1 1 auto; min-width: 84px; }

.plane-status { display: flex; gap: 8px; justify-content: center; margin: 14px 0 0; }
.plane-chip {
  font-size: 12px; padding: 5px 12px; border-radius: 20px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
}
.plane-chip.on { background: rgba(34, 211, 238, .15); border-color: var(--accent); color: var(--accent); }

/* ---------------- 对战页 ---------------- */
.score-row { display: flex; gap: 12px; margin-bottom: 14px; }
.score-card {
  flex: 1; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; text-align: center;
}
.score-label { font-size: 11px; color: var(--muted); }
.score-val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.score-card.me .score-val { color: #fca5a5; }
.score-card.op .score-val { color: var(--ok); }
.score-sub { font-size: 11px; color: var(--muted); }

.boards { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.board-block { flex: 1 1 320px; max-width: 400px; }
.board-title { text-align: center; font-size: 13px; margin-bottom: 8px; color: var(--text); font-weight: 600; }
.board-sub { color: var(--muted); font-weight: 400; font-size: 11px; }
.board-block .board { margin: 0 auto; }

.battle-tools { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

.log {
  margin-top: 16px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; max-height: 150px; overflow-y: auto;
  font-size: 12.5px; line-height: 1.9; color: var(--muted);
}
.log div:first-child { color: var(--text); }
.log .l-hit { color: var(--warn); }
.log .l-dead { color: var(--bad); font-weight: 600; }
.log .l-miss { color: #6b80a3; }
.log .coord { font-family: ui-monospace, monospace; color: var(--accent); }

/* ---------------- 结算页 ---------------- */
.result-banner {
  text-align: center; font-size: 38px; font-weight: 800; letter-spacing: 6px; margin: 6px 0 4px;
}
.result-banner.win { color: var(--ok); text-shadow: 0 0 24px rgba(52, 211, 153, .35); }
.result-banner.lose { color: var(--bad); text-shadow: 0 0 24px rgba(248, 113, 113, .3); }
.result-reason { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.over-actions { display: flex; gap: 12px; margin-top: 18px; }
.over-actions .btn { flex: 1; }

/* ---------------- 回放 ---------------- */
.modal {
  position: fixed; inset: 0; background: rgba(3, 7, 15, .88);
  display: none; align-items: center; justify-content: center; padding: 16px; z-index: 50;
  overflow-y: auto;
}
.modal.open { display: flex; }
.modal-body {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; width: 100%; max-width: 860px;
}
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; font-weight: 600; }
.replay-progress { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.replay-controls { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.replay-caption { text-align: center; margin-top: 10px; font-size: 13px; color: var(--muted); min-height: 20px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(20px);
  background: #1e293b; border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 8px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 100;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { border-color: var(--bad); color: #fecaca; }
.toast.good { border-color: var(--ok); color: #bbf7d0; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 780px) {
  :root { --cell: 27px; }
  .boards { flex-direction: column; align-items: center; }
  .board-block { max-width: 100%; width: 100%; }
}
@media (max-width: 420px) {
  :root { --cell: 25px; --gap: 2px; }
  #app { padding: 12px 10px 30px; }
  .logo { font-size: 24px; letter-spacing: 4px; }
}
@media (max-width: 360px) {
  :root { --cell: 22px; }
}

/* ---------------- 提示横幅 ---------------- */
.notice-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  padding: 11px 16px 12px; text-align: center;
  font-size: 15px; font-weight: 700; letter-spacing: .5px;
  color: #04222b; background: linear-gradient(90deg, #22d3ee, #67e8f9);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
  transform: translateY(-100%);
  transition: transform .32s cubic-bezier(.2, .9, .3, 1.3);
  pointer-events: none;
}
.notice-banner.show { transform: translateY(0); }
.notice-banner.join  { background: linear-gradient(90deg, #60a5fa, #93c5fd); }
.notice-banner.ready { background: linear-gradient(90deg, #fbbf24, #fde68a); }
.notice-banner.start { background: linear-gradient(90deg, #34d399, #6ee7b7); }
.notice-banner.kill  { background: linear-gradient(90deg, #f87171, #fca5a5); color: #450a0a; }
.notice-banner small { display: block; font-size: 11.5px; font-weight: 500; opacity: .82; margin-top: 2px; }

/* ---------------- 轮到你：棋盘发光脉冲 ---------------- */
@keyframes boardPulse {
  0%, 100% { box-shadow: 0 0 0 1px var(--accent), 0 0 10px rgba(34, 211, 238, .22); }
  50%      { box-shadow: 0 0 0 3px var(--accent), 0 0 30px rgba(34, 211, 238, .55); }
}
.board.turn-active {
  border-radius: 6px;
  animation: boardPulse 1.5s ease-in-out infinite;
}
@keyframes tagPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .5; }
}
.turn-tag.mine { animation: tagPulse 1.5s ease-in-out infinite; }
@keyframes timerPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.16); }
}
.timer-tag.urgent { animation: timerPulse .8s ease-in-out infinite; }

/* ---------------- 音效开关 ---------------- */
.sound-fab {
  position: fixed; top: 12px; right: 12px; z-index: 70;
  width: 38px; height: 38px; border-radius: 50%; padding: 0;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, transform .1s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}
.sound-fab:hover { background: #1d2c46; }
.sound-fab:active { transform: scale(.92); }
.sound-fab.off { color: #64748b; }
.sound-fab svg { width: 19px; height: 19px; }

/* ---------------- 等待对手的呼吸提示 ---------------- */
@keyframes waitBreath {
  0%, 100% { opacity: .5; }
  50%      { opacity: 1; }
}
.wait-hint { animation: waitBreath 1.8s ease-in-out infinite; }
.msg.ok.wait-hint { color: var(--warn); font-weight: 600; }
