/* TSUBUSHI BEAT — design tokens (anti-slop constraints)
   紙 #f2ead8 / 墨 #17140f / 朱 #e0392b(主役) / 黄 #ffc81a(機能のみ)
   角丸4px統一 / ハードシャドウ / グラデ・ガラス・Inter禁止 */
:root {
  --paper: #f2ead8;
  --paper-dim: #d9cfb6;
  --ink: #17140f;
  --cabinet: #141210;
  --cabinet-2: #1e1a14;
  --aka: #e0392b;
  --aka-deep: #a92418;
  --coin: #ffc81a;
  --radius: 4px;
  --shadow: 5px 5px 0 #000;
  --font-display: "DotGothic16", "Hiragino Kaku Gothic ProN", sans-serif;
  --font-body: "Zen Kaku Gothic New", -apple-system, "Hiragino Kaku Gothic ProN", sans-serif;
  --ease-press: cubic-bezier(.2, 1.6, .36, 1);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--cabinet); color: var(--paper);
  font-family: var(--font-body);
  touch-action: none; user-select: none; -webkit-user-select: none;
  position: fixed; width: 100%;
}
#app { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- HUD : ticket chips ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
#hud.hidden { display: none; }
#hud-top { display: flex; align-items: stretch; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 12px 0; }
.chip {
  background: var(--paper); color: var(--ink);
  border: 3px solid #000; border-radius: var(--radius);
  box-shadow: 4px 4px 0 #000;
  padding: 4px 12px 5px; min-width: 92px;
  display: flex; flex-direction: column; line-height: 1.1;
}
.chip-label { font-family: var(--font-display); font-size: 11px; letter-spacing: .12em; }
#score, #level, #duo-state { font-family: var(--font-display); font-size: 24px; }
#duo-lamp.duo-off #duo-state { color: #8a8271; }
#duo-lamp.duo-on { background: var(--coin); }
#duo-lamp.duo-on #duo-state { color: var(--ink); }
#pause-btn {
  margin-left: auto; pointer-events: auto;
  width: 48px; border: 3px solid #000; border-radius: var(--radius);
  background: var(--paper); color: var(--ink);
  font-family: var(--font-display); font-size: 16px;
  box-shadow: 4px 4px 0 #000; cursor: pointer;
  transition: transform 120ms var(--ease-press), box-shadow 120ms var(--ease-press);
}
#pause-btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 #000; }
#mute-btn {
  pointer-events: auto;
  min-width: 56px; border: 3px solid #000; border-radius: var(--radius);
  background: var(--coin); color: var(--ink);
  font-family: var(--font-display); font-size: 13px;
  box-shadow: 4px 4px 0 #000; cursor: pointer;
  transition: transform 120ms var(--ease-press), box-shadow 120ms var(--ease-press);
}
#mute-btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 #000; }
#mute-btn.off { background: var(--paper); color: #8a8271; }
#hp-wrap { display: flex; align-items: center; gap: 8px; margin: 10px 12px 0; }
#hp-label { font-family: var(--font-display); font-size: 14px; background: #000; padding: 2px 8px; border-radius: var(--radius); }
#hp-bar { flex: 1; height: 16px; border: 3px solid #000; border-radius: var(--radius); background: #000; overflow: hidden; }
#hp-fill { height: 100%; width: 100%; background: var(--coin); transition: width 180ms var(--ease-out); }
#hp-fill.low { background: var(--aka); }
#beat-dots { display: flex; gap: 6px; margin: 8px 12px 0; }
#beat-dots span { width: 22px; height: 10px; background: #000; border: 2px solid #000; border-radius: 2px; }
#beat-dots span.on { background: var(--coin); }
#combo { position: absolute; top: 20%; width: 100%; text-align: center; }
#combo.hidden { display: none; }
#combo-num { font-family: var(--font-display); font-size: 64px; color: var(--coin); text-shadow: 3px 3px 0 #000; }
.combo-label { display: block; font-family: var(--font-display); letter-spacing: .34em; font-size: 13px; }

/* ---------- Screens : paper card on cabinet ---------- */
.screen {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  background: rgba(10, 8, 6, .72);
}
.screen.hidden { display: none; }
.card {
  width: min(430px, 100%); max-height: 100%; overflow-y: auto;
  touch-action: pan-y; overscroll-behavior: contain;
  background: var(--paper); color: var(--ink);
  border: 3px solid #000; border-radius: 6px;
  box-shadow: 8px 8px 0 #000;
  padding: 18px 16px 16px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.hanko {
  font-family: var(--font-display);
  background: var(--aka); color: var(--paper);
  font-size: 52px; line-height: 1;
  width: 76px; height: 76px;
  display: flex; align-items: center; justify-content: center;
  border: 3px solid #000; border-radius: 6px;
  box-shadow: 4px 4px 0 #000;
  transform: rotate(-4deg);
}
.hanko.small { font-size: 44px; width: 68px; height: 68px; }
h1 { font-family: var(--font-display); font-size: 34px; letter-spacing: .04em; text-wrap: balance; }
h2 { font-family: var(--font-display); font-size: 32px; letter-spacing: .06em; }
.tagline { font-size: 14px; font-weight: 700; }
.duo-demo { display: flex; align-items: stretch; gap: 0; background: var(--ink); border-radius: var(--radius); padding: 12px 20px; }
.duo-demo .panel { width: 54px; height: 78px; background: #e6e2d8; border: 3px solid #000; position: relative; box-shadow: 3px 4px 0 #000; }
.duo-demo .panel::after { content: ""; position: absolute; inset: 12px 8px 22px; background: #0b0b0e; border-radius: 6px; }
.duo-demo .p-left { border-radius: 12px 3px 3px 12px; transform: perspective(220px) rotateY(24deg); }
.duo-demo .p-right { border-radius: 3px 12px 12px 3px; transform: perspective(220px) rotateY(-24deg); }
.duo-demo .hinge { width: 12px; background: var(--aka); border-top: 3px solid #000; border-bottom: 3px solid #000; border-radius: 2px; }
.fold-hint { font-family: var(--font-display); font-size: 13px; }
#fold-badge { font-family: var(--font-display); background: var(--ink); color: var(--coin); padding: 2px 10px; border-radius: var(--radius); }
#fold-badge[data-state="ok"] { background: var(--coin); color: var(--ink); animation: badge-pulse 1.4s ease-in-out infinite; }
#fold-badge[data-state="folded"] { background: var(--aka); color: var(--paper); animation: badge-pulse 0.7s ease-in-out infinite; }
#fold-badge[data-state="off"] { background: var(--ink); color: #8a8271; }
@keyframes badge-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { #fold-badge[data-state] { animation: none; } }
.howto { text-align: left; font-size: 13px; line-height: 1.75; list-style: none; background: #fff8; border: 2px dashed var(--ink); border-radius: var(--radius); padding: 10px 14px; width: 100%; }
.dot { display: inline-block; width: 13px; height: 13px; margin-right: 4px; vertical-align: -1px; border: 2px solid #000; }
.ball-dot { background: var(--paper); border-radius: 50%; }
.bomb-dot { background: var(--ink); border-radius: 50%; outline: 2px solid var(--aka); outline-offset: -4px; }
.bpm-row { font-family: var(--font-display); display: flex; gap: 10px; align-items: center; font-size: 16px; }
#bpm-lock { font-size: 12px; background: var(--ink); color: var(--coin); padding: 2px 8px; border-radius: var(--radius); }
#bpm-lock.hidden { display: none; }
select:disabled { opacity: 0.55; }
.cal-row { font-family: var(--font-display); display: flex; gap: 10px; align-items: center; font-size: 16px; }
.mode-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.mode-btn {
  font-family: var(--font-display); font-size: 13px;
  background: var(--paper); color: var(--ink);
  border: 3px solid #000; border-radius: var(--radius);
  box-shadow: 3px 3px 0 #000; padding: 3px 9px; cursor: pointer;
  transition: transform 120ms var(--ease-press), box-shadow 120ms var(--ease-press), background 150ms var(--ease-out);
}
.mode-btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 #000; }
.mode-btn.sel { background: var(--ink); color: var(--paper); }
#mode-desc { min-height: 1.6em; font-size: 11.5px; opacity: .75; }
.cal-note { font-size: 11.5px; opacity: .7; }
.step-btn {
  font-family: var(--font-display); font-size: 18px; line-height: 1;
  width: 38px; height: 34px;
  background: var(--coin); color: var(--ink);
  border: 3px solid #000; border-radius: var(--radius);
  box-shadow: 3px 3px 0 #000; cursor: pointer;
  transition: transform 120ms var(--ease-press), box-shadow 120ms var(--ease-press);
}
.step-btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 #000; }
#lat-val { min-width: 64px; }
select { font-family: var(--font-display); font-size: 16px; padding: 6px 10px; border: 3px solid #000; border-radius: var(--radius); background: #fff; color: var(--ink); }
.big-btn {
  font-family: var(--font-display); font-size: 22px; letter-spacing: .12em;
  background: var(--aka); color: var(--paper);
  border: 3px solid #000; border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 9px 48px; cursor: pointer;
  transition: transform 120ms var(--ease-press), box-shadow 120ms var(--ease-press), background 150ms var(--ease-out);
}
.big-btn:active { transform: translate(5px, 5px); box-shadow: 0 0 0 #000; background: var(--aka-deep); }
.ghost-btn {
  font-family: var(--font-display); font-size: 15px;
  background: transparent; border: 3px solid var(--ink); color: var(--ink);
  border-radius: var(--radius); padding: 7px 22px; cursor: pointer;
  transition: transform 120ms var(--ease-press);
}
.ghost-btn:active { transform: translate(2px, 2px); }
.note { font-size: 11.5px; line-height: 1.8; opacity: .75; }
#result-score { font-family: var(--font-display); font-size: 52px; }
#result-detail { font-size: 13.5px; line-height: 2; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); padding: 8px 4px; white-space: pre-line; width: 100%; }

#countdown {
  position: absolute; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 104px; color: var(--coin);
  text-shadow: 5px 5px 0 #000; pointer-events: none;
}
#countdown.hidden { display: none; }
#toast {
  position: absolute; left: 50%; top: 13%; transform: translateX(-50%) rotate(-2deg); z-index: 8;
  font-family: var(--font-display); font-size: 17px;
  background: var(--coin); color: var(--ink);
  border: 3px solid #000; border-radius: var(--radius); box-shadow: 4px 4px 0 #000;
  padding: 6px 18px; white-space: nowrap;
}
#toast.hidden { display: none; }

@media (prefers-reduced-motion: reduce) {
  .big-btn, #pause-btn, .ghost-btn { transition: none; }
  .hanko { transform: none; }
  #toast { transform: translateX(-50%); }
}

/* 高さに余裕のないスマホに収める */
@media (max-height: 860px) {
  .card { gap: 7px; padding: 12px 12px 10px; }
  .hanko { width: 56px; height: 56px; font-size: 38px; }
  .hanko.small { width: 48px; height: 48px; font-size: 30px; }
  h1 { font-size: 26px; }
  h2 { font-size: 23px; }
  .tagline { font-size: 12px; }
  .duo-demo { padding: 6px 12px; }
  .duo-demo .panel { width: 42px; height: 58px; }
  .fold-hint, .note, .cal-note { display: none; }
  .howto { font-size: 11.5px; line-height: 1.6; padding: 7px 9px; }
  .bpm-row, .cal-row { font-size: 13px; }
  select { font-size: 14px; padding: 4px 8px; }
  .big-btn { font-size: 19px; padding: 7px 40px; }
  #result-score { font-size: 34px; }
  #result-detail { font-size: 11.5px; line-height: 1.7; padding: 6px 4px; }
}
/* リザルトの誤タップ防止: 表示直後はボタンを押せない */
#result-screen .big-btn, #result-screen .ghost-btn {
  opacity: 0; pointer-events: none; transform: translateY(8px);
  transition: opacity 250ms var(--ease-out), transform 250ms var(--ease-out);
}
#result-screen.armed .big-btn, #result-screen.armed .ghost-btn {
  opacity: 1; pointer-events: auto; transform: none;
}
#share-btn { background: #000; color: var(--paper); font-size: 17px; padding: 8px 32px; }
