:root {
  --bg: #f2f5f4;
  --card: #ffffff;
  --line: #dfe6e3;
  --ink: #14261f;
  --muted: #6b7f77;
  --green: #1b7a4b;
  --green-d: #14603a;
  --green-l: #e6f3ec;
  --accent: #d98324;
  --danger: #c0392b;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 38, 31, .06), 0 8px 24px rgba(20, 38, 31, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 17px; line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--green); }

/* ---------- レイアウト ---------- */
.app { max-width: 1100px; margin: 0 auto; padding: 0 16px 120px; }

header.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(242,245,244,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  margin: 0 -16px 16px; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.topbar .brand { font-weight: 800; font-size: 18px; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.topbar .brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-l); }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card h2 { margin: 0 0 14px; font-size: 19px; }
.card h3 { margin: 22px 0 10px; font-size: 16px; color: var(--muted); font-weight: 700; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }

/* ---------- フォーム ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=date], input[type=number], input[type=password], select, textarea {
  width: 100%; padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff; outline: none; min-height: 48px;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-l); }
textarea { min-height: 92px; resize: vertical; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 12px; border: 1.5px solid var(--line);
  background: #fff; font-weight: 700; cursor: pointer; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f0cfca; }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: 14px; }
.btn.block { width: 100%; }

/* ---------- 生徒リスト ---------- */
.student-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.student {
  background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 16px; cursor: pointer; text-align: left; box-shadow: var(--shadow);
}
.student:active { border-color: var(--green); }
.student .nm { font-weight: 800; font-size: 18px; }
.student .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.student .score { margin-top: 10px; display: flex; align-items: baseline; gap: 6px; }
.student .score b { font-size: 26px; color: var(--green); }
.student .delta { font-size: 13px; font-weight: 700; }
.up { color: var(--green); } .down { color: var(--danger); } .flat { color: var(--muted); }

/* ---------- スコア入力（5段階タップ） ---------- */
.scoreitem { border-bottom: 1px dashed var(--line); padding: 14px 0; }
.scoreitem:last-child { border-bottom: none; }
.scoreitem .lbl { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 700; }
.scoreitem .cat { font-size: 11px; background: var(--green-l); color: var(--green-d); padding: 2px 8px; border-radius: 999px; font-weight: 800; }
.scoreitem .prev { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 600; }
.pills { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pill {
  min-height: 52px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff;
  font-weight: 800; font-size: 18px; cursor: pointer;
}
.pill[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff; }
.scale-hint { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }

/* ---------- サマリー ---------- */
.summary { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(280px, 1.1fr); gap: 20px; align-items: center; }
@media (max-width: 720px) { .summary { grid-template-columns: 1fr; } }
.bigscore { text-align: center; }
.bigscore .v { font-size: 64px; font-weight: 900; color: var(--green); line-height: 1; }
.bigscore .u { color: var(--muted); font-size: 14px; }
.legend { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--green-l); color: var(--green-d); font-size: 12px; font-weight: 700; }

/* ---------- カルテ履歴 ---------- */
.karte-row { display: flex; gap: 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.karte-row:last-child { border-bottom: none; }
.karte-row .d { font-weight: 800; min-width: 105px; }
.karte-row .t { flex: 1; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.karte-row .s { font-weight: 800; color: var(--green); min-width: 52px; text-align: right; }

/* ---------- その他 ---------- */
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px;
  font-weight: 700; z-index: 100; box-shadow: var(--shadow);
}
.sticky-save {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(255,255,255,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding: 12px 16px;
  display: flex; gap: 12px; justify-content: center;
}
.sticky-save .btn { flex: 1; max-width: 260px; }
.hidden { display: none !important; }
.center-wrap { max-width: 420px; margin: 8vh auto; }
table.metrics { width: 100%; border-collapse: collapse; font-size: 15px; }
table.metrics th, table.metrics td { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.metrics th { color: var(--muted); font-size: 13px; font-weight: 700; }
table.metrics td.n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.note { font-size: 13px; color: var(--muted); }
.textblock { white-space: pre-wrap; background: #fafbfa; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
