:root {
  --ink: #fbf7ef;
  --ink-dim: rgba(251, 247, 239, 0.7);
  --shadow: rgba(10, 8, 6, 0.55);
  --glass: rgba(18, 20, 26, 0.52);
  --glass-strong: rgba(18, 20, 26, 0.55);
  --line: rgba(255, 255, 255, 0.22);
  --accent: #ff6a3d;
  --accent2: #ffc65c;
  --win: #7fe0a5;
  --lose: #ff7a6b;
  --draw: #a9c6ff;
  --mincho: 'Shippori Mincho B1', 'Yu Mincho', 'Hiragino Mincho ProN', serif;
  --gothic: 'Zen Kaku Gothic New', 'Hiragino Sans', 'Yu Gothic', sans-serif;
  --impact: 'Dela Gothic One', 'Zen Kaku Gothic New', sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #0b0d12; color: var(--ink);
  font-family: var(--gothic);
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
canvas#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; border: none; background: none; cursor: pointer; }
/* ドット絵（絵文字の代わり）。拡大してもにじませない */
img.px { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }

/* ---------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#topbar {
  position: absolute; top: calc(12px + var(--safe-t)); left: 16px; right: 16px;
  display: flex; justify-content: center; align-items: center;
  pointer-events: none;
}
#score {
  display: flex; gap: 6px; padding: 6px;
  background: var(--glass); border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.18);
  pointer-events: auto;
  transition: opacity .6s, transform .6s;
}
.score-item {
  min-width: 74px; padding: 6px 12px 7px; border-radius: 11px;
  display: flex; flex-direction: column; align-items: center; line-height: 1;
  background: rgba(255,255,255,0.06);
}
.score-item .label { font-size: 11px; letter-spacing: .2em; color: var(--ink-dim); font-weight: 700; margin-bottom: 5px; padding-left: .2em; }
.score-item .num { font-family: var(--impact); font-size: 26px; font-variant-numeric: tabular-nums; text-shadow: 0 2px 8px var(--shadow); }
.score-item.win .num { color: var(--win); }
.score-item.lose .num { color: var(--lose); }
.score-item.draw .num { color: var(--draw); }
.num.bump { animation: bump .55s cubic-bezier(.2,1.6,.4,1); }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.55); } 100% { transform: scale(1); } }

#sound-control {
  position: fixed; right: 16px; top: calc(26px + var(--safe-t)); z-index: 37;
}
#sound-toggle {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--glass); border: 1px solid var(--line);
  display: grid; place-items: center; pointer-events: auto;
}
#sound-toggle > * { grid-area: 1 / 1; }
#sound-toggle .note { font-size: 26px; line-height: 1; }
#sound-toggle svg { width: 24px; height: 24px; }
#sound-panel {
  position: absolute; right: 50%; top: calc(100% + 8px); transform: translateX(50%); width: 60px; padding: 12px 10px;
  border-radius: 16px; background: rgba(18, 20, 26, 0.96); border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
#sound-panel label { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; }
#volume {
  display: block; width: 100%; height: clamp(88px, 24vh, 132px); margin: 10px 0 0;
  writing-mode: vertical-lr; direction: rtl; accent-color: var(--accent2); cursor: pointer; touch-action: none;
}
#sound-control :focus-visible { outline: 2px solid var(--accent2); outline-offset: 3px; }
#codex-btn {
  position: absolute; right: 50px; top: 50%; transform: translateY(-50%);
  height: 42px; min-width: 42px; padding: 0 12px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; gap: 8px; pointer-events: auto;
  font-size: 12px; font-weight: 700; letter-spacing: .12em;
  transition: background .2s;
}
#codex-btn:hover { background: rgba(48, 52, 64, 0.62); }
#codex-btn img { width: 26px; height: 26px; flex: none; margin: -2px -2px 0; }
#codex-btn .lbl { display: none; }
#codex-btn .badge { display: none; position: absolute; top: 5px; right: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px rgba(18,20,26,0.8); }
#codex-btn.has-new .badge { display: block; }
@media (min-width: 760px) {
  #codex-btn { padding: 0 16px 0 14px; }
  #codex-btn .lbl { display: inline; }
  #codex-btn .badge { top: 4px; right: 6px; }
}
#sound-toggle .off { display: none; }
#sound-toggle.muted { color: var(--accent2); }
#sound-toggle.muted .note { opacity: .45; }
#sound-toggle.muted .off { display: block; }

#repertoire {
  position: absolute; top: calc(78px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; padding: 5px 12px 5px 14px;
  border-radius: 999px; background: rgba(18,20,26,0.45); border: 1px solid rgba(255,255,255,0.14);
  font-size: 11px; color: var(--ink-dim); letter-spacing: .15em;
  transition: opacity .6s;
}
.rep-label { margin-right: 4px; font-weight: 700; }
.rep { filter: grayscale(1) brightness(.5); opacity: .35; transition: all .6s; }
.rep img { width: 20px; height: 20px; }
/* エンドレス中は「カニの手」の代わりに、連勝・連敗・連続あいこを表示する */
body.endless #repertoire .rep-label, body.endless #repertoire .rep { display: none; }
body.endless #mode-tag { margin-left: 0; }
#streak-tag { margin-left: 8px; padding: 2px 10px; border-radius: 999px; font-weight: 900; letter-spacing: .1em; }
#streak-tag.hidden { display: none; }
#streak-tag.streak-win { background: rgba(127, 224, 165, 0.2); color: var(--win); }
#streak-tag.streak-lose { background: rgba(255, 122, 107, 0.2); color: var(--lose); }
#streak-tag.streak-draw { background: rgba(169, 198, 255, 0.2); color: var(--draw); }
#mode-tag { margin-left: 6px; padding: 2px 8px; border-radius: 999px; background: rgba(255, 198, 92, 0.2); color: var(--accent2); font-weight: 700; letter-spacing: .1em; }
/* クリア後「カニの手を見る」：カニが次に出す手 */
#crab-next {
  position: absolute; top: calc(116px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; padding: 5px 12px 5px 14px; border-radius: 999px;
  background: rgba(18,20,26,0.6); border: 1px solid rgba(255, 198, 92, 0.45);
  font-size: 11px; font-weight: 700; letter-spacing: .14em; color: var(--accent2); pointer-events: none !important;
}
#crab-next img { width: 28px; height: 28px; }
.rep.known { filter: none; opacity: 1; }
.rep.unlock { animation: unlock 1.6s cubic-bezier(.2,1.4,.4,1); }
@keyframes unlock {
  0% { transform: scale(0.4) rotate(-30deg); filter: brightness(3); }
  40% { transform: scale(1.9) rotate(8deg); filter: brightness(2) drop-shadow(0 0 12px #ffd46b); }
  100% { transform: scale(1) rotate(0); }
}

/* じゃん・けん・ぽん */
#call {
  position: absolute; left: 0; right: 0; top: 38%;
  text-align: center; font-family: var(--impact);
  font-size: clamp(54px, 13vw, 132px); letter-spacing: .04em;
  color: #fff; pointer-events: none;
  text-shadow: 0 6px 0 rgba(0,0,0,0.25), 0 12px 40px rgba(0,0,0,0.35);
  -webkit-text-stroke: 2px rgba(60,20,10,0.35);
  transition: opacity .3s ease, filter .3s ease;
}
#call.hide { opacity: 0; filter: blur(6px); }
#call .w { display: inline-block; animation: callIn .42s cubic-bezier(.15,1.6,.35,1) both; }
#call.pon .w { color: #ffdf6b; animation: ponIn .5s cubic-bezier(.1,1.8,.3,1) both; }
#call.s3 .w { background: linear-gradient(180deg, #fff6c2, #ffb13b 55%, #ff5a2a); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-stroke: 0; filter: drop-shadow(0 6px 0 rgba(90,30,0,.5)) drop-shadow(0 0 30px rgba(255,170,60,.6)); }
#call.slow .w { animation-duration: 1.6s; }
@keyframes callIn { 0% { transform: scale(2.4) translateY(-10px); opacity: 0; filter: blur(8px); } 100% { transform: scale(1); opacity: 1; filter: blur(0); } }
@keyframes ponIn { 0% { transform: scale(4) rotate(-8deg); opacity: 0; } 60% { transform: scale(0.92) rotate(2deg); opacity: 1; } 100% { transform: scale(1) rotate(0); } }

#speedlines {
  position: absolute; inset: -20%; pointer-events: none; opacity: 0;
  background: repeating-conic-gradient(from 0deg at 50% 50%, rgba(255,255,255,0) 0deg 4deg, rgba(255,255,255,0.55) 4.4deg 5deg, rgba(255,255,255,0) 5.4deg 9deg);
  -webkit-mask-image: radial-gradient(circle at 50% 50%, transparent 22%, #000 60%);
  mask-image: radial-gradient(circle at 50% 50%, transparent 22%, #000 60%);
}
#speedlines.on { animation: speed .9s ease-out; }
@keyframes speed { 0% { opacity: .9; transform: scale(1.25) rotate(0); } 100% { opacity: 0; transform: scale(1) rotate(6deg); } }

/* ナレーション */
#message {
  position: absolute; left: 16px; right: 16px; bottom: calc(150px + var(--safe-b));
  display: flex; justify-content: center; pointer-events: none;
}
#message span {
  display: inline-block; max-width: 760px; text-align: center;
  font-family: var(--mincho); font-weight: 700;
  font-size: clamp(16px, 2.3vw, 23px); line-height: 1.7; letter-spacing: .12em;
  padding: 10px 26px 11px; border-radius: 4px;
  background: linear-gradient(90deg, rgba(8,8,10,0) 0%, rgba(8,8,10,0.55) 18%, rgba(8,8,10,0.55) 82%, rgba(8,8,10,0) 100%);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  opacity: 0; transform: translateY(6px); filter: blur(3px);
  transition: opacity .5s ease, transform .6s ease, filter .5s ease;
}
#message.show span { opacity: 1; transform: none; filter: none; }

/* ボタン */
#controls {
  position: absolute; left: 0; right: 0; bottom: calc(22px + var(--safe-b));
  display: flex; justify-content: center; gap: clamp(12px, 4vw, 30px);
  transition: transform .5s cubic-bezier(.2,.9,.3,1), opacity .4s;
}
#controls.off { transform: translateY(40px); opacity: 0; pointer-events: none; }
.hand-btn {
  position: relative;
  width: clamp(86px, 24vw, 112px); height: clamp(98px, 27vw, 118px);
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(70,74,86,0.62), rgba(24,26,32,0.62));
  border: 1px solid rgba(255,255,255,0.35);
  box-shadow: 0 14px 30px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.5), inset 0 -10px 20px rgba(0,0,0,0.12);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  transition: transform .18s cubic-bezier(.2,1.4,.4,1), box-shadow .2s, background .2s, opacity .3s;
  overflow: hidden;
}
.hand-btn::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(115deg, transparent 30%, rgba(255,255,255,0.35) 45%, transparent 60%);
  transform: translateX(-120%); transition: transform .7s;
}
.hand-btn:hover::after { transform: translateX(120%); }
.hand-btn .emoji { width: clamp(40px, 11vw, 52px); height: clamp(40px, 11vw, 52px); filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3)); transition: transform .2s; }
.hand-btn .name { font-weight: 900; font-size: 14px; letter-spacing: .2em; padding-left: .2em; text-shadow: 0 1px 3px rgba(0,0,0,0.5); }
@media (hover: hover) {
  .hand-btn:hover { transform: translateY(-6px); background: linear-gradient(180deg, rgba(95,99,112,0.7), rgba(34,36,44,0.66)); }
  .hand-btn:hover .emoji { transform: scale(1.12) rotate(-6deg); }
}
.hand-btn:active { transform: translateY(2px) scale(0.95); }
.hand-btn.chosen { background: linear-gradient(180deg, rgba(255,190,90,0.7), rgba(255,110,60,0.4)); border-color: rgba(255,220,160,0.9); }
#controls.busy .hand-btn:not(.chosen) { opacity: .35; }
#controls.busy { pointer-events: none; }

/* スキップ案内・発見通知（クリックを邪魔しない） */
#skip-hint {
  position: absolute; right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(18px + var(--safe-b));
  display: flex; align-items: center; gap: 8px; padding: 8px 16px 9px 13px; border-radius: 999px;
  background: rgba(18,20,26,0.66); border: 1px solid rgba(255,255,255,0.3);
  font-size: 12px; font-weight: 700; letter-spacing: .14em; color: var(--ink);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  opacity: 0; transform: translateY(8px); transition: opacity .4s, transform .4s; pointer-events: none !important;
}
#skip-hint.show { opacity: 1; transform: none; }
#skip-hint .ff { font-size: 18px; line-height: 1; margin-top: -2px; color: var(--accent2); animation: ffNudge 1.1s ease-in-out infinite; }
@keyframes ffNudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(3px); } }
#toast {
  position: absolute; left: 16px; right: 16px; top: calc(158px + var(--safe-t));
  display: flex; justify-content: center; pointer-events: none !important;
}
#toast span {
  display: inline-block; padding: 6px 16px 7px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .14em;
  background: rgba(18,20,26,0.62); border: 1px solid rgba(255,255,255,0.2); color: var(--accent2);
  opacity: 0; transform: translateY(-6px); transition: opacity .4s, transform .4s;
}
#toast.show span { opacity: 1; transform: none; }
body.cinematic #toast { display: none; }

/* フィナーレ大文字 */
#bigtext {
  position: fixed; left: 0; right: 0; bottom: 17%; display: flex; justify-content: center; pointer-events: none; z-index: 20;
}
#bigtext span {
  font-family: var(--mincho); font-weight: 800;
  font-size: min(6vw, 96px); letter-spacing: .14em; padding-left: .14em;
  color: #fff7e2; opacity: 0;
  text-shadow: 0 0 30px rgba(255,190,90,0.6), 0 0 80px rgba(255,140,60,0.35), 0 4px 0 rgba(0,0,0,0.4);
  white-space: nowrap;
}
/* エンドレスの節目：ナレーションの帯と重ならないよう上寄りに */
#bigtext.upper { bottom: auto; top: max(24%, calc(118px + var(--safe-t))); }
#bigtext.show span { animation: bigIn 2.6s cubic-bezier(.2,.8,.2,1) forwards; }
#bigtext.hide span { opacity: 1; animation: bigOut 1.6s ease forwards; }
@keyframes bigIn { 0% { opacity: 0; letter-spacing: .2em; filter: blur(16px); transform: scale(1.1); } 100% { opacity: 1; letter-spacing: .14em; filter: blur(0); transform: scale(1); } }
@keyframes bigOut { to { opacity: 0; filter: blur(10px); transform: scale(0.96); } }

/* ---------------------------------------------------------------- タイトル */
#title-screen {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 60%, rgba(0,0,0,0) 30%, rgba(0,0,0,0.45) 100%);
  transition: opacity 1.2s;
}
#title-screen.fade { opacity: 0; pointer-events: none; }
.title-inner { text-align: center; transform: translateY(-6vh); }
#title-screen h1 {
  margin: 0; font-family: var(--mincho); font-weight: 800;
  font-size: clamp(46px, 11vw, 120px); letter-spacing: .08em; line-height: 1.1;
  color: #fffaf0;
  text-shadow: 0 4px 0 rgba(90,30,10,0.35), 0 20px 60px rgba(0,0,0,0.45);
}
#title-screen h1 span { display: inline-block; opacity: 0; animation: titleIn 1.4s cubic-bezier(.2,.8,.2,1) forwards; }
#title-screen h1 .t1 { color: #ff8a5c; animation-delay: .2s; }
#title-screen h1 .t2 { font-size: .55em; margin: 0 .1em; animation-delay: .5s; }
#title-screen h1 .t3 { animation-delay: .75s; }
/* 全行動観察の達成マーク（タイトルロゴの右上に押されたスタンプ） */
.title-logo { position: relative; display: inline-block; }
#title-complete {
  position: absolute; right: -5%; bottom: -62%;
  width: clamp(76px, 11vw, 112px); aspect-ratio: 1; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: radial-gradient(circle at 40% 35%, #ffe7a6, #f0b445 60%, #c9801f);
  border: 3px double #7a3f10; box-shadow: 0 8px 24px rgba(0,0,0,0.35), inset 0 0 0 3px rgba(255,255,255,0.25);
  color: #4a2408; font-family: var(--mincho); font-weight: 800; font-size: clamp(11px, 1.4vw, 15px);
  letter-spacing: .14em; line-height: 1.12; text-align: center;
  transform: rotate(12deg); opacity: 0; animation: stampIn .7s 2.1s cubic-bezier(.2,1.5,.4,1) forwards;
}
#title-complete img { width: 54%; height: auto; margin-top: -4px; }
@media (max-width: 520px) {
  /* スマホではロゴの上の空いているところに */
  #title-complete { right: auto; bottom: auto; left: 50%; top: -112%; margin-left: -38px; }
}
@keyframes stampIn { 0% { opacity: 0; transform: rotate(12deg) scale(2.4); } 100% { opacity: 1; transform: rotate(12deg) scale(1); } }
@keyframes titleIn { 0% { opacity: 0; transform: translateY(24px); filter: blur(12px); } 100% { opacity: 1; transform: none; filter: none; } }
#title-screen .en {
  margin: 12px 0 0; font-family: var(--gothic); font-weight: 700;
  letter-spacing: .7em; padding-left: .7em; font-size: clamp(11px, 1.6vw, 15px);
  color: rgba(255,255,255,0.85); opacity: 0; animation: titleIn 1.4s 1.1s forwards;
}
#start-btn, #retry-btn {
  padding: 16px 52px 17px;
  font-family: var(--mincho); font-weight: 800; font-size: clamp(17px, 2.2vw, 21px); letter-spacing: .3em; padding-left: calc(52px + .3em);
  color: #2a120a; border-radius: 999px;
  background: linear-gradient(180deg, #fff3dd, #ffc58f);
  box-shadow: 0 14px 40px rgba(255,120,60,0.35), inset 0 1px 0 #fff, inset 0 -3px 0 rgba(160,70,20,0.25);
  opacity: 0; animation: titleIn 1.2s 1.5s forwards;
  transition: transform .2s cubic-bezier(.2,1.5,.4,1), box-shadow .2s;
}
#start-btn:hover, #retry-btn:hover { transform: translateY(-3px) scale(1.03); box-shadow: 0 18px 50px rgba(255,120,60,0.5), inset 0 1px 0 #fff, inset 0 -3px 0 rgba(160,70,20,0.25); }
#start-btn:active, #retry-btn:active { transform: scale(0.97); }
.hint { margin-top: 18px; font-size: 12px; letter-spacing: .25em; color: rgba(255,255,255,0.65); opacity: 0; animation: titleIn 1s 2s forwards; }

/* ---------------------------------------------------------------- エンディング */
#ending {
  position: fixed; inset: 0; z-index: 25; display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 50%, rgba(5,4,3,0.55), rgba(0,0,0,0.88));
  opacity: 0; transition: opacity 2.5s ease;
  padding: 16px; overflow-y: auto;
}
#ending.show { opacity: 1; }
.ending-inner { text-align: center; max-width: 900px; }
.ending-line {
  margin: 0; min-height: 1.6em;
  font-family: var(--mincho); font-weight: 700;
  font-size: clamp(19px, 3.6vw, 40px); letter-spacing: .14em; line-height: 1.6;
  color: #fff6e6; text-shadow: 0 0 24px rgba(255,190,110,0.35);
}
.ending-line .seg { display: inline-block; white-space: nowrap; }
.ending-line .ch { opacity: 0; display: inline-block; animation: chIn .9s forwards; }
.ending-sub {
  margin: 18px 0 0; min-height: 1.6em; font-family: var(--mincho); font-weight: 500;
  font-size: clamp(13px, 1.9vw, 18px); letter-spacing: .16em; color: rgba(255, 246, 230, 0.75);
  opacity: 0; transition: opacity 1.6s;
}
.ending-sub.show { opacity: 1; }
@keyframes chIn { from { opacity: 0; filter: blur(6px); transform: translateY(4px); } to { opacity: 1; filter: none; transform: none; } }
.ending-stats {
  display: flex; justify-content: center; gap: clamp(18px, 6vw, 60px); margin-top: 48px;
  opacity: 0; transform: translateY(10px); transition: opacity 1.4s, transform 1.4s;
}
.ending-stats.show { opacity: 1; transform: none; }
.ending-stats div { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.ending-stats .label { font-size: 13px; letter-spacing: .3em; color: rgba(255,255,255,0.6); font-weight: 700; padding-left: .3em; }
.ending-stats .num { font-family: var(--mincho); font-weight: 800; font-size: clamp(36px, 6vw, 60px); color: #fff; }
#retry-btn { animation: none; opacity: 1; letter-spacing: .14em; padding-left: calc(40px + .14em); padding-right: 40px; }
.start-row { margin-top: 48px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px 16px; }
.reveal-opt {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 999px; cursor: pointer;
  background: rgba(18,20,26,0.5); border: 1px solid rgba(255,255,255,0.28);
  font-size: 13px; font-weight: 700; letter-spacing: .1em; color: var(--ink);
}
.reveal-opt input { width: 18px; height: 18px; margin: 0; accent-color: #ffb46b; }
.sub-btn {
  margin-top: 14px; padding: 11px 26px 12px; border-radius: 999px;
  font-family: var(--mincho); font-weight: 800; font-size: clamp(14px, 1.8vw, 17px); letter-spacing: .14em;
  background: rgba(18,20,26,0.55); border: 1px solid rgba(255, 210, 150, 0.55); color: #fff3dd;
  transition: transform .2s cubic-bezier(.2,1.5,.4,1), background .2s;
}
.sub-btn:hover { transform: translateY(-2px); background: rgba(48,40,32,0.7); }
.sub-btn:disabled, #retry-btn:disabled { cursor: default; }
#title-screen .reveal-opt, #title-screen .sub-btn { opacity: 0; animation: titleIn 1.2s 1.7s forwards; }
.ending-actions { display: flex; flex-direction: column; align-items: center; opacity: 0; transition: opacity 1.2s; pointer-events: none; }
.ending-actions.show { opacity: 1; pointer-events: auto; }

/* ---------------------------------------------------------------- ローディング */
#loading {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: #0b0d12; transition: opacity 1s;
}
#loading.fade { opacity: 0; pointer-events: none; }
.loading-inner { text-align: center; }
.loading-crab { width: 64px; height: 64px; margin: 0 auto; animation: scuttle 1.2s ease-in-out infinite; }
@keyframes scuttle { 0%,100% { transform: translateX(-18px); } 50% { transform: translateX(18px); } }
.loading-bar { width: 200px; height: 2px; background: rgba(255,255,255,0.12); margin: 22px auto 14px; border-radius: 2px; overflow: hidden; }
.loading-bar div { height: 100%; width: 0; background: linear-gradient(90deg, #ff8a5c, #ffd18a); transition: width .4s; }
#loading-text { font-family: var(--mincho); font-size: 13px; letter-spacing: .25em; color: rgba(255,255,255,0.6); margin: 0; }

#blackout { position: fixed; inset: 0; background: #000; z-index: 40; opacity: 0; pointer-events: none; transition: opacity .05s; }
#blackout.on { opacity: 1; }

#file-warning { position: fixed; inset: 0; z-index: 100; background: #0b0d12; display: grid; place-items: center; text-align: center; padding: 24px; line-height: 1.9; font-family: var(--mincho); }
#file-warning code { background: rgba(255,255,255,0.1); padding: 2px 8px; border-radius: 4px; font-family: ui-monospace, monospace; }

body.cinematic #topbar, body.cinematic #repertoire { opacity: 0; }
body.cinematic #codex-btn { visibility: hidden; }
body.cinematic #score { opacity: 0; }

@media (max-width: 520px) {
  #skip-hint { right: 8px; bottom: calc(1px + var(--safe-b)); padding: 3px 11px 4px 9px; font-size: 10px; gap: 6px; }
  #skip-hint .ff { font-size: 14px; }
  #crab-next { top: calc(106px + var(--safe-t)); }
  #toast { top: calc(150px + var(--safe-t)); }
  .score-item { min-width: 62px; padding: 5px 8px 6px; }
  .score-item .num { font-size: 22px; }
  #topbar { justify-content: flex-start; }
  #sound-toggle { width: 38px; height: 38px; }
  #sound-control { top: calc(24px + var(--safe-t)); }
  #repertoire { top: calc(70px + var(--safe-t)); }
  #message { bottom: calc(138px + var(--safe-b)); }
}
@media (max-height: 520px) and (orientation: landscape) {
  #message { bottom: calc(118px + var(--safe-b)); }
  .hand-btn { height: 86px; width: 92px; }
  .hand-btn .emoji { width: 36px; height: 36px; }
  #repertoire { display: none; }
  body.endless #repertoire { display: flex; top: calc(70px + var(--safe-t)); }
  #call { top: 30%; }
}

/* ---------------------------------------------------------------- 観察記録 */
#codex {
  position: fixed; inset: 0; z-index: 35; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 12px;
  background: rgba(6, 7, 10, 0.8);
  transition: opacity .25s;
}
#codex.away { opacity: 0; visibility: hidden; pointer-events: none; }
.cx-panel {
  width: min(980px, 100%); min-width: 0; height: min(88vh, 780px); display: flex; flex-direction: column;
  background: rgba(20, 22, 29, 0.94); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.12);
  overflow: hidden;
}
.cx-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 6px; }
.cx-head h2 { margin: 0; font-family: var(--mincho); font-weight: 800; font-size: clamp(19px, 2.6vw, 25px); letter-spacing: .18em; }
#codex-close { width: 38px; height: 38px; border-radius: 50%; font-size: 24px; line-height: 1; background: rgba(255,255,255,0.08); }
#codex-close:hover { background: rgba(255,255,255,0.16); }
.cx-stats {
  display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 14px; padding: 4px 22px 10px;
}
.cx-label { font-size: 12px; letter-spacing: .2em; color: var(--ink-dim); font-weight: 700; }
.cx-rate { grid-column: 2; grid-row: 1 / span 2; font-size: 13px; letter-spacing: .1em; color: var(--accent2); font-weight: 700; align-self: center; }
.cx-count { font-family: var(--impact); font-size: 30px; font-variant-numeric: tabular-nums; }
.cx-meter { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.1); overflow: hidden; margin-top: 4px; }
.cx-meter div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .5s; }
.cx-tabs { display: flex; gap: 6px; padding: 0 20px 10px; overflow-x: auto; scrollbar-width: none; }
.cx-tabs::-webkit-scrollbar { display: none; }
.cx-tab {
  flex: none; padding: 7px 14px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .08em;
  background: rgba(255,255,255,0.07); border: 1px solid transparent; color: var(--ink-dim); white-space: nowrap;
}
.cx-tab.on { background: rgba(255, 198, 92, 0.16); border-color: rgba(255, 198, 92, 0.5); color: var(--ink); }
.cx-note { margin: 0 22px 8px; font-size: 12px; color: var(--ink-dim); letter-spacing: .06em; }
.cx-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px 18px; overscroll-behavior: contain; touch-action: pan-y; }
.cx-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px 10px; }
.cx-card {
  position: relative; display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 14px; min-width: 0;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
}
.cx-card.lock { background: rgba(255,255,255,0.025); border-style: dashed; }
.cx-card.new { border-color: rgba(255, 106, 61, 0.7); box-shadow: 0 0 0 1px rgba(255,106,61,0.25); }
.cx-card.new::after { content: "NEW"; position: absolute; top: -7px; left: 10px; padding: 1px 7px; border-radius: 999px; font-size: 10px; font-weight: 900; letter-spacing: .1em; background: var(--accent); color: #2a120a; }
.cx-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; background: rgba(255,255,255,0.08); }
.cx-icon img { width: 48px; height: 48px; }
.cx-card.lock .cx-icon img { opacity: .55; }
.cx-head h2 { display: flex; align-items: center; gap: 10px; }
.cx-logo { width: 34px; height: 34px; }
.cx-empty { margin: 24px 6px; color: var(--ink-dim); font-size: 13px; letter-spacing: .1em; }
.cx-body { min-width: 0; }
.cx-name { font-weight: 900; font-size: 14px; letter-spacing: .08em; overflow-wrap: anywhere; }
.cx-card.lock .cx-name { color: rgba(255,255,255,0.4); letter-spacing: .2em; }
.cx-desc { margin-top: 2px; font-size: 12px; line-height: 1.5; color: var(--ink-dim); overflow-wrap: anywhere; }
.cx-meta { margin-top: 3px; font-size: 10px; letter-spacing: .12em; color: rgba(255,255,255,0.4); }
.cx-play {
  align-self: center; padding: 7px 11px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .06em; white-space: nowrap;
  background: rgba(255, 198, 92, 0.18); border: 1px solid rgba(255, 198, 92, 0.45);
}
.cx-play:hover:not(:disabled) { background: rgba(255, 198, 92, 0.32); }
.cx-play:disabled { opacity: .4; cursor: default; background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.14); }
@media (max-width: 520px) {
  .cx-card { grid-template-columns: 42px 1fr; }
  .cx-icon, .cx-icon img { width: 42px; height: 42px; }
  .cx-play { grid-column: 1 / -1; justify-self: end; }
  .cx-list { grid-template-columns: minmax(0, 1fr); }
}
#preview-bar {
  position: fixed; left: 0; right: 0; top: calc(14px + var(--safe-t)); z-index: 36;
  display: flex; justify-content: center; align-items: center; gap: 12px; pointer-events: none;
}
#preview-bar > * { pointer-events: auto; }
#preview-bar span { font-size: 12px; font-weight: 700; letter-spacing: .2em; padding: 8px 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); color: var(--accent2); }
#preview-stop { padding: 9px 16px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .06em; background: var(--glass); border: 1px solid var(--line); }
#preview-stop:hover { background: rgba(48, 52, 64, 0.7); }
