/* かぶせ三目道場 — スタイル (設計書 v2 §9/§10 準拠の初期値) */

/* ===== デザイントークン (§9.2) ===== */
:root {
  --walnut: #6b4a2b;
  --walnut-dark: #4e3520;
  --maple: #c8a874;
  --maple-light: #ddc398;
  --tatami: #ede4d3;
  --tatami-deep: #e2d6bf;
  --sumi: #2b2622;
  --brass: #b08d57;
  --brass-light: #d9bd86;
  --indigo: #3a5a78;   /* プレイヤーA 藍 */
  --indigo-hi: #5b80a3;
  --vermilion: #b5462f; /* プレイヤーB 朱 */
  --vermilion-hi: #d56a52;
  --danger: #b5462f;

  --radius-ui: 14px;
  --gap: 12px;

  /* 立体感: 2層影 (接地影 + 環境影) §9.5 */
  --piece-shadow: 0 1px 2px rgba(43,38,34,.55), 0 6px 12px rgba(43,38,34,.28);
  --piece-shadow-lift: 0 3px 4px rgba(43,38,34,.5), 0 14px 22px rgba(43,38,34,.32);

  --ease: cubic-bezier(.2, 0, 0, 1);
  --t-fast: 120ms;
  --t-move: 240ms;

  --font-serif: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  --font-sans: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font-sans);
  color: var(--sumi);
  background:
    radial-gradient(120% 80% at 50% -10%, var(--tatami) 0%, var(--tatami-deep) 70%, #d2c4a8 100%);
  min-height: 100%;
}
body {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
  -webkit-user-select: none; user-select: none;
}

.app { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 14px; }

/* ===== ヘッダー (看板) ===== */
.header { text-align: center; padding-top: 4px; }
.title {
  font-family: var(--font-serif);
  font-size: 26px; letter-spacing: .12em; margin: 0;
  color: var(--walnut-dark);
  text-shadow: 0 1px 0 rgba(255,255,255,.4);
}
.title .ruby { font-size: 11px; display: block; letter-spacing: .3em; color: var(--brass); margin-bottom: 2px; }
.subtitle { font-size: 11px; color: var(--brass); letter-spacing: .25em; margin-top: 2px; }

/* ===== 手番表示 ===== */
.turnbar {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-family: var(--font-serif); font-size: 15px;
  background: linear-gradient(180deg, var(--maple-light), var(--maple));
  border: 1px solid var(--brass);
  border-radius: var(--radius-ui);
  padding: 8px 12px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 2px 6px rgba(43,38,34,.15);
}
.turn-dot { width: 16px; height: 16px; border-radius: 50%; box-shadow: var(--piece-shadow); }
.turn-dot.A { background: radial-gradient(circle at 35% 30%, var(--indigo-hi), var(--indigo)); }
.turn-dot.B { background: radial-gradient(circle at 35% 30%, var(--vermilion-hi), var(--vermilion)); }

/* ===== 盤 (§9.2 木目) ===== */
.board-wrap { position: relative; }
.board {
  position: relative;
  width: 100%; aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  padding: 14px;
  border-radius: 18px;
  background:
    repeating-linear-gradient(91deg, rgba(0,0,0,.05) 0 2px, transparent 2px 9px),
    linear-gradient(145deg, var(--walnut) 0%, var(--walnut-dark) 100%);
  border: 3px solid var(--brass);
  box-shadow:
    inset 0 2px 8px rgba(0,0,0,.35),
    0 10px 30px rgba(43,38,34,.35);
}

.cell {
  position: relative;
  border-radius: 12px;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.03) 0 3px, transparent 3px 8px),
    linear-gradient(150deg, #5e4126, #432e1c);
  box-shadow: inset 0 2px 5px rgba(0,0,0,.45), inset 0 -1px 0 rgba(255,255,255,.05);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: box-shadow var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.cell.legal::after {
  content: ""; position: absolute; inset: 14%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(217,189,134,.55), rgba(217,189,134,0) 70%);
  border: 2px dashed var(--brass-light);
  animation: pulse 1.4s var(--ease) infinite;
}
.cell.danger::after {
  content: ""; position: absolute; inset: 12%;
  border-radius: 50%;
  border: 2px solid var(--danger);
  background: radial-gradient(circle, rgba(181,70,47,.28), rgba(181,70,47,0) 70%);
  animation: pulse 1s var(--ease) infinite;
}
.cell.win { box-shadow: inset 0 0 0 3px var(--brass-light), inset 0 2px 5px rgba(0,0,0,.45); }
@keyframes pulse { 0%,100%{opacity:.5;} 50%{opacity:1;} }

/* ===== コマ (§9.5 立体・2層影) ===== */
.piece {
  position: relative;
  border-radius: 50%;
  box-shadow: var(--piece-shadow);
  transition: transform var(--t-move) var(--ease), box-shadow var(--t-fast) var(--ease);
  display: flex; align-items: center; justify-content: center;
}
.piece::before { /* ハイライト(面取り) */
  content: ""; position: absolute; inset: 12%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, rgba(255,255,255,.45), rgba(255,255,255,0) 55%);
}
.piece::after { /* 木の年輪リング */
  content: ""; position: absolute; inset: 22%;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,.12);
}
.piece.A { background: radial-gradient(circle at 38% 30%, var(--indigo-hi), var(--indigo) 70%, #2b4258); }
.piece.B { background: radial-gradient(circle at 38% 30%, var(--vermilion-hi), var(--vermilion) 70%, #8f3424); }
/* サイズ: 盤マスに対する比率 */
.piece.s1 { width: 40%; height: 40%; }
.piece.s2 { width: 60%; height: 60%; }
.piece.s3 { width: 82%; height: 82%; }

.piece.selected { transform: translateY(-4px) scale(1.06); box-shadow: var(--piece-shadow-lift); }
.piece.placed { animation: drop var(--t-move) var(--ease); }
@keyframes drop {
  0% { transform: translateY(-26px) scale(1.12); opacity: .4; }
  70% { transform: translateY(2px) scale(.98); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
.cell.shake { animation: shake .26s var(--ease); }
@keyframes shake { 0%,100%{transform:translateX(0);} 25%{transform:translateX(-5px);} 75%{transform:translateX(5px);} }

/* ===== 埋まったコマ: 案A 常時インジケータ (§8.6) ===== */
.buried {
  position: absolute; bottom: 6%;
  display: flex; gap: 3px; justify-content: center; width: 100%;
  pointer-events: none;
}
.buried .ring {
  width: 8px; height: 8px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,.25);
}
.buried .ring.A { background: var(--indigo); }
.buried .ring.B { background: var(--vermilion); }

/* お助けモード(案C): 全コマ表示時はスタックを縦に少しずらして全部見せる */
.cell.showstacks .stack { position: relative; width: 82%; height: 82%; }
.cell.showstacks .stack .piece {
  position: absolute; left: 50%; transform: translateX(-50%);
}

/* ===== トレイ (手駒) ===== */
.trays { display: flex; flex-direction: column; gap: 8px; }
.tray {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--radius-ui);
  background: linear-gradient(180deg, var(--maple-light), var(--maple));
  border: 1px solid var(--brass);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 2px 6px rgba(43,38,34,.12);
  opacity: .55; transition: opacity var(--t-fast) var(--ease);
}
.tray.active { opacity: 1; box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 0 0 2px var(--brass-light), 0 3px 8px rgba(43,38,34,.18); }
.tray-label { font-family: var(--font-serif); font-size: 13px; min-width: 64px; color: var(--walnut-dark); }
.tray-pieces { display: flex; align-items: center; gap: 14px; flex: 1; justify-content: space-around; }
.tray-slot { position: relative; width: 46px; height: 46px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.tray-slot[data-count="0"] { opacity: .25; pointer-events: none; }
.tray-slot .piece { position: static; }
.tray-slot .count {
  position: absolute; right: -2px; bottom: -2px;
  font-size: 11px; font-variant-numeric: tabular-nums;
  background: var(--sumi); color: var(--tatami);
  border-radius: 8px; padding: 0 5px; line-height: 16px;
}
.tray-slot.selected .piece { transform: scale(1.1); box-shadow: var(--piece-shadow-lift); }

/* ===== コントロール ===== */
.controls { display: flex; flex-direction: column; gap: 10px; }
.modes { display: flex; gap: 8px; }
.sides { display: flex; gap: 8px; align-items: center; }
.sides-label { font-size: 11px; color: var(--brass); letter-spacing: .05em; white-space: nowrap; }
.sides .side { font-size: 12px; padding: 9px 6px; }
.btn {
  flex: 1; font-family: var(--font-sans); font-size: 13px;
  padding: 11px 8px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--brass);
  background: linear-gradient(180deg, #fff7ea, var(--maple-light));
  color: var(--walnut-dark);
  box-shadow: 0 2px 4px rgba(43,38,34,.15);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  min-height: 44px;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 2px rgba(43,38,34,.15); }
.btn.active { background: linear-gradient(180deg, var(--brass-light), var(--brass)); color: #fff; font-weight: 700; }
.btn.ghost { background: rgba(255,255,255,.4); }
.row { display: flex; gap: 8px; align-items: center; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--walnut-dark); }
.toggle input { width: 18px; height: 18px; accent-color: var(--brass); }
.stats { font-size: 12px; color: var(--brass); text-align: center; letter-spacing: .05em; }

/* ===== 勝敗オーバーレイ ===== */
.overlay {
  position: fixed; inset: 0; display: none;
  align-items: center; justify-content: center; padding: 24px;
  background: rgba(43,38,34,.55); backdrop-filter: blur(3px);
  z-index: 20;
}
.overlay.show { display: flex; animation: fade .3s var(--ease); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.card {
  background: linear-gradient(160deg, #fff7ea, var(--maple-light));
  border: 3px solid var(--brass); border-radius: 20px;
  padding: 28px 26px; text-align: center; max-width: 320px; width: 100%;
  box-shadow: 0 20px 50px rgba(43,38,34,.45);
  animation: rise .4s var(--ease);
}
@keyframes rise { from { transform: translateY(20px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.card h2 { font-family: var(--font-serif); font-size: 28px; margin: 0 0 6px; color: var(--walnut-dark); }
.card p { font-size: 14px; color: var(--sumi); margin: 0 0 18px; }
.card .winner-dot { width: 40px; height: 40px; border-radius: 50%; margin: 0 auto 12px; box-shadow: var(--piece-shadow); }
.card .winner-dot.A { background: radial-gradient(circle at 35% 30%, var(--indigo-hi), var(--indigo)); }
.card .winner-dot.B { background: radial-gradient(circle at 35% 30%, var(--vermilion-hi), var(--vermilion)); }

/* 紙吹雪(金粉) */
.confetti { position: fixed; top: -10px; width: 8px; height: 8px; z-index: 21; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
