/* ちりトレ！九州地方 — 海の青＋県ごとの色。文字は2行まで、絵が主役 */
:root {
  --sea: #0b2a5b;
  --sea2: #13458c;
  --land: #fff6e0;
  --ink: #1d2340;
  --accent: #ff4d4d;     /* 九州地方の色 */
  --gold: #ffcc33;
  --me: #2f80ff;
  --cpu: #ff4d4d;
  --ok: #23c16b;
  --ng: #ff5a5a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Noto Sans JP", "Yu Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sea); color: var(--ink); }
body { overscroll-behavior: none; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#frame {
  position: fixed; inset: 0;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,.12) 0 2px, transparent 3px) 0 0 / 34px 34px,
    linear-gradient(180deg, #1a5bb5 0%, var(--sea2) 40%, var(--sea) 100%);
}
#boot-fail { position: fixed; inset: auto 0 40% 0; text-align: center; color: #fff; }

.screen {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center;
  padding: calc(var(--safe-t) + 10px) 12px calc(var(--safe-b) + 12px);
  max-width: 560px; margin: 0 auto; overflow-y: auto;
}
.screen.active { display: flex; }
.screen > :first-child { margin-top: auto; }
.screen > :last-child { margin-bottom: auto; }
.screen.game > :first-child, .screen.game > :last-child { margin-top: 0; margin-bottom: 0; }
.screen.game { gap: 8px; }
.screen.game > .grid { margin-bottom: auto; }

/* ---- ボタン ---- */
.btn {
  font: inherit; font-weight: 800; font-size: 17px; color: var(--ink);
  background: #fff; border: 0; border-radius: 14px; padding: 12px 18px; min-height: 48px;
  box-shadow: 0 4px 0 rgba(0,0,0,.25); cursor: pointer;
  transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.btn.primary { background: linear-gradient(180deg, #ffe066, var(--gold)); box-shadow: 0 5px 0 #c58a00; }
.btn.big { font-size: 24px; padding: 16px 40px; border-radius: 20px; }
.btn.ghost { background: rgba(255,255,255,.16); color: #fff; box-shadow: none; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 15px; }
.btn:disabled { opacity: .45; }

/* ---- タイトル ---- */
.title-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.title-map { width: min(70vw, 320px, 42vh); aspect-ratio: 1; margin-bottom: -14px; filter: drop-shadow(0 10px 0 rgba(0,0,0,.25)); animation: float 4s ease-in-out infinite; }
.title-map .kmap .pref { stroke: #fff; stroke-width: 4; }
.title-map .pref-label { font-size: 40px; }
@keyframes float { 50% { transform: translateY(-8px) rotate(-1deg); } }
.logo { margin: 0; display: flex; flex-direction: column; align-items: center; line-height: 1; transform: rotate(-4deg); position: relative; z-index: 2; }
.logo-sub { font-size: 15px; letter-spacing: .3em; color: #fff; background: var(--accent); padding: 5px 12px; border-radius: 99px; margin-bottom: 4px; box-shadow: 0 3px 0 #a3262b; }
.logo-main {
  position: relative; font-size: clamp(56px, 17vw, 84px); font-weight: 900; letter-spacing: -.02em;
  color: #fff7c2;
  -webkit-text-stroke: 3px #b3141c;
  paint-order: stroke fill;
  text-shadow:
    0 1px 0 #ff9f1c, 0 2px 0 #ff9f1c, 0 3px 0 #f2810c, 0 4px 0 #f2810c, 0 5px 0 #d9650a, 0 6px 0 #d9650a,
    0 7px 0 #b3141c, 0 8px 0 #b3141c, 0 9px 0 #8a0f15, 0 14px 18px rgba(0,0,0,.45);
}
.logo-main::after {
  content: attr(data-text); position: absolute; inset: 0; color: transparent; -webkit-text-stroke: 0;
  background: linear-gradient(110deg, transparent 35%, rgba(255,255,255,.9) 48%, transparent 60%) 0 0 / 250% 100%;
  -webkit-background-clip: text; background-clip: text; text-shadow: none;
  animation: shine 3.2s ease-in-out infinite;
}
@keyframes shine { 0%, 40% { background-position: 120% 0; } 100% { background-position: -120% 0; } }
.logo-region { font-size: 26px; font-weight: 900; color: var(--ink); background: #fff; padding: 6px 18px; border-radius: 12px; margin-top: 4px; box-shadow: 0 4px 0 rgba(0,0,0,.25); border: 3px solid var(--accent); }
.title-note { color: #dfe9ff; font-size: 14px; margin: 0 0 18px; }
.version { position: absolute; right: 10px; bottom: calc(var(--safe-b) + 6px); color: rgba(255,255,255,.75); font-size: 12px; }

/* ---- 地図 ---- */
.kmap { width: 100%; height: 100%; display: block; }
.kmap .pref { fill: var(--land); stroke: #6b7aa8; stroke-width: 2.5; stroke-linejoin: round; transition: fill .3s; }
.kmap-inset { fill: rgba(255,255,255,.08); stroke: rgba(255,255,255,.5); stroke-width: 3; stroke-dasharray: 10 8; }
.pref-label { font-size: 34px; font-weight: 900; text-anchor: middle; dominant-baseline: middle; fill: var(--ink); stroke: #fff; stroke-width: 7px; paint-order: stroke; pointer-events: none; }
.kmap.mini .pref { fill: #dfe6f5; stroke: #9aa6c8; stroke-width: 6; }
.kmap.mini .pref.hot { fill: var(--c, var(--accent)); stroke: #1d2340; stroke-width: 8; }
.kmap.mini .kmap-inset { stroke: #9aa6c8; stroke-width: 6; fill: none; }
.kmap .pref.got { animation: got .5s ease-out; }
@keyframes got { 40% { filter: brightness(1.5); } }
.map-box { width: 100%; height: min(34vh, 300px); background: rgba(255,255,255,.08); border-radius: 18px; padding: 6px; flex-shrink: 0; }
.map-box.tall { height: auto; flex: 1; min-height: 0; max-height: 62vh; }

/* ---- 上の表示 ---- */
.bar, .hud { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #fff; }
.bar h2 { margin: 0; font-size: 22px; }
.bar > span { width: 90px; }
.hud-item { background: rgba(0,0,0,.25); border-radius: 12px; padding: 4px 10px; text-align: center; min-width: 64px; }
.hud-item.wide { min-width: 120px; }
.hud-item small { display: block; font-size: 11px; opacity: .8; }
.hud-item b { font-size: 20px; font-variant-numeric: tabular-nums; }

/* ---- モード選択 ---- */
.modes { display: flex; flex-direction: column; gap: 12px; width: 100%; margin: 14px 0; }
.mode {
  font: inherit; text-align: left; border: 0; border-radius: 20px; padding: 14px 16px 14px 84px; position: relative;
  background: #fff; box-shadow: 0 6px 0 rgba(0,0,0,.28); cursor: pointer; color: var(--ink);
  display: flex; flex-direction: column; gap: 2px; min-height: 104px;
}
.mode:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.28); }
.mode-ico { position: absolute; left: 14px; top: 50%; translate: 0 -50%; font-size: 50px; }
.mode-tag { align-self: flex-start; font-size: 12px; font-weight: 800; color: #fff; background: var(--accent); padding: 2px 10px; border-radius: 99px; }
.mode[data-mode="sorter"] .mode-tag { background: #ff9f1c; }
.mode[data-mode="battle"] .mode-tag { background: var(--me); }
.mode-name { font-size: 21px; font-weight: 900; }
.mode-desc { font-size: 13px; color: #4a5272; }
.mode-best { font-size: 12px; color: #8a6d00; font-weight: 700; }
.weak-note { color: #fff; font-size: 14px; background: rgba(0,0,0,.25); padding: 8px 14px; border-radius: 12px; }

/* ---- 案A カード ---- */
.peek { width: 100%; display: flex; align-items: center; gap: 10px; }
.peek[hidden] { display: none; }
.peek .btn { flex-shrink: 0; }
.peek-bar { flex: 1; height: 12px; background: rgba(255,255,255,.2); border-radius: 99px; overflow: hidden; }
.peek-bar i { display: block; height: 100%; background: var(--gold); transform-origin: left; }
.grid { width: 100%; max-width: calc(100vh - min(34vh, 300px) - 172px); max-width: calc(100dvh - min(34dvh, 300px) - 172px - var(--safe-t) - var(--safe-b)); display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.card { position: relative; aspect-ratio: 3 / 4; border: 0; padding: 0; background: none; perspective: 600px; cursor: pointer; font: inherit; }
.card > span {
  position: absolute; inset: 0; border-radius: 12px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  transition: transform .28s; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 0 4px 0 rgba(0,0,0,.28);
}
.card .back {
  background: repeating-linear-gradient(45deg, #ff6b6b 0 8px, #ff4d4d 8px 16px);
  border: 3px solid #fff;
}
.card .back::after { content: "？"; color: #fff; font-size: 30px; font-weight: 900; text-shadow: 0 2px 0 #a3262b; }
.card .face { background: #fff; border: 4px solid #2b3a63; transform: rotateY(180deg); padding: 4px; }
.card.up .back { transform: rotateY(180deg); }
.card.up .face { transform: rotateY(360deg); }
.card .face i { font-style: normal; font-size: clamp(26px, 9vw, 40px); line-height: 1.1; }
.card .face b { font-size: clamp(12px, 3.6vw, 16px); text-align: center; line-height: 1.15; word-break: keep-all; overflow-wrap: anywhere; }
.card .face b.long { font-size: clamp(10px, 3vw, 13px); white-space: nowrap; }
.card .face b.xlong { font-size: clamp(8px, 2.4vw, 11px); }
.card .face b.xlong.nw { white-space: nowrap; }
.card .face.is-pref { background: #fffaf0; }
.card .face.is-pref svg { width: 92%; height: auto; flex: 1; min-height: 0; }
.card.done .face { opacity: .35; transform: rotateY(360deg) scale(.92); }
.card.shake .face { animation: shake .35s; }
@keyframes shake { 25% { translate: -5px 0; } 75% { translate: 5px 0; } }

/* ---- 案B 物流センター ---- */
.sorter {
  position: relative; width: 100%; flex: 1; min-height: 360px; max-height: 640px; border-radius: 22px;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.06) 0 20px, transparent 20px 40px),
    linear-gradient(180deg, #2b3a63, #1d2847);
  border: 4px solid rgba(255,255,255,.2);
}
.exit {
  position: absolute; width: 30%; aspect-ratio: 1; border: 0; border-radius: 18px; padding: 6px; cursor: pointer;
  background: #fff; box-shadow: 0 5px 0 rgba(0,0,0,.35), inset 0 0 0 5px var(--c);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font: inherit;
  transition: transform .12s;
}
.exit svg { width: 82%; flex: 1; min-height: 0; }
.exit b { font-size: clamp(16px, 5vw, 22px); font-weight: 900; color: var(--ink); line-height: 1.1; }
.exit[data-dir="up"] { top: 10px; left: 35%; }
.exit[data-dir="down"] { bottom: 10px; left: 35%; }
.exit[data-dir="left"] { left: 10px; top: 50%; translate: 0 -50%; }
.exit[data-dir="right"] { right: 10px; top: 50%; translate: 0 -50%; }
.exit.gold { background: #fff3c4; }
.exit.gold svg { width: 100%; }
.exit.hit { transform: scale(1.12); box-shadow: 0 0 0 6px var(--ok), 0 5px 0 rgba(0,0,0,.35); }
.exit.answer { animation: blink .3s 3; box-shadow: 0 0 0 7px var(--gold), 0 5px 0 rgba(0,0,0,.35); }
@keyframes blink { 50% { filter: brightness(1.4); } }
.belt { position: absolute; left: 50%; top: 50%; translate: -50% -50%; width: 32%; aspect-ratio: 1; }
.parcel {
  width: 100%; height: 100%; border-radius: 16px; touch-action: none; cursor: grab;
  background: linear-gradient(180deg, #e8b878, #c98f4d); border: 3px solid #8a5a26;
  box-shadow: 0 6px 0 #6b4319, 0 12px 20px rgba(0,0,0,.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative;
  animation: arrive .22s ease-out;
}
.parcel::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 14%; translate: -50% 0; background: rgba(255,255,255,.25); }
.parcel i { font-style: normal; font-size: clamp(34px, 11vw, 52px); position: relative; }
.parcel b { position: relative; background: #fff; border-radius: 8px; padding: 2px 6px; font-size: clamp(13px, 4vw, 17px); font-weight: 900; text-align: center; line-height: 1.15; max-width: 96%; }
.parcel b.long { font-size: clamp(10px, 3vw, 13px); }
.parcel.gold { background: linear-gradient(180deg, #ffe680, #f0b800); border-color: #a87a00; box-shadow: 0 6px 0 #7a5800, 0 0 30px rgba(255,210,0,.7); }
.ptimer { position: absolute; left: 6px; right: 6px; bottom: -14px; height: 7px; background: rgba(0,0,0,.35); border-radius: 99px; overflow: hidden; text-decoration: none; }
.ptimer u { display: block; height: 100%; background: var(--ok); transform-origin: left; }
@keyframes arrive { from { transform: scale(.4); opacity: 0; } }
.parcel.fly-up { transition: transform .25s ease-in, opacity .25s; transform: translateY(-160%) scale(.4); opacity: 0; }
.parcel.fly-down { transition: transform .25s ease-in, opacity .25s; transform: translateY(160%) scale(.4); opacity: 0; }
.parcel.fly-left { transition: transform .25s ease-in, opacity .25s; transform: translateX(-160%) scale(.4); opacity: 0; }
.parcel.fly-right { transition: transform .25s ease-in, opacity .25s; transform: translateX(160%) scale(.4); opacity: 0; }
.parcel.shake { animation: shake .35s 2; }
.sort-hint { position: absolute; left: 0; right: 0; top: 70%; text-align: center; color: #fff; font-weight: 800; font-size: 14px; opacity: .85; }
.sort-hint[hidden] { display: none; }

/* ---- 案C 陣取り ---- */
.score-vs { display: flex; gap: 6px; flex: 1; justify-content: flex-end; }
.score-vs span { font-weight: 900; padding: 6px 10px; border-radius: 12px; font-size: 15px; }
.score-vs .me { background: var(--me); }
.score-vs .cpu { background: var(--cpu); }
.bubble { width: 100%; background: #fff; border-radius: 16px; padding: 10px 14px; font-weight: 800; font-size: 16px; min-height: 68px; line-height: 1.35; display: flex; align-items: center; position: relative; box-shadow: 0 4px 0 rgba(0,0,0,.25); }
#s-battle .kmap .pref { cursor: pointer; }
#s-battle .kmap .pref.me { fill: #8fc0ff; stroke: var(--me); stroke-width: 5; }
#s-battle .kmap .pref.cpu { fill: #ffa8a8; stroke: var(--cpu); stroke-width: 5; }
#s-battle .kmap .pref.castle.me { fill: var(--me); }
#s-battle .kmap .pref.castle.cpu { fill: var(--cpu); }
#s-battle .kmap .pref.target { fill: var(--gold); animation: blink .5s infinite; }
.stars-pick { position: absolute; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 12px); background: #fff; border-radius: 20px; padding: 12px; box-shadow: 0 8px 0 rgba(0,0,0,.3); text-align: center; }
.stars-pick[hidden] { display: none; }
.stars-pick p { margin: 0 0 8px; font-weight: 900; font-size: 17px; }
.stars-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.btn.star { display: flex; flex-direction: column; align-items: center; color: #e09a00; font-size: 20px; background: #fffaf0; border: 3px solid #ffd666; padding: 8px 4px; }
.btn.star small { color: var(--ink); font-size: 11px; font-weight: 700; }
.btn.star.gold { background: linear-gradient(180deg, #fff2b3, #ffd84d); }
.stars-pick .btn.ghost { color: #4a5272; background: #eef1f8; }

/* ---- 問題 ---- */
.quiz { position: absolute; inset: 0; background: rgba(5,15,40,.72); display: flex; align-items: center; justify-content: center; padding: calc(var(--safe-t) + 12px) 12px calc(var(--safe-b) + 12px); z-index: 10; }
.quiz[hidden] { display: none; }
.quiz-card { width: 100%; max-width: 520px; background: #fff; border-radius: 22px; padding: 16px; box-shadow: 0 10px 0 rgba(0,0,0,.3); display: flex; flex-direction: column; gap: 10px; animation: arrive .2s ease-out; }
.quiz-tag { margin: 0; align-self: flex-start; background: var(--me); color: #fff; font-weight: 800; font-size: 13px; padding: 3px 12px; border-radius: 99px; }
.quiz-mini { height: 90px; display: flex; justify-content: center; }
.quiz-mini:empty { display: none; }
.quiz-mini svg { width: 90px; height: 90px; }
.quiz-q { margin: 0; font-size: 20px; font-weight: 900; line-height: 1.4; }
.quiz-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn.choice { background: #f2f5fc; border: 3px solid #d5dcef; font-size: 16px; min-height: 58px; padding: 8px; line-height: 1.2; }
.btn.choice.on { background: #ddeaff; border-color: var(--me); }
.btn.choice.right { background: #d9f7e6; border-color: var(--ok); }
.btn.choice.wrong { background: #ffe0e0; border-color: var(--ng); }
.btn.choice:disabled { opacity: 1; }
.quiz-choices.multi::before { content: "2つ選んで「決定」"; grid-column: 1 / -1; font-size: 13px; color: #4a5272; font-weight: 700; }
.quiz-fb { text-align: center; }
.quiz-fb[hidden] { display: none; }
.quiz-fb p { margin: 4px 0; }
.fb-mark { font-size: 30px; font-weight: 900; }
.fb-mark.ok { color: var(--ok); }
.fb-mark.ng { color: var(--ng); }
.fb-ans { font-size: 18px; font-weight: 900; }
.fb-exp { font-size: 15px; color: #4a5272; }

/* ---- 結果 ---- */
.result { width: 100%; background: #fff; border-radius: 26px; padding: 22px 18px; text-align: center; box-shadow: 0 10px 0 rgba(0,0,0,.3); }
.result p { margin: 4px 0; }
.res-mode { font-size: 14px; color: #4a5272; font-weight: 700; }
.res-rank { font-size: 30px; font-weight: 900; color: var(--accent); transform: rotate(-3deg); }
.res-score b { font-size: 64px; font-weight: 900; font-variant-numeric: tabular-nums; -webkit-text-stroke: 2px var(--ink); color: var(--gold); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); }
.res-score small { font-size: 22px; font-weight: 900; margin-left: 4px; }
.res-best { font-size: 14px; color: #8a6d00; font-weight: 700; }
.res-best.new { color: var(--accent); font-size: 18px; }
.res-lines { list-style: none; padding: 0; margin: 10px 0; font-weight: 700; font-size: 16px; }
.res-miss { background: #fff4f4; border-radius: 14px; padding: 8px 12px; text-align: left; font-size: 14px; }
.res-miss:empty { display: none; }
.res-miss p:first-child { font-weight: 900; color: var(--ng); }
.res-miss .m { line-height: 1.35; }
.res-hint { font-size: 14px; background: #eef5ff; border-radius: 12px; padding: 8px; margin-top: 10px !important; }
.res-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; align-items: center; }

/* ---- 飛び出す文字 ---- */
.pops { position: absolute; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.pop {
  position: absolute; translate: -50% -50%; white-space: nowrap; font-weight: 900; font-size: 22px; color: #fff;
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; animation: popup 1.1s ease-out forwards;
}
.pop.big { font-size: 34px; color: var(--gold); }
.pop.combo { font-size: 28px; color: #7dfcff; font-style: italic; }
.pop.money { font-size: 30px; color: #8dff8d; }
.pop.gold { font-size: 26px; color: var(--gold); }
.pop.ng { font-size: 24px; color: #ffb3b3; }
.pop.fact { font-size: 20px; background: var(--ink); -webkit-text-stroke: 0; padding: 6px 12px; border-radius: 99px; }
@keyframes popup { 0% { transform: scale(.4); opacity: 0; } 15% { transform: scale(1.15); opacity: 1; } 30% { transform: scale(1); } 80% { opacity: 1; } 100% { transform: translateY(-30px); opacity: 0; } }

.vol { position: absolute; right: 10px; top: calc(var(--safe-t) + 10px); z-index: 30; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(0,0,0,.3); font-size: 20px; cursor: pointer; }
.screen.game.active ~ .vol { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media (min-width: 900px) {
  .map-box { height: 300px; }
}
