:root {
  --accent: #b7282e;
  --accent-dark: #8f1f24;
  --bg: #fdf8f2;
  --surface: #ffffff;
  --text: #2b2320;
  --text-muted: #6b625c;
  --border: #d8cfc4;
  --correct: #6aaa64;
  --present: #c9a227;
  --absent: #8a8580;
  --key-bg: #e7e0d6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #201a17;
    --surface: #2a221e;
    --text: #f1e9e0;
    --text-muted: #baafa4;
    --border: #453a33;
    --key-bg: #3a322c;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  min-height: 100%;
  overflow-x: hidden;
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
}

/* --- タイトル画面 --- */
.title-wrap {
  max-width: 480px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding-top: 8vh;
}
.logo {
  font-size: 2.1rem;
  margin: 0;
  letter-spacing: 0.05em;
}
.logo-accent { color: var(--accent); }
.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  margin-top: 12px;
}
.title-icons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--key-bg); color: var(--text); }

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}
.icon-btn.small { padding: 6px 9px; font-size: 1rem; }

.ad-slot {
  width: 100%;
  min-height: 60px;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 0;
  margin-top: 18px;
  overflow: hidden;
}
.shop-banner-slot { padding: 10px; }
.shop-banner-scroller {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  width: 100%;
  padding-bottom: 2px;
}
.shop-banner-scroller img {
  height: 60px;
  width: auto;
  border-radius: 6px;
  flex: 0 0 auto;
}

.cross-game-nav {
  width: 100%;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  text-align: center;
}
.cross-game-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0 0 8px;
}
.cross-game-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.cross-game-card {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--key-bg);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 700;
}
.cross-game-icon { font-size: 1rem; }

/* --- ゲーム画面 --- */
.game-header {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 14px;
}
.game-title { font-weight: 700; font-size: 0.95rem; }
.header-icons { display: flex; gap: 6px; }

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 50;
}

.hint-row {
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.category-badge {
  background: var(--key-bg);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
}
.btn-hint {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-hint:disabled { opacity: 0.5; cursor: default; }

.board {
  --cols: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0 18px;
  width: 100%;
  max-width: 420px;
}
.board-row {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 6px;
}
.board-row.shake { animation: shake 0.4s ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

.tile {
  aspect-ratio: 1 / 1;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 5vw, 1.6rem);
  font-weight: 700;
  background: var(--surface);
  color: var(--text);
}
.tile-filled { border-color: var(--text-muted); }
.tile-flip { animation: flip 0.5s ease; }
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
.tile-correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.tile-present { background: var(--present); border-color: var(--present); color: #fff; }
.tile-absent { background: var(--absent); border-color: var(--absent); color: #fff; }

.keyboard {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-bottom: 24px;
}
.kana-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  width: 100%;
}
.key {
  background: var(--key-bg);
  color: var(--text);
  border: none;
  border-radius: 5px;
  padding: 8px 0;
  font-size: clamp(0.75rem, 3vw, 0.95rem);
  cursor: pointer;
}
.key:active { transform: scale(0.95); }
.key-wide {
  width: 100%;
  padding: 10px 0;
  font-weight: 700;
}
.key-correct { background: var(--correct); color: #fff; }
.key-present { background: var(--present); color: #fff; }
.key-absent { background: var(--absent); color: #fff; opacity: 0.7; }

/* --- モーダル --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  padding: 24px 20px;
  max-width: 420px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  position: relative;
}
.modal h2 { margin-top: 0; }
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
}
.help-list { padding-left: 20px; line-height: 1.7; }
.example-row { display: flex; gap: 6px; margin: 14px 0; }
.example-row .tile { width: 44px; height: 44px; aspect-ratio: unset; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 14px 0;
}
.stat-box { text-align: center; }
.stat-num { font-size: 1.5rem; font-weight: 800; }
.stat-label { font-size: 0.7rem; color: var(--text-muted); }

.dist-chart { display: flex; flex-direction: column; gap: 5px; }
.dist-row { display: flex; align-items: center; gap: 8px; }
.dist-idx { width: 14px; font-size: 0.8rem; color: var(--text-muted); }
.dist-bar {
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  padding: 3px 6px;
  border-radius: 4px;
  min-width: 18px;
  text-align: right;
}

.answer-reveal { text-align: center; margin: 10px 0 4px; }
.answer-kanji { font-size: 1.4rem; font-weight: 800; margin-right: 8px; }
.answer-kana { color: var(--text-muted); }
.trivia {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.result-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}
.next-note { font-size: 0.8rem; color: var(--text-muted); text-align: center; }

/* --- おみやげ(アフィリエイト) --- */
.goods-panel { width: 100%; margin-top: 16px; }
.goods-heading {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.pr-badge {
  background: var(--text-muted);
  color: var(--bg);
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 4px;
}
.goods-scroller {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.goods-card {
  flex: 0 0 auto;
  width: 108px;
  background: var(--key-bg);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.goods-img { line-height: 0; }
.goods-img img {
  width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
}
.goods-title {
  color: var(--text);
  text-decoration: none;
  font-size: 0.7rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- 紙吹雪 --- */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 200;
}
.confetti-piece {
  position: absolute;
  top: -10%;
  font-size: 1.4rem;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  to { top: 110%; transform: rotate(360deg); }
}
