/* ============================================================
   style.css (v3)
   - 先後選択モーダル
   - 駒移動アニメーション
   - last-from（指し手の元マス）ハイライト
   - KIF コピーボタン
   - その他 v2 継承
   ============================================================ */
:root {
  --bg: #16130f;
  --bg-vignette: #201a12;
  --board-light: #e7c07f;
  --board-dark: #cf9f56;
  --board-line: #6b4423;
  --frame: #3a2a18;
  --frame-shadow: #0b0906;
  --piece-face: #f4e8d0;
  --piece-face-edge: #d8c399;
  --piece-ink: #241a0d;
  --accent: #b6392a;
  --accent-soft: rgba(182, 57, 42, 0.18);
  --accent-dim: rgba(182, 57, 42, 0.09);
  --ink-cream: #efe4cc;
  --ink-dim: #a99b86;
  --panel: #211b13;
  --panel-border: #4a3a25;
  --font-display: 'Shippori Mincho', serif;
  --font-body: 'Zen Kaku Gothic New', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, var(--bg-vignette) 0%, var(--bg) 60%);
  color: var(--ink-cream);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 60px;
  display: grid;
  grid-template-columns: 1fr 240px;
  grid-template-areas: "top top" "board log";
  gap: 18px 24px;
}

/* ---------- ヘッダー ---------- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--panel-border);
}

.logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.06em;
  margin: 0;
  color: var(--ink-cream);
}
.logo span { color: var(--accent); font-style: normal; }

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.move-counter {
  font-family: var(--font-display); font-size: 13px;
  color: var(--ink-dim); padding: 4px 10px;
  border: 1px solid var(--panel-border); border-radius: 6px;
}
.move-counter span { color: var(--ink-cream); font-weight: 700; }

.btn {
  background: var(--accent); color: #fff2ea; border: none;
  border-radius: 6px; padding: 8px 16px; font-family: var(--font-body);
  font-weight: 700; font-size: 13px; letter-spacing: 0.03em;
  cursor: pointer; transition: filter 0.15s ease, transform 0.1s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn-ghost {
  background: transparent; color: var(--ink-dim);
  border: 1px solid var(--panel-border);
}
.btn-ghost:hover { color: var(--ink-cream); border-color: var(--ink-dim); }

/* ---------- 盤エリア ---------- */
.board-area {
  grid-area: board;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}

.side-panel {
  width: 100%; max-width: 660px;
  display: flex; align-items: center; gap: 14px;
}
.side-panel--top { flex-direction: row; }
.side-panel--bottom { flex-direction: row; }

.player-tag {
  font-family: var(--font-display); font-weight: 700; font-size: 15px;
  white-space: nowrap; display: flex; align-items: center; gap: 8px;
  color: var(--ink-cream);
}
.status-pill {
  font-family: var(--font-body); font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: transparent;
  color: var(--ink-dim); border: 1px solid var(--panel-border); min-width: 12px;
}
.status-pill.turn { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.status-pill.check { background: var(--accent); color: #fff; border-color: var(--accent); }

.hand {
  flex: 1; min-height: 52px; background: var(--panel);
  border: 1px solid var(--panel-border); border-radius: 8px;
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; flex-wrap: wrap;
}

.hand-piece {
  position: relative; width: 40px; height: 44px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.hand-piece.selected .piece-shape { outline: 2px solid var(--accent); outline-offset: 2px; }
.hand-piece .count {
  position: absolute; bottom: -4px; right: -4px;
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
  border-radius: 999px; padding: 1px 5px; line-height: 1.3;
}
.hand-empty { color: var(--ink-dim); font-size: 12px; padding: 0 4px; }

/* ---------- 座標 + 評価バー ---------- */
.board-with-coords { display: flex; align-items: stretch; gap: 6px; }

.coord-files {
  display: flex; justify-content: space-around;
  padding: 0 14px 0 30px;
  font-family: var(--font-display); font-size: 11px;
  color: var(--ink-dim); max-width: 660px; width: 100%;
}
.coord-ranks {
  display: flex; flex-direction: column; justify-content: space-around;
  padding: 14px 0; font-family: var(--font-display); font-size: 11px;
  color: var(--ink-dim); width: 16px; flex-shrink: 0; text-align: center;
}

.eval-bar-wrap {
  width: 10px; flex-shrink: 0; border-radius: 4px; overflow: hidden;
  background: var(--accent); border: 1px solid var(--panel-border); position: relative;
}
.eval-bar-sente {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--ink-cream); transition: height 0.4s ease; height: 50%;
}

/* ---------- 盤面 ---------- */
.board-wrap {
  position: relative; padding: 14px;
  background: linear-gradient(180deg, var(--frame), #2a1d10);
  border-radius: 10px;
  box-shadow: 0 18px 40px -12px var(--frame-shadow), 0 0 0 1px #000;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(38px, 56px));
  grid-template-rows: repeat(9, minmax(38px, 56px));
  background: linear-gradient(135deg, var(--board-light), var(--board-dark));
  border: 2px solid var(--board-line);
}

.cell {
  position: relative; border: 1px solid var(--board-line);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

.cell.highlight::after {
  content: ""; position: absolute; inset: 6px; border-radius: 50%;
  background: rgba(182, 57, 42, 0.25); border: 2px solid var(--accent);
  pointer-events: none;
}
.cell.selected { box-shadow: inset 0 0 0 3px var(--accent); }
.cell.last-move { box-shadow: inset 0 0 0 2px rgba(182,57,42,0.55); }
/* 前手の出発マス（薄めに） */
.cell.last-from { background: rgba(182,57,42,0.10); }

/* 将棋の駒 */
.piece-shape {
  width: 84%; height: 90%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, var(--piece-face), var(--piece-face-edge));
  clip-path: polygon(50% 0%, 92% 22%, 100% 100%, 0% 100%, 8% 22%);
  box-shadow: 0 2px 3px rgba(0,0,0,0.35); user-select: none;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.piece-shape.gote { transform: rotate(180deg); }
.piece-shape .label {
  font-family: var(--font-display); font-weight: 700;
  color: var(--piece-ink); line-height: 1; text-align: center; white-space: pre;
}
.piece-shape.promoted .label { color: var(--accent); }
.piece-shape.king .label { font-weight: 700; }

/* ---------- 棋譜パネル ---------- */
.log-panel {
  grid-area: log; background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 14px; max-height: 680px; overflow-y: auto;
}
.log-panel h2 {
  font-family: var(--font-display); font-size: 15px; margin: 0 0 8px;
  color: var(--ink-cream); border-bottom: 1px solid var(--panel-border); padding-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.move-log {
  margin: 0; padding: 0 0 0 20px; font-size: 13px;
  color: var(--ink-dim); line-height: 1.9;
}
.move-log li::marker { color: var(--ink-dim); font-size: 11px; }
.move-log li.mine { color: var(--ink-cream); }

.btn-kif {
  background: transparent; color: var(--ink-dim);
  border: 1px solid var(--panel-border); border-radius: 4px;
  padding: 2px 8px; font-size: 11px; font-family: var(--font-body); cursor: pointer;
  flex-shrink: 0;
}
.btn-kif:hover { color: var(--ink-cream); border-color: var(--ink-dim); }

/* ---------- モーダル（共通） ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(10, 8, 5, 0.72);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 10px; padding: 24px 28px; text-align: center; min-width: 260px;
}
.modal-card p {
  font-family: var(--font-display); font-size: 17px; margin: 0 0 16px;
  color: var(--ink-cream); white-space: pre-line;
}
.modal-actions { display: flex; gap: 10px; justify-content: center; }

.btn-online {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-online:hover { background: var(--accent-soft); }

.online-badge {
  font-size: 11px; font-weight: 700; color: var(--accent);
  border: 1px solid var(--accent); border-radius: 999px;
  padding: 4px 10px; background: var(--accent-soft);
}

.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--accent);
  color: var(--ink-cream); padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 100; box-shadow: 0 8px 20px rgba(0,0,0,0.4);
  animation: toast-in-out 4s ease forwards;
}
@keyframes toast-in-out {
  0% { opacity: 0; transform: translate(-50%, -10px); }
  10%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -10px); }
}

.modal-card--online { min-width: 300px; max-width: 340px; }
.room-code {
  font-family: var(--font-display); font-size: 40px; font-weight: 700;
  letter-spacing: 0.15em; color: var(--accent); text-align: center;
  padding: 10px 0; margin: 4px 0;
}
.online-hint { font-size: 12px; color: var(--ink-dim); text-align: center; margin: 4px 0 0; }
.online-divider {
  text-align: center; font-size: 11px; color: var(--ink-dim);
  margin: 18px 0; position: relative;
}
.online-divider::before, .online-divider::after {
  content: ""; position: absolute; top: 50%; width: 40%;
  height: 1px; background: var(--panel-border);
}
.online-divider::before { left: 0; }
.online-divider::after { right: 0; }
.join-row { display: flex; gap: 8px; justify-content: center; }
.join-row input {
  width: 100px; text-align: center; font-size: 20px;
  letter-spacing: 0.2em; background: var(--bg); color: var(--ink-cream);
  border: 1px solid var(--panel-border); border-radius: 6px; padding: 8px;
  font-family: var(--font-display);
}
.online-error {
  font-size: 12px; color: var(--accent); text-align: center; margin: 12px 0 0;
}

/* ---------- レスポンシブ ---------- */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "board" "log";
  }
  .log-panel { max-height: 200px; }
  .board {
    grid-template-columns: repeat(9, minmax(28px, 40px));
    grid-template-rows: repeat(9, minmax(28px, 40px));
  }
  .hand-piece { width: 34px; height: 38px; }
  .coord-files { font-size: 9px; }
  .coord-ranks { font-size: 9px; width: 12px; }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
  .eval-bar-sente { transition: none; }
  .piece-shape { transition: none; }
}

/* ---------- ニックネーム入力 ---------- */
.nickname-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 16px; justify-content: center;
}
.nickname-label {
  font-size: 13px; color: var(--ink-dim); white-space: nowrap;
}
.nickname-input {
  background: var(--bg); color: var(--ink-cream);
  border: 1px solid var(--panel-border); border-radius: 6px;
  padding: 6px 10px; font-family: var(--font-body); font-size: 13px;
  width: 140px;
}
.nickname-input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

/* ---------- ロビー ---------- */
.lobby-section {
  margin-top: 18px; border-top: 1px solid var(--panel-border); padding-top: 14px;
}
.lobby-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.lobby-title {
  font-family: var(--font-display); font-size: 14px; color: var(--ink-cream); font-weight: 700;
}
.btn-lobby-refresh {
  background: transparent; border: 1px solid var(--panel-border); color: var(--ink-dim);
  border-radius: 4px; padding: 2px 8px; cursor: pointer; font-size: 14px;
}
.btn-lobby-refresh:hover { color: var(--ink-cream); border-color: var(--ink-dim); }
.lobby-list {
  max-height: 130px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
}
.lobby-empty {
  font-size: 12px; color: var(--ink-dim); text-align: center; padding: 8px 0;
}
.lobby-room {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--panel-border);
  border-radius: 6px; padding: 6px 10px;
}
.lobby-room-code {
  font-family: var(--font-display); font-size: 16px; font-weight: 700;
  color: var(--accent); letter-spacing: 0.1em; min-width: 48px;
}
.lobby-room-nick {
  flex: 1; font-size: 13px; color: var(--ink-cream); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-lobby-join {
  background: var(--accent); color: #fff2ea; border: none;
  border-radius: 4px; padding: 4px 12px; font-size: 12px; font-weight: 700;
  cursor: pointer; flex-shrink: 0;
}
.btn-lobby-join:hover { filter: brightness(1.12); }

/* ---------- チャット ---------- */
.chat-area {
  width: 100%; max-width: 660px;
  border: 1px solid var(--panel-border); border-radius: 8px;
  background: var(--panel); overflow: hidden; margin-top: 4px;
}
.chat-messages {
  height: 120px; overflow-y: auto; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 4px;
}
.chat-msg {
  display: flex; gap: 6px; align-items: baseline; font-size: 12px;
}
.chat-msg--mine {
  flex-direction: row-reverse;
}
.chat-name {
  font-weight: 700; color: var(--accent); white-space: nowrap; font-size: 11px;
}
.chat-msg--mine .chat-name { color: var(--ink-dim); }
.chat-text {
  background: var(--bg); border-radius: 4px; padding: 3px 8px;
  color: var(--ink-cream); max-width: 80%; word-break: break-word;
}
.chat-msg--mine .chat-text { background: rgba(182,57,42,0.18); }
.chat-input-row {
  display: flex; gap: 0; border-top: 1px solid var(--panel-border);
}
.chat-input {
  flex: 1; background: transparent; border: none; padding: 8px 10px;
  color: var(--ink-cream); font-family: var(--font-body); font-size: 13px;
  outline: none;
}
.btn-chat {
  background: var(--accent); color: #fff2ea; border: none;
  padding: 8px 14px; font-family: var(--font-body); font-size: 12px;
  font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.btn-chat:hover { filter: brightness(1.12); }

/* ---------- プレイヤータグ em (ニックネーム) ---------- */
.player-tag em {
  font-style: normal; color: var(--accent); font-size: 13px; font-weight: 400;
}


/* ============================================================
   プレミアム設定 追加スタイル (v5)
   ============================================================ */

/* ---------- 設定モーダル セレクト ---------- */
.settings-select {
  background: var(--bg); color: var(--ink-cream);
  border: 1px solid var(--panel-border); border-radius: 6px;
  padding: 4px 8px; font-family: var(--font-body); font-size: 13px;
  cursor: pointer; min-width: 110px;
}
.settings-select:focus { outline: 2px solid var(--accent); }

/* ---------- プレミアムロック行 ---------- */
.settings-row.premium-locked { opacity: 0.45; pointer-events: none; position: relative; }
.premium-lock-badge {
  font-size: 10px; background: linear-gradient(45deg,#ffd700,#ff8c00);
  color: #fff; border-radius: 4px; padding: 1px 5px; margin-left: 6px;
  font-weight: 700; vertical-align: middle; white-space: nowrap;
}

/* ---------- 持ち時間表示 ---------- */
.clock-wrap {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; max-width: 660px; padding: 4px 0;
}
.clock-box {
  font-family: var(--font-display); font-size: 22px; font-weight: 700;
  color: var(--ink-cream); background: var(--panel);
  border: 1px solid var(--panel-border); border-radius: 6px;
  padding: 4px 14px; letter-spacing: 0.06em; min-width: 90px; text-align: center;
}
.clock-box.active { color: var(--accent); border-color: var(--accent); }
.clock-box.low { color: #e74c3c; border-color: #e74c3c; animation: clock-blink 1s step-end infinite; }
@keyframes clock-blink { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* ---------- 駒移動アニメーション ---------- */
@keyframes piece-move {
  0%   { transform: scale(1.18) translateY(-4px); opacity: 0.7; }
  100% { transform: scale(1) translateY(0);       opacity: 1; }
}
.piece-shape.moving { animation: piece-move 0.18s ease-out forwards; }

/* ---------- 王手エフェクト ---------- */
@keyframes check-flash {
  0%,100% { box-shadow: inset 0 0 0 3px rgba(231,76,60,0); }
  50%      { box-shadow: inset 0 0 0 3px rgba(231,76,60,0.9); }
}
.cell.check-king { animation: check-flash 0.6s ease 3; }

/* ---------- 勝利エフェクト ---------- */
.victory-overlay {
  position: fixed; inset: 0; pointer-events: none; z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.victory-text {
  font-family: var(--font-display); font-size: 64px; font-weight: 700;
  color: #ffd700; text-shadow: 0 0 30px rgba(255,215,0,0.8), 0 4px 12px rgba(0,0,0,0.6);
  animation: victory-anim 2.5s ease forwards;
}
@keyframes victory-anim {
  0%   { opacity: 0; transform: scale(0.5); }
  20%  { opacity: 1; transform: scale(1.1); }
  40%  { transform: scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1); }
}

/* ---------- ダークモード / ライトモード ---------- */
body.theme-light {
  --bg: #f5f0e8; --bg-vignette: #ede5d5;
  --board-light: #e7c07f; --board-dark: #cf9f56;
  --frame: #8b6340; --frame-shadow: rgba(0,0,0,0.2);
  --piece-face: #f4e8d0; --piece-face-edge: #d8c399;
  --piece-ink: #241a0d; --accent: #b6392a; --accent-soft: rgba(182,57,42,0.12);
  --ink-cream: #2c1f0e; --ink-dim: #6b5540;
  --panel: #fff9f0; --panel-border: #d4b896;
  background: radial-gradient(ellipse at 50% 0%, var(--bg-vignette) 0%, var(--bg) 60%);
}

/* ---------- 盤面テーマ ---------- */
body.board-theme-kuro .board-wrap {
  background: linear-gradient(180deg, #1a1a1a, #0d0d0d);
}
body.board-theme-kuro .board {
  background: linear-gradient(135deg, #2a2a2a, #1a1a1a);
  --board-line: #444;
}
body.board-theme-washi .board {
  background: linear-gradient(135deg, #f0e8d0, #e0d0b0);
  --board-line: #9b8060;
}
body.board-theme-ao .board {
  background: linear-gradient(135deg, #c8dff0, #a0c4e0);
  --board-line: #5080a0;
}

/* ---------- 駒デザイン ---------- */
body.piece-style-en .piece-shape .label { font-family: monospace; font-size: 11px !important; letter-spacing: 0; }
body.piece-style-brush .piece-shape .label { font-family: var(--font-display); font-style: italic; }

/* ---------- 盤面サイズ ---------- */
body.board-size-small .board {
  grid-template-columns: repeat(9, 32px);
  grid-template-rows: repeat(9, 32px);
}
body.board-size-large .board {
  grid-template-columns: repeat(9, 64px);
  grid-template-rows: repeat(9, 64px);
}

/* ---------- チャットスタンプ ---------- */
.stamp-bar {
  display: flex; gap: 6px; padding: 4px 8px; border-top: 1px solid var(--panel-border);
  flex-wrap: wrap;
}
.stamp-btn {
  background: var(--bg); border: 1px solid var(--panel-border); border-radius: 4px;
  color: var(--ink-cream); font-size: 12px; padding: 3px 8px; cursor: pointer;
}
.stamp-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- プレミアムバッジ（ニックネーム横） ---------- */
.nick-premium-badge {
  font-size: 9px; background: linear-gradient(45deg,#ffd700,#ff8c00);
  color: #fff; border-radius: 3px; padding: 1px 4px; font-weight: 700;
  vertical-align: middle; margin-left: 4px;
}

/* ---------- 対局履歴モーダル ---------- */
.history-list { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.history-item {
  background: var(--bg); border: 1px solid var(--panel-border); border-radius: 6px;
  padding: 8px 12px; display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
}
.history-item-info { color: var(--ink-dim); font-size: 11px; }
.history-item-result { font-weight: 700; color: var(--accent); }

/* ---------- 観戦モード ---------- */
.spectate-badge {
  font-size: 11px; color: #27ae60; border: 1px solid #27ae60;
  border-radius: 999px; padding: 2px 8px; background: rgba(39,174,96,0.1);
}
