:root {
  --bg: #0b0614;
  --ink: #fff;
  --muted: #b9a9d6;
  --panel: rgba(24, 14, 40, .82);
  --line: rgba(255, 255, 255, .14);
  --wood-1: #f3d49a;
  --wood-2: #e2b56c;
  --wood-3: #c98f45;
  /* 盤1マスの大きさ。app.js が空き高さから計算して上書きする（これはJS前のフォールバック） */
  --sq: min(42vw, 22vh, 200px);
  --rainbow: linear-gradient(90deg, #ff004c, #ff8a00, #ffe600, #2bff00, #00e5ff, #3d5afe, #d500f9, #ff004c);
  --conic: conic-gradient(from var(--angle, 0deg), #ff004c, #ff8a00, #ffe600, #2bff00, #00e5ff, #3d5afe, #d500f9, #ff004c);
  --vh: 100vh;
}
@supports (height: 100dvh) { :root { --vh: 100dvh; } }

@property --angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation; /* ダブルタップズーム無効 */
}
body {
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(213, 0, 249, .25), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(0, 229, 255, .18), transparent 60%),
    var(--bg);
}
body.shake { animation: shake .5s cubic-bezier(.36, .07, .19, .97) both; }
button { font: inherit; color: inherit; }

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}
.flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  opacity: 0;
  background: #fff;
}
.flash.on { animation: flash .6s ease-out; }
.flash.lose { background: #ff003c; }

/* ---------- layout: 1画面に収める ---------- */
.app {
  position: relative;
  max-width: 480px;
  height: var(--vh);
  min-height: 0;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding-bottom: var(--dock-h, 150px);
  z-index: 1;
}

/* ---------- header ---------- */
.head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
}
.title {
  margin: 0;
  font-family: "Dela Gothic One", sans-serif;
  font-weight: 400;
  font-size: clamp(30px, 9.5vw, 46px);
  letter-spacing: .04em;
  line-height: 1.1;
  background: var(--rainbow);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: slide 3s linear infinite;
  filter: drop-shadow(0 0 12px rgba(255, 0, 200, .55));
}

/* ---------- stats ---------- */
.stat {
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 5px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.stat-label { font-size: 10px; color: var(--muted); letter-spacing: .15em; }
.stat-num {
  font-family: "Dela Gothic One", sans-serif;
  font-size: 28px;
  line-height: 1.1;
}
.stat-num.small { font-size: 15px; margin-top: 4px; }
.stat-streak {
  background: linear-gradient(var(--bg), var(--bg)) padding-box, var(--rainbow) border-box;
  border: 2px solid transparent;
}
.stat-streak .stat-num {
  background: var(--rainbow);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: slide 2s linear infinite;
}
.stat-num.bump { animation: bump .6s cubic-bezier(.2, 2, .4, 1), slide 2s linear infinite; }

/* ---------- stage (残りの高さを全部使う) ---------- */
.stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.turn-badge {
  position: absolute;
  z-index: 5;
  padding: 3px 12px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .1em;
  color: #000;
  background: var(--rainbow);
  background-size: 200% 100%;
  animation: slide 2s linear infinite;
  box-shadow: 0 0 16px rgba(255, 255, 255, .5);
  white-space: nowrap;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
}

.board-wrap {
  position: relative;
  padding: 8px;
  border-radius: 8px;
  background: #1a0f08;
  isolation: isolate;
}
.board-wrap::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 10px;
  padding: 6px;
  background: var(--conic);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: spin 3s linear infinite;
  z-index: -1;
}
.board-wrap::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 12px;
  background: var(--conic);
  filter: blur(28px);
  opacity: .85;
  /* ぼかした層は回さない（毎フレームぼかし再計算になりiPhoneで重い）。明るさの脈動だけにする */
  animation: glowPulse 1.6s ease-in-out infinite alternate;
  will-change: opacity;
  z-index: -2;
}
@keyframes glowPulse { from { opacity: .55; } to { opacity: 1; } }
.board-wrap.hype::before, .board-wrap.hype::after { animation-duration: .6s; }
.board-wrap.hype::after { opacity: 1; }
body.fever .board-wrap::before, body.fever .board-wrap::after { animation-duration: 1.2s; }
body.fever .board-wrap::after { opacity: 1; inset: -10px; filter: blur(36px); }
body.auto-on .board-wrap::before, body.auto-on .board-wrap::after { animation-duration: .8s; }

.board {
  position: relative;
  width: var(--sq);
  height: calc(var(--sq) * 2);
  display: grid;
  grid-template-rows: 1fr 1fr;
  border: 3px solid #1b1007;
  background:
    repeating-linear-gradient(92deg, rgba(120, 70, 20, .09) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(88deg, rgba(255, 255, 255, .08) 0 1px, transparent 1px 14px),
    linear-gradient(160deg, var(--wood-1), var(--wood-2) 60%, var(--wood-3));
}
.sq {
  position: relative;
  border-bottom: 3px solid #1b1007;
}
.sq:last-child { border-bottom: none; }
.sq.target { cursor: pointer; }
.sq.target::before {
  content: "";
  position: absolute;
  inset: 3px;
  z-index: 3;
  pointer-events: none;
  border-radius: 4px;
  background: radial-gradient(circle, rgba(255, 40, 90, .15), rgba(255, 0, 120, .45));
  box-shadow: inset 0 0 0 4px #ff1f5a, inset 0 0 26px rgba(255, 0, 100, .9), 0 0 28px rgba(255, 0, 100, .9);
  animation: targetPulse .5s ease-in-out infinite alternate;
}
.sq.target::after {
  content: "取";
  position: absolute;
  right: 6px;
  top: 4px;
  z-index: 3;
  font-weight: 900;
  font-size: 14px;
  color: #fff;
  background: #ff1f5a;
  border-radius: 6px;
  padding: 1px 6px;
  box-shadow: 0 0 10px #ff1f5a;
}
.sq.last { background: rgba(255, 230, 0, .25); }

/* ---------- pieces ---------- */
.piece {
  position: absolute;
  left: 50%;
  width: calc(var(--sq) * .68);
  height: calc(var(--sq) * .78);
  margin-left: calc(var(--sq) * -.34);
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  z-index: 2;
  transition: top .38s cubic-bezier(.6, -0.4, .3, 1.6), transform .2s;
  filter: drop-shadow(0 6px 4px rgba(0, 0, 0, .45));
  color: #111;
  outline: none;
}
.piece::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(50% 0, 84% 14%, 100% 100%, 0 100%, 16% 14%);
  background:
    repeating-linear-gradient(95deg, rgba(150, 90, 30, .12) 0 2px, transparent 2px 7px),
    linear-gradient(170deg, #fbe3b0, #e9c27e 55%, #d9a55c);
}
.piece span {
  position: relative;
  display: block;
  padding-top: 22%;
  font-family: "Yuji Syuku", "Hiragino Mincho ProN", serif;
  font-size: calc(var(--sq) * .4);
  line-height: 1;
  text-align: center;
}
.piece.mine { top: calc(var(--sq) * 1.11); }
.piece.enemy { top: calc(var(--sq) * .11); transform: rotate(180deg); cursor: default; }
.piece.mine.at-top { top: calc(var(--sq) * .11); }
.piece.enemy.at-bottom { top: calc(var(--sq) * 1.11); }

.piece.mine:focus-visible { filter: drop-shadow(0 0 6px #00e5ff); }
.piece.selected {
  transform: translateY(-10%) scale(1.08);
  filter: drop-shadow(0 0 10px #fff) drop-shadow(0 0 22px #00e5ff) drop-shadow(0 0 40px #d500f9);
  animation: float .9s ease-in-out infinite alternate;
}
.piece.ready:not(.selected) { animation: nudge 1.4s ease-in-out infinite; }
.piece.enemy.thinking { animation: think .5s ease-in-out infinite alternate; }
.piece.captured { z-index: 1; animation: fly 1s cubic-bezier(.2, .8, .3, 1) forwards; }
.piece.mine.captured { animation-name: flyMine; }

/* ---------- furigoma ---------- */
.furigoma {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  background: rgba(11, 6, 20, .72);

  border-radius: 12px;
  perspective: 600px;
}
.coin {
  position: relative;
  width: 56px;
  height: 64px;
  transform-style: preserve-3d;
  animation: toss 1.2s cubic-bezier(.3, .1, .3, 1) forwards;
}
.coin:nth-child(2) { animation-delay: .08s; }
.coin:nth-child(3) { animation-delay: .16s; }
.coin .face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-top: 8px;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  clip-path: polygon(50% 0, 84% 14%, 100% 100%, 0 100%, 16% 14%);
  background: linear-gradient(170deg, #fbe3b0, #d9a55c);
  font-family: "Yuji Syuku", serif;
  font-size: 28px;
  color: #111;
}
.coin .back { transform: rotateY(180deg); color: #c4001a; }
.coin.show-back { --end: 1980deg; }

/* ---------- message / kifu ---------- */
.status {
  text-align: center;
  padding-bottom: 18px;
}
.message {
  margin: 0;
  min-height: 1.5em;
  font-size: 15px;
  font-weight: 800;
  text-shadow: 0 0 12px rgba(255, 0, 200, .6);
}
.kifu {
  margin: 0;
  min-height: 1.3em;
  font-family: "Yuji Syuku", serif;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- bottom dock ---------- */
/* ボトムシート: 画面下に固定し、メニューを開くとハンドルごと上に伸びる。
   閉じた状態の高さ分だけ .app に余白を取る（--dock-h は app.js が計測） */
.dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  padding: 0 max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  /* backdrop-filter は背後のパーティクルが動くたびに再計算されて重いので、ほぼ不透明な背景にする */
  background: rgba(22, 12, 38, .96);
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .45);
}
.dock-handle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  padding: 7px 0 6px;
  border: none;
  cursor: pointer;
  touch-action: none;
  position: sticky;
  top: 0;
  z-index: 1;
  background: linear-gradient(rgba(24, 14, 40, .98) 70%, rgba(24, 14, 40, 0));
}
.grabber {
  width: 40px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .35);
}
.dock-handle-label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .15em;
}
.dock-handle-label::after { content: " ▲"; font-size: 9px; }
.dock.open .dock-handle-label::after { content: " ▼"; }

/* 引き出しメニュー: ハンドルの下で高さをアニメーションさせる */
.dock-menu {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .32s cubic-bezier(.3, 1.1, .4, 1);
}
.dock.open .dock-menu { grid-template-rows: 1fr; }
.dock-menu-inner {
  min-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: opacity .2s;
}
.dock.open .dock-menu-inner { opacity: 1; }
.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px 0 10px;
}
.menu-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .06);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.menu-item.danger { color: #ff8aa5; }
a.menu-item { color: inherit; text-decoration: none; }
.howto {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .04);
  border: 1px dashed var(--line);
  font-size: 12px;
  line-height: 1.7;
  color: #e6dcf7;
}
.howto ol { margin: 0; padding-left: 1.3em; }
.howto b { color: #ffe600; }

/* メニューの見出しとリンク: 項目が増えても、どこに何があるか分かるように区切る */
.menu-label {
  margin: 6px 0 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .15em;
}
.menu-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
  margin: 4px 0 10px;
  padding: 10px 0 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.menu-links a {
  padding: 6px 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.menu-links a:hover { color: #fff; }
.menu-links .menu-reset {
  padding: 6px 0;
  border: none;
  background: none;
  color: #ff8aa5;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(5, 2, 12, .55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.sheet-backdrop.on { opacity: 1; pointer-events: auto; }

/* 極ドパガキモード */
.auto {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 7px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
  cursor: pointer;
}
.auto input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  position: relative;
  flex: none;
  width: 50px;
  height: 28px;
  border-radius: 999px;
  background: #3a2d4f;
  transition: background .2s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
  transition: transform .25s cubic-bezier(.3, 1.6, .5, 1);
}
.auto input:checked + .switch {
  background: var(--rainbow);
  background-size: 200% 100%;
  animation: slide 1s linear infinite;
  box-shadow: 0 0 16px rgba(255, 0, 200, .8);
}
.auto input:checked + .switch::after { transform: translateX(22px); }
.auto input:focus-visible + .switch { outline: 2px solid #00e5ff; outline-offset: 3px; }
.auto-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.auto-name {
  font-family: "Dela Gothic One", sans-serif;
  letter-spacing: .06em;
  white-space: nowrap;
  font-size: clamp(13px, 4.2vw, 16px);
}
.auto-desc { font-size: 11px; color: var(--muted); }
.auto-state {
  margin-left: auto;
  flex: none;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--muted);
  border: 1px solid var(--line);
}
body.auto-on .auto {
  background: linear-gradient(#1a0f2a, #1a0f2a) padding-box, var(--rainbow) border-box;
  border: 1px solid transparent;
}
body.auto-on .auto-name {
  background: var(--rainbow);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: slide 1s linear infinite;
}
body.auto-on .auto-state { color: #000; background: #ffe600; border-color: #ffe600; }

/* ---------- buttons ---------- */
.dock-row {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 8px;
}
.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  min-height: 50px;
  padding: 8px 10px;
  font: 400 18px/1.1 "Dela Gothic One", sans-serif;
  letter-spacing: .06em;
  cursor: pointer;
  text-decoration: none;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  text-align: center;
  transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: default; animation: none; }
.btn-main {
  color: #000;
  background: var(--rainbow);
  background-size: 200% 100%;
  animation: slide 2s linear infinite, pulse 1.2s ease-in-out infinite;
}
.btn-x {
  color: #fff;
  background: #000;
  border: 1px solid #555;
  font-family: "Hiragino Sans", system-ui, sans-serif;
  font-weight: 800;
  letter-spacing: 0;
  font-size: 13px;
  gap: 5px;
  padding-inline: 6px;
}
.btn-x svg { flex: none; }
.btn-x.hot {
  background: linear-gradient(#000, #000) padding-box, var(--rainbow) border-box;
  border: 2px solid transparent;
  animation: pulse 1s ease-in-out infinite;
}

/* ---------- result overlay ---------- */
.result {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.result-inner { text-align: center; animation: slam .7s cubic-bezier(.2, 1.8, .4, 1) both; }
.result-big {
  font-family: "Dela Gothic One", sans-serif;
  font-size: clamp(80px, 30vw, 160px);
  line-height: 1;
  background: var(--rainbow);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  /* 巨大文字に「流れる虹色」＋2重のぼかし影は毎フレーム再計算で重いので、静止グラデ＋影1つ */
  filter: drop-shadow(0 0 24px rgba(255, 0, 200, .85));
  -webkit-text-stroke: 2px rgba(255, 255, 255, .6);
}
.result-sub {
  margin-top: 8px;
  font-family: "Dela Gothic One", sans-serif;
  font-size: clamp(22px, 7vw, 34px);
  color: #fff;
  text-shadow: 0 0 12px #ff00c8, 0 0 24px #00e5ff;
}
.result.lose .result-big {
  background: linear-gradient(180deg, #8aa0c0, #3a4560);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 16px rgba(0, 120, 255, .6));
  animation: none;
}
.result.lose .result-sub { text-shadow: 0 0 12px #0050ff; }
.result.fade .result-inner { animation: fadeOut .5s ease-in forwards; }

/* ---------- keyframes ---------- */
@keyframes slide { to { background-position: 200% 0; } }
@keyframes spin { to { --angle: 360deg; } }
@keyframes pulse { 50% { transform: scale(1.03); } } /* box-shadow を動かすと毎フレーム再描画になるので transform だけ */
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.9) rotate(-8deg); } 100% { transform: scale(1); } }
@keyframes targetPulse { from { opacity: .45; } to { opacity: 1; } }
@keyframes float { to { transform: translateY(-16%) scale(1.1); } }
@keyframes nudge { 0%, 70%, 100% { transform: none; } 80% { transform: translateY(-6%) rotate(-3deg); } 90% { transform: translateY(-6%) rotate(3deg); } }
@keyframes think { from { transform: rotate(180deg) translateX(-3px); } to { transform: rotate(180deg) translateX(3px); } }
@keyframes fly {
  0% { transform: rotate(180deg) scale(1); opacity: 1; }
  100% { transform: translate(140vw, 60vh) rotate(1260deg) scale(.4); opacity: 0; }
}
@keyframes flyMine {
  0% { transform: none; opacity: 1; }
  100% { transform: translate(-140vw, 60vh) rotate(-1080deg) scale(.4); opacity: 0; }
}
@keyframes toss {
  0% { transform: translateY(0) rotateY(0); }
  45% { transform: translateY(-90px) rotateY(900deg) rotateX(30deg); }
  100% { transform: translateY(0) rotateY(var(--end, 1800deg)); }
}
@keyframes flash { 0% { opacity: .95; } 100% { opacity: 0; } }
@keyframes shake {
  10%, 90% { transform: translate(-2px, 1px); }
  20%, 80% { transform: translate(4px, -2px); }
  30%, 50%, 70% { transform: translate(-8px, 4px) rotate(-1deg); }
  40%, 60% { transform: translate(8px, -4px) rotate(1deg); }
}
@keyframes slam { 0% { transform: scale(4) rotate(-12deg); opacity: 0; } 100% { transform: scale(1) rotate(-4deg); opacity: 1; } }
@keyframes fadeOut { to { transform: scale(.6) rotate(-4deg); opacity: 0; } }

/* ---------- 大きい画面 ---------- */
@media (min-width: 521px) {
  .app { gap: 12px; }
  .dock { padding: 0 16px 16px; border: 1px solid var(--line); border-bottom: none; }
}

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

/* ---------- FEVER (5連勝以上): 盤の色は変えず、周りを派手にする ---------- */
.aurora {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .8s;
  background:
    radial-gradient(circle at 20% 30%, rgba(255, 0, 76, .55), transparent 35%),
    radial-gradient(circle at 80% 25%, rgba(0, 229, 255, .5), transparent 35%),
    radial-gradient(circle at 30% 80%, rgba(43, 255, 0, .35), transparent 35%),
    radial-gradient(circle at 75% 75%, rgba(213, 0, 249, .55), transparent 35%);
  filter: blur(30px);
}
body.fever .aurora { opacity: 1; animation: aurora 6s ease-in-out infinite alternate, beat .5s ease-out infinite; will-change: transform, opacity; }
body.fever .title { animation: slide .8s linear infinite, wobble .5s ease-in-out infinite alternate; }
body.fever .stat-streak { box-shadow: 0 0 18px rgba(255, 120, 0, .9), 0 0 36px rgba(255, 0, 120, .6); animation: beatScale .5s ease-out infinite; }
body.fever .stat-streak .stat-label::before { content: "🔥"; }
body.fever .dock { box-shadow: 0 -10px 40px rgba(255, 0, 200, .35); }
@keyframes aurora {
  0% { transform: translate(0, 0) rotate(0deg) scale(1); }
  100% { transform: translate(4%, -3%) rotate(25deg) scale(1.15); }
}
@keyframes beat { 0% { opacity: 1; } 100% { opacity: .7; } }
@keyframes beatScale { 0% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes wobble { from { transform: rotate(-2deg) scale(1); } to { transform: rotate(2deg) scale(1.05); } }

/* ---------- サウンド表示 ---------- */
.sound-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .08);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  flex: none;
}
.sound-pill-icon::before { content: "🔊"; }
.sound-pill[data-state="off"] { color: var(--muted); }
.sound-pill[data-state="off"] .sound-pill-icon::before { content: "🔇"; }
.sound-pill[data-state="on"] {
  color: #000;
  border-color: transparent;
  background: var(--rainbow);
  background-size: 200% 100%;
  animation: slide 2s linear infinite;
  box-shadow: 0 0 12px rgba(255, 0, 200, .6);
}
.eq { display: none; align-items: flex-end; gap: 2px; height: 11px; }
.sound-pill[data-state="on"] .eq { display: flex; }
.sound-pill[data-state="on"] .sound-pill-icon { display: none; }
.eq i { width: 3px; background: #000; border-radius: 1px; animation: eq .6s ease-in-out infinite alternate; }
.eq i:nth-child(2) { animation-delay: .2s; }
.eq i:nth-child(3) { animation-delay: .4s; }
@keyframes eq { from { height: 3px; } to { height: 11px; } }

/* 最初の対局を始めて10秒後、サウンド表示の代わりに出すゲーム一覧への案内。
   入りきらない幅では、文字を2つ並べて右から左へ流し続ける（.scroll は app.js が付ける） */
.more-pill {
  display: block;
  /* タイトルは縮めず、残りの幅だけを使う */
  flex: 1 1 0;
  min-width: 0;
  max-width: max-content;
  overflow: hidden;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: linear-gradient(#22123a, #22123a) padding-box, var(--rainbow) border-box;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 0 12px rgba(255, 0, 200, .45);
  animation: morePillIn .4s cubic-bezier(.3, 1.6, .5, 1);
}
.more-pill:focus-visible { outline: 2px solid #00e5ff; outline-offset: 2px; }
.more-pill-track { display: inline-flex; }
.more-pill.scroll .more-pill-track { animation: marquee var(--marquee-s, 6s) linear infinite; }
.more-pill.scroll .more-pill-track > span { padding-right: 2em; }
@keyframes marquee { to { transform: translateX(-50%); } }
@keyframes morePillIn { from { opacity: 0; transform: scale(.6); } }
@keyframes blink { 50% { opacity: .45; } }

.menu-item[aria-pressed="true"] {
  background: linear-gradient(#22123a, #22123a) padding-box, var(--rainbow) border-box;
  border: 1px solid transparent;
}
.menu-item[aria-pressed="true"] b { color: #2bff00; }
.menu-item[aria-pressed="false"] { color: var(--muted); }
.menu-item b { font-weight: 900; }

.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 56px);
  left: 50%;
  z-index: 60;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .85);
  border: 1px solid #ffe600;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -10px);
  transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* 縦が短い画面では上の連勝表示の上まで伸びてOK。入りきらなければメニュー部分だけをスクロールし、
   モードのスイッチと対局開始・ポストのボタンは常に画面内に残す */
.dock.open {
  display: flex;
  flex-direction: column;
  max-height: calc(var(--vh) - max(8px, env(safe-area-inset-top)));
  overflow: hidden;
}
.dock.open > * { flex: none; }
.dock.open > .dock-menu { flex: 0 1 auto; min-height: 0; }
.dock.open .dock-menu-inner {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* モード名は折り返さない */
.auto-text { flex: 1; }

/* ---------- レイアウト節約: タイトル1行 + 盤の横に戦績 ---------- */
.head .title { font-size: clamp(28px, 8.5vw, 40px); }
.side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 104px;
  flex: none;
}
.side .stat { padding: 8px 4px; }
.side .stat-streak { padding: 10px 4px 12px; }
.side .stat-streak .stat-num { font-size: 44px; line-height: 1; margin-top: 2px; }
.side .stat-num.small { font-size: 16px; margin-top: 2px; }
.fever-chip {
  display: none;
  margin-top: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  color: #000;
  background: #ffe600;
}
body.fever .fever-chip { display: inline-block; animation: beatScale .5s ease-out infinite; }

.btn-x span { white-space: nowrap; }

/* ---------- 真・極ドパガキモード ---------- */
.shin-dialog {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 215, 0, .35), transparent 55%),
    rgba(5, 2, 12, .82);
  animation: fadeIn .25s ease-out;
}
.shin-card {
  position: relative;
  width: min(100%, 360px);
  padding: 26px 20px 18px;
  border-radius: 24px;
  text-align: center;
  background: #150a24;
  isolation: isolate;
  animation: shinPop .6s cubic-bezier(.2, 1.8, .4, 1) both;
}
.shin-card::before, .shin-card::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 27px;
  background: var(--conic);
  animation: spin 1.2s linear infinite;
  z-index: -1;
}
.shin-card::after { z-index: -2; filter: blur(30px); opacity: .9; inset: -10px; animation: glowPulse .6s ease-in-out infinite alternate; }
.shin-card > * { position: relative; }
/* 子の擬似要素(z負)はカード自身の背景より上に描かれるので、塗りも ::before 側で持つ */
.shin-card { background: none; }
.shin-card::before {
  border: 3px solid transparent;
  background: linear-gradient(#150a24, #150a24) padding-box, var(--conic) border-box;
}
.shin-kanji {
  margin: -70px auto 0;
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-family: "Yuji Syuku", serif;
  font-size: 64px;
  color: #3a2200;
  background: radial-gradient(circle at 35% 30%, #fff6c2, #ffd23f 45%, #c88a00);
  box-shadow: 0 0 0 4px #fff3, 0 0 30px #ffd23f, 0 0 60px #ff00c8;
  animation: wobble .4s ease-in-out infinite alternate;
}
.shin-eyebrow { margin: 12px 0 4px; font-weight: 900; color: #ffe600; letter-spacing: .1em; }
.shin-title {
  margin: 0;
  font-family: "Dela Gothic One", sans-serif;
  font-weight: 400;
  font-size: 22px;
  line-height: 1.35;
  background: var(--rainbow);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: slide 1s linear infinite;
}
.shin-perks {
  list-style: none;
  margin: 14px 0 16px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .06);
  text-align: left;
  font-size: 14px;
  line-height: 1.9;
}
.shin-perks li:last-child { font-size: 11px; color: var(--muted); }
.shin-yes { width: 100%; font-size: 22px; min-height: 58px; animation: slide .8s linear infinite, pulse .6s ease-in-out infinite; }
.shin-no {
  margin-top: 10px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}
@keyframes shinPop { 0% { transform: scale(.2) rotate(-20deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } }

/* 真モードのスイッチは金色 */
.shin-switch input:checked + .switch { background: linear-gradient(90deg, #c88a00, #ffd23f, #fff6c2, #ffd23f, #c88a00); background-size: 200% 100%; box-shadow: 0 0 16px #ffd23f; }
body.shin-on .shin-switch {
  background: linear-gradient(#22160a, #22160a) padding-box, linear-gradient(90deg, #c88a00, #ffd23f, #fff6c2, #ffd23f, #c88a00) border-box;
  border: 1px solid transparent;
}
body.shin-on .shin-switch .auto-name { color: #ffd23f; text-shadow: 0 0 10px #ffd23f; }
body.shin-on .shin-switch .auto-state { color: #000; background: #ffd23f; border-color: #ffd23f; }

/* 真モード中: 盤の枠を金×虹で太く、タイトルに「真」 */
body.shin-on .board-wrap::before { inset: -7px; padding: 9px; animation-duration: .5s; }
body.shin-on .board-wrap::after { opacity: 1; inset: -16px; filter: blur(30px); animation-duration: .5s; }
body.shin-on .board-wrap { box-shadow: 0 0 0 2px #ffd23f, 0 0 40px #ffd23f; }
body.shin-on .title::before {
  content: "真";
  display: inline-block;
  margin-right: 4px;
  padding: 0 6px;
  border-radius: 8px;
  font-family: "Yuji Syuku", serif;
  font-size: .7em;
  vertical-align: middle;
  color: #3a2200;
  -webkit-text-fill-color: #3a2200;
  background: radial-gradient(circle at 35% 30%, #fff6c2, #ffd23f 50%, #c88a00);
}
.revive-chip {
  margin-top: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  color: #fff;
  background: #ff2d7a;
  box-shadow: 0 0 10px #ff2d7a;
}
.result.revive .result-big {
  background: linear-gradient(90deg, #ffd23f, #fff6c2, #ff2d7a, #ffd23f);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
}

/* 真モード中はアニメーションも高速 */
body.shin-on .coin { animation-duration: .5s; }
body.shin-on .coin:nth-child(2) { animation-delay: .03s; }
body.shin-on .coin:nth-child(3) { animation-delay: .06s; }
body.shin-on .piece { transition-duration: .16s; }
body.shin-on .piece.captured { animation-duration: .6s; }

/* 狭い画面（360px未満）ではボタンを2段に */
@media (max-width: 359px) {
  .dock-row { grid-template-columns: 1fr; gap: 6px; }
  .dock-row .btn { min-height: 44px; }
  .btn-x { font-size: 14px; }
  /* ドックを詰めて盤の高さを確保 */
  .head .title { font-size: clamp(22px, 7.8vw, 30px); white-space: nowrap; }
  .auto { padding: 6px 10px; gap: 8px; margin-bottom: 6px; }
  .auto-name { font-size: 14px; white-space: nowrap; }
  .auto-desc { display: none; }
  .switch { width: 42px; height: 24px; }
  .switch::after { width: 18px; height: 18px; }
  .auto input:checked + .switch::after { transform: translateX(18px); }
  .side { width: 84px; }
  .side .stat-streak .stat-num { font-size: 34px; }
  .side .stat-num.small { font-size: 13px; }
}

/* ページ自体はスクロールさせない（スクロールは開いたシートの中だけ） */
html, body { overflow: hidden; }

/* 初回だけ出る「音が鳴ります」吹き出し（対局開始ボタンの上） */
.dock-row { position: relative; }
.sound-hint {
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  z-index: 3;
  padding: 7px 12px;
  border-radius: 12px;
  background: #ffe600;
  color: #000;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .4), 0 0 18px rgba(255, 230, 0, .6);
  pointer-events: none;
  animation: hintBounce 1s ease-in-out infinite;
}
.sound-hint small { display: block; font-size: 10px; font-weight: 700; opacity: .75; }
.sound-hint::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 36px;
  border: 8px solid transparent;
  border-top-color: #ffe600;
}
@keyframes hintBounce { 50% { transform: translateY(-4px); } }

/* 10連勝で新モード解放の告知 */
.secret {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: linear-gradient(#1a0d2c, #1a0d2c) padding-box, var(--conic) border-box;
  border: 2px solid transparent;
  animation: spin 2s linear infinite, secretPulse 1.2s ease-in-out infinite;
  box-shadow: 0 0 18px rgba(255, 210, 63, .45);
}
.secret-lock { font-size: 26px; animation: wobble .35s ease-in-out infinite alternate; }
.secret b { display: block; font-size: 15px; font-weight: 900; color: #fff; letter-spacing: .02em; }
.secret em {
  font-style: normal;
  font-family: "Dela Gothic One", sans-serif;
  font-weight: 400;
  background: var(--rainbow);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: slide 1s linear infinite;
}
.secret small { display: block; margin-top: 2px; font-size: 11px; color: #ffd23f; }
.secret.unlocked { box-shadow: 0 0 18px rgba(255, 210, 63, .8); }
@keyframes secretPulse { 50% { transform: scale(1.02); box-shadow: 0 0 28px rgba(255, 0, 200, .6); } }

/* ---------- 軽量モード（Android・低スペック端末。app.js が <html class="lite"> を付ける） ---------- */
/* 常に流れている虹色テキストや影を止めて、描画し直しを減らす */
.lite .title,
.lite .stat-streak .stat-num,
.lite .auto-name,
.lite .turn-badge,
.lite .sound-pill,
.lite .secret em,
.lite .shin-title { animation: none; }
.lite .title { filter: none; }
.lite body.fever .title { animation: wobble .5s ease-in-out infinite alternate; }
.lite .piece.selected { filter: drop-shadow(0 0 14px #00e5ff); }
.lite .result-big { filter: none; }
.lite .board-wrap::after { filter: blur(18px); }
.lite .aurora { filter: blur(20px); }
