/* 真・MAGICAL CLAY
   ※ Dela Gothic One は英字・数字専用（漢字・かなを小さく使うとつぶれるため、日本語の見出しは M PLUS Rounded の 800）
   — 夜のストリート × 魔法
   パレット: 夜インク #1a1033 / アスファルト #2a2145 / チョーク白 #f4f0ff / ステッカーピンク #ff6fb5 / 魔法陣の金 #ffe08a
   書体: 見出し Dela Gothic One（ストリートのポスター）、本文 M PLUS Rounded 1c（粘土の丸み） */
:root {
  color-scheme: dark;
  --ink: #1a1033;
  --asphalt: #2a2145;
  --asphalt-hi: #3a2f5e;
  --chalk: #f4f0ff;
  --muted: #b3a8d6;
  --pink: #ff6fb5;
  --gold: #ffe08a;
  --display: "Dela Gothic One", "Hiragino Kaku Gothic StdN", system-ui, sans-serif;
  --body: "M PLUS Rounded 1c", system-ui, -apple-system, "Hiragino Maru Gothic ProN", sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  height: 100vh; height: 100dvh;
  overflow: hidden; overscroll-behavior: none;
  background: var(--ink); color: var(--chalk);
  font-family: var(--body); font-weight: 700;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; display: block; touch-action: none; }
#ui {
  position: absolute; inset: 0; pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#ui > * { pointer-events: auto; }
#ui > .passthrough { pointer-events: none; }
#ui > .passthrough * { pointer-events: auto; }

/* ---- 画面の枠（縦レイアウトを中央に） ---- */
.screen {
  position: absolute; inset: 0; margin: 0 auto; width: min(100%, 560px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 20px 18px; text-align: center; overflow-y: auto;
}
.screen.top { justify-content: flex-start; }

.logo { font-family: var(--display); line-height: .95; letter-spacing: .02em; }
.logo .shin {
  display: inline-block; font-family: var(--body); font-weight: 800; font-size: clamp(30px, 10vw, 46px); line-height: 1.1;
  color: var(--ink); background: var(--pink); padding: 0 14px 2px; border-radius: 8px; transform: rotate(-6deg); margin-bottom: 8px;
}
.logo .name { display: block; font-size: clamp(38px, 13vw, 72px); color: var(--chalk); text-shadow: 0 0 18px rgba(255, 224, 138, .45), 4px 4px 0 var(--asphalt-hi); }
.logo .sub { display: block; font-family: var(--body); font-size: 13px; color: var(--gold); letter-spacing: .3em; margin-top: 10px; }

h2.title { font-size: clamp(22px, 7vw, 30px); font-weight: 800; letter-spacing: .04em; }
.note { color: var(--muted); font-size: 14px; line-height: 1.6; }
.tap-start { font-size: 16px; color: var(--gold); animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* ---- ボタン（ステッカー風） ---- */
.btn {
  min-height: 52px; width: min(100%, 320px); padding: 10px 18px; border: 0; border-radius: 14px;
  font: inherit; font-size: 17px; color: var(--ink); background: var(--chalk);
  box-shadow: 0 4px 0 #8f84b8; cursor: pointer; touch-action: manipulation;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #8f84b8; }
.btn.primary { background: var(--pink); box-shadow: 0 4px 0 #b4417c; }
.btn.sub { background: var(--asphalt-hi); color: var(--chalk); box-shadow: 0 4px 0 #120b26; }
.btn:focus-visible, .icon-btn:focus-visible, .choice:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.btn small { font-size: 12px; opacity: .75; font-weight: 500; }
.btn[disabled] { opacity: .45; cursor: default; }
.menu { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }

.icon-btn {
  width: 48px; height: 48px; border: 0; border-radius: 12px; background: rgba(42, 33, 69, .85); color: var(--chalk);
  font: inherit; font-size: 20px; cursor: pointer; touch-action: manipulation;
}
.corner { position: absolute; top: calc(env(safe-area-inset-top) + 6px); }
.corner.left { left: calc(env(safe-area-inset-left) + 6px); }
.corner.right { right: calc(env(safe-area-inset-right) + 6px); }

/* ---- 選択（キャラ・強さ） ---- */
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(100%, 360px); }
.choice {
  min-height: 56px; border: 2px solid transparent; border-radius: 12px; background: var(--asphalt);
  color: var(--chalk); font: inherit; font-size: 14px; cursor: pointer; touch-action: manipulation; padding: 6px 4px;
}
.choice[aria-pressed="true"] { border-color: var(--gold); background: var(--asphalt-hi); }
.choice[disabled] { opacity: .45; cursor: default; }
.choice .dot { display: block; width: 22px; height: 22px; border-radius: 50%; margin: 0 auto 4px; }
.label { font-size: 13px; color: var(--muted); letter-spacing: .1em; align-self: center; }

/* ---- ストーリーの一覧 ---- */
.stage-btn { flex-direction: column; gap: 2px; }
.stage-btn .t { font-size: 16px; }
.stage-btn .d { font-size: 12px; font-weight: 500; opacity: .8; }

/* ---- 会話 ---- */
.talk { justify-content: flex-end; padding-bottom: 28px; }
.talk-box {
  width: 100%; min-height: 128px; background: rgba(26, 16, 51, .92); border: 2px solid var(--asphalt-hi);
  border-radius: 16px; padding: 14px 16px 18px; text-align: left; cursor: pointer;
}
.talk-name { font-weight: 800; font-size: 17px; margin-bottom: 6px; }
.talk-text { font-size: 16px; line-height: 1.7; font-weight: 500; white-space: pre-wrap; }
.talk-next { display: block; text-align: right; font-size: 12px; color: var(--gold); margin-top: 4px; }

/* ---- 遊び方 ---- */
.howto { text-align: left; }
.howto-card { width: 100%; background: var(--asphalt); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.howto-card h3 { font-weight: 800; font-size: 18px; }
.howto-card p, .howto-card li { font-size: 14px; line-height: 1.7; font-weight: 500; }
.howto-card ul { padding-left: 1.2em; }
.howto-card canvas { width: 100%; height: auto; border-radius: 10px; background: var(--ink); }
.pager { display: flex; gap: 10px; width: 100%; justify-content: center; }
.pager .btn { width: auto; min-width: 120px; }
.wheel { display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; font-size: 15px; }
.el { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; color: #1a1033; font-size: 13px; }

/* ---- 設定 ---- */
.toggle-row { display: flex; align-items: center; justify-content: space-between; width: min(100%, 320px); gap: 12px; font-size: 16px; }
.toggle-row .btn { width: 110px; min-height: 48px; }

/* ---- リザルト ---- */
.result-head { font-family: var(--display); font-weight: 400; font-size: clamp(40px, 14vw, 64px); line-height: 1; }
.result-head.win { color: var(--gold); text-shadow: 0 0 20px rgba(255, 224, 138, .5); }
.result-head.lose { color: var(--muted); }
.stats { display: grid; grid-template-columns: auto auto; gap: 4px 18px; font-size: 15px; font-weight: 500; text-align: left; }
.stats b { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---- シャッフルボタン（盤面の下。位置は battle.js がレイアウトから決める） ---- */
.shuffle-btn {
  position: absolute; --cd: 0; border: 0; border-radius: 14px; padding: 0 10px;
  font: inherit; font-size: 15px; font-weight: 800; color: var(--ink); cursor: pointer; touch-action: manipulation;
  background: linear-gradient(90deg, var(--asphalt-hi) calc(var(--cd) * 100%), var(--gold) calc(var(--cd) * 100%));
  box-shadow: 0 4px 0 #b39a4f;
}
.shuffle-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b39a4f; }
.shuffle-btn[disabled] { color: var(--muted); box-shadow: 0 4px 0 #120b26; cursor: default; }
.shuffle-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* ---- アンケート ---- */
.survey { border: 0; width: min(100%, 340px); display: flex; flex-direction: column; gap: 8px; text-align: left; }
.survey legend { font-size: 16px; font-weight: 800; margin-bottom: 10px; text-align: center; width: 100%; }
.radio { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 14px; border-radius: 12px; background: var(--asphalt); cursor: pointer; font-size: 15px; }
.radio:has(input:checked) { outline: 2px solid var(--gold); background: var(--asphalt-hi); }
.radio input { width: 24px; height: 24px; accent-color: var(--pink); }

/* ---- 重ね表示（一時停止・確認・回転） ---- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(10, 6, 24, .74); backdrop-filter: blur(4px);
}
#rotate { display: none; z-index: 40; }
@media (orientation: landscape) and (max-height: 500px) {
  body[data-orientation="portrait"] #rotate { display: flex; }
}
.card {
  width: min(100%, 340px); max-height: 100%; overflow-y: auto; background: var(--asphalt); border-radius: 18px;
  padding: 22px 18px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
}
.card-title { font-weight: 800; font-size: 22px; }
.card-note { color: var(--muted); font-size: 14px; font-weight: 500; }
.card .btn { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  .tap-start { animation: none; }
}
