/* ============ エレメント将棋 スタイル ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #110e1c;
  --bg2: #1d1930;
  --panel: rgba(38, 32, 64, .72);
  --panel-2: #2e2750;
  --line: #3d3563;
  --line-soft: rgba(139, 92, 246, .25);
  --text: #f1ecff;
  --text-dim: #a79fc9;
  --accent: #8b5cf6;
  --col-f: #ff5a3c;
  --col-w: #3a86ff;
  --col-a: #2dc653;
  --col-l: #ffd60a;
  --col-d: #9d4edd;
  --col-k: #ffd700;
  --sq: min(21.5vw, 88px);
  --serif: "Hiragino Mincho ProN", "Hiragino Serif", "Yu Mincho", YuMincho, serif;
}

html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  background:
    radial-gradient(1100px 560px at 12% -12%, rgba(255, 90, 60, .13), transparent 62%),
    radial-gradient(1000px 560px at 112% 12%, rgba(58, 134, 255, .12), transparent 62%),
    radial-gradient(900px 640px at 50% 118%, rgba(157, 78, 221, .17), transparent 62%),
    radial-gradient(600px 400px at 82% 88%, rgba(45, 198, 83, .07), transparent 65%),
    var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* 星屑（軽量な繰り返しグラデーション） */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    radial-gradient(1.3px 1.3px at 22% 28%, rgba(255, 255, 255, .55), transparent 100%),
    radial-gradient(1px 1px at 68% 12%, rgba(255, 255, 255, .4), transparent 100%),
    radial-gradient(1.6px 1.6px at 84% 62%, rgba(196, 181, 253, .5), transparent 100%),
    radial-gradient(1px 1px at 38% 78%, rgba(255, 255, 255, .35), transparent 100%),
    radial-gradient(1.2px 1.2px at 8% 55%, rgba(160, 200, 255, .4), transparent 100%);
  background-size: 340px 340px, 260px 260px, 420px 420px, 300px 300px, 380px 380px;
  opacity: .5;
}

#app {
  position: relative; z-index: 1;
  width: 100%;
  max-width: 520px;
  min-height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
}

/* ---------- ヘッダー ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 4px 8px;
}
#logo-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
#logo {
  font-size: 21px; font-weight: 800; letter-spacing: .03em; white-space: nowrap;
  background: linear-gradient(100deg, #ffc46b, #ff6a4a 30%, #c49bff 65%, #6fd6ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 14px rgba(157, 78, 221, .35));
}
#mode-badge {
  border: 1px solid var(--line); background: var(--panel); color: var(--text-dim);
  font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 999px; cursor: pointer;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
}
#topbar-buttons { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, .05), transparent 55%), var(--panel);
  font-size: 17px; cursor: pointer; color: var(--text);
  display: grid; place-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
.icon-btn:active { transform: scale(.93); }

/* ---------- 対局エリア ---------- */
#game-area { display: flex; flex-direction: column; align-items: center; gap: 7px; flex: 1; }

.player-strip {
  width: 100%; max-width: calc(var(--sq) * 4 + 44px);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 48px; padding: 2px 2px;
}
.player-info { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.player-name {
  font-size: 13px; font-weight: 800; color: var(--text-dim); letter-spacing: .04em;
  transition: color .2s ease;
}
.player-name.active { color: var(--text); text-shadow: 0 0 12px rgba(124, 252, 154, .35); }
.turn-dot {
  width: 9px; height: 9px; border-radius: 50%; background: #453d6e; flex-shrink: 0;
  transition: background .2s ease;
}
.turn-dot.active { background: #7CFC9A; box-shadow: 0 0 10px #7CFC9A; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* 持ち駒トレイ */
.hand {
  display: flex; gap: 6px; flex-wrap: wrap; min-height: 44px; align-items: center;
  padding: 3px 8px; border-radius: 12px; flex: 1;
  background: rgba(0, 0, 0, .22);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, .4), inset 0 -1px 0 rgba(255, 255, 255, .04);
}
#strip-top .hand { justify-content: flex-end; }
.hand-chip {
  position: relative; width: 38px; height: 42px; border: none; background: none; cursor: pointer;
  padding: 0; display: grid; place-items: center;
}
.hand-chip .count {
  position: absolute; right: -4px; bottom: -2px; z-index: 3;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  font-size: 10px; font-weight: 800; min-width: 16px; height: 16px; border-radius: 8px;
  display: grid; place-items: center; padding: 0 3px;
}
.hand-chip.selected .piece { outline: 2px solid #ffe066; outline-offset: 2px; }
.hand-chip:disabled { cursor: default; }

/* ---------- 盤面 ---------- */
#board-wrap {
  --frame: 10px;
  position: relative;
  padding: var(--frame);
  border-radius: 20px;
  background:
    linear-gradient(175deg, rgba(255, 255, 255, .14), rgba(255, 255, 255, 0) 22%),
    linear-gradient(160deg, #5a4c96 0%, #372e63 34%, #241d47 68%, #191338 100%);
  box-shadow:
    0 14px 44px rgba(0, 0, 0, .55),
    0 2px 10px rgba(0, 0, 0, .4),
    inset 0 0 0 1px rgba(196, 181, 253, .22);
}
#board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, var(--sq));
  grid-template-rows: repeat(4, var(--sq));
  border-radius: 10px;
  overflow: hidden;
  background:
    radial-gradient(130% 100% at 50% -10%, rgba(139, 92, 246, .16), transparent 62%),
    repeating-linear-gradient(43deg, rgba(255, 255, 255, .015) 0 2px, transparent 2px 5px),
    repeating-linear-gradient(-47deg, rgba(0, 0, 0, .05) 0 3px, transparent 3px 7px),
    linear-gradient(160deg, #262045, #181334 55%, #1c1638);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(139, 92, 246, .3);
}
/* 星点（盤の目印） */
#board::after {
  content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    radial-gradient(2.5px 2.5px at 25% 25%, rgba(196, 181, 253, .5), transparent 100%),
    radial-gradient(2.5px 2.5px at 75% 25%, rgba(196, 181, 253, .5), transparent 100%),
    radial-gradient(2.5px 2.5px at 25% 75%, rgba(196, 181, 253, .5), transparent 100%),
    radial-gradient(2.5px 2.5px at 75% 75%, rgba(196, 181, 253, .5), transparent 100%),
    radial-gradient(3px 3px at 50% 50%, rgba(196, 181, 253, .6), transparent 100%);
}
.square {
  position: relative; border: none; padding: 0; cursor: pointer;
  background: transparent;
  box-shadow: inset 0 0 0 .5px var(--line-soft);
  display: grid; place-items: center;
  transition: background-color .12s ease;
}
@media (hover: hover) {
  .square:hover { background-color: rgba(255, 255, 255, .045); }
}
/* 成りゾーン（相手陣最奥）: 外縁の光る一線＋かすかな色味 */
.square.zone-top {
  background-image: linear-gradient(180deg, rgba(244, 162, 97, .09), transparent 62%);
  box-shadow: inset 0 2px 0 rgba(244, 162, 97, .38), inset 0 0 0 .5px var(--line-soft);
}
.square.zone-bottom {
  background-image: linear-gradient(0deg, rgba(108, 210, 255, .09), transparent 62%);
  box-shadow: inset 0 -2px 0 rgba(108, 210, 255, .34), inset 0 0 0 .5px var(--line-soft);
}
.square.sel {
  background-color: rgba(255, 224, 102, .08);
  box-shadow: inset 0 0 0 2px rgba(255, 224, 102, .85), inset 0 0 22px rgba(255, 224, 102, .28);
}
.square.last { background-color: rgba(139, 92, 246, .17); box-shadow: inset 0 0 0 1px rgba(139, 92, 246, .45), inset 0 0 18px rgba(139, 92, 246, .2); }
.square.droppable { box-shadow: inset 0 0 0 1.5px rgba(124, 252, 154, .6), inset 0 0 16px rgba(124, 252, 154, .16); }

/* 移動先マーク */
.square .mark { position: absolute; pointer-events: none; z-index: 3; }
.mark.m-move {
  width: 24%; height: 24%; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #b8ffd0, #52e07e 65%, #2bab52);
  box-shadow: 0 0 12px rgba(124, 252, 154, .7), 0 1px 3px rgba(0, 0, 0, .4);
  animation: markpulse 1.3s ease-in-out infinite;
}
.mark.m-capture {
  inset: 7%; border: 2.5px solid rgba(255, 96, 64, .95); border-radius: 16px;
  box-shadow: 0 0 14px rgba(255, 90, 60, .55), inset 0 0 14px rgba(255, 90, 60, .35);
  animation: markpulse 1.3s ease-in-out infinite;
}
.mark.m-mutual {
  inset: 7%; border: 2.5px dashed rgba(255, 200, 60, .95); border-radius: 16px;
  display: grid; place-items: center; font-size: calc(var(--sq) * .3); color: #ffc83c;
  text-shadow: 0 0 10px rgba(255, 200, 60, .9);
  box-shadow: inset 0 0 14px rgba(255, 200, 60, .22);
  animation: markpulse 1.3s ease-in-out infinite;
}
@keyframes markpulse { 50% { opacity: .55; } }

/* ---------- 駒 ---------- */
/* 属性ごとの配色（縁・面・墨色・オーラ） */
.el-F { --rim1: #8a1a12; --rim2: #450905; --face1: #ffb066; --face2: #ef4b32; --face3: #a81a10; --ink: #fff; --aura: rgba(255, 96, 64, .5); }
.el-W { --rim1: #143a78; --rim2: #091d44; --face1: #7cc4ff; --face2: #3577e8; --face3: #1b3f95; --ink: #fff; --aura: rgba(80, 150, 255, .5); }
.el-A { --rim1: #0e5e2a; --rim2: #04331a; --face1: #8beea4; --face2: #2bab52; --face3: #0f6b30; --ink: #fff; --aura: rgba(70, 220, 130, .45); }
.el-L { --rim1: #a37400; --rim2: #5c3d00; --face1: #fff6c9; --face2: #ffd93d; --face3: #dda300; --ink: #5a3c00; --aura: rgba(255, 214, 10, .5); }
.el-D { --rim1: #421270; --rim2: #200640; --face1: #c08bef; --face2: #7b34b8; --face3: #41125f; --ink: #fff; --aura: rgba(157, 78, 221, .55); }
.el-K { --rim1: #93763f; --rim2: #594420; --face1: #fffdf2; --face2: #efe3c0; --face3: #c8ad7e; --ink: #7c1f1f; --aura: rgba(255, 220, 130, .45); }

.piece, .gpiece {
  position: relative; z-index: 2;
  /* 本物の将棋駒のように、頭が小さく裾が広い五角形 */
  clip-path: polygon(50% 0%, 82% 18%, 94% 100%, 6% 100%, 18% 18%);
  display: grid; place-items: center;
  color: var(--ink);
  background: linear-gradient(168deg, var(--rim1), var(--rim2) 78%);
}
.piece {
  width: calc(var(--sq) * .8); height: calc(var(--sq) * .84);
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .5)) drop-shadow(0 0 9px var(--aura));
  transition: filter .15s ease;
}
/* 駒の面（縁の内側）: 属性グラデーション＋艶 */
.piece::before, .gpiece::before {
  content: ""; position: absolute; inset: 4.5% 5.5% 4% 5.5%;
  clip-path: polygon(50% 0%, 82% 18%, 94% 100%, 6% 100%, 18% 18%);
  background:
    radial-gradient(90% 50% at 50% 0%, rgba(255, 255, 255, .38), transparent 58%),
    linear-gradient(115deg, rgba(255, 255, 255, .22), transparent 42%),
    linear-gradient(168deg, var(--face1), var(--face2) 52%, var(--face3));
}
.kanji {
  position: relative; z-index: 1;
  font-family: var(--serif);
  font-weight: 800;
  font-size: calc(var(--sq) * .4);
  line-height: 1;
  transform: translateY(6%);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 0 10px rgba(0, 0, 0, .18);
}
.piece .el-en {
  position: absolute; z-index: 1; left: 0; right: 0; bottom: 13%;
  text-align: center; font-size: max(7px, calc(var(--sq) * .12)); font-weight: 800; letter-spacing: .04em;
  line-height: 1; text-transform: uppercase; opacity: .9;
}
.piece:has(.el-en) .kanji { transform: translateY(-4%); }
.el-L .kanji, .el-K .kanji { text-shadow: 0 1px 0 rgba(255, 255, 255, .45), 0 0 6px rgba(255, 255, 255, .2); }

.hand-chip .piece { --sq: 46px; }
#setup-tray .piece { --sq: 54px; }
.piece.owner-1 { transform: rotate(180deg); }

/* 動ける方向ドット */
.mdot {
  position: absolute; z-index: 1;
  width: calc(var(--sq) * .06); height: calc(var(--sq) * .06);
  min-width: 3px; min-height: 3px; border-radius: 50%;
  background: currentColor; opacity: .8; pointer-events: none;
  box-shadow: 0 0 3px rgba(0, 0, 0, .3);
}
.el-L .mdot, .el-K .mdot { box-shadow: 0 0 2px rgba(255, 255, 255, .5); }
.d-n { top: 6%; left: 50%; transform: translateX(-50%); }
.d-s { bottom: 3%; left: 50%; transform: translateX(-50%); }
.d-w { left: 15%; top: 54%; transform: translateY(-50%); }
.d-e { right: 15%; top: 54%; transform: translateY(-50%); }
.d-nw { top: 25%; left: 19%; }
.d-ne { top: 25%; right: 19%; }
.d-sw { bottom: 6%; left: 13%; }
.d-se { bottom: 6%; right: 13%; }

/* 成り駒: 金の縁とオーラ */
.piece.promoted {
  background: linear-gradient(168deg, #ffe08a, #c8951d 55%, #7c5a10);
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .5)) drop-shadow(0 0 10px rgba(255, 200, 60, .75));
}
.piece.promoted::after {
  content: "✦"; position: absolute; z-index: 1; top: 14%; left: 50%; transform: translateX(-50%);
  font-size: calc(var(--sq) * .15); line-height: 1;
  color: #ffe066; text-shadow: 0 0 6px #ffb703;
}

.square.in-check .piece { animation: checkflash .6s ease-in-out infinite; }
@keyframes checkflash { 50% { filter: drop-shadow(0 0 12px #ff2d2d) brightness(1.35); } }

.piece.pop { animation: pop .22s ease; }
@keyframes pop { 0% { scale: .55; } 70% { scale: 1.12; } 100% { scale: 1; } }
.piece.owner-1.pop { animation: pop-r .22s ease; }
@keyframes pop-r { 0% { transform: rotate(180deg) scale(.55); } 70% { transform: rotate(180deg) scale(1.12); } 100% { transform: rotate(180deg) scale(1); } }

.square .clash {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center;
  font-size: calc(var(--sq) * .55); pointer-events: none;
  animation: clash .5s ease forwards;
}
@keyframes clash { 0% { scale: .4; opacity: 0; } 30% { scale: 1.25; opacity: 1; } 100% { scale: 1; opacity: 0; } }

/* 非公開カバー */
#setup-cover {
  position: absolute; left: var(--frame); right: var(--frame); top: var(--frame);
  height: calc(50% - var(--frame));
  background: repeating-linear-gradient(45deg, rgba(17, 14, 28, .97), rgba(17, 14, 28, .97) 12px, rgba(46, 39, 80, .97) 12px, rgba(46, 39, 80, .97) 24px);
  border-radius: 10px 10px 0 0; z-index: 5;
  display: grid; place-items: center; color: var(--text-dim); font-weight: 700; font-size: 14px;
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, .25);
}

/* ---------- ステータス・相性 ---------- */
#status-line {
  font-size: 14px; font-weight: 700; color: var(--text-dim);
  min-height: 20px; text-align: center; letter-spacing: .03em;
}
#legend-strip {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, .04), transparent 60%), var(--panel);
  color: var(--text-dim);
  border-radius: 999px; padding: 6px 14px; font-size: 12px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
}
.lg { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; color: #fff; font-size: 11px; font-weight: 800; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 2px rgba(0, 0, 0, .35); }
.lg-f { background: linear-gradient(160deg, #ff8a5c, #d3311f); } .lg-w { background: linear-gradient(160deg, #6fb4ff, #2059c9); } .lg-a { background: linear-gradient(160deg, #63d987, #17853c); }
.lg-l { background: linear-gradient(160deg, #ffe98f, #eab308); color: #5a3c00; } .lg-d { background: linear-gradient(160deg, #b07ce0, #5f2596); } .lg-k { background: linear-gradient(160deg, #fdf3d0, #d9b968); color: #7c1f1f; }
.lg-sep { color: #4a4370; margin: 0 2px; }

/* ---------- 配置パネル ---------- */
#setup-panel { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 4px 0 10px; }
#setup-tray {
  display: flex; gap: 9px; min-height: 62px; align-items: center; justify-content: center;
  padding: 8px 14px; border: 1px dashed var(--line); border-radius: 14px; min-width: 280px;
  background: rgba(0, 0, 0, .18);
  box-shadow: inset 0 1px 5px rgba(0, 0, 0, .3);
}
#setup-tray .tray-slot { background: none; border: none; padding: 0; cursor: pointer; }
#setup-tray .tray-slot.selected .piece { outline: 2px solid #ffe066; outline-offset: 2px; }
#setup-tray:empty::after { content: "All placed! Tap Start."; color: var(--text-dim); font-size: 12px; }
#setup-buttons { display: flex; gap: 8px; }

/* ---------- ツールバー ---------- */
#play-toolbar { display: flex; gap: 8px; padding: 2px 0 10px; }
.tool-btn {
  display: flex; align-items: center; gap: 6px; padding: 10px 15px;
  border: 1px solid var(--line); border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .05), transparent 55%), var(--panel);
  color: var(--text); font-size: 13px; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}
.tool-btn:disabled { opacity: .38; cursor: default; box-shadow: none; }
.tool-btn:not(:disabled):active { transform: scale(.95); }
.tool-icon { font-size: 15px; }

/* ---------- ボタン共通 ---------- */
.btn {
  border: none; border-radius: 13px; padding: 12px 20px;
  font-size: 15px; font-weight: 800; cursor: pointer; color: var(--text);
  letter-spacing: .02em;
}
.btn:active { transform: scale(.96); }
.btn-primary {
  background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 40%, #6d28d9 100%);
  box-shadow: 0 5px 18px rgba(139, 92, 246, .45), inset 0 1px 0 rgba(255, 255, 255, .3);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.btn-primary:disabled { opacity: .4; box-shadow: none; cursor: default; }
.btn-sub {
  background: linear-gradient(180deg, rgba(255, 255, 255, .05), transparent 55%), var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}

/* ---------- オーバーレイ・モーダル ---------- */
.overlay, .modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(9, 7, 16, .8); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 16px;
}
.overlay-box, .modal-box {
  width: 100%; max-width: 400px;
  background:
    linear-gradient(175deg, rgba(255, 255, 255, .06), transparent 30%),
    var(--bg2);
  border: 1px solid rgba(139, 92, 246, .4); border-radius: 20px; padding: 24px 20px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .65), 0 0 40px rgba(139, 92, 246, .12);
  animation: rise .28s cubic-bezier(.2, .9, .3, 1.2);
  text-align: center;
}
.modal-box { text-align: left; max-height: 82dvh; overflow-y: auto; animation: rise .22s ease; }
@keyframes rise { from { transform: translateY(16px) scale(.97); opacity: 0; } }
.overlay-title { font-size: 28px; font-weight: 900; margin-bottom: 6px; letter-spacing: .04em; }
.overlay-title.win {
  background: linear-gradient(175deg, #fff3b0, #ffd60a 55%, #f4a261);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 16px rgba(255, 214, 10, .45));
}
.overlay-title.lose { color: #8f86b8; }
.overlay-title.draw { color: #4cc9f0; text-shadow: 0 0 16px rgba(76, 201, 240, .4); }
#result-sub, #handoff-text { color: var(--text-dim); font-size: 14px; line-height: 1.7; margin-bottom: 14px; }
#result-stats { display: flex; justify-content: center; gap: 20px; margin-bottom: 16px; }
.rstat { display: flex; flex-direction: column; gap: 2px; }
.rstat-label { font-size: 11px; color: var(--text-dim); font-weight: 700; }
.rstat span:last-child { font-size: 19px; font-weight: 800; }
.overlay-buttons { display: flex; flex-direction: column; gap: 8px; }

.modal-title { font-size: 18px; font-weight: 800; margin-bottom: 14px; text-align: center; letter-spacing: .05em; }
.menu-section { margin-bottom: 18px; }
.menu-caption {
  font-size: 11px; font-weight: 800; color: var(--text-dim); margin-bottom: 8px;
  letter-spacing: .12em;
}
.menu-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 2px; font-size: 14px; font-weight: 600; }

.mode-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.mode-btn {
  display: flex; flex-direction: column; gap: 2px; align-items: center; padding: 11px 4px;
  border: 1px solid var(--line); border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .04), transparent 55%), var(--panel);
  color: var(--text); font-size: 13px; font-weight: 800; cursor: pointer;
}
.mode-btn small { font-size: 10px; color: var(--text-dim); font-weight: 700; }
.mode-btn.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(167, 139, 250, .25), rgba(139, 92, 246, .12));
  box-shadow: 0 0 14px rgba(139, 92, 246, .3), inset 0 1px 0 rgba(255, 255, 255, .12);
}

.toggle {
  position: relative; width: 46px; height: 26px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.toggle .knob {
  position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: #8f86b8; transition: transform .15s ease, background .15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
.toggle.on { background: rgba(139, 92, 246, .4); border-color: var(--accent); }
.toggle.on .knob { transform: translateX(20px); background: #d6c8ff; }

/* 相性表 */
.guide-grid { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; }
.guide-row { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 700; }
.gpiece {
  --sq: 44px;
  width: 36px; height: 38px; flex-shrink: 0;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .45));
}
.gpiece .kanji { font-size: 17px; }
.guide-arrow { color: var(--text-dim); }
.guide-note, .guide-note-wide { color: var(--text-dim); font-size: 13px; }
.guide-subtitle { font-size: 14px; font-weight: 800; margin: 14px 0 6px; }
.howto { list-style: none; display: flex; flex-direction: column; gap: 7px; font-size: 13px; line-height: 1.65; color: var(--text-dim); }
.howto b { color: var(--text); }
.mark-demo { display: inline-grid; place-items: center; vertical-align: -4px; width: 18px; height: 18px; margin-right: 2px; }
.mark-demo.mark-move { border-radius: 50%; background: radial-gradient(circle at 38% 32%, #b8ffd0, #52e07e 65%, #2bab52); width: 12px; height: 12px; margin: 0 5px 0 3px; }
.mark-demo.mark-capture { border: 2px solid rgba(255, 90, 60, .9); border-radius: 5px; }
.mark-demo.mark-mutual { border: 2px dashed rgba(255, 200, 60, .95); border-radius: 5px; font-size: 10px; color: #ffc83c; }

/* ---------- トースト ---------- */
#toast {
  /* フッター固定バナー広告に隠れないよう持ち上げる（広告なしのときは 0px） */
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom) + var(--ad-space, 0px)); transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(255, 255, 255, .06), transparent 55%), var(--panel-2);
  border: 1px solid var(--line); color: var(--text);
  padding: 10px 20px; border-radius: 999px; font-size: 14px; font-weight: 800;
  z-index: 60; box-shadow: 0 10px 28px rgba(0, 0, 0, .55); white-space: nowrap;
  animation: toast-in .2s ease;
}
@keyframes toast-in { from { transform: translate(-50%, 8px); opacity: 0; } }
#toast.check { color: #ff6b6b; border-color: rgba(255, 107, 107, .7); box-shadow: 0 10px 28px rgba(0, 0, 0, .55), 0 0 18px rgba(255, 60, 60, .25); }

/* ---------- フッター ---------- */
#footer {
  text-align: center; font-size: 11px; color: var(--text-dim);
  padding: 14px 0 10px; line-height: 1.8; opacity: .85;
}
#footer a { color: var(--text-dim); }

.hidden { display: none !important; }

/* 小さい端末 */
@media (max-height: 700px) {
  :root { --sq: min(20vw, 76px); }
  #topbar { padding-top: 6px; }
  .hand { min-height: 38px; }
}
/* 320px 幅では配置トレイ（駒6つ）が画面からはみ出して横スクロールが出るので詰める */
@media (max-width: 349px) {
  #setup-tray { min-width: 0; gap: 5px; padding: 8px; }
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / js/ad-banner.js が挿入する）
   --ad-h    : 広告そのものの高さ。広告なしのときは 0px
   --ad-space: レイアウトが空けるべき高さ（広告 + セーフエリア）
   ========================================================================== */
:root {
  --ad-h: 0px;
  --ad-space: 0px;
}
html.has-ad-banner {
  --ad-space: calc(var(--ad-h, 0px) + env(safe-area-inset-bottom, 0px));
}

.ad-banner {
  /* height は広告そのものの高さ。セーフエリアぶんの padding は外側に足す */
  box-sizing: content-box;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* ランキング・リザルト等の全画面オーバーレイ（2147483000）よりは下に置く */
  z-index: 2147482000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: var(--ad-h, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow: hidden;
  background: rgba(14, 16, 20, 0.86);
  /* border ではなく inset shadow にして、枠線ぶん高さがずれないようにする */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.ad-banner__frame {
  display: block;
  width: 100%;
  height: var(--ad-h, 0px);
  border: 0;
  color-scheme: light;
}

@media print {
  .ad-banner { display: none; }
}
