:root {
  --bg: #f6f9fc;
  --surface: #ffffff;
  --surface-soft: #f9fbfd;
  --line: #e3ebf3;
  --text: #122033;
  --muted: #627086;
  --green: #12a05c;
  --green-dark: #078047;
  --blue: #1976f3;
  --cyan: #2aa6d9;
  --amber: #f59e0b;
  --red: #ef4444;
  --shadow: 0 10px 30px rgba(26, 43, 72, 0.08);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 212px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 28px 14px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px 34px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border: 3px solid var(--green);
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--green);
  font-size: 22px;
  font-weight: 900;
}

.brand strong {
  display: block;
  color: var(--green-dark);
  font-size: 22px;
  line-height: 1.1;
}

.brand span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.main-nav {
  display: grid;
  gap: 12px;
}

.nav-item {
  height: 50px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #48566c;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 0 18px;
  font-size: 18px;
  font-weight: 700;
  text-align: left;
}

.nav-item span {
  width: 24px;
  color: #75839a;
  font-weight: 900;
}

.nav-item.active {
  background: linear-gradient(135deg, #0aaa61, #078246);
  color: #fff;
  box-shadow: 0 10px 18px rgba(18, 160, 92, 0.22);
}

.nav-item.active span {
  color: #fff;
}

.study-note {
  margin-top: auto;
  text-align: center;
  color: var(--green-dark);
  padding-bottom: 12px;
}

.study-note p,
.study-note strong {
  margin: 0;
  display: block;
  font-size: 18px;
  line-height: 1.6;
}

.study-stack {
  position: relative;
  width: 120px;
  height: 84px;
  margin: 18px auto 0;
}

.study-stack span {
  position: absolute;
  left: 20px;
  width: 76px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid rgba(17, 130, 78, 0.22);
  background: #fff;
  box-shadow: 0 4px 10px rgba(26, 43, 72, 0.08);
}

.study-stack span:nth-child(1) {
  top: 16px;
  background: #9dd9f5;
  transform: rotate(-8deg);
}

.study-stack span:nth-child(2) {
  top: 34px;
  background: #ffe6a9;
  transform: rotate(3deg);
}

.study-stack span:nth-child(3) {
  top: 52px;
  background: #bde8ce;
  transform: rotate(-3deg);
}

.main {
  min-width: 0;
}

.topbar {
  min-height: 100px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 28px;
}

.topbar h1 {
  margin: 0 0 10px;
  font-size: 28px;
  letter-spacing: 0;
}

.topbar p {
  margin: 0;
  color: #314058;
}

.profile {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
}

.sync-status {
  min-height: 32px;
  border: 1px solid #cfe0ed;
  border-radius: 999px;
  padding: 0 12px;
  background: #f5f9fc;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.sync-status.syncing {
  color: var(--blue);
  border-color: #b9d7ff;
  background: #edf5ff;
}

.sync-status.synced {
  color: var(--green-dark);
  border-color: #bce5cf;
  background: #eefaf4;
}

.sync-status.error {
  color: var(--red);
  border-color: #ffd0d0;
  background: #fff3f3;
}

.avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #d8eeff;
  color: var(--green-dark);
  display: grid;
  place-items: center;
  font-weight: 900;
  border: 4px solid #b9ddf7;
}

.view {
  display: none;
  padding: 12px 14px 26px;
}

.view.active {
  display: block;
}

.summary-panel,
.panel,
.records-list,
.reward-timeline {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-width: 100%;
}

.summary-panel,
.panel {
  padding: 20px;
  min-width: 0;
  overflow: hidden;
}

.section-title-row,
.section-page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

h2,
h3,
p {
  letter-spacing: 0;
}

.section-title-row h2,
.section-page-title h2,
.panel h2 {
  margin: 0;
  font-size: 20px;
}

.section-page-title {
  margin: 6px 0 16px;
}

.section-page-title p {
  margin: 7px 0 0;
  color: var(--muted);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

#latest-meta {
  color: #44536a;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin-top: 26px;
}

.metric {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 28px;
  min-height: 96px;
  border-left: 1px solid var(--line);
}

.metric:first-child {
  border-left: 0;
}

.metric p {
  margin: 0 0 7px;
  color: var(--muted);
}

.metric strong {
  display: block;
  font-size: 36px;
  line-height: 1;
}

.metric small {
  display: block;
  margin-top: 12px;
  color: var(--muted);
}

.metric-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 900;
  border: 3px solid currentColor;
}

.blue {
  color: var(--blue);
}

.green {
  color: var(--green);
}

.amber {
  color: var(--amber);
}

.cyan {
  color: var(--cyan);
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(360px, 2fr);
  gap: 12px;
  margin-top: 12px;
}

.two-column > *,
.trend-grid > * {
  min-width: 0;
}

.lower {
  align-items: stretch;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 14px;
  max-width: 100%;
  min-width: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th {
  background: var(--surface-soft);
  color: #516076;
  font-size: 14px;
  text-align: left;
  padding: 12px 10px;
}

td {
  padding: 13px 10px;
  border-top: 1px solid var(--line);
  font-weight: 650;
}

td small {
  color: var(--muted);
  font-weight: 500;
}

.up {
  color: var(--green);
}

.down {
  color: var(--red);
}

.flat {
  color: #8a96a8;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
  padding: 6px 0;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 800;
}

.primary-button {
  background: var(--green);
  color: #fff;
}

.secondary-button {
  background: #eef4fb;
  color: #2f3d52;
}

.danger-button {
  background: #fff1f1;
  color: var(--red);
  border-color: #ffd7d7;
}

.segmented {
  display: inline-flex;
  background: #eef4fb;
  border-radius: 999px;
  padding: 3px;
}

.segmented button {
  border: 0;
  min-width: 64px;
  height: 28px;
  padding: 0 14px;
  border-radius: 999px;
  color: #4f5d71;
  background: transparent;
}

.segmented button.active {
  background: var(--green);
  color: #fff;
  font-weight: 800;
}

canvas {
  width: 100%;
  max-width: 100%;
  margin-top: 14px;
}

.chart-tip {
  text-align: center;
  color: #5b6880;
  margin: 8px 0 0;
}

.reflection-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 20px;
}

.reflection-grid article {
  min-height: 158px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.reflection-grid h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.reflection-grid p {
  margin: 0;
  color: #3e4d63;
  line-height: 1.75;
}

.green-text {
  color: var(--green);
}

.amber-text {
  color: var(--amber);
}

.blue-text {
  color: var(--blue);
}

.reward-list {
  display: grid;
  gap: 6px;
  margin-top: 16px;
}

.reward-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  border-top: 1px solid var(--line);
}

.reward-row:first-child {
  border-top: 0;
}

.reward-badge {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #eaf8f1;
  color: var(--green);
  font-weight: 900;
}

.reward-row strong {
  display: block;
  margin-bottom: 4px;
}

.reward-row small,
.reward-row time {
  color: var(--muted);
}

.records-list {
  padding: 4px 18px;
}

.record-card {
  display: grid;
  grid-template-columns: minmax(180px, 1.3fr) repeat(4, minmax(120px, 1fr)) auto;
  gap: 16px;
  align-items: center;
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.record-card:first-child {
  border-top: 0;
}

.record-card h3 {
  margin: 0 0 6px;
}

.record-card p {
  margin: 0;
  color: var(--muted);
}

.record-stat span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.record-stat strong {
  font-size: 21px;
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.span-two {
  grid-column: 1 / -1;
}

.analysis-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.analysis-panel {
  min-height: 120px;
}

.analysis-pill {
  border-radius: 999px;
  background: #eef8f3;
  color: #146c42;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 14px;
}

.reward-timeline {
  padding: 0 22px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  gap: 22px;
  padding: 22px 0;
  border-top: 1px solid var(--line);
  align-items: center;
}

.timeline-item:first-child {
  border-top: 0;
}

.timeline-item time {
  color: var(--muted);
}

.timeline-item h3 {
  margin: 0 0 6px;
}

.timeline-item p {
  margin: 0;
  color: var(--muted);
}

dialog {
  width: min(920px, calc(100vw - 28px));
  border: 0;
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 30px 80px rgba(18, 32, 51, 0.28);
}

dialog::backdrop {
  background: rgba(18, 32, 51, 0.45);
}

.exam-form {
  padding: 24px;
  max-height: min(86vh, 880px);
  overflow: auto;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.dialog-head h2 {
  margin: 0 0 6px;
}

.dialog-head p {
  margin: 0;
  color: var(--muted);
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #eef4fb;
  font-size: 24px;
  color: #4b5a70;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #46556c;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #d9e4ef;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 104px;
  padding: 11px 12px;
  resize: vertical;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(25, 118, 243, 0.12);
}

.exam-form h3 {
  margin: 22px 0 12px;
}

.subject-inputs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.subject-score-input {
  display: grid;
  grid-template-columns: minmax(100px, 1fr) 100px 100px;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.subject-score-input span {
  font-weight: 800;
}

.subject-score-input small {
  color: var(--muted);
}

.subject-score-input label {
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.subject-score-input input {
  min-width: 0;
}

.subject-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}

.subject-form-head h3 {
  margin: 0;
}

.subject-form {
  padding: 24px;
  max-height: min(86vh, 820px);
  overflow: auto;
}

.grade-setting-select {
  max-width: 320px;
}

.subject-setting-list {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.subject-setting-row {
  display: grid;
  grid-template-columns: 1fr 120px auto;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.subject-setting-row:first-child {
  border-top: 0;
}

.subject-setting-row strong {
  font-size: 16px;
}

.add-subject-row {
  display: grid;
  grid-template-columns: 1fr 140px auto;
  gap: 12px;
  align-items: end;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.subject-actions {
  grid-template-columns: 1fr 1fr auto auto;
}

#access-dialog {
  width: min(420px, calc(100vw - 28px));
}

.access-form {
  padding: 32px;
  display: grid;
  gap: 18px;
}

.access-form h2,
.access-form p {
  margin: 0;
  text-align: center;
}

.access-form p {
  color: var(--muted);
  line-height: 1.6;
}

.access-mark {
  width: 54px;
  height: 54px;
  margin: 0 auto;
  border: 3px solid var(--green);
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--green);
  font-size: 25px;
  font-weight: 900;
}

.access-form .form-error {
  min-height: 20px;
  color: var(--red);
  font-size: 14px;
}

.reflection-inputs {
  grid-template-columns: repeat(3, 1fr);
}

.dialog-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  margin-top: 22px;
}

.empty-state {
  padding: 34px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    padding-bottom: 14px;
  }

  .main-nav {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .nav-item {
    justify-content: center;
    padding: 0 8px;
    font-size: 15px;
  }

  .study-note {
    display: none;
  }

  .metric-grid,
  .two-column,
  .trend-grid,
  .reflection-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 18px 0;
  }

  .metric:first-child {
    border-top: 0;
  }

  .span-two {
    grid-column: auto;
  }
}

@media (max-width: 720px) {
  .topbar,
  .section-title-row,
  .section-page-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .profile {
    display: none;
  }

  .view {
    padding: 10px;
  }

  .main-nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid,
  .subject-inputs,
  .reflection-inputs {
    grid-template-columns: 1fr;
  }

  .page-actions {
    width: 100%;
  }

  .page-actions button {
    flex: 1;
  }

  .subject-score-input {
    grid-template-columns: 1fr 92px 92px;
  }

  .subject-setting-row,
  .add-subject-row {
    grid-template-columns: 1fr;
  }

  .record-card,
  .timeline-item {
    grid-template-columns: 1fr;
  }
}
