:root {
  --bg: #fdf3ea; --bg2: #eee6f7; --surface: rgba(255,255,255,0.84); --ink: #1f3a3d; --ink-soft: #4f6f73;
  --line: rgba(31,58,61,0.10); --teal: #c2503a; --teal-dark: #8f3626; --orange: #e8563a;
  --shadow: 0 10px 30px rgba(30,70,80,0.14);
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); }
body { font-family: "Avenir Next", "Helvetica Neue", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", Roboto, Arial, sans-serif; font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#app { position: fixed; inset: 0; overflow: hidden; background: linear-gradient(180deg, var(--bg), var(--bg2)); }
.screen { position: absolute; inset: 0; z-index: 1; display: none; flex-direction: column; padding: calc(12px + var(--sat)) calc(12px + var(--sar)) calc(12px + var(--sab)) calc(12px + var(--sal)); }
.screen.active { display: flex; }
.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; font-size: 16px; min-height: 48px; min-width: 48px; padding: 0 18px; border-radius: 999px; cursor: pointer; box-shadow: 0 2px 8px rgba(30,70,80,0.08); display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: transform .08s ease; }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: linear-gradient(135deg, #e8563a, #ffb03d); color: #fff; border-color: transparent; box-shadow: 0 8px 20px rgba(232,86,58,0.35); }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; }
.btn-small { min-height: 40px; font-size: 14px; padding: 0 14px; }
#screen-boot { align-items: center; justify-content: center; }
.boot-card { text-align: center; color: var(--ink-soft); }
.boot-lantern { width: 40px; height: 54px; margin: 0 auto 14px; border-radius: 14px; background: linear-gradient(180deg, #ff8a5c, #ffc46b); box-shadow: 0 0 24px rgba(255,150,80,0.6); animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-6deg);} 50% { transform: translateY(-6px) rotate(6deg);} }
.boot-bar { width: 160px; height: 6px; margin: 12px auto 0; border-radius: 3px; background: rgba(0,0,0,0.08); overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 20%; background: var(--teal); transition: width .25s ease; }
#screen-title { align-items: center; justify-content: center; }
.title-card { width: min(460px, 100%); text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 28px; padding: 22px 22px 18px; box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.title-art { width: 100%; max-width: 360px; aspect-ratio: 16 / 9; height: auto; border-radius: 18px; display: block; margin: 0 auto 10px; }
h1 { margin: 6px 0 2px; font-size: clamp(30px, 6vw, 40px); font-weight: 800; letter-spacing: .02em; }
.tagline { margin: 0 0 16px; color: var(--ink-soft); font-size: 15px; }
.title-actions { display: flex; flex-direction: column; gap: 10px; }
.title-actions .btn { width: 100%; min-height: 52px; font-size: 17px; }
.title-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; gap: 8px; }
.progress-pill { display: inline-block; font-size: 13px; color: var(--ink-soft); background: rgba(0,0,0,0.05); padding: 6px 12px; border-radius: 999px; }
#screen-play { padding: 0; }
#board-wrap { flex: 1; min-height: 0; position: relative; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.hud-over { position: absolute; left: calc(8px + var(--sal)); right: calc(8px + var(--sar)); top: calc(8px + var(--sat)); display: flex; align-items: flex-start; justify-content: space-between; pointer-events: none; }
.hud-over .btn { pointer-events: auto; }
.score-box { text-align: right; background: rgba(255,255,255,0.75); border-radius: 16px; padding: 6px 14px; box-shadow: 0 2px 8px rgba(30,70,80,0.08); }
.score-box b { display: block; font-size: 30px; line-height: 1; }
.score-box small { color: var(--ink-soft); font-size: 12.5px; }
.tip { position: absolute; left: 50%; bottom: calc(24px + var(--sab)); transform: translateX(-50%); background: rgba(255,255,255,0.85); color: var(--ink); padding: 10px 16px; border-radius: 999px; font-size: 15px; font-weight: 600; white-space: nowrap; box-shadow: 0 2px 8px rgba(30,70,80,0.1); pointer-events: none; }
.tip[hidden] { display: none; }
@media (orientation: landscape) and (max-height: 520px) {
  #screen-title { flex-direction: row; }
  .title-card { padding: 12px 16px; }
  .title-art { max-width: 200px; margin-bottom: 4px; }
  h1 { font-size: 24px; margin: 0; }
  .tagline { margin-bottom: 8px; font-size: 13px; }
  .title-actions { flex-direction: row; }
  .title-actions .btn { min-height: 44px; font-size: 15px; }
  .title-foot { margin-top: 8px; }
}
.modal { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(30,60,70,0.28); backdrop-filter: blur(4px); }
.modal[hidden] { display: none; }
.modal-card { width: min(420px, 100%); background: #fff; border-radius: 22px; padding: 20px 20px 16px; box-shadow: var(--shadow); text-align: center; max-height: calc(100% - 24px); overflow-y: auto; }
.modal-card h3 { margin: 0 0 8px; font-size: 22px; }
.modal-card p { margin: 6px 0; color: var(--ink-soft); }
.big-score { font-size: 44px; font-weight: 800; margin: 4px 0; color: var(--orange); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.modal-actions .btn { flex: 1 1 120px; }
.howto { text-align: left; display: grid; gap: 10px; margin-top: 6px; }
.howto div { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center; }
.howto canvas { width: 44px; height: 44px; border-radius: 10px; background: rgba(0,0,0,0.04); }
.howto p { margin: 0; color: var(--ink); font-size: 14.5px; }
.toast { position: absolute; left: 50%; bottom: calc(90px + var(--sab)); transform: translateX(-50%); z-index: 6; background: rgba(31,58,61,0.9); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 90%; text-align: center; }
.toast[hidden] { display: none; }
@media (prefers-reduced-motion: reduce) { .boot-lantern { width: 40px; height: 54px; margin: 0 auto 14px; border-radius: 14px; background: linear-gradient(180deg, #ff8a5c, #ffc46b); box-shadow: 0 0 24px rgba(255,150,80,0.6); animation: bob 1.4s ease-in-out infinite; } }
