/* 盤面デザインはUIモック（docs/UIモック_盤面デザイン.html）のトークンを踏襲 */
:root {
  --bg: #14171f;
  --panel: #1d222e;
  --panel-edge: #2a3040;
  --ink: #e8e4da;
  --ink-dim: #9a968c;
  --accent: #c9a44c;
  --board-light: #e9c88f;
  --board-dark: #dcb572;
  --board-line: #6b4a26;
  --piece-face: #f3ddb0;
  --piece-edge: #b98d4f;
  --last-move: rgba(201, 164, 76, .45);
  --turn-glow: #c9a44c;
  --hint: rgba(58, 122, 66, .55);
  --danger: #b3593f;
  --cell: min(52px, calc((100vw - 130px) / 9));
}
/* 和テーマ: 和紙の質感 + 朱のアクセント */
[data-theme="wa"] {
  --bg: #ede4cf;
  --panel: #faf5e8;
  --panel-edge: #d6c8a6;
  --ink: #33291a;
  --ink-dim: #8a7c63;
  --accent: #b0541c;
  --last-move: rgba(176, 84, 28, .26);
  --turn-glow: #b0541c;
  --hint: rgba(74, 128, 82, .5);
}
[data-theme="wa"] body {
  background:
    radial-gradient(ellipse at 15% -5%, rgba(255, 253, 245, .8), transparent 55%),
    radial-gradient(ellipse at 90% 100%, rgba(176, 84, 28, .05), transparent 45%),
    repeating-linear-gradient(2deg, transparent 0 3px, rgba(140, 110, 60, .022) 3px 4px),
    repeating-linear-gradient(92deg, transparent 0 5px, rgba(140, 110, 60, .018) 5px 7px),
    var(--bg);
}
[data-theme="wa"] .card {
  box-shadow: 0 2px 14px rgba(122, 90, 46, .14);
  background:
    radial-gradient(ellipse at 0% 0%, rgba(255, 255, 255, .7), transparent 60%),
    var(--panel);
}
[data-theme="wa"] .card h2 { color: var(--accent); }
[data-theme="wa"] .player.active { box-shadow: 0 0 14px rgba(176, 84, 28, .22); }
[data-theme="wa"] .kifu li.cur { background: rgba(176, 84, 28, .12); }
[data-theme="wa"] .banner { background: var(--panel); }
[data-theme="wa"] input, [data-theme="wa"] select, [data-theme="wa"] textarea {
  background: #fffdf6;
}
[data-theme="wa"] .btn { background: #fffdf6; }
[data-theme="wa"] .btn.primary { background: var(--accent); color: #fffdf6; border-color: var(--accent); }
[data-theme="wa"] .btn.primary:hover { opacity: .88; color: #fffdf6; }
* { margin: 0; padding: 0; box-sizing: border-box; }
/* display指定を持つ要素（.modal, .btn, .promo-dialog等）でもhidden属性を必ず優先させる */
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  min-height: 100vh;
  transition: background .3s, color .3s;
}
header { display: flex; align-items: baseline; gap: 14px; padding: 16px 20px 8px; }
header h1 { font-size: 21px; letter-spacing: .35em; font-weight: 600; }
header h1 .h1-sub { font-size: 12px; letter-spacing: .25em; color: var(--ink-dim); font-weight: 400; }
header .sub { color: var(--ink-dim); font-size: 12px; letter-spacing: .1em; }
header .spacer { flex: 1; }
.plainlink { color: inherit; text-decoration: none; }
.plainlink:hover { color: var(--accent); }
.ai-face { display: inline-flex; align-items: center; cursor: default; }
.ai-face svg { display: block; }
#ai-list .ai-face { cursor: pointer; }
.avatar svg { display: block; }
#user-chip.linked { cursor: pointer; }
#user-chip.linked:hover { color: var(--accent); }

/* ---- トップのモード選択 ---- */
.mode-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.mode-btn {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 18px 10px 14px; cursor: pointer; font-family: inherit;
  color: var(--ink); background: var(--bg); border: 1px solid var(--panel-edge); border-radius: 10px;
}
.mode-btn:hover { border-color: var(--accent); }
.mode-btn:hover .mode-title { color: var(--accent); }
.mode-icon {
  width: 40px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  clip-path: polygon(50% 0%, 91% 16%, 100% 100%, 0% 100%, 9% 16%);
  background: linear-gradient(165deg, var(--piece-face) 55%, #e2c187);
  border-bottom: 2px solid var(--piece-edge);
  font-size: 22px; font-weight: 700; color: #2a1c0d;
}
.mode-title { font-size: 15px; letter-spacing: .25em; }
.mode-desc { font-size: 11px; color: var(--ink-dim); }

#tooltip {
  position: fixed; max-width: 280px; z-index: 70; pointer-events: none;
  background: var(--panel); border: 1px solid var(--accent); color: var(--ink);
  border-radius: 8px; padding: 9px 12px; font-size: 11px; line-height: 1.8;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

#app-footer {
  text-align: center; color: var(--ink-dim); font-size: 11px;
  letter-spacing: .18em; padding: 20px 0 26px; opacity: .8;
}

/* ---- 背景装飾（自前描画の将棋盤。外部素材なし。ログイン画面・ロビーで表示） ---- */
.auth-bg { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
main > section { position: relative; z-index: 1; }
/* 対局画面では盤面に集中できるよう背景装飾を消す */
main:has(#view-game:not([hidden])) .auth-bg { display: none; }
.auth-bg::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 42%, rgba(233, 200, 143, .16), transparent 62%);
}
.auth-board {
  position: absolute; left: 50%; top: 56%; width: 940px; height: 940px;
  transform: translate(-50%, -50%) perspective(1100px) rotateX(38deg) rotateZ(-3deg);
  background:
    repeating-linear-gradient(0deg, transparent 0 102.4px, var(--board-line) 102.4px 104.4px),
    repeating-linear-gradient(90deg, transparent 0 102.4px, var(--board-line) 102.4px 104.4px),
    radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, .2), transparent 60%),
    linear-gradient(160deg, var(--board-light), var(--board-dark));
  border: 3px solid var(--board-line); border-radius: 6px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
  opacity: .42;
}
.auth-piece {
  position: absolute; width: 44px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  clip-path: polygon(50% 0%, 91% 16%, 100% 100%, 0% 100%, 9% 16%);
  background: linear-gradient(165deg, var(--piece-face) 55%, #e2c187);
  border-bottom: 2px solid var(--piece-edge);
  font-size: 26px; font-weight: 700; color: #2a1c0d;
  opacity: .3; filter: blur(.5px);
}
.card.bright {
  background: linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, 0) 40%), var(--panel);
  border-color: rgba(201, 164, 76, .45);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .55);
}
.card.bright h2 { color: var(--accent); }
#auth-switch a { color: var(--accent); }

.btn {
  font-family: inherit; font-size: 12px; letter-spacing: .12em;
  color: var(--ink); background: var(--panel); border: 1px solid var(--panel-edge);
  border-radius: 6px; padding: 7px 14px; cursor: pointer; text-decoration: none; display: inline-block;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { border-color: var(--accent); color: var(--accent); }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn[disabled] { opacity: .45; cursor: default; }

main { padding: 8px 16px 40px; }
.card {
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 12px;
  padding: 16px 18px; margin: 0 auto 14px;
}
.card.narrow { max-width: 420px; margin-top: 8vh; }
.card h2 { font-size: 13px; letter-spacing: .3em; color: var(--ink-dim); font-weight: 600; margin-bottom: 12px; }
.lobby-grid { max-width: 560px; margin: 0 auto; }
.form-col { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input, select {
  font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--panel-edge); border-radius: 6px; padding: 8px 10px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
details { margin-top: 12px; font-size: 12px; color: var(--ink-dim); }
details .form-col { margin-top: 8px; }
.msg { margin-top: 10px; font-size: 12px; color: var(--danger); min-height: 1em; white-space: pre-wrap; }
.msg.ok { color: var(--accent); }

.history { list-style: none; font-size: 13px; }
.history li { display: flex; gap: 10px; padding: 6px 2px; border-bottom: 1px dashed var(--panel-edge); align-items: baseline; }
.history li:last-child { border-bottom: none; }
.history .res-win { color: var(--accent); }
.history .res-lose { color: var(--danger); }
.history .res-draw { color: var(--ink-dim); }
.history a { color: inherit; }
.history .when { margin-left: auto; color: var(--ink-dim); font-size: 11px; }

/* ---- 対局画面（モック踏襲） ---- */
.stage { display: flex; justify-content: center; align-items: flex-start; gap: 26px; padding: 4px 0 20px; flex-wrap: wrap; }
.arena { display: flex; flex-direction: column; gap: 10px; }
.player {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--panel-edge);
  border-radius: 10px; padding: 8px 14px;
}
.player.active { border-color: var(--turn-glow); box-shadow: 0 0 14px rgba(201, 164, 76, .18); }
.player.offline { opacity: .75; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, #5a6acf, #303a7a);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: #fff; flex-shrink: 0;
}
.avatar.gote { background: linear-gradient(135deg, #b3593f, #6e2c1d); }
.avatar.big { width: 56px; height: 56px; font-size: 22px; }
.avatar.has-img { background-size: cover; background-position: center; color: transparent; }
textarea {
  font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--panel-edge); border-radius: 6px; padding: 8px 10px;
  resize: vertical;
}
textarea:focus { outline: none; border-color: var(--accent); }
.pname .plink { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.pname { font-size: 15px; }
.pmeta { font-size: 11px; color: var(--ink-dim); letter-spacing: .08em; }
.tag { font-size: 10px; border: 1px solid var(--accent); color: var(--accent); border-radius: 4px; padding: 1px 6px; margin-left: 6px; }
.clock { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; font-family: Georgia, serif; }
.clock .time { font-size: 21px; letter-spacing: .06em; }
.clock .byo { font-size: 10px; color: var(--ink-dim); letter-spacing: .12em; }
.player.active .time { color: var(--accent); }
.clock .time.byoyomi { color: var(--danger); }

.board-row { display: flex; gap: 12px; align-items: stretch; }
.komadai {
  width: calc(var(--cell) * 1.42); border-radius: 8px;
  background: linear-gradient(160deg, var(--board-light), var(--board-dark));
  border: 1px solid var(--board-line);
  box-shadow: inset 0 0 18px rgba(90, 55, 20, .25), 0 4px 14px rgba(0, 0, 0, .35);
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 4px; gap: 6px;
}
.komadai .kl { font-size: 10px; color: #6b4a26; letter-spacing: .3em; writing-mode: vertical-rl; opacity: .75; }
.komadai.top { align-self: flex-start; }
.komadai.bottom { align-self: flex-end; }
.hand-piece { position: relative; cursor: pointer; }
.hand-piece .cnt {
  position: absolute; right: -7px; bottom: -3px; font-size: 11px; font-family: Georgia, serif;
  color: var(--ink); background: var(--panel); border: 1px solid var(--panel-edge);
  border-radius: 8px; padding: 0 4px; pointer-events: none;
}
.hand-piece.selected .piece { outline: 2px solid var(--accent); outline-offset: 1px; }

.board-wrap { position: relative; padding: 20px 22px 6px 6px; }
.coords-top { display: grid; grid-template-columns: repeat(9, var(--cell)); margin-left: 6px; }
.coords-top span { text-align: center; font-size: 11px; color: var(--ink-dim); padding-bottom: 4px; }
.coords-right { position: absolute; right: 4px; top: 20px; display: grid; grid-template-rows: repeat(9, var(--cell)); }
.coords-right span { display: flex; align-items: center; font-size: 11px; color: var(--ink-dim); }

.board {
  display: grid; grid-template-columns: repeat(9, var(--cell)); grid-template-rows: repeat(9, var(--cell));
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, .18), transparent 60%),
    repeating-linear-gradient(87deg, transparent 0 14px, rgba(120, 80, 30, .05) 14px 16px),
    linear-gradient(160deg, var(--board-light), var(--board-dark));
  border: 2px solid var(--board-line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45), inset 0 0 24px rgba(90, 55, 20, .18);
  border-radius: 4px; margin-left: 6px; position: relative;
}
.cell {
  border-right: 1px solid var(--board-line);
  border-bottom: 1px solid var(--board-line);
  position: relative; display: flex; align-items: center; justify-content: center;
}
.cell:nth-child(9n) { border-right: none; }
.cell:nth-last-child(-n+9) { border-bottom: none; }
.cell.last { background: var(--last-move); }
.cell.selected { background: rgba(90, 140, 200, .35); }
.cell.hint::after {
  content: ""; position: absolute; width: 26%; height: 26%;
  background: var(--hint); border-radius: 50%; pointer-events: none;
}
.cell.hint-capture { box-shadow: inset 0 0 0 3px var(--hint); }
.star { position: absolute; width: 7px; height: 7px; background: var(--board-line); border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; }

.piece {
  width: calc(var(--cell) * .85); height: calc(var(--cell) * .92); position: relative;
  display: flex; align-items: center; justify-content: center;
  clip-path: polygon(50% 0%, 91% 16%, 100% 100%, 0% 100%, 9% 16%);
  background: linear-gradient(165deg, var(--piece-face) 55%, #e2c187);
  box-shadow: inset 0 -2px 3px rgba(120, 80, 30, .5), inset 0 1px 1px rgba(255, 255, 255, .7);
  border-bottom: 2px solid var(--piece-edge);
  font-size: calc(var(--cell) * .5); font-weight: 700; color: #2a1c0d;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .35);
  user-select: none; -webkit-user-select: none;
}
.piece.small2 { font-size: calc(var(--cell) * .34); letter-spacing: -.1em; writing-mode: vertical-rl; }
.piece.gote { transform: rotate(180deg); }
.piece.promoted { color: #a3341f; }
.komadai .piece { width: calc(var(--cell) * .7); height: calc(var(--cell) * .77); font-size: calc(var(--cell) * .4); }
.cell .piece { cursor: pointer; }

.promo-dialog {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .35); z-index: 5;
}
.promo-box { display: flex; gap: 10px; background: var(--panel); border: 1px solid var(--accent); border-radius: 10px; padding: 14px 18px; }
.promo-box .btn { font-size: 18px; padding: 10px 22px; }

.banner {
  text-align: center; padding: 12px; border-radius: 10px; font-size: 15px; letter-spacing: .1em;
  background: var(--panel); border: 1px solid var(--accent); color: var(--accent);
}

.side {
  width: 250px; background: var(--panel); border: 1px solid var(--panel-edge);
  border-radius: 12px; padding: 16px 0 12px; align-self: stretch;
  display: flex; flex-direction: column;
}
.evalbox { padding: 12px 14px 8px; border-bottom: 1px solid var(--panel-edge); }
#news-list { max-height: 230px; overflow-y: auto; }
#lang-sel { padding: 5px 6px; max-width: 110px; }

/* T-021 広告枠（表示がある時だけ出る控えめなカード） */
.ad-card { position: relative; padding: 14px 18px; }
.ad-card .ad-label {
  position: absolute; top: 8px; right: 12px; font-size: 10px; letter-spacing: .2em;
  color: var(--ink-dim); border: 1px solid var(--panel-edge); border-radius: 4px; padding: 1px 6px;
}
.ad-card a { display: block; color: inherit; text-decoration: none; }
.ad-card img { max-width: 100%; height: auto; display: block; border-radius: 8px; }
.ad-card #ad-text { display: block; font-size: 13px; line-height: 1.7; padding: 4px 0; }
.ad-card a:hover #ad-text { color: var(--accent); }
/* 対局画面のサイドパネル下部の広告（T-028。カードではなく区切り線で控えめに） */
.side-ad { border-top: 1px solid var(--panel-edge); margin-top: 4px; }
.side-ad #game-ad-text { display: block; font-size: 12.5px; line-height: 1.7; padding: 4px 0; }
.side-ad a:hover #game-ad-text { color: var(--accent); }

.eval-names { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; font-size: 11px; color: var(--ink-dim); }
.eval-names span { max-width: 48%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eval-bar {
  height: 10px; border-radius: 5px; overflow: hidden;
  background: linear-gradient(180deg, #f6f0e2, #e8dfc8); border: 1px solid var(--panel-edge);
}
#eval-fill {
  height: 100%; width: 50%; transition: width .4s;
  background: linear-gradient(180deg, #4a4038, #2a241e); border-radius: 5px 0 0 5px;
}
.eval-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 5px; }
#eval-num { font-size: 13px; font-family: Georgia, serif; letter-spacing: .05em; }
#eval-graph { width: 100%; height: 36px; margin-top: 6px; display: block; }
.side h2 { font-size: 12px; letter-spacing: .35em; color: var(--ink-dim); padding: 0 18px 10px; border-bottom: 1px solid var(--panel-edge); font-weight: 600; }
#cmt-box { border-top: 1px solid var(--panel-edge); padding-top: 10px; }
.cmt-list { max-height: 180px; overflow-y: auto; padding: 4px 14px 8px; display: flex; flex-direction: column; gap: 6px; }
.cmt-list .cmt { font-size: 13px; line-height: 1.5; }
.cmt-list .cmt .who { font-weight: 600; color: var(--ink-dim); margin-right: 6px; font-size: 12px; }
.cmt-list .cmt-empty { font-size: 12px; color: var(--ink-dim); }
#cmt-form { display: flex; gap: 6px; padding: 0 14px 12px; }
#cmt-form input { flex: 1; min-width: 0; font-size: 13px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--panel-edge); background: transparent; color: inherit; }
.cmt-note { font-size: 12px; color: var(--ink-dim); padding: 0 14px 12px; }
.kifu { flex: 1; overflow-y: auto; padding: 8px 6px; max-height: 380px; min-height: 120px; }
.kifu ol { list-style: none; }
.kifu li { display: flex; gap: 10px; padding: 5px 14px; font-size: 14px; border-radius: 6px; cursor: pointer; }
.kifu li .no { color: var(--ink-dim); font-size: 11px; width: 24px; text-align: right; padding-top: 2px; font-family: Georgia, serif; }
.kifu li.cur { background: rgba(201, 164, 76, .14); color: var(--accent); }
.nav-row { display: flex; gap: 6px; padding: 10px 14px 0; flex-wrap: wrap; }
.nav-row .btn { flex: 1 1 auto; text-align: center; font-family: monospace; padding: 7px 8px; min-width: 34px; }
.btn.icon { display: inline-flex; align-items: center; justify-content: center; padding: 7px 8px; }
.btn.icon svg { display: block; }
.side .actions { display: flex; gap: 8px; padding: 12px 14px 0; flex-wrap: wrap; }
.side .actions .btn { flex: 1 1 auto; text-align: center; }
.btn.mini { padding: 7px 9px; flex: 0 0 auto; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 22px; max-width: 440px; }
.modal-box h2 { font-size: 15px; letter-spacing: .2em; margin-bottom: 10px; }
.modal-box p { font-size: 13px; line-height: 1.8; color: var(--ink-dim); margin-bottom: 12px; }
.recovery-code {
  font-family: Georgia, monospace; font-size: 17px; letter-spacing: .08em; text-align: center;
  background: var(--bg); border: 1px dashed var(--accent); border-radius: 8px; padding: 12px; margin-bottom: 14px;
  user-select: all;
}

#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--accent); color: var(--ink);
  border-radius: 8px; padding: 10px 18px; font-size: 13px; z-index: 60;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}

/* ---- スマホ縦（M4完了条件） ---- */
@media (max-width: 720px) {
  :root { --cell: calc((100vw - 46px) / 9); }
  header { padding: 10px 12px 6px; }
  header h1 { font-size: 17px; }
  header .sub { display: none; }
  main { padding: 4px 8px 24px; }
  .stage { gap: 12px; }
  .board-row { flex-direction: column; gap: 8px; }
  .komadai {
    width: auto; flex-direction: row; align-self: stretch;
    padding: 5px 8px; gap: 8px; min-height: calc(var(--cell) * .95);
  }
  .komadai .kl { writing-mode: horizontal-tb; letter-spacing: .1em; }
  .komadai.top { order: 0; }
  .board-wrap { order: 1; padding-right: 18px; }
  .komadai.bottom { order: 2; }
  .side { width: 100%; }
  .kifu { max-height: 180px; }
  .clock .time { font-size: 17px; }
}
