/* サンタのソリすべり style.css — 構造とクラス名は docs/design.md を参照 */

:root {
  --c-ink: #3b2f2f;
  --c-ink-sub: #7a6a5e;
  --c-paper: #fffdf7;
  --c-line: #eadcc0;
  --c-red: #e8413b;
  --c-red-deep: #b8302c;
  --c-green: #3fa66a;
  --c-green-deep: #2b7a4b;
  --c-gold: #ffc83d;
  --c-gold-deep: #d99a00;
  --c-ice: #8fd3ff;
  --c-ice-deep: #4f9fd8;
  --c-snow: #f4f9ff;
  --c-sky-top: #1b2960;
  --c-sky-mid: #7a5aa8;
  --c-sky-low: #ff9a6b;
  --c-night: #0b1438;
  --c-plus: #3fa66a;
  --c-minus: #e8413b;
  --c-off: #c9cbd8;

  --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-m: 18px;
  --radius-l: 28px;
  --btn-depth: 6px;
  --card-w: min(92vw, 560px);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --dur-fast: 0.15s;
  --dur-mid: 0.35s;
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font-base);
  color: var(--c-ink);
  background: var(--c-night);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
  line-height: 1.5;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; }
.num { font-family: var(--font-num); font-weight: 900; font-variant-numeric: tabular-nums; }

/* ---------- 土台 ---------- */
.app { position: fixed; inset: 0; overflow: hidden; }
.game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.screen {
  position: absolute; inset: 0; z-index: 10;
  display: flex; 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;
  opacity: 1; visibility: visible;
  transition: opacity var(--dur-mid) ease, visibility 0s;
}
.screen.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity var(--dur-mid) ease, visibility 0s var(--dur-mid); }
.screen--dim { background: rgba(11, 20, 56, 0.55); }

.card {
  position: relative;
  width: var(--card-w);
  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 24px;
  text-align: center;
}
.card__title { margin: 0 0 12px; font-size: 24px; font-weight: 900; letter-spacing: 0.04em; }

/* ---------- ボタン（押すと沈む） ---------- */
.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;
  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: 0.04em;
  cursor: pointer;
  box-shadow: 0 var(--btn-depth) 0 var(--btn-edge), 0 var(--btn-depth) 0 3px var(--c-ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter var(--dur-fast);
}
.btn::after {
  content: ""; position: absolute; top: 5px; left: 18%; right: 18%; height: 6px;
  border-radius: 999px; background: rgba(255, 255, 255, 0.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(0.8) opacity(0.6); cursor: not-allowed; }
.btn--block { display: flex; width: 100%; }
.btn--green { --btn-bg: var(--c-green); --btn-edge: var(--c-green-deep); }
.btn--gold { --btn-bg: var(--c-gold); --btn-edge: var(--c-gold-deep); --btn-fg: var(--c-ink); }
.btn--ice { --btn-bg: var(--c-ice); --btn-edge: var(--c-ice-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; }
.btn-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

.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: 18px; font-weight: 900; line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--c-ink);
  transition: transform 0.08s ease, box-shadow 0.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 { color: var(--c-off); }

/* ---------- タイトル ---------- */
.title { justify-content: space-between; }
.title__logo { margin: 4vh 0 0; text-align: center; line-height: 1.1; }
.title__logo-sub {
  display: inline-block; padding: 2px 14px; margin-bottom: 6px;
  background: var(--c-green); color: #fff; border: 3px solid var(--c-ink); border-radius: 999px;
  font-size: clamp(13px, 2.6vmin, 18px); font-weight: 800;
}
.title__logo-main {
  display: block;
  font-size: clamp(34px, 9vmin, 72px); font-weight: 900; letter-spacing: 0.04em;
  color: #fff;
  -webkit-text-stroke: 8px var(--c-ink); paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--c-ink);
  transform: rotate(-3deg);
}
.title__logo-main em { font-style: normal; color: var(--c-gold); }
.title__hero { width: min(60vw, 320px); height: auto; aspect-ratio: 2 / 1; }
.title__best {
  display: inline-flex; gap: 8px; align-items: baseline;
  padding: 4px 16px; background: rgba(255, 253, 247, 0.9);
  border: 3px solid var(--c-ink); border-radius: 999px; font-weight: 800;
}
.title__best .num { font-size: 22px; }
.title__actions { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 4vh; }
.title__corner { position: absolute; top: calc(12px + var(--safe-top)); right: calc(12px + var(--safe-right)); display: flex; gap: 10px; }
@media (orientation: landscape) and (max-height: 520px) {
  .title { flex-direction: row; justify-content: space-around; }
  .title__logo { margin: 0; }
  .title__actions { margin: 0; }
}

/* ---------- 初回ルール ---------- */
.rules__steps { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 8px 0 4px; }
@media (orientation: portrait) and (max-width: 420px) { .rules__steps { grid-template-columns: 1fr; } }
.rule {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px; background: #eef4fc; border: 3px solid var(--c-ink); border-radius: var(--radius-m);
}
.rule__no {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  background: var(--c-red); color: #fff; border: 3px solid var(--c-ink); border-radius: 50%; font-weight: 900;
}
.rule__fig { position: relative; width: 100%; max-width: 220px; aspect-ratio: 16 / 10; border-radius: 12px; overflow: hidden; background: linear-gradient(#ffd9b8, #f4f9ff); }
.rule__fig canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.rule__text { margin: 0; font-size: 15px; font-weight: 700; }
.rule__text b { color: var(--c-red); }
/* 指マーク（丸＋影）：図1は左下へ引いて戻る、図2は押して沈む */
.rule__finger {
  position: absolute; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.85); border: 3px solid var(--c-ink);
  box-shadow: 0 0 0 6px rgba(255, 200, 61, 0.45);
}
.rule__finger--pull { left: 42%; top: 40%; animation: rule-pull 2.2s ease-in-out infinite; }
.rule__finger--press { right: 12%; bottom: 14%; animation: rule-press 1.6s ease-in-out infinite; }
.rule__arrow {
  position: absolute; left: 14%; top: 56%; width: 30%; height: 6px; background: var(--c-red);
  border: 2px solid var(--c-ink); border-radius: 3px; transform: rotate(-28deg); transform-origin: right center;
}
.rule__arrow::before {
  content: ""; position: absolute; left: -12px; top: -8px;
  border: 9px solid transparent; border-right: 12px solid var(--c-red);
}
@keyframes rule-pull {
  0%, 15% { transform: translate(0, 0); }
  60%, 70% { transform: translate(-46px, 26px); }
  75% { transform: translate(-46px, 26px) scale(0.8); opacity: 0.6; }
  100% { transform: translate(0, 0); opacity: 1; }
}
@keyframes rule-press {
  0%, 30% { transform: scale(1); box-shadow: 0 0 0 6px rgba(255, 200, 61, 0.45); }
  45%, 85% { transform: scale(0.82); box-shadow: 0 0 0 14px rgba(255, 200, 61, 0.65); }
  100% { transform: scale(1); }
}

/* ---------- スタート時のガイド ---------- */
.guide {
  position: absolute; z-index: 5; pointer-events: none;
  left: 50%; top: calc(14% + var(--safe-top)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px; background: rgba(255, 253, 247, 0.94);
  border: 3px solid var(--c-ink); border-radius: 999px; box-shadow: 0 4px 0 var(--c-ink);
  font-size: clamp(15px, 3vmin, 20px); font-weight: 800; white-space: nowrap;
  animation: guide-bob 1.4s ease-in-out infinite;
}
.guide__key {
  display: inline-block; padding: 0 8px; background: var(--c-gold);
  border: 2px solid var(--c-ink); border-radius: 8px; font-size: 0.85em;
}
/* キャンバス上のソリ位置に置く指（JS で left/top を設定） */
.guide-finger {
  position: absolute; z-index: 5; pointer-events: none; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.9); border: 3px solid var(--c-ink);
  box-shadow: 0 0 0 8px rgba(255, 200, 61, 0.5);
  animation: guide-drag 2s ease-in-out infinite;
}
/* 強さメーター（引っ張り中だけ表示） */
.power {
  position: absolute; z-index: 5; pointer-events: none;
  left: calc(16px + var(--safe-left)); bottom: calc(16px + var(--safe-bottom));
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: rgba(255, 253, 247, 0.94); border: 3px solid var(--c-ink); border-radius: 999px; font-weight: 800;
}
.power__bar { width: 120px; height: 14px; border: 2px solid var(--c-ink); border-radius: 999px; background: #e3e8f3; overflow: hidden; }
.power__fill { height: 100%; width: calc(var(--p, 0) * 100%); background: linear-gradient(90deg, var(--c-green), var(--c-gold), var(--c-red)); }
.power__angle { font-size: 16px; }
@keyframes guide-bob { 50% { transform: translate(-50%, -4px); } }
@keyframes guide-drag { 0%, 20% { transform: translate(0, 0); } 65%, 80% { transform: translate(-50px, 28px); } 100% { transform: translate(0, 0); } }

/* ---------- 滑走中 HUD ---------- */
.hud {
  position: absolute; z-index: 6; left: 0; right: 0; top: 0; pointer-events: none;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: calc(10px + var(--safe-top)) calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
}
.hud__main { display: flex; gap: 8px; flex-wrap: wrap; }
.hud__chip {
  display: inline-flex; align-items: baseline; gap: 4px;
  padding: 4px 14px; background: rgba(255, 253, 247, 0.94);
  border: 3px solid var(--c-ink); border-radius: 999px; box-shadow: 0 3px 0 var(--c-ink);
}
.hud__chip .num { font-size: clamp(20px, 4.4vmin, 30px); line-height: 1.1; }
.hud__unit { font-size: 13px; font-weight: 800; color: var(--c-ink-sub); }
.hud__chip--dist .num { font-size: clamp(26px, 6vmin, 40px); }
.hud__diff { font-size: 15px; font-weight: 900; }
.hud__diff.is-plus { color: var(--c-plus); }
.hud__diff.is-minus { color: var(--c-minus); }
.hud__right { display: flex; gap: 8px; pointer-events: auto; }
.hud__stars { display: inline-flex; gap: 2px; align-self: center; }
.hud__star { width: 18px; height: 18px; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); background: var(--c-off); }
.hud__star.is-on { background: var(--c-gold); animation: pop var(--dur-mid) var(--ease-pop); }
/* 押している間のヒント（画面下） */
.hud__hold {
  position: absolute; z-index: 6; left: 50%; bottom: calc(14px + var(--safe-bottom)); transform: translateX(-50%);
  padding: 4px 16px; border: 3px solid var(--c-ink); border-radius: 999px;
  background: rgba(255, 253, 247, 0.8); font-weight: 800; font-size: 14px; pointer-events: none;
}
.hud__hold.is-active { background: var(--c-gold); transform: translateX(-50%) translateY(3px); }

/* ---------- ポーズ ---------- */
.pause .card { width: min(86vw, 360px); }
.pause .btn { width: 100%; }
.pause__list { display: flex; flex-direction: column; gap: 14px; }

/* ---------- 結果 ---------- */
.result .card { padding-top: 16px; }
.result__head { margin: 0; font-size: 18px; font-weight: 900; color: var(--c-ink-sub); }
.result__dist { margin: 0; line-height: 1; }
.result__dist .num { font-size: clamp(54px, 13vmin, 88px); }
.result__dist-unit { font-size: 26px; font-weight: 900; margin-left: 4px; }
.result__stars { display: flex; justify-content: center; gap: 8px; margin: 8px 0 4px; }
.result__star {
  width: 52px; height: 52px; position: relative;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  background: var(--c-ink);
}
.result__star::after {
  content: ""; position: absolute; inset: 5px 5px 6px;
  clip-path: inherit; background: var(--c-off);
}
.result__star.is-on::after { background: var(--c-gold); }
.result__star.is-on { animation: star-in 0.5s var(--ease-pop) both; }
.result__star:nth-child(2).is-on { animation-delay: 0.15s; }
.result__star:nth-child(3).is-on { animation-delay: 0.3s; }
.result__next { margin: 2px 0 0; font-weight: 800; font-size: 15px; }
.result__next .num { color: var(--c-red); font-size: 20px; }
.result__best {
  display: inline-block; margin: 8px 0 0; padding: 4px 16px;
  background: var(--c-gold); border: 3px solid var(--c-ink); border-radius: 999px;
  font-weight: 900; transform: rotate(-4deg);
  animation: pop 0.5s var(--ease-pop) 0.5s both;
}
.result__best-prev { margin: 4px 0 0; font-size: 13px; color: var(--c-ink-sub); font-weight: 700; }
.result__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.stat { padding: 8px 4px; background: #eef4fc; border: 3px solid var(--c-ink); border-radius: 14px; }
.stat__label { display: block; font-size: 12px; font-weight: 800; color: var(--c-ink-sub); }
.stat__value .num { font-size: 22px; }
.stat__unit { font-size: 12px; font-weight: 800; margin-left: 2px; }
/* 横向きで背が低いときは 2 カラム */
@media (orientation: landscape) and (max-height: 560px) {
  .result .card { width: min(94vw, 760px); display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; align-items: center; padding: 14px 18px 18px; }
  .result__main { grid-column: 1; }
  .result__side { grid-column: 2; }
  .result__dist .num { font-size: clamp(44px, 15vh, 72px); }
  .result__star { width: 40px; height: 40px; }
  .result__stats { margin-top: 0; }
}

/* ---------- トースト・汎用 ---------- */
.toast {
  position: absolute; z-index: 30; left: 50%; bottom: calc(80px + var(--safe-bottom)); transform: translateX(-50%);
  padding: 8px 18px; background: var(--c-ink); color: #fff; border-radius: 999px; font-weight: 800;
  animation: pop var(--dur-mid) var(--ease-pop);
}
/* 縦向きで遊んでいるときの「横向きがおすすめ」 */
.rotate-tip {
  display: none; align-items: center; gap: 6px;
  margin-top: 10px; padding: 2px 12px; font-size: 13px; font-weight: 800;
  background: rgba(255, 253, 247, 0.9); border: 2px solid var(--c-ink); border-radius: 999px;
}
@media (orientation: portrait) and (max-width: 600px) { .rotate-tip { display: inline-flex; } }

@keyframes pop { 0% { transform: scale(0.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes star-in { 0% { transform: scale(0) rotate(-90deg); } 100% { transform: scale(1) rotate(0); } }

/* ---------- ゲーム一覧へ戻る（himaratsu.com/games/ 配下のときだけ表示） ---------- */
.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: 700 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; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important; }
  .guide, .guide-finger, .rule__finger { animation: none !important; }
  .title__logo-main { transform: none; }
}

/* 修正（エンジニア）: 背の低い横画面でルールカードが上下にはみ出し、上端がスクロールでも見えなかった */
.screen--dim { justify-content: safe center; }
@media (orientation: landscape) and (max-height: 520px) {
  .rules .card { padding: 12px 16px 14px; }
  .rules .card__title { margin-bottom: 4px; font-size: 20px; }
  .rule { padding: 6px; gap: 4px; }
  .rule__fig { max-width: 150px; }
  .rules .btn-row { margin-top: 8px; }
}
/* 追加（エンジニア）: 転倒理由、360x640 でのルールカード（M1）と前かがみヒントの折り返し（L2） */
.result__reason { margin: 6px auto 0; max-width: 22em; padding: 4px 12px; border-radius: 12px; background: #ffe9e6; color: var(--c-red-deep); font-size: 14px; font-weight: 800; line-height: 1.35; }
.hud__hold { white-space: nowrap; }
@media (orientation: portrait) and (max-height: 760px) {
  .rules .card { padding: 12px 14px 14px; }
  .rules .card__title { margin-bottom: 4px; font-size: 20px; }
  .rules__steps { gap: 8px; }
  .rule { padding: 6px; gap: 4px; }
  .rule__fig { max-width: 150px; }
  .rules .btn-row { margin-top: 8px; }
}
