:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-sub: #f0f3f7;
  --border: #d9e1ec;
  --text: #1b2430;
  --muted: #5c6878;
  --primary: #243b53;
  --primary-hover: #1b2e42;
  --accent: #1d5d9b;
  --accent-hover: #174b7d;
  --success: #1b7a46;
  --success-bg: #e7f6ed;
  --danger: #c0392b;
  --danger-bg: #fdecec;
  --warn: #b45309;
  --warn-bg: #fef5e7;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  line-height: 1.5;
  touch-action: manipulation;
}

.hidden { display: none !important; }
.tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-size: 0.9rem; margin: 2px 0 0; }
.muted-sm { color: var(--muted); font-size: 0.82rem; margin: 2px 0 0; }
.label-xs { color: var(--muted); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em; }

/* Auth pages */
.auth-shell { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px 20px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.auth-brand h1 { margin: 0; font-size: 1.25rem; }
.brand-mark { width: 48px; height: 48px; border-radius: 12px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1rem; flex-shrink: 0; }
.brand-mark-dark { background: #334e68; }
.seg-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-sub); padding: 4px; border-radius: 10px; margin-bottom: 16px; }
.seg-tab { border: none; background: transparent; padding: 10px 8px; border-radius: 8px; font-size: 0.9rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.84rem; font-weight: 600; color: var(--text); }
.field input, .field select, .field textarea { width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px; font-size: 0.95rem; font-family: inherit; background: #fff; color: var(--text); }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(29, 93, 155, 0.14); }
.form-hint { margin: 0; font-size: 0.8rem; color: var(--muted); }
.auth-footer { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); text-align: center; }
.link-subtle { color: var(--muted); font-size: 0.85rem; text-decoration: none; }
.link-subtle:hover { text-decoration: underline; }

/* Notices */
.notice { padding: 11px 14px; border-radius: 10px; font-size: 0.88rem; font-weight: 500; margin-bottom: 14px; }
.notice-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f5c2c0; }
.notice-success { background: var(--success-bg); color: var(--success); border: 1px solid #bde5cd; }
.notice-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f6d8a8; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; border-radius: 10px; padding: 11px 18px; font-size: 0.94rem; font-weight: 700; cursor: pointer; text-decoration: none; transition: background 0.12s ease, transform 0.06s ease; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-full { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 0.82rem; border-radius: 8px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-sub); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #f5c2c0; }
.btn-text { background: transparent; border: none; color: var(--muted); font-size: 0.88rem; font-weight: 600; padding: 6px 8px; cursor: pointer; }

/* App layout */
.app-root { min-height: 100dvh; padding-bottom: 76px; }
.teacher-root { padding-bottom: 32px; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 560px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topbar-wide { max-width: 980px; }
.topbar-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 0.98rem; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.badge-mini { background: var(--primary); color: #fff; font-size: 0.72rem; font-weight: 800; padding: 3px 7px; border-radius: 6px; }
.container { max-width: 560px; margin: 0 auto; padding: 14px 14px 20px; }
.container-wide { max-width: 980px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h2 { margin: 0; font-size: 1rem; }
.card h3 { margin: 0; font-size: 0.96rem; }
.card-warn { border-color: #f3c681; background: #fffdf8; }
.card-note { background: #f5f8fc; border-color: #c5d6ea; }
.note-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.note-tag { font-size: 0.74rem; font-weight: 700; color: var(--accent); background: #e3eef9; padding: 2px 8px; border-radius: 6px; }
.note-body { margin: 0; font-size: 0.9rem; white-space: pre-wrap; }
.card-assignment { border-left: 4px solid var(--primary); }
.assignment-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; background: var(--surface-sub); border-radius: 9px; }
.assignment-done { opacity: 0.65; background: #f0f7f3; }
.section-heading { font-size: 0.86rem; font-weight: 700; color: var(--muted); margin: 16px 4px 8px; letter-spacing: 0.04em; }
.card-head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }

/* Status & Goal */
.status-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.rank-name { font-size: 1.65rem; font-weight: 800; color: var(--primary); line-height: 1.2; }
.streak-box { text-align: right; }
.streak-val { font-size: 1.5rem; font-weight: 800; color: var(--accent); line-height: 1.2; }
.streak-val .unit { font-size: 0.85rem; font-weight: 600; margin-left: 2px; color: var(--muted); }
.rank-next { margin-top: 8px; padding: 8px 10px; background: var(--surface-sub); border-radius: 8px; font-size: 0.8rem; color: var(--muted); }
.goal-box { margin-top: 12px; }
.goal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; }
.goal-text { font-size: 0.82rem; font-weight: 700; color: var(--primary); }
.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.kpi-row-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .kpi-row-4 { grid-template-columns: repeat(4, 1fr); } }
.kpi-item { text-align: center; }
.kpi-val { font-size: 1.15rem; font-weight: 800; color: var(--text); }
.kpi-lbl { font-size: 0.74rem; color: var(--muted); margin-top: 2px; }

/* Mode selection */
.mode-card-accent { border-left: 4px solid var(--accent); }
.dan-selector { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; margin-top: 12px; }
.dan-btn { height: 40px; border: 1px solid var(--border); background: var(--surface-sub); border-radius: 8px; font-weight: 700; font-size: 0.95rem; color: var(--text); cursor: pointer; }
.dan-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.option-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { padding: 7px 13px; border: 1px solid var(--border); background: var(--surface-sub); border-radius: 999px; font-size: 0.84rem; font-weight: 600; color: var(--text); cursor: pointer; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.mode-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; padding-top: 10px; border-top: 1px solid #edf1f6; }
.best-hint { font-size: 0.8rem; color: var(--muted); }

/* Bottom Nav */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr; padding-bottom: env(safe-area-inset-bottom, 0); }
.bottom-nav-3 { grid-template-columns: repeat(3, 1fr); }
.nav-item { border: none; background: transparent; padding: 14px 8px; font-size: 0.92rem; font-weight: 700; color: var(--muted); cursor: pointer; border-top: 3px solid transparent; }
.nav-item.active { color: var(--primary); border-top-color: var(--primary); }

/* Play Screen */
.play-screen { position: fixed; inset: 0; height: 100dvh; background: var(--bg); display: flex; flex-direction: column; z-index: 50; max-width: 560px; margin: 0 auto; overflow: hidden; user-select: none; -webkit-user-select: none; }
.play-topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 6px; background: var(--surface); }
.play-meta { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 0.9rem; }
.play-mode-label { color: var(--muted); font-size: 0.82rem; }
.play-timer { font-weight: 800; font-size: 0.95rem; color: var(--primary); min-width: 60px; text-align: right; }
.play-subbar { background: var(--surface); padding: 0 14px 10px; border-bottom: 1px solid var(--border); }
.progress-track { height: 6px; background: var(--surface-sub); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.15s ease; }
.play-best-line { font-size: 0.76rem; color: var(--muted); margin-top: 5px; min-height: 1.1em; text-align: right; }
.play-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 10px 16px; min-height: 0; }
.play-feedback { font-size: 0.95rem; font-weight: 700; min-height: 1.5em; margin-bottom: 10px; }
.play-feedback.ok { color: var(--success); }
.play-feedback.ng { color: var(--danger); }
.play-question { font-size: clamp(2.1rem, 9.5vw, 3.2rem); font-weight: 800; color: var(--text); display: flex; align-items: center; justify-content: center; gap: 10px; letter-spacing: 0.02em; }
.answer-slot { display: inline-flex; align-items: center; justify-content: center; min-width: 2.3ch; height: 1.35em; padding: 0 10px; border-radius: 12px; background: var(--surface); border: 2.5px solid var(--primary); color: var(--primary); }
.answer-slot.empty { color: #b0bac9; }
.play-key-hint { margin-top: 14px; font-size: 0.78rem; color: var(--muted); }

/* Keypad */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0)); background: var(--surface); border-top: 1px solid var(--border); }
.key-btn { height: clamp(54px, 8.6dvh, 68px); border: 1px solid var(--border); border-radius: 12px; background: #f9fafc; color: var(--text); font-size: 1.55rem; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; touch-action: manipulation; }
.key-btn:active { background: #e2e8f0; transform: scale(0.97); }
.key-fn { background: var(--surface-sub); font-size: 1rem; color: var(--muted); }
.key-submit { background: var(--primary); border-color: var(--primary); color: #fff; font-size: 1.1rem; }
.key-submit:active { background: var(--primary-hover); }

/* Result Screen */
.result-mode { text-align: center; font-weight: 700; color: var(--muted); font-size: 0.9rem; }
.result-score-wrap { text-align: center; margin: 10px 0 6px; }
.result-score { font-size: 2.6rem; font-weight: 800; color: var(--primary); line-height: 1.15; }
.best-banners { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 8px; }
.best-pill { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 0.82rem; font-weight: 700; }
.best-pill-new { background: var(--success-bg); color: var(--success); }
.best-pill-diff { background: var(--surface-sub); color: var(--muted); }
.sub-h3 { font-size: 0.9rem; margin: 16px 0 8px; color: var(--text); }
.sub-h4 { font-size: 0.84rem; color: var(--muted); margin: 14px 0 6px; }
.result-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }

/* Settings & Push */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid #edf1f6; }
.setting-row:last-child { border-bottom: none; }
.setting-title { font-weight: 700; font-size: 0.92rem; }
.switch-chk { width: 22px; height: 22px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.input-compact { width: 110px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.94rem; text-align: right; background: #fff; color: var(--text); }
.push-box { margin-top: 12px; padding: 12px; background: var(--surface-sub); border-radius: 10px; }
.push-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }

/* Heatmap */
.mini-seg { display: inline-flex; background: var(--surface-sub); padding: 3px; border-radius: 8px; }
.mini-seg-btn { border: none; background: transparent; padding: 5px 10px; border-radius: 6px; font-size: 0.78rem; font-weight: 700; color: var(--muted); cursor: pointer; }
.mini-seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.heatmap-grid { display: grid; grid-template-columns: 20px repeat(9, 1fr); gap: 3px; margin-top: 10px; }
.hm-axis { display: flex; align-items: center; justify-content: center; font-size: 0.72rem; font-weight: 700; color: var(--muted); }
.hm-cell { aspect-ratio: 1 / 1; border: 1px solid rgba(0, 0, 0, 0.05); border-radius: 5px; display: flex; align-items: center; justify-content: center; font-size: 0.68rem; font-weight: 700; cursor: pointer; padding: 0; color: var(--text); }
.hm-cell.selected { outline: 2.5px solid var(--primary); outline-offset: 1px; z-index: 2; }
.hm-none { background: #edf1f6; color: #9aa5b1; }
.hm-lv4 { background: #c6ebd4; color: #124d2c; }
.hm-lv3 { background: #dff2c4; color: #2b5414; }
.hm-lv2 { background: #fde6a8; color: #7a4b00; }
.hm-lv1 { background: #f8c6c4; color: #7d1e1a; }
.heatmap-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; font-size: 0.74rem; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 4px; }
.legend-dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.hm-detail { margin-top: 10px; padding: 10px 12px; background: var(--surface-sub); border-radius: 8px; font-size: 0.84rem; color: var(--text); }

/* Lists & Badges */
.simple-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 11px; background: var(--surface-sub); border-radius: 8px; font-size: 0.86rem; }
.list-row-main { font-weight: 700; }
.list-row-sub { color: var(--muted); font-size: 0.8rem; text-align: right; }
.badge-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 8px; }
.badge-card { padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-sub); opacity: 0.55; }
.badge-card.unlocked { opacity: 1; background: #f4f9f6; border-color: #a9dbbe; }
.badge-name { font-weight: 700; font-size: 0.86rem; color: var(--text); }
.badge-desc { font-size: 0.75rem; color: var(--muted); margin-top: 3px; }
.badge-status { font-size: 0.7rem; font-weight: 700; margin-top: 5px; color: var(--success); }
.badge-inline-list { display: flex; flex-wrap: wrap; gap: 6px; }
.badge-pill { background: var(--success-bg); color: var(--success); border: 1px solid #bde5cd; padding: 5px 10px; border-radius: 8px; font-size: 0.82rem; font-weight: 700; }

/* Teacher Dashboard */
.toggle-wrap { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 600; cursor: pointer; }
.pill-count { display: inline-block; background: var(--warn); color: #fff; font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; margin-left: 6px; }
.pending-list, .student-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.pending-item, .student-item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.student-item { cursor: pointer; transition: border-color 0.12s ease; }
.student-item:hover, .student-item.active { border-color: var(--accent); background: #f8fbff; }
.student-stats-inline { display: flex; flex-wrap: wrap; gap: 10px; font-size: 0.82rem; color: var(--muted); }
.status-tag { font-size: 0.72rem; font-weight: 700; padding: 2px 7px; border-radius: 6px; margin-left: 6px; }
.status-approved { background: var(--success-bg); color: var(--success); }
.status-disabled { background: var(--danger-bg); color: var(--danger); }
.detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 10px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.teacher-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 760px) { .teacher-grid { grid-template-columns: 1.15fr 0.85fr; } }
.summary-toggle { cursor: pointer; font-weight: 700; font-size: 0.94rem; color: var(--primary); }
.notif-panel { margin-top: 12px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
@media (min-width: 680px) { .form-grid-2 { grid-template-columns: 1.6fr 0.8fr; } }
.form-inline-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.diff-up { color: var(--success); font-size: 0.76rem; font-weight: 700; }
.diff-down { color: var(--danger); font-size: 0.76rem; font-weight: 700; }
.diff-flat { color: var(--muted); font-size: 0.76rem; }
.weekly-strip { margin-top: 12px; padding: 10px 12px; background: var(--surface-sub); border-radius: 8px; font-size: 0.84rem; display: flex; flex-wrap: wrap; gap: 14px; }

/* Daily bar chart */
.daily-chart { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; align-items: end; height: 150px; padding-top: 22px; margin-top: 8px; }
.daily-col { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 4px; }
.daily-bar-wrap { width: 100%; flex: 1; display: flex; align-items: flex-end; justify-content: center; }
.daily-bar { width: 78%; min-height: 2px; background: var(--accent); border-radius: 4px 4px 0 0; }
.daily-bar.zero { background: #e2e8f0; height: 2px !important; }
.daily-val { font-size: 0.65rem; color: var(--muted); }
.daily-lbl { font-size: 0.65rem; color: var(--muted); }

/* Table */
.table-scroll { overflow-x: auto; margin-top: 8px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.data-table th, .data-table td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.data-table th { font-size: 0.76rem; color: var(--muted); background: var(--surface-sub); }
