:root {
  --green: #2e7d32;
  --green-dark: #1b5e20;
  --green-soft: #a5d6a7;
  --green-bg: #e8f5e9;
  --cream: #fbf8f1;
  --card: #ffffff;
  --ink: #22302a;
  --muted: #6b7a72;
  --line: #e2e8e3;
  --yellow: #f9a825;
  --water: #4fc3f7;
  --red: #d84315;
  --shadow: 0 6px 20px rgba(34, 48, 42, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  background: var(--cream);
  color: var(--ink);
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button { font-family: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--green); color: #fff;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; }
.kappa { width: 40px; height: 40px; }
.brand-sub { font-size: 11px; opacity: .85; letter-spacing: .08em; }
.brand-title { font-size: 18px; font-weight: 700; line-height: 1.2; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.userbox .link { color: #fff; opacity: .9; }

#app { max-width: 520px; margin: 0 auto; padding: 16px 16px 40px; }
.view[hidden] { display: none; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 16px;
}

.tabs { display: flex; gap: 4px; background: var(--green-bg); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.tab { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 9px; font-size: 15px; color: var(--muted); cursor: pointer; }
.tab.active { background: #fff; color: var(--green-dark); font-weight: 700; box-shadow: 0 2px 6px rgba(0,0,0,.06); }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form input {
  font-size: 17px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
.form input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(46,125,50,.15); }

.btn {
  border: 0; border-radius: 14px; padding: 14px 18px; font-size: 16px; font-weight: 700; cursor: pointer;
  transition: transform .06s ease, background .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.ghost { background: var(--green-bg); color: var(--green-dark); }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--green-dark); font-size: 14px; cursor: pointer; padding: 4px 0; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.error { color: var(--red); font-size: 14px; min-height: 1.4em; margin: 12px 0 0; }
.note { color: var(--muted); font-size: 13px; margin: 12px 0 0; }

/* ホーム */
.hero { background: linear-gradient(135deg, #2e7d32, #43a047); color: #fff; }
.hero-date { font-size: 14px; opacity: .9; }
.hero-stats { display: flex; justify-content: space-around; margin: 12px 0 6px; }
.stat { text-align: center; }
.stat-num { font-size: 34px; font-weight: 800; line-height: 1.1; }
.stat-label { font-size: 12px; opacity: .9; }
.hero-msg { margin: 10px 0 0; font-size: 14px; text-align: center; opacity: .95; }

.games { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.game-item {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--card); border: 0; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); cursor: pointer;
  color: var(--ink);
}
.game-item:active { transform: scale(.99); }
.game-icon { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 26px; flex-shrink: 0; }
.game-icon.calc { background: #fff3e0; }
.game-icon.memory { background: #e3f2fd; }
.game-icon.stroop { background: #fce4ec; }
.game-info { flex: 1; min-width: 0; }
.game-name { font-weight: 700; font-size: 17px; }
.game-desc { font-size: 13px; color: var(--muted); }
.game-score { text-align: right; flex-shrink: 0; }
.game-score .pts { font-size: 22px; font-weight: 800; color: var(--green-dark); }
.game-score .pts.none { color: var(--muted); font-size: 14px; font-weight: 600; }
.game-score .done { font-size: 11px; color: var(--green); }

/* ゲーム */
.game-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.game-title { font-weight: 700; font-size: 16px; }
.game-progress { font-size: 14px; color: var(--muted); min-width: 60px; text-align: right; }
.game-card { min-height: 420px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }

.intro h2 { margin: 0 0 8px; color: var(--green-dark); }
.intro p { margin: 0 0 20px; color: var(--muted); font-size: 15px; }
.intro .btn { min-width: 200px; }

.countdown { font-size: 72px; font-weight: 800; color: var(--green); }

.question { font-size: 44px; font-weight: 800; letter-spacing: .04em; margin: 8px 0 12px; }
.answer-display {
  font-size: 36px; font-weight: 700; min-height: 54px; min-width: 160px; border-bottom: 3px solid var(--green-soft); margin-bottom: 16px;
}
.answer-display.empty { color: var(--line); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 300px; }
.key {
  font-size: 24px; font-weight: 700; padding: 14px 0; border: 0; border-radius: 14px; background: var(--green-bg); color: var(--ink); cursor: pointer;
}
.key:active { background: var(--green-soft); }
.key.ok { background: var(--green); color: #fff; }
.key.del { background: #f1f1f1; }
.feedback { font-size: 20px; font-weight: 800; min-height: 32px; margin-bottom: 8px; }
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--red); }

.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: 100%; max-width: 320px; margin: 10px auto; }
.cell {
  aspect-ratio: 1; border-radius: 14px; background: var(--green-bg); border: 0; cursor: pointer;
  transition: background .12s, transform .12s;
}
.cell.lit { background: var(--yellow); transform: scale(1.05); }
.cell.tapped { background: var(--green-soft); }
.cell.wrong { background: #ffcdd2; }
.grid.locked .cell { cursor: default; }
.status { font-size: 16px; color: var(--muted); min-height: 1.6em; margin-bottom: 6px; }
.lives { font-size: 14px; color: var(--muted); }

.stroop-word { font-size: 64px; font-weight: 900; margin: 16px 0 24px; letter-spacing: .05em; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; max-width: 340px; }
.choice {
  padding: 18px 0; font-size: 20px; font-weight: 700; border: 2px solid var(--line); border-radius: 14px; background: #fff; color: var(--ink); cursor: pointer;
}
.choice:active { background: var(--green-bg); }

/* 結果 */
.result { text-align: center; }
.result-title { font-size: 16px; color: var(--muted); }
.result-score { font-size: 64px; font-weight: 900; color: var(--green-dark); line-height: 1.1; margin: 8px 0; }
.result-score .unit { font-size: 22px; margin-left: 4px; }
.result-sub { font-size: 16px; font-weight: 700; color: var(--yellow); min-height: 1.6em; }
.result-detail { color: var(--muted); font-size: 14px; margin: 10px 0 20px; }

/* ランキング・記録 */
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.section-head h2 { margin: 0; font-size: 18px; }
.ranking { list-style: none; padding: 0; margin: 12px 0 0; }
.ranking li { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.ranking li.me { background: var(--green-bg); border-radius: 10px; }
.ranking .rank { width: 32px; font-weight: 800; color: var(--green-dark); text-align: center; }
.ranking .rank.top { font-size: 20px; }
.ranking .nick { flex: 1; font-weight: 600; }
.ranking .total { font-weight: 800; }
.ranking .games { font-size: 12px; color: var(--muted); }

.history { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 10px; }
.history th, .history td { padding: 8px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.history th:first-child, .history td:first-child { text-align: left; }
.history th { font-weight: 600; color: var(--muted); font-size: 12px; }
.history td.total { font-weight: 800; color: var(--green-dark); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); z-index: 10;
}
.toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* hidden 属性を display 指定より優先させる */
[hidden] { display: none !important; }

/* 横並びボタンは小さい画面で折り返さないよう少し詰める */
.row .btn { padding: 14px 8px; font-size: 15px; white-space: nowrap; }

/* パスワード再設定まわり */
.form .forgot { align-self: center; color: var(--muted); font-size: 13px; }
.form .form-lead { margin: 0; font-size: 14px; color: var(--ink); }
.info { color: var(--green-dark); font-size: 14px; min-height: 1.4em; margin: 0; }
