/* ================================================================
   SNAKE（スネーク）
   ================================================================
   ■ フォントは自己ホスト
     Google Fonts への外部リンクは張らない。/kids* の CSP は
     font-src 'self' しか許可していないため、外から読もうとしても
     届かない。他のゲームと同じ方針。

   ■ 構成
     01. フォント
     02. 色（カスタムプロパティ）とベース
     03. ヘッダー・フッター
     04. 画面の切り替え
     05. カード（タイトル・リザルト）
     06. ボタン
     07. ゲーム画面：上の帯
     08. ゲーム画面：盤面・十字ボタン・重ね表示
     09. ぶつかったときの光
     10. 動きを減らす設定
   ================================================================ */

/* ── 01. フォント ───────────────────────────────────────────── */
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/nunito-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/nunito-latin-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url('/fonts/nunito-latin-900.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ── 02. 色とベース ─────────────────────────────────────────── */
:root {
  --bg:        #f5f0e6;
  --card:      #ffffff;
  --primary:   #3f9a5a;   /* 草の緑 */
  --primary-d: #2f7a45;
  --accent:    #e0559b;
  --text:      #383843;
  --muted:     #858588;
  --shadow:    rgba(56, 56, 67, 0.10);
  --grass:     #bde8a8;   /* 盤面の地の色（描画の前に一瞬だけ見える） */
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', system-ui, -apple-system, 'Hiragino Sans',
               'Hiragino Kaku Gothic ProN', 'Yu Gothic', YuGothic,
               'Noto Sans JP', Meiryo, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* 遊んでいるあいだは、画面いっぱいを盤面に使う（ページ全体はスクロールさせない） */
body.playing {
  height: 100dvh;
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.ja { display: block; margin-top: 2px; font-size: 0.92em; color: var(--muted); }

/* ── 03. ヘッダー・フッター ─────────────────────────────────── */
.site-header { padding: 14px 16px 6px; text-align: center; }
.site-title { margin: 0; font-size: 26px; font-weight: 900; letter-spacing: 0.02em; }
.title-accent { color: var(--primary); }
.site-tagline {
  margin: 4px 0 0;
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--muted);
}
/* 遊んでいるあいだは、タイトルを小さくして、フッターは隠す */
body.playing .site-header { padding: 6px 16px 2px; }
body.playing .site-title { font-size: 18px; }
body.playing .site-tagline,
body.playing .site-footer { display: none; }

.site-footer { padding: 14px 16px 22px; text-align: center; }
.footer-copy { margin: 4px 0; font-size: 12px; color: var(--muted); }
.footer-link { color: var(--primary-d); font-weight: 700; text-decoration: none; }
.footer-link:hover, .footer-link:focus-visible { text-decoration: underline; }

/* ── 04. 画面の切り替え ─────────────────────────────────────── */
main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.game-container {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  width: 100%; max-width: 980px; margin: 0 auto; padding: 0 12px;
}
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* ── 05. カード ─────────────────────────────────────────────── */
.card {
  margin: 12px auto;
  width: 100%; max-width: 520px;
  padding: 22px 20px 24px;
  background: var(--card);
  border-radius: 22px;
  box-shadow: 0 8px 28px var(--shadow);
  text-align: center;
}
.card-heading { margin: 0 0 12px; font-size: 18px; font-weight: 900; }

.rules { list-style: none; margin: 0 0 12px; padding: 0; text-align: left; }
.rules li { display: flex; gap: 12px; align-items: flex-start; margin: 10px 0; font-size: 15px; line-height: 1.45; }
.rule-icon { flex: none; font-size: 26px; line-height: 1.2; }

.controls-note { margin: 8px 0 14px; font-size: 13px; font-weight: 700; color: var(--muted); line-height: 1.5; }
.best-line { margin: 0 0 14px; font-size: 15px; font-weight: 900; color: var(--primary-d); }

.result-emoji { margin: 0; font-size: 56px; }
.result-message { margin: 6px 0 8px; font-size: 22px; font-weight: 900; }
.result-detail { margin: 0 0 16px; font-size: 16px; line-height: 1.7; }

/* 色を選ぶ丸（タイトルとリザルトに置く。丸は game.js が作る） */
.color-block { margin: 4px 0 14px; }
.color-label { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.color-picker { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.swatch {
  position: relative;
  width: 36px; height: 36px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--sw);
  box-shadow: 0 0 0 1px rgba(56, 56, 67, 0.25);
  cursor: pointer;
}
.swatch:active { transform: scale(0.92); }
/* 明るい色（白）は、白い縁に埋もれないよう、縁を灰色にして ✓ を濃くする */
.swatch.light { border-color: #cfc8b8; }
.swatch.light.on::after { color: var(--text); text-shadow: none; }
.swatch:focus-visible { outline: 3px solid #2f6fd1; outline-offset: 3px; }
/* 選んでいる色は、太い輪と ✓ で示す（色だけに頼らない） */
.swatch.on { box-shadow: 0 0 0 3px var(--text); }
.swatch.on::after {
  content: '✓';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px; font-weight: 900;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.6);
}

/* ── 06. ボタン ─────────────────────────────────────────────── */
.btn {
  display: block; width: 100%; max-width: 280px;
  margin: 10px auto 0;
  padding: 14px 18px;
  border: 0; border-radius: 16px;
  font: inherit; font-size: 18px; font-weight: 900; letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible, .icon-btn:focus-visible, .dp:focus-visible { outline: 3px solid #2f6fd1; outline-offset: 2px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 0 var(--primary-d); }
.btn-secondary { background: #ece6d8; color: var(--text); }

/* ── 07. ゲーム画面：上の帯 ─────────────────────────────────── */
.hud {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 4px 6px;
  font-weight: 900; font-size: 17px;
}
.hud-hearts { flex: 1; letter-spacing: 2px; white-space: nowrap; }
.hud-stat { white-space: nowrap; min-width: 3.4em; text-align: center; }
.icon-btn {
  width: 40px; height: 40px;
  border: 0; border-radius: 12px;
  background: #ece6d8;
  font-size: 18px; line-height: 1;
  cursor: pointer;
}

/* ── 08. 盤面・十字ボタン・重ね表示 ─────────────────────────── */
.stage {
  position: relative;
  flex: 1; min-height: 0;
  margin-bottom: 10px;
  background: var(--grass);
  border-radius: 18px;
  overflow: hidden;
  touch-action: none;          /* スワイプで画面がスクロール・拡大されないように */
  user-select: none;
  -webkit-user-select: none;
}
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* 十字ボタンは盤面の下の中央。親指で押しやすいよう、横に広く（1つ約108px、
   狭い画面では画面幅の28%まで縮める）、縦は少しだけ大きく（59px）する。
   左右は上下2段ぶんの高さで、真ん中の列に上と下を縦に並べる。 */
.dpad {
  position: absolute; left: 50%; bottom: 12px;
  transform: translateX(-50%);
  display: none;               /* タッチ画面（指で触る画面）でだけ出す。下の @media */
  grid-template-columns: repeat(3, min(108px, 28vw));
  grid-template-rows: repeat(2, 59px);
  gap: 4px;
  opacity: 0.62;
}
@media (hover: none) and (pointer: coarse) {
  .dpad { display: grid; }
}
.dp {
  border: 0; border-radius: 14px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--text);
  font-size: 22px;
  touch-action: none;
}
.dp:active { background: #fff; }
.dp-up    { grid-column: 2; grid-row: 1; }
.dp-down  { grid-column: 2; grid-row: 2; }
.dp-left  { grid-column: 1; grid-row: 1 / 3; }
.dp-right { grid-column: 3; grid-row: 1 / 3; }

.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.45);
  padding: 16px;
}
/* はじめる前の合図は、見せるだけで触れない（pointer-events: none）。
   盤面全体を覆っているので、触れてしまうと、その下のスワイプと十字ボタンが
   効かず、スマホでは「スワイプでスタート」と言いながら始められなくなる。 */
#readyOverlay { pointer-events: none; }
/* 重なりの順：十字ボタンは合図の上、一時停止の画面はそのさらに上 */
.dpad { z-index: 2; }
#pauseOverlay { z-index: 3; }

.overlay-card {
  width: 100%; max-width: 320px;
  padding: 18px 18px 20px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 8px 28px var(--shadow);
  text-align: center;
}
.overlay-title { margin: 0 0 6px; font-size: 20px; font-weight: 900; }
.overlay-text { margin: 0; font-size: 15px; line-height: 1.5; }

/* ── 09. ぶつかったときの光 ─────────────────────────────────── */
.stage::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 0 rgba(224, 85, 85, 0);
  pointer-events: none;
}
.stage.hit::after { animation: hitflash 0.45s ease-out; }
@keyframes hitflash {
  0%   { box-shadow: inset 0 0 0 10px rgba(224, 85, 85, 0.65); }
  100% { box-shadow: inset 0 0 0 0 rgba(224, 85, 85, 0); }
}

/* ── 10. 動きを減らす設定 ───────────────────────────────────── */
/* 光る・ゆれる・跳ねる演出はやめる。ヘビの動きそのものはゲームの中身なので残す。
   （game.js 側でも、粒・ズームのなめらかな変化・くだものの上下を止めている） */
@media (prefers-reduced-motion: reduce) {
  .stage.hit::after { animation: none; }
  .btn { transition: none; }
}
