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

   ■ 盤面の大きさ
     幅は「画面の幅」と「画面の高さから、盤面以外が使う分を引いたもの」の
     小さいほう（上限 540px）。縦に短いスマホでも、数字ボタンまで
     スクロールなしで見えるようにする。数字の大きさは盤面の幅に合わせて
     変える（container query の cqw。使えない古い環境では固定の大きさ）。

   ■ 構成
     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:        #f1f4fa;
  --card:      #ffffff;
  --primary:   #3b78d8;   /* 空の青 */
  --primary-d: #2a5cab;
  --accent:    #f08a24;
  --text:      #2f3342;
  --muted:     #7c8294;
  --shadow:    rgba(47, 51, 66, 0.10);

  --line:        #c9d0df;   /* マスの間の細い線 */
  --line-strong: #3a4052;   /* ブロックの境の太い線 */
  --cell:        #ffffff;
  --cell-peer:   #e8eefa;   /* 選んだマスと同じ 行・列・ブロック */
  --cell-same:   #c7dafb;   /* 選んだマスと同じ数字 */
  --cell-sel:    #9fc2f7;   /* 選んだマス */
  --given:       #2f3342;   /* 最初からある数字 */
  --mine:        #2a5cab;   /* 自分で入れた数字 */
  --err:         #d63a3a;
  --err-bg:      #fde0e0;
}

* { 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;
}

.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: 580px; 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; }

.start-label { margin: 16px 0 0; font-size: 13px; font-weight: 700; color: var(--muted); }
.privacy-note { margin: 16px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); }

.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; }

/* ── 06. ボタン ─────────────────────────────────────────────── */
.btn {
  display: block; width: 100%; max-width: 280px;
  margin: 10px auto 0;
  padding: 12px 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, .toggle:focus-visible,
.tool:focus-visible, .num:focus-visible, .cell:focus-visible { outline: 3px solid #f08a24; outline-offset: 2px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 0 var(--primary-d); }
.btn-secondary { background: #e4e9f3; color: var(--text); }
/* 英語の下に、日本語を小さく添える */
.btn-en { display: block; }
.btn-ja { display: block; margin-top: 1px; font-size: 12px; font-weight: 700; opacity: 0.9; }
/* 難しさごとに色を変えて、取り違えにくくする（Easy は青、Medium はオレンジ、Hard は紫） */
.level-medium { background: var(--accent); box-shadow: 0 4px 0 #c4691a; }
.level-hard   { background: #8e5bd6; box-shadow: 0 4px 0 #6d3fb0; }
.btn-continue { margin-top: 4px; }

/* ── 07. ゲーム画面：上の帯・まちがい表示のスイッチ ─────────── */
.hud {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 0 8px;
}
.icon-btn {
  flex: none;
  width: 40px; height: 40px;
  border: 0; border-radius: 12px;
  background: #e4e9f3;
  font-size: 20px; line-height: 1; font-weight: 900;
  color: var(--text);
  cursor: pointer;
}
.hud-level { flex: 1; margin: 0; font-size: 16px; font-weight: 900; line-height: 1.2; }
.hud-level small { display: block; font-size: 11px; font-weight: 700; color: var(--muted); }

.toggle {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 4px 10px;
  border: 0; border-radius: 12px;
  background: #e4e9f3;
  font: inherit; color: var(--text);
  cursor: pointer;
}
.toggle-text { text-align: right; line-height: 1.15; }
.toggle-en { display: block; font-size: 12px; font-weight: 900; }
.toggle-ja { display: block; font-size: 10px; font-weight: 700; color: var(--muted); }
/* スイッチ。ON は右に寄って青、OFF は左で灰色（色だけでなく位置でも分かる） */
.toggle-switch {
  position: relative; flex: none;
  width: 36px; height: 22px;
  border-radius: 11px;
  background: #aab2c4;
  transition: background 0.15s ease;
}
.toggle-switch::after {
  content: '';
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
.toggle[aria-pressed="true"] .toggle-switch { background: var(--primary); }
.toggle[aria-pressed="true"] .toggle-switch::after { transform: translateX(14px); }

/* ── 08. ゲーム画面：盤面 ───────────────────────────────────── */
.board {
  /* 画面の幅と、（高さ − 盤面以外が使う約 330px）の小さいほう。小さくなりすぎないよう 240px を下限に */
  width: clamp(240px, min(100%, calc(100dvh - 330px)), 540px);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--cell);
  border: 3px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.cell {
  position: relative;
  padding: 0; margin: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--cell);
  color: var(--mine);
  font: inherit;
  font-size: 24px;               /* container query が使えないときの大きさ */
  font-size: 6.4cqw;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
/* 3×3 のブロックの境目は太い線。いちばん右・いちばん下は盤面の枠があるので不要 */
.cell.bx-r { border-right: 2px solid var(--line-strong); }
.cell.bx-b { border-bottom: 2px solid var(--line-strong); }
.cell:nth-child(9n)       { border-right: 0; }
.cell:nth-child(n + 73)   { border-bottom: 0; }

.cell.given { color: var(--given); font-weight: 900; }
.cell.peer  { background: var(--cell-peer); }
.cell.same  { background: var(--cell-same); }
.cell.sel   { background: var(--cell-sel); }
/* ルール違反。赤い字と赤い地（色だけに頼らないよう、字も太くする） */
.cell.err { background: var(--err-bg); color: var(--err); font-weight: 900; }
.cell.sel.err { background: #f7b9b9; }
/* キーボードで動かしているときの目印は、背景ではなく輪で出す（選択の色と重ならないように） */
.cell:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 1; }

.cell .v { display: block; }

/* メモ：3×3 の小さい数字 */
.cell .notes {
  position: absolute; inset: 0;
  display: none;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 2px;
  font-size: 9px;
  font-size: 2.9cqw;
  font-weight: 700;
  color: var(--muted);
  pointer-events: none;
}
.cell.has-notes .notes { display: grid; }
.cell .notes span { display: flex; align-items: center; justify-content: center; }
/* 選んだ数字と同じメモは、青くして太くする */
.cell .notes span.hit { color: var(--primary-d); font-weight: 900; }

/* 完成したとき、左上から右下へ、斜めに波のように光る（--d は行＋列。game.js が入れる） */
.board.solved .cell {
  animation: win 0.6s ease both;
  animation-delay: calc(var(--d, 0) * 45ms);
}
@keyframes win {
  0%, 100% { filter: none; }
  40%      { filter: brightness(1.15) saturate(1.4); background: var(--cell-sel); }
}

.status {
  min-height: 22px;
  margin: 6px 0 0;
  text-align: center;
  font-size: 13px; font-weight: 900;
  color: var(--err);
}

/* ── 09. ゲーム画面：道具・数字ボタン ───────────────────────── */
/* 道具と数字ボタンは、盤面と同じ幅にそろえる（幅の式は .board と同じ） */
.tools {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  width: clamp(240px, min(100%, calc(100dvh - 330px)), 540px);
  margin: 0 auto 8px;
}
.tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0;
  padding: 5px 4px 6px;
  border: 0; border-radius: 14px;
  background: #e4e9f3;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.tool:active { transform: scale(0.97); }
.tool:disabled { opacity: 0.4; cursor: default; transform: none; }
.tool-icon { font-size: 20px; line-height: 1.1; font-weight: 900; }
.tool-en { font-size: 12px; font-weight: 900; line-height: 1.2; }
.tool-ja { font-size: 10px; font-weight: 700; color: var(--muted); line-height: 1.2; }
.tool[aria-pressed="true"] { background: var(--accent); color: #fff; }
.tool[aria-pressed="true"] .tool-ja { color: #fff; }

.numpad {
  display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px;
  width: clamp(240px, min(100%, calc(100dvh - 330px)), 540px);
  margin: 0 auto 10px;
}
.num {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 0;
  padding: 6px 0 4px;
  border: 0; border-radius: 12px;
  background: var(--primary);
  box-shadow: 0 3px 0 var(--primary-d);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.num:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--primary-d); }
.num-d { font-size: 24px; font-weight: 900; line-height: 1.1; }
.num-left { font-size: 10px; font-weight: 700; line-height: 1.2; opacity: 0.85; }
/* 9個そろった数字はうすくする（まちがえて入れていても、押せなくはしない） */
.num.done { background: #c5cde0; box-shadow: 0 3px 0 #aab2c4; color: #fff; }

/* ── 10. 動きを減らす設定 ───────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .btn, .toggle-switch, .toggle-switch::after { transition: none; }
  .board.solved .cell { animation: none; }
}
