:root {
  --paper: #f6f1e4;
  --paper-2: #fffdf6;
  --ink: #22395d;
  --ink-soft: #5b6b85;
  --line: rgba(34, 57, 93, 0.16);
  --red: #d1442c;
  --gold: #e3a13a;
  --sea: #4a90c2;
  --ok: #3f9a62;
  --shadow: 0 1px 0 rgba(34, 57, 93, 0.08), 0 8px 24px -12px rgba(34, 57, 93, 0.35);
  --radius: 14px;
  color-scheme: light;
}
* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: -1px -1px;
  color: var(--ink);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
button:disabled {
  cursor: default;
}
#app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
}

/* ---------------------------------------------------------------- 顶栏 */
.top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
}
/* 嵌在盒子里时左上角有盒子的 44px 按钮，让开 */
.embedded .top {
  padding-left: 52px;
}
.brand {
  font-weight: 800;
  font-size: 19px;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.04em;
}
.grow {
  flex: 1;
}
.net {
  font-size: 13px;
  padding: 2px 10px;
  border-radius: 99px;
  background: rgba(34, 57, 93, 0.08);
}
.net.bad {
  background: rgba(209, 68, 44, 0.12);
  color: var(--red);
}
.ghost-btn {
  border: 0;
  background: rgba(34, 57, 93, 0.07);
  border-radius: 99px;
  padding: 6px 14px;
  font-size: 15px;
  min-height: 36px;
}

/* ---------------------------------------------------------------- 卡片与按钮 */
.card {
  background: var(--paper-2);
  border: 1.5px solid rgba(34, 57, 93, 0.18);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card + .card {
  margin-top: 14px;
}
summary {
  cursor: pointer;
  font-weight: 700;
}
.rules {
  margin: 10px 0 0;
  padding-left: 1.3em;
  color: var(--ink-soft);
}
.rules li + li {
  margin-top: 6px;
}
.tools button,
.seat-acts button,
.primary {
  border: 1.5px solid var(--ink);
  background: var(--paper-2);
  border-radius: 12px;
  padding: 10px 16px;
  min-height: 46px;
  font-weight: 600;
  transition: transform 0.12s, background 0.12s;
}
.tools button:active,
.seat-acts button:active,
.primary:active {
  transform: translateY(1px) scale(0.98);
}
.primary,
.tools .primary {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 3px 0 #15253f;
}
.primary:disabled,
.tools .primary:disabled {
  background: #9aa4b5;
  border-color: #9aa4b5;
  box-shadow: none;
}
.big {
  width: 100%;
  min-height: 54px;
  font-size: 18px;
}
.link {
  display: block;
  margin: 12px auto 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 15px;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.hint {
  text-align: center;
  color: var(--ink-soft);
}

.held {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  margin-bottom: 12px;
  border-color: var(--gold);
  background: #fff6e3;
}
.held span {
  color: var(--ink-soft);
  font-size: 15px;
}

.clock-pick {
  margin: 0 0 16px;
  text-align: left;
}
.clock-pick h3 {
  margin: 0 0 8px;
  font-size: 16px;
}
.clock-pick h3 small {
  font-weight: 400;
  color: var(--ink-soft);
  font-size: 13px;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.chips span {
  width: 5.2em;
  font-size: 14px;
  color: var(--ink-soft);
}
.chip {
  border: 1.5px solid rgba(34, 57, 93, 0.25);
  background: var(--paper-2);
  border-radius: 99px;
  padding: 4px 12px;
  min-height: 36px;
  font-size: 15px;
}
.chip.on {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  font-weight: 700;
}
.chip:disabled:not(.on) {
  opacity: 0.55;
}
.clock-pick .small {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}
.bank {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 15px;
  padding: 1px 8px;
  border-radius: 8px;
  background: rgba(34, 57, 93, 0.08);
}
.bank.low {
  background: rgba(209, 68, 44, 0.15);
  color: var(--red);
}

/* ---------------------------------------------------------------- 首页 */
.landing {
  max-width: 440px;
  margin: 0 auto;
  padding-top: 4vh;
}
.hero {
  text-align: center;
  margin-bottom: 18px;
}
svg.hero-plane {
  position: relative;
  inset: auto;
  width: 150px;
  height: 130px;
  animation: cruise 4s ease-in-out infinite;
}
@keyframes cruise {
  50% {
    transform: translateY(-8px) rotate(-3deg);
  }
}
.hero h1 {
  margin: 4px 0 0;
  font-size: 44px;
  letter-spacing: 0.12em;
}
.hero p {
  margin: 4px 0 0;
  color: var(--ink-soft);
}
#join-form label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}
#join-form input {
  width: 100%;
  font: inherit;
  font-size: 18px;
  padding: 12px 14px;
  border: 1.5px solid rgba(34, 57, 93, 0.35);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  margin-bottom: 12px;
}
#join-form input:focus {
  outline: 3px solid rgba(74, 144, 194, 0.35);
  border-color: var(--sea);
}
.who {
  margin: 0 0 12px;
  font-size: 18px;
}

/* ---------------------------------------------------------------- 大厅 */
.lobby {
  max-width: 520px;
  margin: 0 auto;
  padding-top: 2vh;
}
.lobby h2 {
  margin: 0 0 12px;
}
.seats {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: grid;
  gap: 10px;
}
.seat {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(34, 57, 93, 0.04);
  flex-wrap: wrap;
}
.seat > div:first-of-type {
  flex: 1;
  min-width: 0;
}
.seat b {
  display: block;
}
.seat small,
.pinfo small {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 13px;
}
.seat.empty {
  border: 1.5px dashed rgba(34, 57, 93, 0.3);
  background: none;
}
.seat-acts {
  display: flex;
  gap: 8px;
}
.seat-acts button {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 15px;
}
em {
  font-style: normal;
  font-size: 12px;
  padding: 0 7px;
  border-radius: 99px;
  background: rgba(34, 57, 93, 0.1);
  color: var(--ink);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b9bfca;
  display: inline-block;
}
.dot.on {
  background: var(--ok);
}
.avatar {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 19px;
  color: #fff;
  background: var(--ink);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1.5px var(--ink);
}
.avatar.s1 {
  background: var(--red);
  box-shadow: 0 0 0 1.5px var(--red);
}

/* ---------------------------------------------------------------- 棋盘 */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: 7% 0 0 7%;
  user-select: none;
  -webkit-user-select: none;
}
.cols,
.rows {
  position: absolute;
  display: flex;
  color: var(--ink-soft);
  font-size: clamp(10px, 2.4vw, 13px);
  font-weight: 600;
}
.cols {
  left: 7%;
  right: 0;
  top: 0;
  height: 7%;
}
.rows {
  top: 7%;
  bottom: 0;
  left: 0;
  width: 7%;
  flex-direction: column;
}
.cols b,
.rows b {
  flex: 1;
  display: grid;
  place-items: center;
}
.grid {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template: repeat(10, 1fr) / repeat(10, 1fr);
  background-color: #fff;
  background-image:
    linear-gradient(rgba(74, 144, 194, 0.32) 1px, transparent 1px),
    linear-gradient(90deg, rgba(74, 144, 194, 0.32) 1px, transparent 1px);
  background-size: 10% 10%;
  border: 2px solid var(--ink);
  border-radius: 4px;
  box-shadow: var(--shadow);
}
.cell {
  border: 0;
  padding: 0;
  background: none;
  display: block;
}
.board.live .cell:not(:disabled) {
  cursor: crosshair;
}
.board.live .cell:not(:disabled):hover,
.board.live .cell:not(:disabled):focus-visible {
  background: rgba(209, 68, 44, 0.12);
  outline: 2px solid var(--red);
  outline-offset: -2px;
  border-radius: 3px;
}
.board.live .grid {
  border-color: var(--red);
  animation: armed 1.6s ease-in-out infinite;
}
@keyframes armed {
  50% {
    box-shadow: 0 0 0 5px rgba(209, 68, 44, 0.15), var(--shadow);
  }
}
.board.place .grid {
  touch-action: none;
  cursor: grab;
}
svg.ink {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.plane use {
  stroke-linejoin: round;
}
.plane use {
  fill: #4d6185;
  stroke: var(--ink);
  stroke-width: 0.06;
}
.plane .cockpit {
  fill: rgba(255, 255, 255, 0.75);
}
.plane.sel use {
  fill: #e9ad4c;
  stroke: #9a6414;
  stroke-width: 0.08;
}
.plane.bad use {
  fill: #e2836f;
  stroke: var(--red);
}
.plane.down use {
  fill: url(#hatch);
  stroke: var(--red);
  stroke-width: 0.07;
  filter: url(#ink);
}
.plane.down .cockpit,
.plane.ghost .cockpit {
  fill: none;
}
.plane.ghost use {
  fill: #e4e8ef;
  stroke: var(--ink);
  stroke-width: 0.06;
  stroke-dasharray: 0.16 0.12;
}
.plane.falling use {
  fill: #d8604a;
  stroke: #7d2312;
  stroke-width: 0.06;
}
.mine-side .plane.down use {
  fill: #c3c7cf;
  stroke: #8a909b;
}
.m-miss circle {
  fill: var(--sea);
  opacity: 0.85;
}
.m-hit {
  stroke: var(--red);
  stroke-width: 0.11;
  stroke-linecap: round;
  fill: none;
  filter: url(#ink);
}
.m-kill {
  fill: none;
  stroke: var(--red);
  stroke-width: 0.08;
  filter: url(#ink);
}

/* ---------------------------------------------------------------- 摆飞机 */
.place {
  max-width: 520px;
  margin: 0 auto;
}
/* 矮屏上棋盘按高度收，保证按钮不被挤出屏幕 */
.place .board {
  max-width: max(280px, calc(100dvh - 250px));
  margin: 0 auto;
}
.status h2 {
  margin: 0;
  font-size: 22px;
}
.status p {
  margin: 4px 0 8px;
  color: var(--ink-soft);
}
.tools {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.tools .primary {
  flex: 1;
}
.clock {
  position: relative;
  height: 22px;
  border-radius: 99px;
  background: rgba(34, 57, 93, 0.08);
  overflow: hidden;
  margin-bottom: 12px;
}
.clock i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background: rgba(63, 154, 98, 0.35);
  transition: width 0.12s linear;
}
.clock.low i {
  background: rgba(209, 68, 44, 0.4);
}
.clock.idle i {
  width: 0;
}
.clock span {
  position: relative;
  display: block;
  text-align: center;
  font-size: 13px;
  line-height: 22px;
  font-weight: 600;
}

/* ---------------------------------------------------------------- 对战 */
.players {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}
.vs {
  font-weight: 900;
  color: var(--ink-soft);
  font-size: 14px;
}
.pcard {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--paper-2);
  border: 1.5px solid rgba(34, 57, 93, 0.15);
  min-width: 0;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.pcard.turn {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(227, 161, 58, 0.25);
}
.pcard.won {
  border-color: var(--gold);
  background: #fff6e3;
}
.pinfo {
  flex: 1;
  min-width: 0;
}
.pinfo b {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pips {
  display: flex;
  gap: 1px;
  font-size: 16px;
}
.pip.lost {
  color: var(--red);
  opacity: 0.35;
  text-decoration: line-through;
}
.wins {
  position: absolute;
  top: -8px;
  right: -6px;
  min-width: 22px;
  height: 22px;
  border-radius: 99px;
  background: var(--gold);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  display: grid;
  place-items: center;
}
.battle .status {
  margin: 12px 0 6px;
}
.battle .status p {
  margin: 0 0 6px;
  font-weight: 700;
  color: var(--ink);
  font-size: 18px;
  text-align: center;
}
.battle .status.go p {
  color: var(--red);
}
.auto-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: #fff6e3;
  border: 1.5px solid var(--gold);
  font-weight: 700;
}
.auto-bar .primary {
  min-height: 40px;
  padding: 6px 14px;
}
.boards {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
@media (min-width: 761px) {
  .enemy-side .board {
    max-width: max(320px, calc(100dvh - 230px));
  }
  .mine-side .board {
    max-width: max(260px, calc(100dvh - 330px));
  }
}
.side h3 {
  margin: 4px 0 6px;
  font-size: 16px;
}
.side h3 small {
  font-weight: 400;
  color: var(--ink-soft);
  font-size: 13px;
  margin-left: 6px;
}
.emojis {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.emojis button {
  border: 1.5px solid rgba(34, 57, 93, 0.15);
  background: var(--paper-2);
  border-radius: 10px;
  width: 44px;
  height: 44px;
  font-size: 22px;
}
.log {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  font-size: 14px;
  color: var(--ink-soft);
}
.log li:first-child {
  color: var(--ink);
}
.result {
  text-align: center;
  margin: 8px 0 14px;
  animation: pop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.result h2 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0.2em;
}
.result.win h2 {
  color: var(--gold);
}
.result p {
  margin: 4px 0;
  font-size: 18px;
  font-weight: 700;
}
.result p.small {
  font-size: 14px;
  font-weight: 400;
  color: var(--ink-soft);
  margin-bottom: 12px;
}
@keyframes pop {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
}

/* ---------------------------------------------------------------- 特效层 */
#fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  overflow: hidden;
}
.fx {
  position: fixed;
  transform: translate(-50%, -50%);
}
.shell {
  border-radius: 50% 50% 45% 45%;
  background: radial-gradient(circle at 35% 30%, #6a7d9c, #1c2c47 70%);
  box-shadow: 0 0 0 2px #fff;
}
.aim {
  border: 2px dashed var(--red);
  border-radius: 50%;
}
.splash {
  border: 2.5px solid var(--sea);
  border-radius: 50%;
}
.boom {
  border-radius: 50%;
  background: radial-gradient(circle, #fff3c2 0%, #f0a33a 35%, rgba(209, 68, 44, 0.6) 60%, transparent 72%);
}
.spark {
  border-radius: 50%;
}
.smoke {
  border-radius: 50%;
  background: radial-gradient(circle, rgba(80, 80, 90, 0.4), transparent 70%);
}
.crash {
  transform: none;
}
.bubble {
  display: grid;
  place-items: center;
  font-size: 34px;
  z-index: 30;
}

/* ---------------------------------------------------------------- 横幅与提示 */
#banner {
  position: fixed;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(0.8);
  opacity: 0;
  pointer-events: none;
  z-index: 40;
  text-align: center;
  background: var(--ink);
  color: #fff;
  padding: 14px 28px;
  border-radius: 16px;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.5);
  transition: opacity 0.2s, transform 0.25s cubic-bezier(0.2, 1.4, 0.4, 1);
  max-width: calc(100vw - 32px);
}
#banner.on {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
#banner.gold {
  background: var(--gold);
  color: #3a2505;
}
#banner.bad {
  background: var(--red);
}
#banner strong {
  display: block;
  font-size: 26px;
  letter-spacing: 0.08em;
}
#banner span {
  display: block;
  font-size: 15px;
  opacity: 0.9;
}
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  background: rgba(20, 30, 48, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 15px;
  transition: 0.2s;
  max-width: calc(100vw - 32px);
  text-align: center;
}
#toast.on {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------------------------------------------------------- 手机 */
@media (max-width: 760px) {
  body {
    font-size: 16px;
  }
  .boards {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }
  /* 手机上：对方空域占满宽度，自己的空域缩小放在下面一行，和表情、战报并排 */
  .mine-side {
    display: grid;
    grid-template-columns: minmax(0, 52%) minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    column-gap: 12px;
  }
  .mine-side h3 {
    grid-column: 1 / -1;
  }
  .mine-side .board {
    grid-row: 2 / 4;
  }
  .mine-side .emojis {
    margin-top: 0;
    align-content: start;
  }
  .mine-side .emojis button {
    width: 38px;
    height: 38px;
    font-size: 19px;
  }
  .mine-side .log {
    font-size: 13px;
  }
  .pcard {
    padding: 6px 8px;
    gap: 6px;
  }
  .pcard .avatar {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }
  .pips {
    font-size: 13px;
  }
  .pinfo small em {
    display: none;
  }
  .pinfo small em:first-child {
    display: inline;
  }
  .hero h1 {
    font-size: 38px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
