:root {
  --ink: #18191b;
  --muted: #65696f;
  --line: #d9dbdd;
  --surface: #f7f7f8;
  --paper: #ffffff;
  --accent: #e4002b;
  --accent-dark: #aa001f;
  --green: #00766a;
  --blue: #1d4f8f;
  --amber: #9a5a00;
  --shadow: 0 1px 0 rgba(24, 25, 27, 0.04);
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface);
  color: var(--ink);
  font-family: Arial, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-variant-numeric: tabular-nums;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

a {
  color: var(--blue);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.app-root {
  min-height: 100vh;
}

.gate-panel {
  max-width: 620px;
  margin: 9vh auto 0;
  padding: 36px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.gate-stamp,
.eyebrow,
.panel-tag {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
}

.gate-panel h1,
.topbar h1 {
  margin: 8px 0 6px;
  font-size: 2rem;
  line-height: 1.15;
  letter-spacing: 0;
}

.gate-panel p {
  color: var(--muted);
  line-height: 1.7;
}

.gate-form {
  margin-top: 28px;
}

.field-label,
.gate-form label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.84rem;
  font-weight: 700;
}

.gate-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.gate-row input {
  min-width: 0;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  padding: 9px 10px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(228, 0, 43, 0.12);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.primary-button,
.secondary-button,
.text-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 4px;
  min-height: 40px;
  padding: 9px 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper);
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.secondary-button,
.text-button {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
}

.secondary-button:hover,
.text-button:hover {
  border-color: var(--ink);
}

.text-button {
  min-height: 34px;
  padding: 6px 10px;
}

.icon-button {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}

.gate-error {
  min-height: 24px;
  color: var(--accent);
  font-weight: 700;
}

.dashboard {
  padding: 22px 24px 48px;
}

.topbar {
  max-width: 1440px;
  margin: 0 auto 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 16px;
}

.topbar h1 {
  margin-bottom: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.layout {
  max-width: 1440px;
  margin: 0 auto;
}

.summary-grid {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) repeat(3, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.summary-card,
.panel,
.phase-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.summary-card {
  min-height: 128px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.summary-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.summary-title {
  margin: 10px 0 6px;
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.35;
}

.summary-meta {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.metric {
  margin-top: 8px;
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.15;
}

.metric strong {
  font-size: 2.1rem;
}

.summary-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.bar {
  height: 6px;
  margin-top: 14px;
  overflow: hidden;
  background: #e7e8e9;
  border-radius: 3px;
}

.bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 160ms ease;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 16px;
  align-items: start;
}

.phase-stack,
.side-stack {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.phase-card {
  overflow: hidden;
  box-shadow: var(--shadow);
}

.phase-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.phase-head h2 {
  margin: 0 0 4px;
  font-size: 1.28rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.phase-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.phase-meta {
  text-align: right;
  flex: none;
}

.phase-score {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
}

.phase-mini {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.76rem;
}

.phase-head[data-phase="pre"] {
  border-left: 5px solid #d63a2f;
}

.phase-head[data-phase="semester"] {
  border-left: 5px solid var(--green);
}

.phase-head[data-phase="exam"] {
  border-left: 5px solid var(--blue);
}

.task-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.task-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.task-row:last-child {
  border-bottom: 0;
}

.task-row.is-done {
  background: #fbfbfb;
}

.task-check {
  width: 19px;
  height: 19px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.task-title {
  display: block;
  font-weight: 700;
  line-height: 1.4;
}

.task-row.is-done .task-title {
  color: var(--muted);
  text-decoration: line-through;
}

.task-detail {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.task-note {
  margin: 8px 0 0;
  padding-left: 10px;
  border-left: 2px solid var(--line);
  color: var(--ink);
  font-size: 0.84rem;
  line-height: 1.5;
}

.task-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 7px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.tag--priority {
  color: var(--accent);
  border-color: rgba(228, 0, 43, 0.34);
  background: rgba(228, 0, 43, 0.05);
}

.task-actions {
  display: flex;
  gap: 5px;
  opacity: 0;
  transition: opacity 120ms ease;
}

.task-row:hover .task-actions,
.task-actions:focus-within {
  opacity: 1;
}

.mini-button {
  min-height: 28px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper);
  color: var(--muted);
  font-size: 0.76rem;
}

.mini-button:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.panel {
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.routine-list,
.resource-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.routine-list {
  counter-reset: routine;
}

.routine-list li {
  position: relative;
  padding: 0 0 10px 30px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
  border-bottom: 1px dashed var(--line);
}

.routine-list li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.routine-list li::before {
  counter-increment: routine;
  content: counter(routine, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.78rem;
}

.resource-category {
  border-bottom: 1px solid var(--line);
  padding: 2px 0 12px;
}

.resource-category:first-child {
  padding-top: 0;
}

.resource-category:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.resource-category-title {
  margin: 0 0 4px;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 700;
}

.resource-entry {
  border-top: 1px dashed var(--line);
}

.resource-entry summary {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 10px 24px 10px 0;
  cursor: pointer;
  list-style: none;
}

.resource-entry summary::-webkit-details-marker {
  display: none;
}

.resource-entry summary::after {
  content: "展开";
  position: absolute;
  top: 12px;
  right: 0;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
}

.resource-entry[open] summary::after {
  content: "收起";
}

.resource-entry-title {
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.4;
}

.resource-entry-summary {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.resource-entry-body {
  margin: 0 0 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}

.resource-entry-body p {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 0.84rem;
  line-height: 1.6;
}

.resource-link-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.resource-link-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 10px;
  align-items: baseline;
  padding: 4px 0;
  border-top: 1px solid var(--line);
}

.resource-link-item a {
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
}

.resource-link-item a:hover {
  text-decoration: underline;
}

.resource-link-item span {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.review-method {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -2px 0 14px;
}

.review-method span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.journal-panel textarea,
.journal-panel input {
  margin-bottom: 12px;
}

.journal-panel textarea {
  min-height: 44px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button-row .secondary-button {
  flex: 1 1 130px;
}

.footnote {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
}

.loading-panel {
  display: none;
  position: fixed;
  right: 20px;
  bottom: 18px;
  padding: 10px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.12);
  font-size: 0.88rem;
}

.loading-panel.is-visible {
  display: block;
}

.task-dialog {
  width: min(680px, calc(100vw - 24px));
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: var(--paper);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.task-dialog::backdrop {
  background: rgba(24, 25, 27, 0.42);
}

.review-dialog {
  width: min(760px, calc(100vw - 24px));
}

.review-dialog .dialog-head {
  margin-bottom: 0;
  padding: 20px 20px 0;
}

.task-form {
  padding: 20px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0;
}

.task-form .field-label {
  margin: 14px 0 7px;
}

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

.review-guide {
  max-height: min(68vh, 720px);
  overflow: auto;
  padding: 2px 20px 20px;
}

.review-steps {
  margin: 0;
  padding-left: 24px;
}

.review-steps li {
  margin-bottom: 16px;
  padding-left: 4px;
}

.review-steps strong,
.review-orid strong {
  color: var(--ink);
  font-size: 0.92rem;
}

.review-steps p,
.review-orid p,
.review-timebox p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.65;
}

.review-orid,
.review-timebox {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.review-orid h3,
.review-timebox h3 {
  margin: 0 0 6px;
  font-size: 0.94rem;
  letter-spacing: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 16px;
  background: var(--ink);
  border-radius: 4px;
  color: var(--paper);
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-card--wide {
    grid-column: span 2;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 720px) {
  .dashboard {
    padding: 14px 12px 40px;
  }

  .gate-panel {
    margin-top: 28px;
    padding: 22px 18px;
  }

  .gate-panel h1,
  .topbar h1 {
    font-size: 1.45rem;
  }

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

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .summary-card--wide {
    grid-column: auto;
  }

  .side-stack {
    grid-template-columns: 1fr;
  }

  .phase-head {
    flex-direction: column;
  }

  .phase-meta {
    text-align: left;
  }

  .task-row {
    grid-template-columns: 26px minmax(0, 1fr);
  }

  .task-actions {
    grid-column: 2;
    opacity: 1;
  }

  .task-form .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
