/* Battle Shapes 在线版 —— 视觉上沿用工作纸的「纸 + 铅笔」感觉 */

:root {
  --paper: #f7f4ec;
  --paper-2: #fffdf7;
  --ink: #23201c;
  --ink-soft: #6b655c;
  --line: #d9d2c4;
  --line-strong: #b6ad9b;
  --accent: #2f6fd0;
  --accent-soft: #e4edfb;
  --good: #1f9d59;
  --bad: #d63b4f;
  --warn: #d98800;
  --shadow: 0 2px 0 rgba(0, 0, 0, .06), 0 8px 24px rgba(60, 50, 30, .10);
  --radius: 14px;
  --font: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1b1a18;
    --paper-2: #26241f;
    --ink: #ece7dc;
    --ink-soft: #a49c8e;
    --line: #3b382f;
    --line-strong: #565144;
    --accent: #6fa8ff;
    --accent-soft: #22334d;
    --shadow: 0 2px 0 rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

/* 作者样式里的 display 会盖掉 hidden 属性，这里统一按 hidden 优先 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background-image:
    linear-gradient(rgba(120, 140, 170, .07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 140, 170, .07) 1px, transparent 1px);
  background-size: 28px 28px;
}

.screen { display: none; min-height: 100dvh; }
.screen.active { display: block; }

h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; }
h2 { font-size: 1.05rem; letter-spacing: .01em; }
h3 { font-size: .95rem; color: var(--ink-soft); font-weight: 600; }
p { margin: .4em 0; }

/* ─────────────── 按钮 ─────────────── */
.btn {
  font: inherit;
  font-weight: 600;
  padding: .6em 1.1em;
  border-radius: 10px;
  border: 1.5px solid var(--line-strong);
  background: var(--paper-2);
  color: var(--ink);
  cursor: pointer;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover:not(:disabled) { box-shadow: 0 2px 0 var(--line-strong); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); box-shadow: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.small { padding: .4em .8em; font-size: .88rem; }
.btn.block { width: 100%; }

.link-btn {
  background: none; border: none; font: inherit; color: var(--accent);
  cursor: pointer; padding: .3em .5em; border-radius: 8px;
}
.link-btn:hover { background: var(--accent-soft); }
.link-btn.danger { color: var(--bad); }
.link-btn.danger:hover { background: rgba(214, 59, 79, .12); }

.icon-btn {
  font: inherit; display: inline-flex; align-items: center; gap: .4em;
  padding: .4em .8em; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--line-strong); background: var(--paper-2); color: var(--ink);
}
.icon-btn.on { background: var(--good); border-color: transparent; color: #fff; }
.icon-btn.connecting { border-color: var(--warn); color: var(--warn); }

/* ─────────────── 登录 ─────────────── */
#screen-login { display: none; place-items: center; padding: 4vh 16px; }
#screen-login.active { display: grid; }

.login-card {
  width: min(420px, 100%);
  background: var(--paper-2);
  border: 1.5px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px 26px 20px;
}
.brand { text-align: center; margin-bottom: 18px; }
.brand-mark { width: 150px; height: 75px; }
.brand h1 { font-size: 1.7rem; letter-spacing: .02em; margin: .2em 0 .1em; }
.subtitle { color: var(--ink-soft); font-size: .92rem; margin: 0; }

#login-form { display: grid; gap: 6px; }
#login-form label { font-size: .85rem; color: var(--ink-soft); font-weight: 600; margin-top: 8px; }
#login-form input {
  font: inherit; padding: .7em .8em; border-radius: 10px;
  border: 1.5px solid var(--line-strong); background: var(--paper);
  color: var(--ink);
}
#login-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#login-form .btn { margin-top: 14px; }

.hint { font-size: .8rem; color: var(--ink-soft); margin: 4px 0 0; }
.error { color: var(--bad); font-size: .88rem; min-height: 1.2em; margin: .5em 0 0; }

.lang-switch { display: flex; justify-content: center; gap: 4px; margin-top: 12px; }
.lang-switch button {
  font: inherit; font-size: .8rem; padding: .25em .7em; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--ink-soft); border-radius: 999px;
}
.lang-switch button.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ─────────────── 顶栏 ─────────────── */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1.5px solid var(--line);
  background: var(--paper-2); position: sticky; top: 0; z-index: 10;
  padding-top: max(10px, env(safe-area-inset-top));
}
.who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 9em; }
.vs { color: var(--ink-soft); font-size: .85rem; }
.muted { color: var(--ink-soft); font-size: .85rem; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); flex: none; }
.dot.online { background: var(--good); }
.badge {
  font-size: .72rem; padding: .15em .6em; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.badge.offline { background: rgba(214, 59, 79, .15); color: var(--bad); }

/* ─────────────── 大厅 ─────────────── */
.lobby-grid {
  display: grid; gap: 16px; padding: 16px;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  max-width: 1000px; margin: 0 auto;
}
@media (max-width: 760px) { .lobby-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--paper-2); border: 1.5px solid var(--line);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 0;
}

.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.player-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--paper);
}
.player-list .pname { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list .pstatus { font-size: .78rem; color: var(--ink-soft); }
.empty-hint { color: var(--ink-soft); font-size: .88rem; line-height: 1.6; }

.chat-log {
  flex: 1; min-height: 140px; max-height: 320px; overflow-y: auto;
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px;
  background: var(--paper); font-size: .9rem; display: flex; flex-direction: column; gap: 6px;
}
.chat-log .msg .cname { font-weight: 600; margin-right: .4em; }
.chat-log .msg.mine .cname { color: var(--accent); }
.chat-form { display: flex; gap: 6px; margin-top: 10px; }
.chat-form input {
  flex: 1; font: inherit; padding: .5em .7em; border-radius: 10px;
  border: 1.5px solid var(--line-strong); background: var(--paper); color: var(--ink); min-width: 0;
}

/* ─────────────── 对局 ─────────────── */
.turn-banner {
  text-align: center; font-weight: 700; padding: 10px 16px;
  background: var(--accent-soft); color: var(--accent);
  border-bottom: 1.5px solid var(--line);
}
.turn-banner.theirs { background: transparent; color: var(--ink-soft); }
.turn-banner.over { background: rgba(31, 157, 89, .12); color: var(--good); }

.game-layout { padding: 16px; max-width: 1200px; margin: 0 auto; }

.phase-placing { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr) 260px; align-items: start; }
@media (max-width: 860px) { .phase-placing { grid-template-columns: 1fr; } }

.board-wrap {
  background: var(--paper-2); border: 1.5px solid var(--line);
  border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); min-width: 0;
}
.board-wrap h3 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.board-wrap canvas { width: 100%; height: auto; display: block; touch-action: manipulation; }
.progress { font-size: .8rem; color: var(--ink-soft); font-weight: 600; }
.coord-readout {
  text-align: center; font-size: .85rem; color: var(--ink-soft);
  font-variant-numeric: tabular-nums; margin: 6px 0 0; min-height: 1.2em;
}

.tray-panel {
  background: var(--paper-2); border: 1.5px solid var(--line);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
.tray { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.tray li {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  border: 1.5px solid var(--line); border-radius: 10px; cursor: pointer;
  background: var(--paper); user-select: none;
}
.tray li:hover { border-color: var(--line-strong); }
.tray li.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tray li.placed { opacity: .5; }
.tray li.placed .tname::after { content: " ✓"; color: var(--good); }
.tray svg { width: 46px; height: 32px; flex: none; }
.tname { font-size: .88rem; }

.checkbox { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--ink-soft); }
.tray-actions { display: flex; gap: 6px; }
.tray-actions .btn { flex: 1; }
.waiting { color: var(--warn); font-weight: 600; font-size: .9rem; }

.phase-battle { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
.boards { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .phase-battle { grid-template-columns: 1fr; } }
@media (max-width: 820px) { .boards { grid-template-columns: 1fr; } }

.side { display: flex; flex-direction: column; gap: 10px; }
.log {
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--paper-2); padding: 10px; font-size: .88rem;
  height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px;
  box-shadow: var(--shadow);
}
.log .entry { line-height: 1.5; }
.log .entry.hit { color: var(--good); font-weight: 600; }
.log .entry.miss { color: var(--ink-soft); }
.log .entry.sunk { color: var(--bad); font-weight: 700; }
.log .entry.sys { color: var(--accent); }
.log .coord { font-variant-numeric: tabular-nums; font-weight: 700; }

/* ─────────────── 浮层 ─────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 18, 14, .45);
  display: grid; place-items: center; padding: 16px; z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--paper-2); border-radius: 18px; padding: 24px;
  width: min(520px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  border: 1.5px solid var(--line); max-height: 86dvh; overflow-y: auto;
}
.modal-actions { display: flex; gap: 8px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }
.modal.result { text-align: center; }
.result-emoji { font-size: 3rem; line-height: 1; }
.reveal { margin-top: 14px; }
.reveal canvas { width: 100%; height: auto; }

.rules-list { margin: 0; padding-left: 1.3em; line-height: 1.7; font-size: .92rem; }
.rules-list li { margin-bottom: .35em; }
.rules-shapes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.rules-shapes figure { margin: 0; text-align: center; font-size: .72rem; color: var(--ink-soft); }
.rules-shapes svg { width: 58px; height: 44px; display: block; }

/* ─────────────── 提示条 ─────────────── */
.toast-host {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px;
  display: flex; flex-direction: column; gap: 8px; z-index: 80; pointer-events: none;
  width: min(420px, calc(100% - 32px));
}
.toast {
  background: var(--ink); color: var(--paper); padding: .7em 1em; border-radius: 12px;
  font-size: .9rem; box-shadow: var(--shadow); animation: pop .25s ease;
  text-align: center;
}
.toast.bad { background: var(--bad); color: #fff; }
.toast.good { background: var(--good); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

.game-settings {
  margin-top: 14px; border-top: 1.5px dashed var(--line); padding-top: 10px;
  font-size: .85rem; color: var(--ink-soft);
}
.game-settings summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.game-settings .checkbox { margin: 6px 0; }

.rotate-btn { display: flex; align-items: center; justify-content: center; gap: .5em; }
.rotate-btn .rot-glyph { font-size: 1.15em; line-height: 1; }
.rotate-btn kbd {
  font: inherit; font-size: .72em; padding: .1em .45em; border-radius: 5px;
  border: 1px solid var(--line-strong); color: var(--ink-soft); background: var(--paper);
}
.rotate-btn:disabled kbd { opacity: .6; }
