/* くだものストラックアウト style.css — 構造は docs/design.md */
:root {
  --c-ink: #3b2f2f; --c-ink-sub: #7a675c; --c-paper: #fffdf7; --c-cream: #fff3d8; --c-line: #e6d6bd;
  --c-red: #e8413b; --c-red-deep: #b8302c; --c-blue: #3f86e8; --c-blue-deep: #2a5fb0;
  --c-green: #3fa66a; --c-green-deep: #2b7a4b; --c-gold: #ffc83d; --c-gold-deep: #d99a00;
  --c-orange: #ff9a2e; --c-orange-deep: #d4691a; --c-purple: #8a5bd6;
  --c-sky: #8fd3ff; --c-sky-low: #d8f2ff; --c-grass: #7fcf5a; --c-grass-deep: #5fb544; --c-leaf: #5cbf4a;
  --c-bg-out: #4fae4a; --c-bg-out-2: #5cbf4a;
  --font-base: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --font-num: "Arial Rounded MT Bold", "Hiragino Maru Gothic ProN", "SF Pro Rounded", ui-rounded, system-ui, sans-serif;
  --radius-s: 10px; --radius-m: 18px; --radius-l: 28px; --btn-depth: 6px; --dur-mid: .25s;
  --safe-top: env(safe-area-inset-top, 0px); --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px); --safe-left: env(safe-area-inset-left, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  font-family: var(--font-base); color: var(--c-ink); background: var(--c-bg-out);
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

/* ---------- 土台 ---------- */
.app {
  position: fixed; inset: 0; overflow: hidden;
  background: repeating-linear-gradient(90deg, var(--c-bg-out) 0 36px, var(--c-bg-out-2) 36px 72px);
}
.stage {
  position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(100%, 62vh); width: min(100%, 62dvh); overflow: hidden;
  background: linear-gradient(var(--c-sky) 0, var(--c-sky-low) 38%, var(--c-grass) 38%, var(--c-grass-deep) 100%);
}
@media (max-width: 480px) { .stage { width: 100%; } }
@media (min-width: 481px) { .stage { border-left: 4px solid var(--c-ink); border-right: 4px solid var(--c-ink); } }

.screen {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  overflow-y: auto; touch-action: pan-y;
}
.screen.is-active { display: flex; animation: screen-in var(--dur-mid) ease both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.bg-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; pointer-events: none; }

.card {
  background: var(--c-paper); border: 4px solid var(--c-ink); border-radius: var(--radius-l);
  box-shadow: 0 8px 0 var(--c-ink); padding: 20px 22px;
}

/* ---------- ボタン（押すと沈む） ---------- */
.btn {
  --btn-bg: var(--c-red); --btn-edge: var(--c-red-deep); --btn-fg: #fff;
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 12px 28px; margin-bottom: var(--btn-depth);
  border: 3px solid var(--c-ink); border-radius: 999px; background: var(--btn-bg); color: var(--btn-fg);
  font-size: 20px; font-weight: 800; letter-spacing: .04em; cursor: pointer; white-space: nowrap;
  box-shadow: 0 var(--btn-depth) 0 var(--btn-edge), 0 var(--btn-depth) 0 3px var(--c-ink);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s;
}
.btn::after { content: ""; position: absolute; top: 5px; left: 18%; right: 18%; height: 6px; border-radius: 999px; background: rgba(255,255,255,.35); pointer-events: none; }
.btn:hover { filter: brightness(1.05); }
.btn:active, .btn.is-pressed { transform: translateY(var(--btn-depth)); box-shadow: 0 0 0 var(--btn-edge), 0 0 0 3px var(--c-ink); }
.btn:disabled { filter: grayscale(.8) opacity(.6); cursor: not-allowed; }
.btn--block { display: flex; width: 100%; }
.btn--blue { --btn-bg: var(--c-blue); --btn-edge: var(--c-blue-deep); }
.btn--green { --btn-bg: var(--c-green); --btn-edge: var(--c-green-deep); }
.btn--orange { --btn-bg: var(--c-orange); --btn-edge: var(--c-orange-deep); }
.btn--gold { --btn-bg: var(--c-gold); --btn-edge: var(--c-gold-deep); --btn-fg: var(--c-ink); }
.btn--ghost { --btn-bg: var(--c-paper); --btn-edge: var(--c-line); --btn-fg: var(--c-ink); }
.btn--small { min-height: 40px; padding: 6px 16px; font-size: 15px; --btn-depth: 4px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 3px solid var(--c-ink); border-radius: 50%; background: var(--c-paper);
  font-size: 20px; font-weight: 900; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 0 var(--c-ink); transition: transform .08s ease, box-shadow .08s ease;
}
.icon-btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--c-ink); }
.icon-btn--pause::before { content: ""; width: 12px; height: 14px; border-left: 4px solid var(--c-ink); border-right: 4px solid var(--c-ink); }
.icon-btn--sound::before { content: "♪"; }
.icon-btn--sound.is-off { opacity: .55; }
.icon-btn--sound.is-off::after { content: ""; position: absolute; width: 26px; height: 3px; background: var(--c-red); transform: rotate(-45deg); border-radius: 2px; }
.icon-btn--sound { position: relative; }
.icon-btn--help::before { content: "?"; }
.icon-btn--close::before { content: "×"; font-size: 26px; }
.btn:focus-visible, .icon-btn:focus-visible, a:focus-visible { outline: 4px solid var(--c-gold); outline-offset: 4px; }

/* ---------- タイトル ---------- */
.screen--title { gap: 14px; text-align: center; justify-content: safe center; }
.screen--title > a.back-to-games {
  position: absolute; top: calc(12px + var(--safe-top)); left: calc(12px + var(--safe-left)); z-index: 6;
  display: inline-flex; align-items: center; padding: 6px 12px 7px; font: 800 13px/1 var(--font-base); color: var(--c-ink); text-decoration: none;
  background: var(--c-paper); border: 3px solid var(--c-ink); border-radius: 999px; box-shadow: 0 3px 0 var(--c-ink);
}
.screen--title > a.back-to-games:active { transform: translateY(3px); box-shadow: none; }
.screen--title:has(> a.back-to-games:not([hidden])) { padding-top: calc(52px + var(--safe-top)); }
.screen--title > :not(.bg-canvas) { position: relative; z-index: 1; }
.logo { margin: 0; line-height: 1.05; }
.logo__sub { display: inline-block; padding: 4px 16px; margin-bottom: 8px; border: 3px solid var(--c-ink); border-radius: 999px; background: var(--c-paper); font-size: 15px; font-weight: 800; box-shadow: 0 3px 0 var(--c-ink); }
.logo__main {
  display: block; font-size: clamp(40px, 12vw, 66px); font-weight: 900; letter-spacing: .02em; white-space: nowrap; color: #fff;
  -webkit-text-stroke: 10px var(--c-ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--c-ink);
}
.logo__main + .logo__main { margin-top: -2px; }
.logo__main .is-red { color: var(--c-red); }
.logo__main .is-gold { color: var(--c-gold); }
.logo__main .is-green { color: #7ddc5a; }
.logo__main .is-orange { color: var(--c-orange); }
.title-art { width: min(300px, 80%, 34vh); aspect-ratio: 1; flex: 0 1 auto; min-height: 110px; animation: bob 2.4s ease-in-out infinite; }
.title-art canvas { width: 100%; height: 100%; display: block; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
.title-best { display: inline-flex; gap: 8px; align-items: baseline; padding: 4px 16px; border: 3px solid var(--c-ink); border-radius: 999px; background: var(--c-cream); font-weight: 800; font-size: 14px; }
.title-best b { font: 900 22px var(--font-num); color: var(--c-red); }
.title-actions { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.title-actions > .btn { min-width: 220px; font-size: 24px; }
.title-sub { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: center; }

/* ---------- モーダル（ルール・ポーズ） ---------- */
.modal {
  position: absolute; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); background: rgba(24, 50, 20, .55);
}
.modal.is-open { display: flex; animation: screen-in var(--dur-mid) ease both; }
.modal > .card { max-height: 100%; overflow-y: auto; touch-action: pan-y; }
.rules { width: min(400px, 100%); text-align: center; }
.rules__title, .sheet__title { margin: 0 0 12px; font-size: 22px; font-weight: 900; }
.rules__list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 10px; }
.rules__item {
  display: grid; grid-template-columns: 84px 1fr; gap: 12px; align-items: center; padding: 8px 10px;
  background: var(--c-cream); border: 3px solid var(--c-ink); border-radius: var(--radius-m); text-align: left;
}
.rules__item canvas { width: 84px; height: 66px; display: block; }
.rules__item p { margin: 0; font-size: 14px; font-weight: 800; line-height: 1.5; word-break: auto-phrase; }
.rules__item b { color: var(--c-red); }
.fruit-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.fruit-chip { display: grid; justify-items: center; gap: 2px; padding: 6px 4px; border: 2.5px solid var(--c-ink); border-radius: var(--radius-s); background: var(--c-paper); }
.fruit-chip canvas { width: 40px; height: 40px; display: block; }
.fruit-chip__name { font-size: 13px; font-weight: 900; }
.fruit-chip__desc { font-size: 11px; font-weight: 700; color: var(--c-ink-sub); line-height: 1.3; word-break: auto-phrase; }
.fruit-chip.is-new { background: #fff3c4; }
.fruit-chip.is-locked canvas { filter: grayscale(1) brightness(.5) opacity(.45); }
.pause { width: min(320px, 100%); display: grid; gap: 10px; text-align: center; }

/* ---------- プレイ ---------- */
.screen--play { padding: 0; overflow: hidden; touch-action: none; }
.play-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud {
  position: absolute; left: 0; right: 0; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  padding: calc(8px + var(--safe-top)) calc(8px + var(--safe-right)) 0 calc(8px + var(--safe-left)); pointer-events: none;
}
.hud > button { pointer-events: auto; flex: none; width: 40px; height: 40px; }
.hud__chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 4px 12px; min-width: 0;
  border: 3px solid var(--c-ink); border-radius: 999px; background: var(--c-paper); box-shadow: 0 3px 0 var(--c-ink);
  font: 900 17px var(--font-num); white-space: nowrap;
}
.hud__chip small { font: 800 11px var(--font-base); color: var(--c-ink-sub); }
.hud__balls { padding: 4px 10px; }
.hud__dots { display: inline-grid; grid-template-columns: repeat(6, 7px); gap: 2px; }
.hud__dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--c-red); box-shadow: inset 0 0 0 1.5px var(--c-ink); }
.hud__dots i.is-used { background: var(--c-line); box-shadow: inset 0 0 0 1.5px rgba(59,47,47,.35); }
.hud__score { margin-left: auto; }
.hud__score.is-up { animation: bump .35s ease; }
@keyframes bump { 40% { transform: scale(1.18); background: var(--c-gold); } }

/* 次の2球（右下）。今投げる球は canvas の投球位置に描く */
.next {
  position: absolute; right: calc(10px + var(--safe-right)); bottom: calc(14px + var(--safe-bottom)); z-index: 5;
  display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none;
}
.next__label { padding: 1px 10px; border: 2.5px solid var(--c-ink); border-radius: 999px; background: var(--c-gold); font-size: 12px; font-weight: 900; }
.next__item { position: relative; width: 52px; height: 52px; border: 3px solid var(--c-ink); border-radius: 50%; background: var(--c-paper); box-shadow: 0 3px 0 var(--c-ink); display: grid; place-items: center; }
.next__item + .next__item { width: 40px; height: 40px; opacity: .85; }
.next__item canvas { width: 80% !important; height: 80% !important; display: block; }
.next__item.is-empty { background: var(--c-cream); border-style: dashed; box-shadow: none; }
.next__item.is-in { animation: slide-in .3s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes slide-in { from { transform: translateY(14px) scale(.6); opacity: 0; } }
.fruit-name {
  position: absolute; left: 50%; bottom: calc(10px + var(--safe-bottom)); z-index: 5; transform: translateX(-50%);
  padding: 3px 12px; border: 2.5px solid var(--c-ink); border-radius: 999px; background: var(--c-paper);
  font-size: 13px; font-weight: 900; white-space: nowrap; pointer-events: none;
}
.fruit-name small { margin-left: 6px; font-size: 11px; color: var(--c-ink-sub); }

.hint {
  position: absolute; left: 50%; bottom: 30%; z-index: 6; transform: translateX(-50%); max-width: 90%; width: max-content;
  padding: 6px 14px; border: 3px solid var(--c-ink); border-radius: 16px; background: var(--c-paper); box-shadow: 0 3px 0 var(--c-ink);
  font-size: 14px; font-weight: 800; line-height: 1.35; text-align: center; pointer-events: none; word-break: auto-phrase;
  animation: hint-float 1.6s ease-in-out infinite;
}
@keyframes hint-float { 50% { transform: translate(-50%, -5px); } }

/* ぐらつき吹き出し（JS が left/top を的パネル上辺の位置に設定） */
.wobble-tip {
  position: absolute; z-index: 7; transform: translate(-50%, -100%); margin-top: -10px; pointer-events: none;
  padding: 3px 10px; border: 3px solid var(--c-ink); border-radius: 14px; background: var(--c-paper); box-shadow: 0 3px 0 var(--c-ink);
  font-size: 13px; font-weight: 900; white-space: nowrap; animation: tip-pop .9s ease both;
}
.wobble-tip::after {
  content: ""; position: absolute; left: 50%; bottom: -9px; width: 12px; height: 12px; margin-left: -6px;
  background: var(--c-paper); border-right: 3px solid var(--c-ink); border-bottom: 3px solid var(--c-ink); transform: rotate(45deg);
}
.wobble-tip b { font: 900 18px var(--font-num); color: var(--c-red); }
.wobble-tip.is-close b { color: var(--c-orange-deep); }
@keyframes tip-pop {
  0% { transform: translate(-50%, -60%) scale(.4); opacity: 0; }
  20% { transform: translate(-50%, -100%) scale(1.1); opacity: 1; }
  30%, 80% { transform: translate(-50%, -100%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -130%) scale(1); opacity: 0; }
}

/* 一言（ぬけた！/ぐらっ/はずれ） */
.callout {
  position: absolute; left: 50%; top: 46%; z-index: 9; transform: translate(-50%, -50%); text-align: center; line-height: 1.2;
  font-size: clamp(30px, 9vw, 48px); font-weight: 900; color: var(--c-gold); white-space: nowrap; pointer-events: none;
  -webkit-text-stroke: 8px var(--c-ink); paint-order: stroke fill; animation: pop .4s cubic-bezier(.2, 1.6, .4, 1) both;
}
.callout small { display: block; font-size: .5em; -webkit-text-stroke-width: 6px; color: #fff; }
.callout.is-bad { color: #d6dde6; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.3); } to { transform: translate(-50%, -50%) scale(1); } }

/* ビンゴ演出 */
.bingo-pop { position: absolute; inset: 0; z-index: 12; display: none; align-items: center; justify-content: center; pointer-events: none; overflow: hidden; }
.bingo-pop.is-open { display: flex; }
.bingo-pop::before {
  content: ""; position: absolute; left: 50%; top: 45%; width: 200vmax; height: 200vmax; margin: -100vmax;
  background: repeating-conic-gradient(rgba(255,208,80,.8) 0 10deg, rgba(255,250,215,.8) 10deg 20deg); animation: spin 16s linear infinite;
}
.bingo-pop.is-perfect::before { background: repeating-conic-gradient(rgba(255,154,46,.85) 0 10deg, rgba(255,232,120,.85) 10deg 20deg); }
@keyframes spin { to { transform: rotate(360deg); } }
.bingo-pop__box { position: relative; margin-bottom: 10vh; text-align: center; animation: pop-box .45s cubic-bezier(.2, 1.7, .4, 1) both; }
@keyframes pop-box { from { transform: scale(.3) rotate(-6deg); } to { transform: none; } }
.bingo-pop__label { display: inline-block; padding: 4px 18px; border: 4px solid var(--c-ink); border-radius: 999px; background: var(--c-green); color: #fff; font-size: 18px; font-weight: 900; }
.bingo-pop__name { margin: 6px 0; font-size: clamp(44px, 14vw, 72px); font-weight: 900; color: #fff; -webkit-text-stroke: 10px var(--c-ink); paint-order: stroke fill; white-space: nowrap; text-shadow: 0 6px 0 var(--c-ink); }
.bingo-pop__name .is-red { color: var(--c-red); }
.bingo-pop__pts { font: 900 40px var(--font-num); color: var(--c-gold); -webkit-text-stroke: 8px var(--c-ink); paint-order: stroke fill; }

/* ---------- 結果シート（下から。上の的は見えたまま） ---------- */
.result-sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 20; max-height: 70%; overflow-y: auto; touch-action: pan-y;
  padding: 14px calc(14px + var(--safe-right)) calc(14px + var(--safe-bottom)) calc(14px + var(--safe-left));
  background: var(--c-paper); border-top: 4px solid var(--c-ink); border-radius: var(--radius-l) var(--radius-l) 0 0;
  box-shadow: 0 -6px 0 rgba(59,47,47,.25); text-align: center; animation: sheet-up .4s cubic-bezier(.2, 1.2, .4, 1) both;
}
@keyframes sheet-up { from { transform: translateY(100%); } }
.result-sheet::before { content: ""; display: block; width: 48px; height: 5px; margin: -4px auto 8px; border-radius: 3px; background: var(--c-line); }
.result { display: grid; grid-template-columns: 112px 1fr; gap: 6px 12px; align-items: center; text-align: left; width: min(440px, 100%); margin: 0 auto; }
.result__board { width: 112px; height: 112px; grid-row: span 3; }
.result__board canvas { width: 100%; height: 100%; display: block; }
.result__title { margin: 0; font-size: 20px; font-weight: 900; line-height: 1.25; word-break: auto-phrase; }
.result__title small { display: block; font-size: 12px; font-weight: 800; color: var(--c-ink-sub); }
.result__score { font: 900 44px/1 var(--font-num); color: var(--c-red); }
.result__score small { font: 800 15px var(--font-base); color: var(--c-ink); margin-left: 2px; }
.result__stars { display: flex; gap: 4px; }
.star { width: 30px; height: 30px; background: var(--c-line); clip-path: polygon(50% 0, 63% 35%, 100% 38%, 71% 61%, 81% 100%, 50% 78%, 19% 100%, 29% 61%, 0 38%, 37% 35%); position: relative; }
.star.is-on { background: var(--c-ink); }
.star.is-on::after { content: ""; position: absolute; inset: 4px; background: var(--c-gold); clip-path: inherit; }
.star.is-on { animation: star-in .45s cubic-bezier(.2, 1.8, .4, 1) both; }
.star.is-on:nth-child(2) { animation-delay: .15s; }
.star.is-on:nth-child(3) { animation-delay: .3s; }
@keyframes star-in { from { transform: scale(0) rotate(-90deg); } }
.result__meta { grid-column: 1 / -1; display: flex; justify-content: center; gap: 6px 12px; flex-wrap: wrap; font-size: 13px; font-weight: 800; color: var(--c-ink-sub); }
.result__meta b { font-family: var(--font-num); color: var(--c-ink); }
.result__new { display: inline-block; padding: 1px 10px; border: 2.5px solid var(--c-ink); border-radius: 999px; background: var(--c-gold); color: var(--c-ink); animation: nudge 1.2s ease-in-out infinite; }
@keyframes nudge { 50% { transform: scale(1.1); } }
.result__near { grid-column: 1 / -1; margin: 2px 0 0; padding: 7px 10px; border-radius: var(--radius-s); background: #ffe6df; font-size: 14px; font-weight: 800; line-height: 1.5; text-align: center; word-break: auto-phrase; }
.result__near b { color: var(--c-red); }
.result-actions { width: min(440px, 100%); margin: 12px auto 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.result-actions .btn--main { grid-column: 1 / -1; }
.result-actions .btn { padding-left: 12px; padding-right: 12px; }
@media (max-height: 700px) {
  .result { grid-template-columns: 92px 1fr; }
  .result__board { width: 92px; height: 92px; }
  .result__score { font-size: 36px; } .result__title { font-size: 17px; } .star { width: 24px; height: 24px; }
  .result-actions .btn { min-height: 44px; font-size: 16px; } .result-actions .btn--main { min-height: 50px; font-size: 19px; }
}
@media (max-width: 360px) { .result-actions .btn { font-size: 15px; } }

/* ---------- 横向き案内・トースト ---------- */
.rotate { position: fixed; inset: 0; z-index: 100; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--c-green-deep); color: #fff; font-size: 20px; font-weight: 900; text-align: center; padding: 16px; }
.rotate__phone { width: 48px; height: 82px; border: 5px solid #fff; border-radius: 12px; animation: tilt 1.8s ease-in-out infinite; }
@keyframes tilt { 0%, 20% { transform: rotate(90deg); } 60%, 100% { transform: rotate(0); } }
@media (orientation: landscape) and (max-height: 500px) { .rotate { display: flex; } }
.toast {
  position: absolute; left: 50%; bottom: calc(24px + var(--safe-bottom)); z-index: 60; transform: translateX(-50%);
  max-width: 94%; width: max-content; padding: 10px 18px; border: 3px solid #fff; border-radius: 22px; background: var(--c-ink); color: #fff;
  font-weight: 800; text-align: center; word-break: auto-phrase; pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
  .title-art, .hint { animation: none !important; }
  .bingo-pop::before { animation: none !important; }
  .wobble-tip { animation: none !important; transform: translate(-50%, -100%); }
}
