:root {
  --mint-25: #f6fff8;
  --mint-50: #effcf3;
  --mint-100: #dff5e5;
  --mint-200: #bfe8cd;
  --mint-500: #36a96a;
  --mint-650: #167846;
  --ink: #173324;
  --muted: #60776a;
  --line: #cfe2d5;
  --paper: #ffffff;
  --warn: #f4a62a;
  --bad: #d94f45;
  --shadow: 0 18px 45px rgba(33, 89, 57, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.85), transparent 24rem),
    linear-gradient(135deg, var(--mint-25), var(--mint-100));
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(480px, 100%);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--mint-500);
  font-size: 28px;
  font-weight: 800;
}

.brand h1,
.page-title h1 {
  margin: 0;
  line-height: 1.12;
  letter-spacing: 0;
}

.brand p,
.page-title p,
.hint,
.muted {
  color: var(--muted);
}

.brand p,
.page-title p {
  margin: 6px 0 0;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  font-weight: 700;
  font-size: 14px;
}

.field input,
.field select,
.small-input {
  width: 100%;
  min-height: 42px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.field input:focus,
.field select:focus,
.small-input:focus {
  border-color: var(--mint-500);
  box-shadow: 0 0 0 3px rgba(54, 169, 106, 0.16);
}

.primary,
.secondary,
.icon-btn,
.tab-btn,
.print-chip {
  min-height: 40px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 800;
}

.primary {
  color: #fff;
  background: var(--mint-650);
}

.secondary,
.icon-btn,
.tab-btn,
.print-chip {
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}

.primary:disabled,
.secondary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 2;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
  background: var(--mint-650);
  flex: 0 0 auto;
}

.user-text {
  min-width: 0;
}

.user-text strong,
.user-text span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tab-btn.active {
  background: var(--mint-650);
  border-color: var(--mint-650);
  color: #fff;
}

.tab-btn:disabled { cursor: default; opacity: 0.55; }

.review-page {
  max-width: 760px;
  margin: 5vh auto 0;
  padding: 32px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.review-label { color: var(--bad); font-weight: 800; }
.review-page h1 { margin: 10px 0 24px; font-size: 28px; }
.review-equation { font-size: clamp(32px, 5vw, 56px); font-weight: 800; }
.review-equation strong { color: var(--mint-650); }
.review-given { color: var(--muted); font-size: 18px; }
.review-steps { margin: 28px 0; padding: 20px; background: var(--mint-50); border-left: 4px solid var(--mint-500); }
.review-steps h2 { margin: 0 0 8px; font-size: 18px; }
.review-steps p { margin: 0; line-height: 1.7; font-size: 18px; }

.content {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px;
  flex: 1;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.stats-row,
.controls-grid,
.practice-layout,
.leader-grid,
.trophy-grid {
  display: grid;
  gap: 14px;
}

.stats-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat,
.panel,
.problem-card,
.rank-card,
.trophy-card {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(33, 89, 57, 0.08);
}

.stat {
  padding: 16px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
}

.checkin-band {
  margin: 14px 0;
  padding: 16px 20px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.checkin-summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.checkin-summary h2 { margin: 0; font-size: 18px; }
.checkin-summary p { margin: 4px 0 0; color: var(--muted); }
.checkin-summary > strong { color: var(--mint-650); white-space: nowrap; }
.checkin-track { height: 8px; margin: 14px 0; border-radius: 4px; background: var(--mint-100); overflow: hidden; }
.checkin-track span { display: block; height: 100%; background: var(--mint-500); }
.checkin-days { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.checkin-day { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); }
.checkin-day.complete { color: var(--mint-650); background: var(--mint-50); border-color: var(--mint-200); }
.checkin-day strong { font-size: 20px; line-height: 1; }

.reward-overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px; background: rgba(16, 39, 25, 0.5); }
.reward-dialog { width: min(440px, 100%); padding: 32px; text-align: center; background: #fff; border-radius: 8px; box-shadow: var(--shadow); }
.reward-symbol { color: #d29315; font-size: 48px; }
.reward-dialog h2 { margin: 8px 0; font-size: 24px; }
.reward-dialog p { margin: 0 0 24px; font-size: 18px; }

.controls-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 14px;
}

.panel {
  padding: 16px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.practice-layout {
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, 0.7fr);
  align-items: start;
}

.problem-card {
  min-height: 360px;
  padding: 26px;
  display: grid;
  gap: 20px;
  align-content: center;
  justify-items: center;
  text-align: center;
}

.problem-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
}

.problem {
  width: 100%;
  min-height: 92px;
  display: grid;
  place-items: center;
  font-size: clamp(42px, 7vw, 76px);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.1;
}

.answer-row {
  display: grid;
  grid-template-columns: minmax(160px, 260px) auto;
  gap: 10px;
  width: min(420px, 100%);
}

.answer-row input {
  text-align: center;
  font-size: 28px;
  font-weight: 900;
}

.feedback {
  min-height: 26px;
  font-weight: 900;
}

.feedback.ok {
  color: var(--mint-650);
}

.feedback.bad {
  color: var(--bad);
}

.queue {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow: auto;
  padding-right: 2px;
}

.queue-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 6px;
  background: var(--mint-50);
  border: 1px solid var(--line);
}

.queue-item.done {
  opacity: 0.65;
}

.mini-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--mint-500);
  font-weight: 900;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.print-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.print-chip.active {
  color: #fff;
  border-color: var(--mint-650);
  background: var(--mint-650);
}

.leader-grid,
.trophy-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.rank-card,
.trophy-card {
  padding: 16px;
}

.rank-card {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 12px;
  align-items: center;
}

.rank-no {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--mint-100);
  color: var(--mint-650);
  font-weight: 900;
}

.rank-card h3,
.trophy-card h3 {
  margin: 0 0 4px;
}

.rank-metrics {
  text-align: right;
  font-weight: 900;
}

.trophy-card {
  display: grid;
  gap: 12px;
}

.trophy-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.trophy-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff6df;
  color: #9b6500;
  border: 1px solid #f1d490;
  font-size: 24px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--mint-650);
  background: var(--mint-100);
  font-size: 13px;
  font-weight: 900;
}

.empty {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.68);
}

.history {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.hidden-print {
  display: none;
}

.print-preview {
  background: #fff;
  border: 1px solid var(--line);
  padding: 24px;
  color: #111;
}

.print-sheet h1 { margin: 0 0 12px; font-size: 22px; }
.print-sheet .meta { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 20px; }
.print-problems { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.print-problems div { min-height: 30px; border-bottom: 1px solid #444; break-inside: avoid; }

@media (max-width: 880px) {
  .topbar,
  .page-head {
    align-items: stretch;
    flex-direction: column;
    height: auto;
  }

  .topbar {
    padding: 14px;
  }

  .nav {
    justify-content: stretch;
  }

  .tab-btn {
    flex: 1;
  }

  .content {
    padding: 16px;
  }

  .stats-row,
  .controls-grid,
  .practice-layout,
  .leader-grid,
  .trophy-grid {
    grid-template-columns: 1fr;
  }

  .answer-row {
    grid-template-columns: 1fr;
  }

  .checkin-day { display: grid; justify-items: center; gap: 4px; padding: 8px 2px; font-size: 12px; }

  .review-page { padding: 20px; margin-top: 0; }

  .print-sheet .meta, .print-problems { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media print {
  body {
    background: #fff;
  }

  .shell,
  .login-wrap {
    display: none !important;
  }

  .print-preview { display: none; }

  .hidden-print {
    display: block;
    color: #000;
    padding: 20px;
  }

  .print-sheet h1 {
    margin: 0 0 8px;
    font-size: 22px;
  }

  .print-sheet .meta {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 14px;
    font-size: 13px;
  }

  .print-problems {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px 18px;
    font-size: 18px;
  }

  .print-problems div {
    break-inside: avoid;
    border-bottom: 1px solid #222;
    min-height: 30px;
  }
}
