
:root {
  color-scheme: light dark;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #152033;
  --muted: #6d7787;
  --line: #dfe4ec;
  --accent: #1f6feb;
  --accent-soft: #eaf2ff;
  --danger: #c93737;
  --good: #18864b;
  --warn: #bb7710;
  --shadow: 0 8px 24px rgba(28, 43, 67, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101319;
    --card: #191e27;
    --text: #f4f7fb;
    --muted: #a8b0bc;
    --line: #303844;
    --accent: #6aa8ff;
    --accent-soft: #172a45;
    --danger: #ff7777;
    --good: #68d69a;
    --warn: #f0bd64;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

#app { min-height: 100%; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.title-wrap { min-width: 0; flex: 1; }
.page-title {
  font-size: 22px;
  line-height: 1.15;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-actions { display: flex; gap: 8px; }

.icon-btn, .primary-icon {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 25px;
  cursor: pointer;
}
.primary-icon {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}
.hidden { display: none !important; }

.main {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 16px 14px calc(28px + env(safe-area-inset-bottom));
}

.section {
  margin: 0 0 22px;
}
.section-title {
  margin: 0 4px 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 700;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.row {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  padding: 14px 16px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
}
.row:last-child { border-bottom: 0; }
.row.clickable { cursor: pointer; }
.row.clickable:active { background: var(--accent-soft); }
.row-main { min-width: 0; flex: 1; }
.row-title {
  font-size: 17px;
  font-weight: 650;
  overflow-wrap: anywhere;
}
.row-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}
.row-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.chevron { color: var(--muted); font-size: 24px; }

.empty {
  text-align: center;
  padding: 34px 20px;
  color: var(--muted);
}
.empty .emoji { font-size: 42px; margin-bottom: 8px; }

.action-card {
  padding: 14px;
  display: grid;
  gap: 10px;
}
.btn {
  min-height: 46px;
  border-radius: 13px;
  border: 1px solid var(--line);
  padding: 10px 14px;
  background: var(--card);
  color: var(--text);
  font-weight: 650;
  cursor: pointer;
}
.btn.primary {
  color: white;
  border-color: var(--accent);
  background: var(--accent);
}
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value {
  margin-top: 5px;
  font-size: 25px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.form-grid { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 650; }
.input, .select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
}
.inline-fields {
  display: grid;
  grid-template-columns: minmax(0,1fr) 100px;
  gap: 10px;
  align-items: end;
}
.weight-input { text-align: right; font-variant-numeric: tabular-nums; }

.grade-table {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
}
.grade-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) 86px;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.grade-row:last-child { border-bottom: 0; }
.grade-name { min-width: 0; font-weight: 600; }
.grade-input {
  width: 100%;
  min-height: 44px;
  text-align: center;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.note-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.small { font-size: 12px; color: var(--muted); }
.error { color: var(--danger); }
.good { color: var(--good); }
.warn { color: var(--warn); }

.modal {
  width: min(560px, calc(100% - 24px));
  border: 0;
  padding: 0;
  border-radius: 20px;
  background: transparent;
}
.modal::backdrop { background: rgba(0,0,0,.45); backdrop-filter: blur(2px); }
.modal-card {
  margin: 0;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.25);
}
.modal-head {
  padding: 14px 14px 8px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal-head h2 { flex: 1; margin: 0; font-size: 20px; }
.modal-body { padding: 10px 18px 18px; max-height: 65vh; overflow: auto; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 9px;
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  max-width: calc(100% - 28px);
  padding: 10px 14px;
  background: #222a;
  color: white;
  border-radius: 999px;
  font-size: 13px;
  transition: .18s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .main { padding-top: 24px; }
  .stats { grid-template-columns: repeat(4, minmax(0,1fr)); }
}

.app-locked{display:none!important}
.auth-gate{min-height:100vh;display:grid;place-items:center;padding:28px 18px;background:var(--bg)}
.auth-gate.hidden{display:none}
.auth-card{width:min(420px,100%);background:var(--card);color:var(--text);border:1px solid var(--line);border-radius:24px;padding:28px 24px;text-align:center;box-shadow:var(--shadow)}
.auth-icon{width:92px;height:92px;border-radius:22px;margin-bottom:12px}
.auth-card h1{margin:0;font-size:28px}
.auth-card p{color:var(--muted);margin:8px 0 22px}
.auth-btn{width:100%}
.auth-note{margin-top:14px;color:var(--muted);font-size:12px}
.logout-btn{min-height:38px;border-radius:11px;border:1px solid var(--line);background:var(--card);color:var(--text);padding:7px 10px;font-size:13px;font-weight:650;cursor:pointer}
