/* layout: 1画面のアプリ。上に手番表示、中央に海図(盤)、下に操作ボタン */
:root {
  --paper: #edf3f2;
  --sea: #d3e4e9;
  --sea-2: #c3d9e0;
  --ink: #0f2a3d;
  --muted: #557080;
  --line: #9db7c2;
  --ship: #47616f;
  --hit: #d13b2b;
  --sunk: #7b1f16;
  --accent: #e4a11b;
  --on-accent: #1b1300;
  --card: #f8fbfa;
  --fog: #8fa3ad;
  --font-display: "Dela Gothic One", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  --cell: min(13vw, 58px, 7.1vh);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0b1720;
    --sea: #12293a;
    --sea-2: #173246;
    --ink: #dae7ee;
    --muted: #8ba4b2;
    --line: #2c495c;
    --ship: #86a4b5;
    --hit: #ff5b45;
    --sunk: #c0412f;
    --accent: #f2b440;
    --on-accent: #1b1300;
    --card: #10212d;
    --fog: #5b7381;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0b1720;
  --sea: #12293a;
  --sea-2: #173246;
  --ink: #dae7ee;
  --muted: #8ba4b2;
  --line: #2c495c;
  --ship: #86a4b5;
  --hit: #ff5b45;
  --sunk: #c0412f;
  --accent: #f2b440;
  --on-accent: #1b1300;
  --card: #10212d;
  --fog: #5b7381;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#app {
  max-width: 480px;
  min-height: 100%;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: max(12px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

h1, h2 { font-family: var(--font-display); font-weight: 400; margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 2.4rem; letter-spacing: 0.02em; }
h2 { font-size: 1.35rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.eyebrow.hot { color: var(--hit); }
.small { font-size: 0.85rem; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  padding: 12px 18px;
  border-radius: 10px;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible, .cell:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------- header ---------- */
.bar { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.eyebrow { font-size: 0.8rem; letter-spacing: 0.12em; color: var(--muted); font-weight: 700; }
.who { font-family: var(--font-display); font-size: 1.3rem; }
.p0 { --pc: #2f6fb0; }
.p1 { --pc: #c2562a; }
.tag { display: inline-block; padding: 1px 10px; border-radius: 999px; background: var(--pc); color: #fff; font-weight: 700; font-size: 0.85rem; }

/* ---------- board ---------- */
.board-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.board-title { align-self: stretch; display: flex; justify-content: space-between; font-weight: 700; font-size: 0.9rem; color: var(--muted); }
.board {
  --n: 6;
  display: grid;
  grid-template-columns: 1.4em repeat(var(--n), var(--c));
  grid-auto-rows: var(--c);
  gap: 3px;
  --c: var(--cell);
}
.board.mini { --c: min(6.4vw, 28px); gap: 2px; font-size: 0.7rem; grid-template-columns: 1.1em repeat(var(--n), var(--c)); grid-template-rows: 1.1em; }
.board.mini .coord { font-size: 0.65rem; }
.coord { display: grid; place-items: center; font-size: 0.75rem; color: var(--muted); font-weight: 700; }
.board .coord.top { height: 1.4em; align-self: end; }
.board { grid-template-rows: 1.4em; }
.cell {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  background: var(--sea);
  border-radius: 6px;
  position: relative;
  display: grid;
  place-items: center;
  touch-action: manipulation;
}
.board.mini .cell { border-radius: 3px; }
button.cell { cursor: pointer; }
button.cell:active { background: var(--sea-2); }
.cell.ship { background: var(--ship); }
.cell.ship.h.s { border-radius: 40% 6px 6px 40%; }
.cell.ship.h.e { border-radius: 6px 40% 40% 6px; }
.cell.ship.v.s { border-radius: 40% 40% 6px 6px; }
.cell.ship.v.e { border-radius: 6px 6px 40% 40%; }
.cell.miss::after { content: ""; width: 22%; height: 22%; border-radius: 50%; background: var(--muted); opacity: 0.8; }
.cell.hit::after, .cell.sunk::after {
  content: "";
  width: 56%; height: 56%;
  background:
    linear-gradient(45deg, transparent 42%, var(--hit) 42% 58%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, var(--hit) 42% 58%, transparent 58%);
}
.cell.near::after, .key.near::after {
  content: ""; width: 46%; height: 46%; border-radius: 50%;
  border: 3px solid var(--accent); box-sizing: border-box;
  background: radial-gradient(circle, var(--accent) 0 22%, transparent 24%);
}
.key { display: inline-grid; place-items: center; width: 1.3em; height: 1.3em; vertical-align: -0.25em; margin-right: 2px; }
.key.near::after { width: 100%; height: 100%; border-width: 2px; }
.banner.near { background: color-mix(in srgb, var(--accent) 30%, var(--sea)); }
.cell.smoke, .key.smoke {
  background:
    radial-gradient(circle at 30% 40%, var(--fog) 0 28%, transparent 30%),
    radial-gradient(circle at 65% 55%, var(--fog) 0 32%, transparent 34%),
    radial-gradient(circle at 45% 70%, var(--fog) 0 24%, transparent 26%),
    var(--sea-2);
}
.cell.ship.smoke { box-shadow: inset 0 0 0 999px color-mix(in srgb, var(--fog) 55%, transparent); }
.cell.smoke-preview { box-shadow: inset 0 0 0 3px var(--accent); background-color: color-mix(in srgb, var(--fog) 60%, var(--sea)); }
.key.smoke { border-radius: 4px; }
.cell.clear, .key.clear { background: repeating-linear-gradient(135deg, transparent 0 5px, color-mix(in srgb, var(--muted) 22%, transparent) 5px 7px), var(--paper); }
.key.clear { border-radius: 4px; border: 1px solid var(--line); }
.cell.nogo { background: repeating-linear-gradient(135deg, var(--sea) 0 6px, color-mix(in srgb, var(--muted) 18%, var(--sea)) 6px 8px); }
.cell.sunk { background: var(--sunk); }
.cell.sunk::after {
  background:
    linear-gradient(45deg, transparent 42%, #fff 42% 58%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, #fff 42% 58%, transparent 58%);
  opacity: 0.85;
}
.cell.last { box-shadow: 0 0 0 3px var(--accent); }
.cell.ghost { background: color-mix(in srgb, var(--accent) 45%, var(--sea)); }
.cell.bad { background: color-mix(in srgb, var(--hit) 35%, var(--sea)); }
.cell.sel { box-shadow: inset 0 0 0 3px var(--accent); }
.cell.aim { background: color-mix(in srgb, var(--accent) 35%, var(--sea)); box-shadow: inset 0 0 0 3px var(--accent); }
.cell.aim::before {
  content: ""; position: absolute; inset: 18%;
  background:
    linear-gradient(var(--ink), var(--ink)) center / 2px 100% no-repeat,
    linear-gradient(var(--ink), var(--ink)) center / 100% 2px no-repeat;
  border-radius: 50%; border: 2px solid var(--ink);
}

/* ---------- battle dock: 自分の艦隊 と 情報 を横に並べて1画面に収める ---------- */
.battle { gap: 10px; }
.dock { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: start; }
.dock-info { gap: 8px; }
.dock-info .banner { flex-wrap: wrap; padding: 8px 12px; }
.dock-info .big { font-size: 1.25rem; }
.dock-info .btn { width: 100%; }
.link { appearance: none; background: none; border: 0; color: var(--muted); font: inherit; text-decoration: underline; padding: 8px 0; cursor: pointer; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 10px 12px; }
.key.hit::after, .key.sunk::after, .key.miss::after { content: ""; display: block; }
.key.hit, .key.sunk, .key.miss { background: var(--sea); border-radius: 4px; position: relative; }
.key.sunk { background: var(--sunk); }
.key.hit::after, .key.sunk::after {
  width: 70%; height: 70%;
  background:
    linear-gradient(45deg, transparent 40%, var(--hit) 40% 60%, transparent 60%),
    linear-gradient(-45deg, transparent 40%, var(--hit) 40% 60%, transparent 60%);
}
.key.sunk::after { filter: brightness(3); }
.key.miss::after { width: 28%; height: 28%; border-radius: 50%; background: var(--muted); }

/* ---------- score bar ---------- */
.score { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.score .side { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.score .side + .vs + .side { align-items: flex-end; }
.score .who-s { font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.score .vs { font-family: var(--font-display); color: var(--muted); font-size: 0.85rem; }
.fleet-pips { display: flex; gap: 6px; flex-wrap: wrap; }
.pips.gone i { background: var(--hit); opacity: 0.5; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.cover .score { text-align: left; }

/* ---------- report of the opponent's turn ---------- */
.report { background: var(--sea); border-radius: 12px; padding: 8px 12px; }
.report ul { list-style: none; margin: 2px 0 0; padding: 0; font-weight: 700; font-size: 0.85rem; display: flex; flex-wrap: wrap; gap: 0 10px; line-height: 1.5; }
.report li { white-space: nowrap; }
.report li.r-hit, .report li.r-sunk { color: var(--hit); }
.report li.r-near { color: color-mix(in srgb, var(--accent) 70%, var(--ink)); }
.note { display: flex; align-items: center; gap: 6px; }
.btn.ghost { border-width: 1px; font-size: 0.9rem; min-height: 44px; padding: 8px 12px; }

/* ---------- segmented control ---------- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 2px solid var(--ink); border-radius: 10px; overflow: hidden; }
.seg button { appearance: none; border: 0; background: transparent; color: var(--ink); font: inherit; font-weight: 700; min-height: 44px; cursor: pointer; }
.seg button + button { border-left: 2px solid var(--ink); }
.seg button.on { background: var(--ink); color: var(--paper); }

/* ---------- panels ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.banner { border-radius: 12px; padding: 10px 14px; font-weight: 700; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.banner.info { background: var(--sea); }
.banner.hit { background: var(--hit); color: #fff; }
.banner.sunk { background: var(--sunk); color: #fff; }
.banner.miss { background: var(--sea-2); }
.big { font-family: var(--font-display); font-size: 1.6rem; }

.ships { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  appearance: none; font: inherit; color: inherit;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 10px; border: 2px solid var(--line); background: transparent;
  min-height: 44px; cursor: pointer;
}
.chip.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); }
.chip.done { opacity: 0.55; }
.pips { display: inline-flex; gap: 2px; }
.pips i { width: 10px; height: 10px; background: var(--ship); border-radius: 2px; display: block; }
.pips i.x { background: var(--hit); }

.fleet-status { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; font-size: 0.8rem; }
.fleet-status span { display: inline-flex; align-items: center; gap: 6px; }
.fleet-status .gone { text-decoration: line-through; color: var(--muted); }

/* ---------- screens ---------- */
.title-screen { justify-content: center; min-height: 100%; gap: 18px; }
.title-mark { font-family: var(--font-display); font-size: clamp(2.4rem, 12vw, 3.4rem); line-height: 1.02; font-weight: 800; font-synthesis: none; letter-spacing: 0.01em; }
.hero { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 18px; padding-bottom: 14px; border-bottom: 2px solid var(--ink); }
.hero-text { display: flex; flex-direction: column; gap: 6px; }
.demo { margin: 0; display: flex; flex-direction: column; gap: 6px; max-width: 168px; }
.demo .board.mini { --c: min(5.1vw, 20px); }
.demo figcaption { color: var(--muted); line-height: 1.45; font-size: 0.72rem; }
.cover { min-height: 70vh; display: flex; flex-direction: column; justify-content: center; align-items: stretch; gap: 18px; text-align: center; }
.rules li { margin-bottom: 4px; }
.rules { padding-left: 1.2em; margin: 0; }

/* ---------- 着弾の演出 (新しい弾のマスだけ .fresh) ---------- */
@keyframes pop { 0% { transform: scale(0.3); opacity: 0; } 60% { transform: scale(1.25); opacity: 1; } 100% { transform: scale(1); } }
@keyframes flash { 0% { background-color: #fff3c4; } 100% { } }
@keyframes ripple { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }
@keyframes splash { 0% { transform: scale(2.4); opacity: 0.2; } 100% { transform: scale(1); opacity: 0.8; } }
@keyframes shake { 0%, 100% { transform: translate(0, 0); } 20% { transform: translate(-3px, 1px); } 40% { transform: translate(3px, -1px); } 60% { transform: translate(-2px, 0); } 80% { transform: translate(2px, 1px); } }
@keyframes sink { 0% { filter: brightness(2.2); transform: scale(1.08); } 100% { filter: none; transform: scale(1); } }
.cell.fresh.hit::after { animation: pop 0.35s ease-out; }
.cell.fresh.hit { animation: flash 0.5s ease-out; }
.cell.fresh.sunk { animation: sink 0.7s ease-out; }
.cell.fresh.near { animation: ripple 0.7s ease-out; }
.cell.fresh.near::after { animation: pop 0.35s ease-out; }
.cell.fresh.miss::after { animation: splash 0.4s ease-out; }
.board.shake { animation: shake 0.25s linear; }
.board.shake-big { animation: shake 0.45s linear; }
@media (prefers-reduced-motion: reduce) {
  .cell.fresh, .cell.fresh::after, .board.shake, .board.shake-big { animation: none !important; }
}

/* ---------- 結果画面 ---------- */
.over h1 { font-size: 2.2rem; }
.stats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stats th, .stats td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: center; }
.stats th[scope="row"] { text-align: left; font-weight: 400; color: var(--muted); font-size: 0.9rem; }
.stats thead th { border-bottom: 2px solid var(--ink); }
.reveal { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.tag.p0 { background: #2f6fb0; }
.tag.p1 { background: #c2562a; }
.reveal .board.mini { --c: min(5.4vw, 24px); }

.toast {
  position: fixed; z-index: 20;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px));
  max-width: 456px; margin: 0 auto;
  display: flex; gap: 8px; align-items: flex-start;
  padding: 10px 8px 10px 14px; border-radius: 12px;
  background: var(--card); border: 2px solid var(--accent);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--ink) 25%, transparent);
  animation: drop 0.25s ease-out;
}
.toast b { color: color-mix(in srgb, var(--accent) 60%, var(--ink)); margin-right: 6px; }
.toast-x { appearance: none; border: 0; background: none; color: var(--muted); font-size: 1.3rem; line-height: 1; min-width: 36px; min-height: 36px; cursor: pointer; }
@keyframes drop { from { transform: translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

.cell.picked { box-shadow: inset 0 0 0 3px var(--accent); filter: brightness(1.15); }
.settings { display: flex; gap: 4px 18px; flex-wrap: wrap; justify-content: center; }
