:root {
  color-scheme: dark;
  --ink: #120d0a;
  --ink-soft: #211712;
  --wood-dark: #3b2418;
  --wood: #73452b;
  --wood-light: #b9794f;
  --board: #d6a568;
  --board-light: #e8c58c;
  --gold: #d9b56d;
  --gold-bright: #f3d894;
  --cream: #f6ead5;
  --muted: #b8a995;
  --danger: #d96f5d;
  --shadow: 0 24px 70px rgba(0, 0, 0, .46);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #0c0907; }
body { min-height: 100dvh; color: var(--cream); overflow-x: hidden; }
button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% -10%, rgba(237, 192, 118, .15), transparent 38%),
    linear-gradient(180deg, rgba(255,255,255,.025), transparent 18%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.012) 0 1px, transparent 1px 52px),
    linear-gradient(160deg, #1b120d, #0d0907 58%, #17100c);
}

.grain {
  position: absolute;
  inset: 0;
  opacity: .22;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 20% 40%, rgba(255,255,255,.09) 0 .6px, transparent .9px),
    radial-gradient(circle at 70% 30%, rgba(255,255,255,.055) 0 .5px, transparent .8px),
    linear-gradient(90deg, transparent 0 48%, rgba(255,255,255,.02) 49%, transparent 50%);
  background-size: 5px 5px, 7px 7px, 43px 100%;
  mix-blend-mode: soft-light;
}

.topbar {
  height: 106px;
  padding: max(14px, env(safe-area-inset-top)) clamp(18px, 4vw, 50px) 10px;
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  border-bottom: 1px solid rgba(240, 208, 147, .1);
  background: linear-gradient(180deg, rgba(7,5,4,.88), rgba(17,11,8,.64));
  backdrop-filter: blur(18px);
  z-index: 5;
}

.icon-btn {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: transparent;
  cursor: pointer;
  transition: background .2s ease, transform .2s ease;
}
.icon-btn:hover { background: rgba(255,255,255,.07); }
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 28px; fill: none; stroke: #f1e3ce; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.turn-display { text-align: center; line-height: 1; }
.timer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 90px;
  height: 34px;
  padding: 0 16px;
  border: 1px solid rgba(241, 220, 178, .22);
  border-radius: 10px;
  color: #f8ecd8;
  background: linear-gradient(180deg, rgba(45,31,24,.92), rgba(17,11,8,.96));
  box-shadow: inset 0 1px rgba(255,255,255,.06), 0 8px 20px rgba(0,0,0,.25);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 17px;
  letter-spacing: .04em;
}
.turn-label {
  margin-top: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 600;
  font-size: clamp(19px, 3vw, 26px);
  color: var(--gold-bright);
}
.micro-label { margin-top: 5px; color: #928473; font-size: 10px; letter-spacing: .14em; text-transform: uppercase; }

.game-stage {
  min-height: calc(100dvh - 106px - 92px);
  padding: 18px clamp(12px, 2.5vw, 34px) 10px;
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(420px, 620px) minmax(220px, 300px);
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 3vw, 42px);
}

.desktop-panel {
  align-self: stretch;
  max-height: 620px;
  border: 1px solid rgba(231, 199, 142, .12);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(40,27,20,.78), rgba(14,10,8,.68));
  box-shadow: inset 0 1px rgba(255,255,255,.04), 0 20px 50px rgba(0,0,0,.2);
  backdrop-filter: blur(14px);
}
.left-panel { padding: 24px; display: flex; flex-direction: column; gap: 24px; }
.brand-lockup { display: flex; gap: 14px; align-items: center; }
.brand-mark {
  width: 48px; height: 54px; display: grid; place-items: center;
  clip-path: polygon(16% 0, 84% 0, 100% 20%, 88% 100%, 12% 100%, 0 20%);
  background: linear-gradient(145deg, #edcf91, #9c6d35);
  color: #26170f; font-weight: 800; font-family: serif; font-size: 26px;
}
.brand-lockup strong { display: block; letter-spacing: .12em; font-size: 14px; }
.brand-lockup small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.level-card { margin-top: auto; padding: 18px; border-radius: 18px; background: rgba(255,255,255,.035); border: 1px solid rgba(255,255,255,.05); }
.level-card > span { display: block; font-size: 10px; letter-spacing: .18em; color: var(--muted); margin-bottom: 12px; }
.level-pill { border: 0; border-radius: 999px; padding: 10px 18px; background: linear-gradient(135deg, #ddbd7b, #8d5f2d); color: #1a100b; font-weight: 800; cursor: pointer; }
.stat-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.stat-grid div { padding: 12px 8px; text-align: center; background: rgba(255,255,255,.028); border-radius: 14px; }
.stat-grid strong { display: block; color: var(--gold-bright); font-size: 18px; }
.stat-grid span { color: var(--muted); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }

.right-panel { padding: 22px; display: flex; flex-direction: column; }
.coach-title { display: flex; justify-content: space-between; align-items: center; color: var(--gold); font-size: 10px; letter-spacing: .18em; font-weight: 700; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #70d39a; box-shadow: 0 0 12px #70d39a; }
.right-panel > p { color: #d8c9b6; font-family: Georgia, serif; line-height: 1.62; font-size: 14px; min-height: 92px; }
.evaluation-track { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; color: #8f8170; font-size: 8px; letter-spacing: .1em; }
.evaluation-track > div { height: 7px; background: #34251d; border-radius: 999px; overflow: hidden; }
.evaluation-track i { display: block; width: 50%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #f0d38f, #9f7040); transition: width .35s ease; }
.move-list { margin-top: 18px; min-height: 0; overflow: auto; flex: 1; border-top: 1px solid rgba(255,255,255,.07); padding-top: 12px; }
.move-row { display: grid; grid-template-columns: 24px 1fr 1fr; gap: 7px; padding: 7px 0; color: #cbbba7; font-family: ui-monospace, monospace; font-size: 11px; border-bottom: 1px solid rgba(255,255,255,.035); }
.move-row b { color: #76695d; font-weight: 500; }
.empty-log { padding: 22px 0; color: #6f6257; font-size: 12px; }

.board-column { width: min(100%, 620px); justify-self: center; }
.hand-zone { min-height: 58px; transition: min-height .18s ease, opacity .18s ease; }
.hand-zone.is-empty { min-height: 0; height: 0; overflow: hidden; opacity: 0; pointer-events: none; }
.hand-label { display: flex; justify-content: space-between; padding: 0 4px 7px; color: #9e8e7b; font-size: 8px; letter-spacing: .14em; text-transform: uppercase; }
.hand-label span:last-child { letter-spacing: .05em; text-transform: none; }
.hand-row { min-height: 42px; display: flex; gap: 6px; align-items: center; overflow-x: auto; scrollbar-width: none; padding: 1px 2px 6px; }
.hand-row::-webkit-scrollbar { display: none; }
.hand-empty { color: #66584d; font-size: 11px; padding-left: 4px; }
.hand-piece {
  position: relative;
  min-width: 40px; height: 42px; border: 0; cursor: pointer;
  clip-path: polygon(16% 0, 84% 0, 100% 19%, 88% 100%, 12% 100%, 0 19%);
  background: linear-gradient(145deg, #efcf91 0%, #cf9858 58%, #9b6434 100%);
  color: #321c10;
  box-shadow: none;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-weight: 800; font-size: 20px;
  transition: transform .18s ease, filter .18s ease;
}
.hand-piece:hover { filter: brightness(1.08); transform: translateY(-2px); }
.hand-piece.selected { filter: brightness(1.15); outline: 2px solid var(--gold-bright); transform: translateY(-3px); }
.hand-piece .count { position: absolute; right: 3px; bottom: 2px; min-width: 15px; height: 15px; border-radius: 8px; display: grid; place-items: center; background: #25160f; color: #ffe9b5; font: 700 9px ui-sans-serif; }
.opponent-zone .hand-piece { transform: rotate(180deg); filter: saturate(.65) brightness(.82); }
.opponent-zone .hand-piece:hover { transform: rotate(180deg) translateY(2px); }

.board-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: clamp(9px, 1.4vw, 14px);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255,255,255,.18), transparent 20%),
    linear-gradient(135deg, #7d4c2b, #382116 50%, #8f5a35);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,231,187,.26), inset 0 -10px 22px rgba(0,0,0,.34);
}
.board-frame::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(255, 223, 166, .25);
  border-radius: 5px;
  pointer-events: none;
}
.board {
  position: relative;
  z-index: 1;
  width: 100%; height: 100%;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border: 2px solid #5c341d;
  background:
    repeating-linear-gradient(90deg, rgba(82,45,22,.08) 0 1px, transparent 1px 16px),
    linear-gradient(135deg, var(--board-light), var(--board));
  box-shadow: inset 0 0 28px rgba(80,43,17,.26);
}
.board-shine { position: absolute; inset: 14px; pointer-events: none; z-index: 2; background: linear-gradient(118deg, rgba(255,255,255,.12), transparent 24% 72%, rgba(255,255,255,.05)); mix-blend-mode: soft-light; }
.cell {
  position: relative;
  border: 0;
  border-right: 1px solid rgba(72,39,20,.64);
  border-bottom: 1px solid rgba(72,39,20,.64);
  background: transparent;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
}
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-last-child(-n + 9) { border-bottom: 0; }
.cell.last-from::before, .cell.last-to::before { content: ""; position: absolute; inset: 3px; background: rgba(78, 128, 92, .22); border: 1px solid rgba(101, 175, 122, .42); }
.cell.selected-cell::before { content: ""; position: absolute; inset: 2px; border: 2px solid rgba(104, 202, 127, .9); background: rgba(86, 160, 102, .17); box-shadow: inset 0 0 14px rgba(82,170,106,.35); }
.cell.legal-target::after { content: ""; width: 18%; aspect-ratio: 1; border-radius: 50%; background: rgba(49, 72, 45, .46); box-shadow: 0 0 0 3px rgba(247, 225, 176, .14); }
.cell.capture-target::after { width: 70%; border-radius: 50%; background: transparent; border: 3px solid rgba(104, 183, 123, .72); box-shadow: inset 0 0 12px rgba(71,145,90,.18); }
.cell.hint-from::before, .cell.hint-to::before { content: ""; position: absolute; inset: 2px; border: 2px solid #f6df94; box-shadow: inset 0 0 14px rgba(246,223,148,.5), 0 0 12px rgba(246,223,148,.28); animation: hintPulse 1s ease-in-out infinite alternate; }
@keyframes hintPulse { to { opacity: .48; } }
.coord-file, .coord-rank { position: absolute; z-index: 5; color: rgba(67,38,21,.55); font: 700 7px ui-monospace, monospace; pointer-events: none; }
.coord-file { top: 2px; right: 3px; }
.coord-rank { bottom: 2px; left: 3px; }

.shogi-piece {
  position: relative;
  width: 76%;
  height: 84%;
  display: grid;
  place-items: center;
  clip-path: polygon(17% 0, 83% 0, 100% 18%, 88% 100%, 12% 100%, 0 18%);
  background:
    linear-gradient(145deg, rgba(255,255,255,.58), transparent 22%),
    linear-gradient(150deg, #f3d59a 0%, #d6a15f 55%, #a86d35 100%);
  color: #2b170d;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif CJK JP", serif;
  font-weight: 900;
  font-size: clamp(14px, 3.1vw, 31px);
  line-height: 1;
  text-shadow: 0 1px rgba(255,255,255,.35);
  filter: drop-shadow(0 3px 2px rgba(48,25,12,.5));
  transform-origin: center;
  transition: transform .15s ease, filter .15s ease;
  z-index: 2;
  user-select: none;
}
.shogi-piece::after { content: ""; position: absolute; inset: 4px 5px 5px; clip-path: inherit; border: 1px solid rgba(88,49,24,.26); }
.shogi-piece.gote { transform: rotate(180deg); background: linear-gradient(145deg, rgba(255,255,255,.12), transparent 22%), linear-gradient(150deg, #4d4039 0%, #2a2320 62%, #15110f 100%); color: #e6d1a7; text-shadow: 0 1px #000; filter: drop-shadow(0 -3px 2px rgba(33,18,11,.5)); }
.shogi-piece.promoted { color: #a22920; }
.shogi-piece.gote.promoted { color: #f28a78; }
.cell:hover .shogi-piece { filter: brightness(1.06) drop-shadow(0 3px 3px rgba(48,25,12,.5)); }
.piece-en { position: absolute; bottom: 5%; font: 700 clamp(4px, .72vw, 8px) ui-sans-serif; letter-spacing: .04em; opacity: .55; }

.thinking-banner {
  position: absolute;
  z-index: 6;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) translateY(8px);
  min-width: 210px;
  padding: 13px 18px;
  border-radius: 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  align-items: center;
  background: rgba(17,11,8,.9);
  border: 1px solid rgba(237,204,144,.25);
  box-shadow: 0 18px 45px rgba(0,0,0,.45);
  backdrop-filter: blur(14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.thinking-banner.open { opacity: 1; transform: translate(-50%, -50%); }
.thinking-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gold-bright); box-shadow: 0 0 16px var(--gold); animation: think 1s ease-in-out infinite alternate; }
@keyframes think { to { opacity: .32; transform: scale(.7); } }
.thinking-banner span:nth-child(2) { font-weight: 750; font-size: 13px; }
.thinking-banner small { grid-column: 2; color: #9f907d; margin-top: 3px; font-size: 9px; }

.bottom-controls {
  position: sticky;
  bottom: 0;
  z-index: 10;
  height: 92px;
  padding: 8px max(14px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: repeat(5, minmax(52px, 92px));
  justify-content: center;
  gap: clamp(8px, 3vw, 28px);
  background: linear-gradient(180deg, rgba(20,13,10,.68), rgba(8,5,4,.98));
  border-top: 1px solid rgba(238, 208, 153, .1);
  backdrop-filter: blur(18px);
}
.control-btn { position: relative; border: 0; background: transparent; border-radius: 16px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: #bfae98; transition: transform .18s ease, background .18s ease, color .18s ease; }
.control-btn:hover { background: rgba(255,255,255,.045); color: #f0dfc6; }
.control-btn:active { transform: scale(.92); }
.control-btn:disabled { opacity: .32; cursor: not-allowed; }
.control-btn small { font-size: 7px; letter-spacing: .12em; }
.control-icon { font-size: 27px; line-height: 1; font-weight: 300; }
.undo-icon { font-size: 36px; font-family: Georgia, serif; transform: translateY(-2px); }
.mini-board { font-size: 29px; }
.level-orb { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle at 35% 30%, #f8e8c7, #b57d3a 60%, #4c2b18); color: #2b180d; font-family: Georgia, serif; font-weight: 900; box-shadow: 0 5px 12px rgba(0,0,0,.35); }
.primary-control { color: var(--gold-bright); }
.primary-control b { position: absolute; top: 6px; right: 16px; width: 17px; height: 17px; border-radius: 50%; display: grid; place-items: center; background: #d5ad62; color: #24150d; font-size: 9px; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(7,5,4,.72);
  backdrop-filter: blur(16px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .25s ease, visibility .25s ease;
}
.modal-backdrop.open { opacity: 1; visibility: visible; pointer-events: auto; }
.modal {
  position: relative;
  width: min(92vw, 780px);
  max-height: min(90dvh, 820px);
  overflow: auto;
  padding: clamp(25px, 4vw, 46px);
  border-radius: 28px;
  text-align: center;
  border: 1px solid rgba(238,205,147,.18);
  background:
    radial-gradient(circle at 50% 0, rgba(221,176,96,.14), transparent 35%),
    linear-gradient(145deg, rgba(41,28,21,.98), rgba(13,9,7,.98));
  box-shadow: 0 40px 120px rgba(0,0,0,.65), inset 0 1px rgba(255,255,255,.06);
  transform: translateY(14px) scale(.98);
  transition: transform .25s ease;
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal-emblem { margin: 0 auto 14px; width: 62px; height: 68px; display: grid; place-items: center; clip-path: polygon(16% 0, 84% 0, 100% 20%, 88% 100%, 12% 100%, 0 20%); background: linear-gradient(145deg, #f1d59a, #a16d34); color: #23140c; font: 900 32px serif; }
.eyebrow { margin: 0 0 9px; color: var(--gold); font-size: 9px; letter-spacing: .24em; font-weight: 800; }
.modal h1, .modal h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 500; color: #f4e7d3; }
.modal h1 { font-size: clamp(30px, 5vw, 48px); }
.modal h2 { font-size: clamp(27px, 4vw, 38px); }
.modal-copy { max-width: 610px; margin: 13px auto 25px; color: #b7a895; line-height: 1.55; font-size: 13px; }
.difficulty-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.difficulty-option {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 190px;
  padding: 22px 18px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.025);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  transition: transform .16s ease, border-color .16s ease, background .16s ease, box-shadow .16s ease;
}
.difficulty-option::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(circle at 50% 12%, rgba(255,226,166,.22), transparent 48%),
    linear-gradient(145deg, rgba(218,168,84,.18), rgba(255,255,255,.025));
  transition: opacity .16s ease;
}
.difficulty-option > * { position: relative; z-index: 1; }
@media (hover: hover) and (pointer: fine) {
  .difficulty-option:hover {
    transform: translateY(-5px);
    border-color: rgba(237,204,145,.42);
    background: rgba(221,178,104,.07);
    box-shadow: 0 14px 30px rgba(0,0,0,.24);
  }
}
.difficulty-option:active,
.difficulty-option.is-selected {
  transform: scale(.975);
  border-color: rgba(244,208,137,.82);
  background: rgba(210,158,78,.1);
  box-shadow:
    0 0 0 1px rgba(238,197,117,.12),
    0 0 28px rgba(191,130,51,.2),
    inset 0 1px 0 rgba(255,239,205,.12);
}
.difficulty-option:active::before,
.difficulty-option.is-selected::before { opacity: 1; }
.difficulty-option:active .difficulty-number,
.difficulty-option.is-selected .difficulty-number {
  color: #fff1c9;
  border-color: rgba(247,214,147,.72);
  background: rgba(184,126,51,.13);
  box-shadow: 0 0 15px rgba(225,173,87,.2);
}
.difficulty-option:active strong,
.difficulty-option.is-selected strong { color: #fff2dc; }
.difficulty-option:active em,
.difficulty-option.is-selected em {
  color: #f8d68e;
  text-shadow: 0 0 10px rgba(235,185,95,.32);
}
.difficulty-option:focus-visible {
  outline: 2px solid rgba(239,205,141,.76);
  outline-offset: 3px;
}
.difficulty-number { width: 34px; height: 34px; border: 1px solid rgba(225,193,133,.3); border-radius: 50%; display: grid; place-items: center; color: var(--gold-bright); font-family: Georgia, serif; margin-bottom: 14px; }
.difficulty-option strong { font-family: Georgia, serif; font-size: 20px; font-weight: 500; }
.difficulty-option small { margin: 10px 0 16px; color: #9d8f7c; line-height: 1.45; font-size: 11px; flex: 1; }
.difficulty-option em { color: var(--gold); font-style: normal; font-size: 8px; letter-spacing: .2em; font-weight: 800; }
.offline-note { margin: 20px 0 0; color: #827466; font-size: 10px; }
.offline-note span { color: #70d39a; margin-right: 5px; }
.compact-modal { width: min(92vw, 500px); }
.two-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.secondary-action, .gold-action { min-height: 48px; border-radius: 14px; cursor: pointer; font-weight: 750; border: 1px solid rgba(255,255,255,.1); }
.secondary-action { background: rgba(255,255,255,.04); color: #d5c5b0; }
.gold-action { border: 0; background: linear-gradient(135deg, #efd395, #9f6e35); color: #21130c; box-shadow: 0 10px 26px rgba(150,100,49,.28); }
.full-action { width: 100%; margin-top: 20px; }
.close-modal { position: absolute; top: 14px; right: 16px; width: 36px; height: 36px; border: 0; background: rgba(255,255,255,.05); border-radius: 50%; color: #c8b7a2; font-size: 24px; cursor: pointer; }
.settings-sheet { text-align: left; }
.settings-sheet .eyebrow, .settings-sheet h2 { text-align: center; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 17px 0; border-bottom: 1px solid rgba(255,255,255,.07); }
.setting-row span { display: block; }
.setting-row strong { display: block; font-size: 14px; }
.setting-row small { display: block; margin-top: 4px; color: #8f8171; font-size: 10px; }
.setting-row input { appearance: none; width: 44px; height: 24px; padding: 3px; border-radius: 999px; background: #3a2d26; cursor: pointer; transition: background .2s ease; }
.setting-row input::after { content: ""; display: block; width: 18px; height: 18px; border-radius: 50%; background: #8f7f6e; transition: transform .2s ease, background .2s ease; }
.setting-row input:checked { background: #8a6439; }
.setting-row input:checked::after { transform: translateX(20px); background: #f4d994; }
.rules-sheet { text-align: left; width: min(92vw, 700px); }
.rules-sheet .eyebrow, .rules-sheet h2 { text-align: center; }
.rules-grid { margin-top: 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rules-grid article { padding: 18px; border-radius: 17px; background: rgba(255,255,255,.03); border: 1px solid rgba(255,255,255,.06); }
.rules-grid b { color: #7e6f60; font: 600 10px ui-monospace; }
.rules-grid strong { display: block; margin-top: 7px; color: #eadcc7; font-family: Georgia, serif; font-size: 18px; }
.rules-grid p { margin: 7px 0 0; color: #9d8f7e; font-size: 11px; line-height: 1.5; }
.result-sheet .modal-emblem { margin-bottom: 18px; }
.toast { position: fixed; z-index: 200; left: 50%; bottom: calc(105px + env(safe-area-inset-bottom)); transform: translate(-50%, 16px); opacity: 0; pointer-events: none; padding: 10px 15px; border-radius: 999px; background: rgba(15,10,8,.94); border: 1px solid rgba(238,203,141,.2); color: #e9d9c2; font-size: 11px; box-shadow: 0 12px 34px rgba(0,0,0,.35); transition: opacity .22s ease, transform .22s ease; white-space: nowrap; }
.toast.open { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1060px) {
  .game-stage { grid-template-columns: minmax(360px, 610px); padding-top: 12px; }
  .desktop-panel { display: none; }
}

@media (max-width: 650px) {
  .app-shell { min-height: 100dvh; }
  .topbar { height: 91px; padding: max(8px, env(safe-area-inset-top)) 18px 6px; grid-template-columns: 44px 1fr 44px; }
  .icon-btn { width: 42px; height: 42px; }
  .icon-btn svg { width: 25px; }
  .timer { min-width: 78px; height: 29px; padding: 0 12px; font-size: 14px; }
  .turn-label { margin-top: 5px; font-size: 19px; }
  .micro-label { display: none; }
  .game-stage { min-height: calc(100dvh - 91px - 78px); display: flex; align-items: center; justify-content: center; padding: 14px 8px 8px; }
  .board-column { width: min(100%, calc(100dvh - 238px)); min-width: 300px; margin: 0 auto; transform: translateY(clamp(5px, 1.1vh, 10px)); }
  .hand-zone { min-height: 39px; }
  .hand-label { padding-bottom: 3px; font-size: 6px; }
  .hand-row { min-height: 30px; gap: 3px; padding-bottom: 3px; }
  .hand-piece { min-width: 29px; height: 30px; font-size: 14px; }
  .hand-piece .count { min-width: 12px; height: 12px; font-size: 7px; }
  .hand-empty { font-size: 8px; }
  .board-frame { padding: 7px; border-radius: 5px; }
  .board-frame::before { inset: 3px; }
  .board-shine { inset: 8px; }
  .shogi-piece { width: 82%; height: 88%; font-size: clamp(13px, 5.3vw, 23px); }
  .piece-en { display: none; }
  .bottom-controls { height: 78px; grid-template-columns: repeat(5, 1fr); gap: 0; padding: 4px 7px max(5px, env(safe-area-inset-bottom)); }
  .control-btn { border-radius: 11px; }
  .control-btn small { font-size: 6px; }
  .control-icon { font-size: 23px; }
  .undo-icon { font-size: 31px; }
  .mini-board { font-size: 25px; }
  .level-orb { width: 30px; height: 30px; }
  .primary-control b { top: 3px; right: 8px; }
  .difficulty-grid { grid-template-columns: 1fr; }
  .difficulty-option { min-height: 112px; display: grid; grid-template-columns: 40px 1fr auto; grid-template-rows: auto auto; text-align: left; column-gap: 12px; padding: 15px; }
  .difficulty-number { grid-row: 1 / span 2; margin: 0; }
  .difficulty-option strong { font-size: 17px; }
  .difficulty-option small { margin: 4px 0 0; }
  .difficulty-option em { grid-column: 3; grid-row: 1 / span 2; align-self: center; }
  .modal { padding: 25px 18px; border-radius: 22px; }
  .modal-copy { margin-bottom: 18px; }
  .rules-grid { grid-template-columns: 1fr; }
}

@media (max-width: 360px), (max-height: 650px) and (max-width: 650px) {
  .topbar { height: 78px; }
  .turn-label { font-size: 16px; }
  .game-stage { min-height: calc(100dvh - 78px - 70px); padding-top: 8px; }
  .board-column { width: min(100%, calc(100dvh - 190px)); min-width: 270px; transform: translateY(3px); }
  .hand-zone { min-height: 31px; }
  .hand-label { display: none; }
  .hand-row { min-height: 27px; }
  .bottom-controls { height: 70px; }
  .control-btn small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

/* Desktop command-center layout. Kept strictly above the tablet breakpoint so the
   original one-screen mobile composition remains unchanged. */
.desktop-only { display: none; }

@media (min-width: 1061px) {
  html, body { height: 100%; overflow: hidden; }

  .app-shell {
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(218px, 270px) minmax(470px, 650px) minmax(250px, 320px);
    grid-template-rows: 76px minmax(0, 1fr) 86px;
    grid-template-areas:
      "top top top"
      "left board right"
      "left controls right";
    column-gap: clamp(16px, 2vw, 30px);
    row-gap: 14px;
    padding: 0 clamp(18px, 2.6vw, 42px) 18px;
    background:
      radial-gradient(circle at 49% 44%, rgba(218, 172, 98, .13), transparent 33%),
      radial-gradient(circle at 8% 78%, rgba(128, 75, 42, .13), transparent 30%),
      linear-gradient(155deg, #17100c 0%, #090706 58%, #130d0a 100%);
  }

  .app-shell::before {
    content: "";
    position: absolute;
    inset: 76px 0 0;
    z-index: -1;
    pointer-events: none;
    background:
      linear-gradient(90deg, transparent 0 18%, rgba(231, 196, 132, .024) 18% 18.08%, transparent 18.08% 81.92%, rgba(231, 196, 132, .024) 81.92% 82%, transparent 82%),
      repeating-linear-gradient(0deg, transparent 0 64px, rgba(255,255,255,.008) 65px);
  }

  .desktop-only { display: block; }

  .topbar {
    grid-area: top;
    height: 76px;
    padding: 10px 0;
    grid-template-columns: 1fr auto 1fr;
    border-bottom: 1px solid rgba(240, 208, 147, .11);
    background: transparent;
    backdrop-filter: none;
  }

  .topbar::before {
    content: "TACTICAL TRAINING ROOM";
    position: absolute;
    left: 50%;
    bottom: -1px;
    transform: translateX(-50%);
    padding: 0 12px;
    background: #0c0907;
    color: #6f6255;
    font-size: 7px;
    letter-spacing: .26em;
  }

  .icon-btn {
    width: max-content;
    min-width: 124px;
    height: 42px;
    padding: 0 15px;
    border: 1px solid rgba(238, 208, 153, .11);
    border-radius: 13px;
    display: flex;
    gap: 10px;
    background: rgba(255,255,255,.022);
    color: #ad9d88;
    font-size: 9px;
    font-weight: 750;
    letter-spacing: .14em;
    text-transform: uppercase;
  }

  #homeBtn { justify-self: start; }
  #restartBtn { justify-self: end; }
  #homeBtn::after { content: "Dojo home"; }
  #restartBtn::after { content: "New match"; }
  .icon-btn svg { width: 18px; }

  .turn-display {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: auto auto;
    column-gap: 14px;
    align-items: center;
    text-align: left;
  }

  .timer {
    grid-row: 1 / span 2;
    min-width: 92px;
    height: 42px;
    border-radius: 12px;
    font-size: 16px;
  }

  .turn-label {
    margin: 0;
    font-size: 19px;
    font-style: normal;
    letter-spacing: .01em;
  }

  .micro-label { margin: 5px 0 0; font-size: 8px; }

  .game-stage {
    display: contents;
    min-height: 0;
    padding: 0;
  }

  .desktop-panel {
    max-height: none;
    min-height: 0;
    border-radius: 22px;
    background:
      linear-gradient(145deg, rgba(40,27,20,.72), rgba(12,9,7,.72));
    box-shadow: inset 0 1px rgba(255,255,255,.045), 0 22px 60px rgba(0,0,0,.24);
  }

  .left-panel {
    grid-area: left;
    padding: 22px;
    gap: 17px;
    overflow: hidden;
  }

  .brand-lockup { padding-bottom: 17px; border-bottom: 1px solid rgba(255,255,255,.065); }
  .brand-mark { width: 43px; height: 49px; font-size: 23px; }
  .brand-lockup strong { font-size: 13px; }
  .brand-lockup small { font-size: 9px; }

  .session-card {
    padding: 16px;
    border: 1px solid rgba(234, 201, 143, .095);
    border-radius: 17px;
    background: linear-gradient(145deg, rgba(255,255,255,.037), rgba(255,255,255,.012));
  }

  .panel-heading {
    display: flex;
    justify-content: space-between;
    color: #8f806e;
    font-size: 7px;
    font-weight: 800;
    letter-spacing: .18em;
  }

  .panel-heading b {
    color: #80d6a1;
    font-size: 7px;
    letter-spacing: .16em;
    font-weight: 800;
  }

  .ai-profile {
    display: grid;
    grid-template-columns: 43px 1fr;
    align-items: center;
    gap: 11px;
    margin-top: 14px;
  }

  .ai-avatar {
    width: 43px;
    height: 47px;
    display: grid;
    place-items: center;
    clip-path: polygon(16% 0,84% 0,100% 20%,88% 100%,12% 100%,0 20%);
    background: linear-gradient(145deg, #53463f, #1b1715);
    color: #e6d1a7;
    font: 800 21px serif;
    box-shadow: inset 0 0 0 1px rgba(240,216,174,.16);
  }

  .ai-profile small,
  .ai-profile strong,
  .ai-profile em { display: block; }
  .ai-profile small { color: #776a5d; font-size: 6px; letter-spacing: .14em; }
  .ai-profile strong { margin-top: 3px; color: #eadcc7; font: 500 15px Georgia, serif; }
  .ai-profile em { margin-top: 3px; color: #9b8c7a; font-size: 8px; font-style: normal; }

  .session-focus {
    margin-top: 16px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 10px;
    align-items: center;
  }

  .session-focus span { color: #796c5f; font-size: 6px; letter-spacing: .1em; }
  .session-focus i { height: 4px; overflow: hidden; border-radius: 999px; background: #2d211b; }
  .session-focus i b { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #9a6b39, #e4c782); }

  .training-note {
    display: grid;
    grid-template-columns: 30px 1fr;
    gap: 10px;
    padding: 14px 0;
    border-top: 1px solid rgba(255,255,255,.055);
    border-bottom: 1px solid rgba(255,255,255,.055);
  }
  .note-index { color: #7a6c5e; font: 600 9px ui-monospace, monospace; }
  .training-note strong { color: #d9cab6; font: 500 12px Georgia, serif; }
  .training-note p { margin: 5px 0 0; color: #827568; font-size: 8px; line-height: 1.45; }

  .level-card {
    margin-top: 0;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 16px;
  }
  .level-card > span { margin: 0; font-size: 7px; }
  .level-pill { padding: 8px 15px; font-size: 9px; }

  .stat-grid { margin-top: auto; }
  .stat-grid div { padding: 10px 5px; }
  .stat-grid strong { font-size: 16px; }
  .stat-grid span { font-size: 7px; }

  .board-column {
    grid-area: board;
    align-self: center;
    justify-self: center;
    width: min(100%, calc(100dvh - 268px));
    max-width: 650px;
    min-width: 430px;
    padding: 0 clamp(2px, .35vw, 5px);
  }

  .hand-zone { min-height: 51px; }
  .hand-label { padding-bottom: 5px; font-size: 7px; }
  .hand-row { min-height: 37px; padding-bottom: 4px; }
  .hand-piece { min-width: 35px; height: 37px; font-size: 17px; }

  .board-frame {
    padding: clamp(9px, .9vw, 13px);
    border-radius: 10px;
    box-shadow: 0 30px 85px rgba(0,0,0,.52), inset 0 0 0 1px rgba(255,231,187,.28), inset 0 -10px 22px rgba(0,0,0,.34);
  }

  .shogi-piece { font-size: clamp(18px, 2.05vw, 29px); }
  .piece-en { font-size: clamp(4px, .5vw, 7px); }

  .right-panel {
    grid-area: right;
    padding: 21px;
    overflow: hidden;
  }

  .right-panel > p {
    min-height: 0;
    margin: 15px 0 17px;
    font-size: 13px;
    line-height: 1.55;
  }

  .tactical-lens {
    margin-top: 17px;
    padding-top: 15px;
    border-top: 1px solid rgba(255,255,255,.06);
  }
  .tactical-lens > span { color: #776a5e; font-size: 7px; letter-spacing: .17em; }
  .tactical-lens div { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
  .tactical-lens b {
    padding: 7px 9px;
    border: 1px solid rgba(236,205,151,.09);
    border-radius: 999px;
    color: #9f907e;
    background: rgba(255,255,255,.025);
    font-size: 7px;
    letter-spacing: .07em;
    font-weight: 650;
  }

  .move-list { margin-top: 17px; }
  .move-row { grid-template-columns: 22px 1fr 1fr; padding: 6px 0; font-size: 9px; }

  .bottom-controls {
    grid-area: controls;
    position: relative;
    bottom: auto;
    height: 86px;
    padding: 8px 10px;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    border: 1px solid rgba(236, 204, 146, .11);
    border-radius: 19px;
    background: linear-gradient(145deg, rgba(39,26,20,.77), rgba(12,9,7,.82));
    box-shadow: inset 0 1px rgba(255,255,255,.035), 0 18px 50px rgba(0,0,0,.23);
    backdrop-filter: blur(16px);
  }

  .control-btn {
    border: 1px solid transparent;
    border-radius: 13px;
  }
  .control-btn:hover {
    border-color: rgba(235,203,145,.11);
    background: rgba(255,255,255,.035);
  }
  .control-btn small { font-size: 6px; }
  .control-icon { font-size: 24px; }
  .undo-icon { font-size: 31px; }
  .mini-board { font-size: 25px; }
  .level-orb { width: 31px; height: 31px; }
  .primary-control {
    background: linear-gradient(145deg, rgba(219,179,104,.1), rgba(255,255,255,.015));
    border-color: rgba(229,194,129,.16);
  }

  .toast { bottom: 112px; }
}

@media (min-width: 1061px) and (max-height: 760px) {
  .app-shell {
    grid-template-rows: 66px minmax(0, 1fr) 76px;
    row-gap: 10px;
    padding-bottom: 12px;
  }
  .topbar { height: 66px; }
  .board-column { width: min(100%, calc(100dvh - 224px)); min-width: 410px; }
  .left-panel, .right-panel { padding: 17px; }
  .session-card { padding: 12px; }
  .training-note { padding: 10px 0; }
  .training-note p { display: none; }
  .bottom-controls { height: 76px; }
}

/* v1.3 mobile polish: compact one-screen entry and a unified brown playfield. */
@media (max-width: 650px) {
  html,
  body {
    min-height: 100%;
    background: #17100c;
  }

  body { overflow: hidden; }

  .app-shell {
    min-height: 100dvh;
    background: #17100c;
  }

  .grain { display: none; }

  .topbar {
    height: 90px;
    padding: max(8px, env(safe-area-inset-top)) 16px 6px;
    grid-template-columns: 42px minmax(0, 1fr) 42px;
    background: #17100c;
    border-bottom: 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  .turn-label {
    margin-top: 9px;
    color: #ead19b;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 13px;
    font-style: normal;
    font-weight: 500;
    line-height: 1.08;
    letter-spacing: .01em;
  }

  .game-stage {
    min-height: calc(100dvh - 90px - 76px);
    padding: 12px 14px 10px;
    align-items: center;
    justify-content: center;
    background: #17100c;
  }

  .board-column {
    width: min(calc(100vw - 28px), calc(100dvh - 240px));
    min-width: 0;
    max-width: 100%;
    margin: 0 auto;
    transform: none;
  }

  .bottom-controls {
    height: 76px;
    padding: 4px 7px max(5px, env(safe-area-inset-bottom));
    background: #17100c;
    border-top-color: rgba(238, 208, 153, .08);
    box-shadow: none;
    backdrop-filter: none;
  }

  #difficultyModal {
    place-items: center;
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
    overflow: hidden;
    background: #0d0907;
    backdrop-filter: none;
  }

  #difficultyModal .difficulty-sheet {
    width: min(100%, 430px);
    height: min(620px, calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    margin: 0 auto;
    padding: clamp(17px, 2.6vh, 23px) 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-radius: 24px;
  }

  .difficulty-sheet .modal-emblem {
    width: 47px;
    height: 52px;
    margin-bottom: 8px;
    font-size: 25px;
    flex: 0 0 auto;
  }

  .difficulty-sheet .eyebrow {
    margin-bottom: 6px;
    font-size: 7px;
    letter-spacing: .23em;
    flex: 0 0 auto;
  }

  .difficulty-sheet h1 {
    font-size: clamp(27px, 7.2vw, 33px);
    line-height: 1.06;
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .difficulty-sheet .modal-copy {
    max-width: 350px;
    margin: 10px auto 13px;
    font-size: 10.5px;
    line-height: 1.42;
    flex: 0 0 auto;
  }

  .difficulty-sheet .difficulty-grid {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    flex: 0 0 auto;
  }

  .difficulty-sheet .difficulty-option {
    width: 100%;
    min-height: 78px;
    padding: 11px 13px;
    grid-template-columns: 36px minmax(0, 1fr) 56px;
    grid-template-rows: auto auto;
    column-gap: 11px;
    align-items: center;
    border-radius: 16px;
    overflow: hidden;
  }

  .difficulty-sheet .difficulty-number {
    width: 34px;
    height: 34px;
    grid-row: 1 / span 2;
  }

  .difficulty-sheet .difficulty-option strong {
    min-width: 0;
    font-size: 16px;
    line-height: 1.1;
  }

  .difficulty-sheet .difficulty-option small {
    min-width: 0;
    margin: 4px 0 0;
    color: #9d8f7c;
    font-size: 9.5px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .difficulty-sheet .difficulty-option em {
    width: 56px;
    grid-column: 3;
    grid-row: 1 / span 2;
    justify-self: end;
    text-align: right;
    font-size: 7px;
    letter-spacing: .16em;
  }

  .difficulty-sheet .offline-note {
    margin: 11px 0 0;
    font-size: 8px;
    flex: 0 0 auto;
  }

  .difficulty-sheet .difficulty-option {
    box-shadow: inset 0 1px 0 rgba(255,255,255,.025);
  }

  .difficulty-sheet .difficulty-option:active,
  .difficulty-sheet .difficulty-option.is-selected {
    transform: scale(.982);
    border-color: rgba(244,208,137,.86);
    box-shadow:
      0 0 0 1px rgba(238,197,117,.11),
      0 8px 20px rgba(0,0,0,.28),
      0 0 25px rgba(191,130,51,.18),
      inset 0 1px 0 rgba(255,239,205,.13);
  }
}

@media (max-width: 650px) and (max-height: 700px) {
  .topbar { height: 78px; }
  .game-stage { min-height: calc(100dvh - 78px - 68px); padding-block: 8px; }
  .board-column { width: min(calc(100vw - 28px), calc(100dvh - 214px)); }
  .bottom-controls { height: 68px; }

  #difficultyModal .difficulty-sheet {
    height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding-block: 12px;
  }

  .difficulty-sheet .modal-emblem { width: 40px; height: 44px; margin-bottom: 5px; font-size: 22px; }
  .difficulty-sheet .eyebrow { margin-bottom: 4px; }
  .difficulty-sheet h1 { font-size: clamp(25px, 6.8vw, 30px); }
  .difficulty-sheet .modal-copy { margin: 7px auto 9px; font-size: 9.5px; line-height: 1.34; }
  .difficulty-sheet .difficulty-grid { gap: 6px; }
  .difficulty-sheet .difficulty-option { min-height: 68px; padding-block: 8px; }
  .difficulty-sheet .difficulty-option small { font-size: 8.5px; }
  .difficulty-sheet .offline-note { margin-top: 7px; }
}
