/* 全ゲーム共通スタイル
   方針: 軽さ最優先。アニメーション無し。スマホ基準(モバイルファースト)。 */

:root {
  --bg: #f4f4ef;
  --fg: #1b1b1b;
  --muted: #666;
  --panel: #fff;
  --border: #d8d8d0;
  --accent: #1f7a4c;
  --accent-fg: #fff;
  --board: #1f7a4c;
  --board-line: #145635;
  --disc-black: #141414;
  --disc-white: #fafafa;
  --hint: rgba(255, 255, 255, 0.45);
  --last: #ff3b30; /* 直前の手を囲む色（1箇所で変更できるよう変数化） */
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --fg: #e9e9e6;
    --muted: #9a9a95;
    --panel: #1f2125;
    --border: #33363c;
    --board: #1a6741;
    --board-line: #0e4128;
    --disc-white: #f2f2ee;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 12px 40px;
}

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.site-header .wrap { padding: 10px 12px; display: flex; align-items: center; gap: 12px; }
.site-header .logo { font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--fg); }
.site-header nav { margin-left: auto; font-size: .9rem; }

h1 { font-size: 1.35rem; margin: 12px 0 4px; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
.lead { color: var(--muted); margin: 0 0 12px; font-size: .92rem; }

/* --- 操作パネル --- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 12px 0;
}

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.controls label { font-size: .85rem; color: var(--muted); }

/* 現在の対戦設定の表示 */
.game-info {
  margin: 8px 0 0;
  font-size: .85rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}
.game-info:empty { display: none; }

select, button, input[type="text"], input[type="password"] {
  font: inherit;
  font-size: .95rem;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  min-height: 40px; /* 指で押しやすい高さ */
}
input[type="text"], input[type="password"] { min-width: 0; flex: 1 1 150px; }
#share-url { font-size: .8rem; color: var(--muted); }

.sep { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }

/* QRコード表示 */
.qr-container {
  margin: 10px 0;
  width: min(60vw, 220px);
  padding: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.qr-container svg { display: block; }
.room-line { margin: 0 0 8px; }
#room-code-view { font-size: 1.15rem; letter-spacing: .08em; font-family: ui-monospace, monospace; }
button { cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }

/* オン/オフ切り替えボタン。押されている状態を色で分かるようにする。 */
button.toggle[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

/* 新規対局ボタン（目立つ赤） */
button.danger {
  background: #d6362a;
  color: #fff;
  border-color: #d6362a;
  font-weight: 700;
}
button.danger:hover { background: #bf2b20; border-color: #bf2b20; }

/* flexの操作列で強制的に改行させるための区切り */
.controls .row-break { flex-basis: 100%; height: 0; margin: 0; }

/* 待ったボタンは枠を太線にして少し強調 */
#undo { border: 3px solid var(--accent); font-weight: 600; }

/* 形勢バー（練習用） */
.evalbar { width: min(94vw, 460px); margin: 0 auto 8px; }
.evalbar-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: .82rem; color: var(--muted); margin-bottom: 3px;
}
.eval-num { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--fg); }
.evalbar-track {
  position: relative; height: 14px; border-radius: 7px; overflow: hidden;
  background: #f0f0eb;                 /* 白側 */
  border: 1px solid var(--border);
}
@media (prefers-color-scheme: dark) { .evalbar-track { background: #d8d8d2; } }
.evalbar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 50%; background: #1b1b1b;      /* 黒側（黒が優勢なほど右へ伸びる） */
  transition: width .25s ease;
}
.evalbar-center {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 1px;
  background: rgba(0, 0, 0, .35); transform: translateX(-0.5px);
}
.evalbar-note { font-size: .72rem; color: var(--muted); margin-top: 3px; }
#eval-score { font-size: 1.05rem; }

/* 対局の振り返り */
.review { margin: 12px 0; }
.review .controls { justify-content: center; }
.review .counter {
  text-align: center; font-size: .9rem; color: var(--muted);
  font-variant-numeric: tabular-nums; margin: 4px 0 8px;
}
.review h2 { margin-top: 0; }

/* --- 対局状況 --- */
.status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0;
  font-size: .95rem;
  min-height: 34px;
}
.score { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.score .chip {
  width: 18px; height: 18px; border-radius: 50%; display: inline-block;
  border: 1px solid var(--board-line);
}
.chip.b { background: var(--disc-black); }
.chip.w { background: var(--disc-white); }
.status .msg { margin-left: auto; color: var(--muted); font-size: .88rem; }
.status .msg.think { color: var(--accent); }

/* --- 盤 --- */
.board {
  width: min(94vw, 460px);
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 1px;
  background: var(--board-line);
  border: 2px solid var(--board-line);
  border-radius: 4px;
  touch-action: manipulation; /* スマホでのダブルタップ拡大を防ぐ */
}

.cell {
  background: var(--board);
  border: 0;
  padding: 0;
  margin: 0;
  position: relative;
  cursor: default;
  min-height: 0;
  -webkit-tap-highlight-color: transparent;
}
.cell.playable { cursor: pointer; }

.disc {
  position: absolute;
  inset: 9%;
  border-radius: 50%;
}
/* 石に縁取りを付け、盤の色に関係なく石が浮き上がるようにする（屋外・日光下の視認性対策）。
   黒石には明るい縁、白石には暗い縁。 */
.disc.b { background: var(--disc-black); box-shadow: 0 0 0 2px rgba(255, 255, 255, .35); }
.disc.w { background: var(--disc-white); box-shadow: 0 0 0 2px rgba(0, 0, 0, .40); }

/* 着手可能マスの目印 */
.dot {
  position: absolute;
  inset: 36%;
  border-radius: 50%;
  background: var(--hint);
}

/* 直前の手（相手の直前の着手が分かりやすいよう、明るい色で太めに） */
.cell.last::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid var(--last);
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35); /* 白石の上でも縁が見えるように */
  pointer-events: none;
}

/* ---- はっきり表示モード（太陽光下でも見やすい高コントラスト） ---- */
.board.hc {
  --board: #279a58;        /* 盤を少し明るくして黒石を際立たせる */
  --board-line: #06331d;   /* 罫線をより濃く */
}
.board.hc .disc.b { box-shadow: 0 0 0 3px #ffffff; }
.board.hc .disc.w { box-shadow: 0 0 0 3px #000000; }
.board.hc .dot {
  inset: 34%;
  background: #ffe94d;                        /* 目印を鮮やかな黄色に */
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .55);
}
.board.hc .cell.last::after { border-width: 3px; border-color: var(--last); }

/* --- ゲーム一覧 --- */
.game-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.game-list a {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-decoration: none;
  color: var(--fg);
}
.game-list .name { font-weight: 600; }
.game-list .desc { color: var(--muted); font-size: .85rem; }
.game-list li.soon a { opacity: .5; pointer-events: none; }
.badge {
  font-size: .7rem; border: 1px solid var(--border); border-radius: 999px;
  padding: 1px 8px; color: var(--muted); margin-left: 6px; vertical-align: middle;
}

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 32px;
  padding: 16px 0;
  color: var(--muted);
  font-size: .82rem;
  text-align: center;
}
.site-footer a { color: var(--muted); }
.sep-dot { margin: 0 4px; }

.notice { font-size: .85rem; color: var(--muted); }
.error { font-size: .85rem; color: #c0392b; margin: 6px 0 0; }

/* --- 対局履歴 --- */
.history { list-style: none; padding: 0; margin: 8px 0 0; font-size: .85rem; }
.history li {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.history li:last-child { border-bottom: 0; }
.history li.replayable { cursor: pointer; }
.history li.replayable:hover { color: var(--accent); }
.history li.replayable .replay-hint { color: var(--accent); font-size: .78rem; margin-left: 6px; }

/* --- ヘッダーのアカウント表示 --- */
.site-header nav { display: flex; align-items: center; gap: 8px; }
.account-name { font-size: .85rem; color: var(--muted); max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linklike {
  border: 0; background: none; color: var(--accent); padding: 4px 2px;
  min-height: 0; font-size: .9rem; cursor: pointer; text-decoration: underline;
}
/* ログイン / ログアウト / 表示名は枠付きボタン */
.header-btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--fg);
  padding: 5px 12px; border-radius: 6px; min-height: 0;
  font-size: .85rem; cursor: pointer; line-height: 1.2;
}
.header-btn:hover { background: var(--bg); border-color: var(--accent); }
/* 表示名ボタンは「変更できる」ことが伝わるよう鉛筆アイコンを添える */
.account-name-btn {
  max-width: 11em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--accent);
}
.account-name-btn::after { content: " ✎"; font-size: .8em; opacity: .8; }

/* --- 対局時計（持ち時間） --- */
#time-over-wrap[hidden] { display: none; }
.clock-bar[hidden] { display: none; }
.clock-bar {
  display: flex; gap: 8px; width: min(96vw, 460px); margin: 8px auto 0;
}
.clock {
  flex: 1; display: flex; align-items: baseline; justify-content: center; gap: 8px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); color: var(--muted);
}
.clock .clk-name { font-size: .8rem; }
.clock .clk-time { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--fg); }
/* 手番側の時計を強調 */
.clock.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.clock.active .clk-name { color: var(--accent); }
/* 残り10秒以下は赤で警告 */
.clock.danger .clk-time { color: var(--shogi-last, #ff3b30); }
.clock.active.danger { border-color: var(--shogi-last, #ff3b30); }

/* --- ログイン/新規登録ダイアログ --- */
.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--fg);
  padding: 0;
  width: min(92vw, 380px);
}
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-close-row { display: flex; justify-content: flex-end; }
.dialog-x {
  border: 0; background: none; color: var(--muted);
  font-size: 1.4rem; line-height: 1; padding: 6px 12px; min-height: 0; cursor: pointer;
}
.dialog-body { padding: 0 16px 16px; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tab {
  flex: 1; background: none; border: 0; border-bottom: 2px solid var(--border);
  border-radius: 0; color: var(--muted); padding: 8px 4px;
}
.tab.is-active { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
.field { display: block; margin: 10px 0; }
.field span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
.field input { width: 100%; flex: none; }
