:root {
  color-scheme: light;
  --ink: #213142;
  --muted: #627083;
  --line: #d8e0e9;
  --panel: #ffffff;
  --band: #edf5f6;
  --blue: #2777d7;
  --teal: #129f8b;
  --gold: #d49a15;
  --rose: #d95757;
  --green: #3a995c;
  --shadow: 0 18px 52px rgba(31, 47, 70, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui,
    sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(237, 245, 246, 0.95), rgba(245, 241, 232, 0.8)),
    #f4f7f8;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 38px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease,
    background 0.15s ease;
}

button:hover {
  border-color: #aac0d4;
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

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

button.quiet {
  width: 100%;
  background: #f6f8fa;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.workspace {
  max-width: 1380px;
  margin: 0 auto;
}

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

.brand-title {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.school-logo {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #fff;
  object-fit: cover;
  box-shadow:
    0 10px 24px rgba(123, 30, 18, 0.18),
    0 0 0 1px rgba(214, 74, 0, 0.18);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 14px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.18;
  letter-spacing: 0;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(7, minmax(70px, 1fr));
  gap: 8px;
  min-width: min(100%, 790px);
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.75);
}

.tab {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}

.tab.active {
  background: #20364b;
  color: #fff;
}

.graph-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  align-items: stretch;
}

.graph-panel,
.control-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.graph-panel {
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #fbfdff;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  min-height: 54px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.control-panel {
  min-height: 690px;
  padding: 18px;
}

.activity {
  display: none;
}

.activity.active {
  display: block;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.section-title span {
  width: 5px;
  height: 28px;
  border-radius: 2px;
  background: var(--gold);
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.25;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
}

.field select,
.field input[type="number"],
.field input[type="text"] {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
}

.field input[type="text"] {
  font-variant-numeric: tabular-nums;
}

.number-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.button-row {
  display: flex;
  gap: 10px;
  margin: 10px 0 16px;
}

.button-row.wrap {
  flex-wrap: wrap;
}

.table-wrap {
  max-height: 252px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  height: 34px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

th {
  position: sticky;
  top: 0;
  background: #eaf3f4;
  color: #405064;
}

tr:last-child td {
  border-bottom: 0;
}

.range-field input {
  width: 100%;
  accent-color: var(--blue);
}

.tracker-readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 12px 0;
}

.parallel-readout {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.tracker-readout div,
.parallel-readout div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbfd;
}

.tracker-readout span,
.tracker-readout strong,
.parallel-readout span,
.parallel-readout strong {
  display: block;
}

.tracker-readout strong,
.parallel-readout strong {
  margin-top: 4px;
  color: var(--blue);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.parallel-readout strong {
  font-size: 19px;
  line-height: 1.25;
}

.record-list {
  display: grid;
  gap: 8px;
  max-height: 230px;
  overflow: auto;
  margin: 14px 0 0;
  padding-left: 26px;
  color: #405064;
  font-variant-numeric: tabular-nums;
}

.record-list li {
  padding: 7px 8px;
  border-radius: 6px;
  background: #f6f8fa;
}

.toggle-row {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.toggle-row label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.custom-function-toggles {
  display: grid;
  gap: 10px;
}

.custom-formula-box,
.view-range-box {
  margin: 10px 0 14px;
  border: 1px solid #d9e5e3;
  border-radius: 8px;
  padding: 12px;
  background: #f8fbfd;
}

.custom-formula-box .field,
.view-range-box .field {
  margin-bottom: 10px;
}

.custom-formula-box .button-row,
.view-range-box .button-row {
  margin: 0;
}

.shared-function-tool.is-hidden {
  display: none;
}

.math-keyboard {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 6px;
  margin: 6px 0 12px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f7;
}

.math-keyboard button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 6px;
  background: #fff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.math-keyboard .abs-key {
  font-family: "Times New Roman", "Cambria Math", serif;
  font-size: 18px;
}

.math-keyboard .danger {
  color: #b64040;
}

.math-keyboard .enter {
  border-color: #20aa78;
  background: #21bf84;
  color: #fff;
}

.keyboard-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.custom-function-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.custom-function-item {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.custom-function-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.custom-function-name {
  min-width: 0;
  color: var(--ink);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.custom-function-delete {
  min-height: 30px;
  padding: 0 9px;
  color: #b64040;
}

.view-range-box {
  margin-bottom: 0;
  background: #fffdf7;
}

.section-title.compact {
  margin-bottom: 10px;
}

.section-title.compact span {
  height: 22px;
}

.section-title.compact h2 {
  font-size: 17px;
}

.formula-status {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.formula-status.error {
  color: #b64040;
}

.formula-status.success {
  color: #2f7d52;
}

.k-preset,
.b-preset,
.perp-preset {
  min-width: 68px;
  padding: 0 10px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 980px) {
  .topbar,
  .graph-area {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .brand-title {
    align-items: center;
  }

  .graph-area {
    display: grid;
  }

  .control-panel {
    min-height: 0;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 14px;
  }

  h1 {
    font-size: 24px;
  }

  .school-logo {
    width: 48px;
    height: 48px;
  }

  .mode-tabs {
    grid-template-columns: 1fr 1fr;
  }

  .graph-panel,
  .control-panel {
    border-radius: 6px;
  }

  .button-row {
    flex-wrap: wrap;
  }

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

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