:root {
  --bg: #070b16;
  --card: rgba(16, 22, 42, 0.92);
  --line: rgba(125, 211, 252, 0.2);
  --text: #e8eefc;
  --muted: #93a0c2;
  --cyan: #3ddcff;
  --gold: #ffb020;
  --ok: #3dff9a;
  --bad: #ff5c7a;
  --tab: #0c1222;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at top, #13203a, var(--bg) 55%);
  color: var(--text);
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(61, 220, 255, 0.2);
}
button:disabled { opacity: 0.4; pointer-events: none; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(14px + env(safe-area-inset-top)) 16px calc(88px + env(safe-area-inset-bottom));
}
#app[data-screen="school"] { max-width: 920px; }

.screen { display: none !important; }
.screen.active { display: block !important; }

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.eyebrow { margin: 0; color: var(--cyan); letter-spacing: 0.12em; font-size: 12px; }
.eyebrow.warn { color: var(--gold); }
.eyebrow.err { color: var(--bad); }
h1 { margin: 4px 0 0; font-size: 28px; }
h2 { margin: 0; font-size: 16px; }
.lead { color: var(--muted); line-height: 1.55; }
.muted, .intro { color: var(--muted); font-size: 13px; line-height: 1.55; }
.intro { margin: 0 0 12px; }
.error { color: var(--bad); font-size: 13px; }

.icon-btn, .primary, .ghost, .text-btn {
  border: 0;
  background: none;
}
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  font-size: 22px;
  line-height: 1;
}
.text-btn {
  color: var(--cyan);
  padding: 8px 4px;
  min-height: 40px;
  white-space: nowrap;
}
.primary, .ghost {
  width: 100%;
  border-radius: 16px;
  padding: 14px 16px;
  font-weight: 800;
  border: 1px solid transparent;
}
.primary { background: linear-gradient(180deg, #4ae6ff, #1aa8c8); color: #06212a; }
.ghost { background: transparent; border-color: var(--line); }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 12px; }

.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  min-height: 40px;
  font-weight: 700;
}
.seg button.on { background: rgba(61, 220, 255, 0.16); color: var(--cyan); }

.cal-nav {
  display: grid;
  grid-template-columns: 42px 1fr 42px auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
#cal-range { margin: 0; text-align: center; font-weight: 800; }

.cal-grid {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
}
.cal-grid.week { grid-template-columns: repeat(7, 1fr); }
.cal-grid.month { grid-template-columns: repeat(7, 1fr); }
.wd-row {
  display: contents;
}
.wd {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  padding: 0 0 4px;
}
.day {
  border: 1px solid transparent;
  background: rgba(255,255,255,0.03);
  border-radius: 12px;
  padding: 6px 0 5px;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text);
}
.cal-grid.month .day { min-height: 48px; border-radius: 10px; padding: 4px 0; }
.day .n { font-size: 16px; font-weight: 800; line-height: 1.2; }
.cal-grid.month .day .n { font-size: 14px; }
.day.off .n { color: var(--bad); }
.day.work .n { color: var(--gold); }
.day.selected.off .n, .day.selected.work .n { color: #06212a; }
.holi-tag {
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}
.day.off .holi-tag { color: var(--bad); }
.day.work .holi-tag { color: var(--gold); }
.day.selected .holi-tag { color: #06212a; }
.day .dots { display: flex; gap: 3px; height: 6px; }
.cal-legend {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin: 8px 0 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}
.cal-legend b.off { color: var(--bad); }
.cal-legend b.work { color: var(--gold); }
.day .dot { width: 5px; height: 5px; border-radius: 99px; background: var(--muted); }
.day .dot.tutor { background: var(--gold); }
.day .dot.exam, .cal-legend .dot.exam { background: #c084fc; }
.day .dot.event, .cal-legend .dot.event { background: #38bdf8; }
.day .dot.todo { background: var(--bad); }
.day .dot.done { background: var(--ok); }
.day.selected .dot { box-shadow: 0 0 0 1px #06212a; }
.cal-legend .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 99px;
  vertical-align: middle;
  margin: 0 4px 0 2px;
}
.day.today { border-color: var(--cyan); }
.day.selected { background: var(--cyan); color: #06212a; }
.day.selected .wd-mini, .day.selected .n { color: #06212a; }
.day.mute { opacity: 0.35; }
.day.empty { background: transparent; pointer-events: none; min-height: 28px; }
.wd-mini { font-size: 10px; color: var(--muted); }

.day-head {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 800;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 12px;
}
.panel-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.panel.folded .panel-h { margin-bottom: 0; }
.panel.folded #school-today { display: none; }
.fold-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  padding: 4px 0;
  min-height: 40px;
}
.fold-title { font-size: 16px; font-weight: 800; white-space: nowrap; }
.fold-sum {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.chev {
  margin-left: auto;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  transform: rotate(0deg);
  transition: transform 0.15s ease;
}
.panel:not(.folded) .chev { transform: rotate(90deg); }
.empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.item {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: flex-start;
  text-align: left;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.period {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  text-align: left;
}
.period:first-child, .item:first-child { border-top: 0; padding-top: 0; }
.item-main { min-width: 0; text-align: left; }
.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.period .title-row { flex: 1; }
.title {
  font-weight: 800;
  font-size: 16px;
  line-height: 1.35;
  text-align: left;
}
.period .title {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.when {
  margin-left: auto;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  text-align: right;
  white-space: nowrap;
}
.meta, .time {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
}
.sub {
  flex: 0 0 auto;
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
}
.check {
  width: 32px; height: 32px;
  margin-top: 2px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ok);
  font-size: 18px;
}
.check.on { background: rgba(61, 255, 154, 0.18); border-color: rgba(61, 255, 154, 0.45); }
.item.done .title { color: var(--muted); text-decoration: line-through; }
.item.skipped .title { color: var(--muted); text-decoration: line-through; }
.skip-tag {
  font-size: 11px;
  font-weight: 800;
  color: var(--gold);
  white-space: nowrap;
}
.skip-btn { font-size: 13px; padding: 4px 6px; min-height: 36px; }
.check:disabled,
.check.locked { opacity: 0.28; cursor: not-allowed; }
.item.exam-row {
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
}
.item.event-row {
  grid-template-columns: 36px 1fr auto auto;
  align-items: center;
}
.sub.kind-event { background: #38bdf8; color: #06212a; }
.sub.kind-sign { background: #fbbf24; color: #06212a; }
.sub.kind-bring { background: #34d399; color: #06212a; }
#btn-add-event { margin-bottom: 14px; }
.soon-h { margin: 12px 0 6px; color: var(--muted); font-size: 12px; }
.soon-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.soon-row span { color: var(--muted); white-space: nowrap; }
.score {
  font-weight: 800;
  font-size: 18px;
  color: var(--cyan);
  white-space: nowrap;
}
.xbtn {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 8px;
  min-width: 36px;
  min-height: 36px;
}
.use-wd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.use-wd .hint { color: var(--muted); font-size: 12px; width: 100%; }
.use-wd button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 6px 10px;
  min-height: 36px;
  font-weight: 700;
  font-size: 13px;
}
.use-wd button.on { background: var(--cyan); color: #06212a; border-color: transparent; }

.tabs {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(560px, 100%);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--tab) 28%);
}
.tabs button, .tabs a {
  border: 1px solid var(--line);
  background: #121a30;
  color: var(--muted);
  border-radius: 14px;
  padding: 12px 8px;
  font-weight: 800;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tabs button.on, .tabs a.on { color: #06212a; background: var(--cyan); border-color: transparent; }
.back { margin: -4px 0 8px; padding-left: 0; }

.lock {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(48px + env(safe-area-inset-top)) 22px 40px;
}
.lock h1 { font-size: 34px; }
.field { display: block; margin: 20px 0 12px; }
.field span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
input, select, textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #0d1426;
  color: var(--text);
}
input[type="date"],
input[type="time"] {
  display: block;
  -webkit-appearance: none;
  appearance: none;
}
textarea { min-height: 72px; resize: vertical; }

.table-wrap { overflow: visible; margin: 0; padding: 0 0 8px; }
.grid {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 3px;
}
.grid th, .grid td {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  text-align: center;
  font-size: 12px;
  vertical-align: middle;
}
.grid th { color: var(--muted); font-weight: 700; padding: 6px 2px; }
.grid th:first-child,
.grid td:first-child { width: 52px; }
.period-meta { padding: 2px !important; }
.p-edit {
  width: 100%;
  border: 0;
  background: none;
  color: inherit;
  padding: 4px 1px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-height: 44px;
}
.p-edit b {
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  word-break: break-all;
}
.p-edit small {
  color: var(--muted);
  font-size: 9px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.cell {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-weight: 800;
  padding: 6px 0;
  font-size: 13px;
}
.cell.has { color: #06212a; }

#app[data-screen="school"] {
  max-width: 920px;
  padding-left: 10px;
  padding-right: 10px;
}
#app[data-screen="school"] #cal-mode,
#app[data-screen="tutoring"] #cal-mode { display: none !important; }
#app[data-screen="school"] .intro { font-size: 12px; margin-bottom: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; min-width: 0; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
}
.chip.on { color: #06212a; border-color: transparent; background: var(--cyan); }

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet[hidden] { display: none !important; }
.sheet-card {
  width: min(520px, 100%);
  max-width: 100%;
  overflow: hidden;
  background: #121a30;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  box-sizing: border-box;
}
.sheet-card h2 { margin-bottom: 12px; }
#sheet-body { min-width: 0; overflow-x: hidden; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.form-grid { display: grid; gap: 10px; min-width: 0; }
.form-grid label { min-width: 0; max-width: 100%; }
.form-grid label span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }

.tutor-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.tutor-card p { margin: 0; font-weight: 800; }
.tutor-card small { display: block; margin-top: 4px; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #1c2744;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  z-index: 30;
  white-space: nowrap;
  font-size: 13px;
}
.toast[hidden] { display: none !important; }

#app[data-screen="school"] .tabs { width: min(920px, 100%); }
