:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #65728a;
  --line: #dfe5ef;
  --panel: #fff;
  --blue: #2f6fed;
  --blue-soft: #e7f0ff;
  --red: #b42020;
  --red-soft: #ffecec;
  --shadow: 0 10px 28px rgba(31, 42, 61, .07);
}

* { box-sizing: border-box; }

html { background: #f5f7fb; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: #1f2a3d;
  background:
    radial-gradient(circle at 5% 0%, rgba(47, 111, 237, .09), transparent 28rem),
    #f5f7fb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.page {
  width: min(100%, 920px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 22px 108px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 24px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .12em;
}

.title {
  margin-top: 4px;
  color: var(--ink);
  font-size: clamp(28px, 6vw, 38px);
  font-weight: 800;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  color: #fff;
  background: #24324b;
  font-size: 24px;
}

.panel,
.axis-section {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.student-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 18px;
}

.field-label,
.detail-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
}

.field-input,
.score-input,
.record-textarea {
  width: 100%;
  border: 1px solid #d8dee9;
  border-radius: 9px;
  outline: 0;
  color: #1f2a3d;
  background: #f9fbfe;
  transition: border-color .15s, box-shadow .15s;
}

.field-input,
.score-input {
  height: 42px;
  padding: 0 12px;
}

.field-input:focus,
.score-input:focus,
.record-textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, .12);
}

.incentive-panel {
  margin-top: 16px;
  padding: 16px;
}

.incentive-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.incentive-row + .incentive-row { margin-top: 10px; }

.incentive-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  border: 1px solid #d8dee9;
  border-radius: 9px;
  color: #27364f;
  background: #f9fbfe;
  font-weight: 700;
}

.incentive-option.active {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-soft);
}

.option-dot {
  width: 11px;
  height: 11px;
  border: 2px solid #9aa5b8;
  border-radius: 50%;
}

.active .option-dot {
  border-color: var(--blue);
  background: var(--blue);
  box-shadow: inset 0 0 0 2px #fff;
}

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

.axis-section { padding: 20px 18px 18px; }

.axis-header,
.result-header,
.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.axis-title,
.result-title,
.record-title,
.history-title {
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
}

.axis-values {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-width: 220px;
}

.axis-total-row {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.axis-value {
  min-height: 32px;
  padding: 7px 8px;
  border-radius: 8px;
  color: var(--muted);
  background: #eef2f8;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.axis-value.positive.filled,
.axis-value.total.filled { color: var(--blue); background: var(--blue-soft); }
.axis-value.negative.filled,
.axis-value.negative-total.filled { color: var(--red); background: var(--red-soft); }
.value-label { margin-right: 4px; font-size: 11px; opacity: .78; }

.scale-wrap { margin-top: 24px; }

.scale-labels {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 800;
}

.scale-label-bad { color: #8b1010; }
.scale-label-mid { color: #217a3a; }
.scale-label-good { color: #c69214; }

.scale-track {
  position: relative;
  height: 72px;
  margin: 6px 18px 0;
  cursor: pointer;
  touch-action: manipulation;
}

.scale-track::before,
.scale-fill {
  position: absolute;
  top: 25px;
  left: 0;
  height: 7px;
  border-radius: 999px;
  content: "";
}

.scale-track::before { right: 0; background: #d8dee9; }
.scale-fill { background: linear-gradient(90deg, #d95555, #e7b94c, #2f9e6d); }

.tick {
  position: absolute;
  top: 17px;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}

.tick-line { width: 1px; height: 24px; margin: auto; background: #8f9bb0; }
.tick-text { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }

.pointer {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  transition: left .18s ease;
}

.pointer-head {
  width: 0;
  height: 0;
  margin: auto;
  border-top: 14px solid #24324b;
  border-right: 9px solid transparent;
  border-left: 9px solid transparent;
}

.pointer-text {
  display: block;
  margin-top: 3px;
  padding: 2px 6px;
  border-radius: 5px;
  color: #fff;
  background: #24324b;
  font-size: 11px;
}

.quick-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.quick-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 43px;
  border: 1px solid #d8dee9;
  border-radius: 9px;
  color: #27364f;
  background: #f9fbfe;
  font-weight: 800;
}

.quick-button:hover { border-color: var(--blue); background: var(--blue-soft); }

.mini-face {
  position: relative;
  width: 25px;
  height: 25px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.face-eye { position: absolute; top: 7px; width: 3px; height: 3px; border-radius: 50%; background: currentColor; }
.eye-left { left: 5px; }
.eye-right { right: 5px; }
.face-mouth { position: absolute; left: 6px; bottom: 4px; width: 10px; height: 5px; border: 2px solid currentColor; border-top: 0; border-radius: 0 0 10px 10px; }
.face-sad { color: #a93636; }
.face-sad .face-mouth { bottom: 3px; transform: rotate(180deg); }
.face-flat { color: #99771d; }
.face-flat .face-mouth { bottom: 6px; height: 0; border-width: 1px 0 0; border-radius: 0; }
.face-smile { color: #217a3a; }

.record-panel,
.result-panel,
.history-panel {
  margin-top: 16px;
  padding: 20px 18px;
}

.record-field { margin-top: 14px; }
.record-textarea { min-height: 82px; padding: 10px 12px; resize: vertical; }

.formula-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: 9px;
  background: #eef2f8;
}

.formula-tab {
  padding: 7px 15px;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.formula-tab.active { color: var(--blue); background: #fff; box-shadow: 0 2px 7px rgba(31,42,61,.12); }

.result-number {
  margin: 18px 0;
  padding: 22px 12px;
  border-radius: 11px;
  color: #8994a6;
  background: #eef2f8;
  font-size: clamp(28px, 8vw, 46px);
  font-weight: 900;
  text-align: center;
}

.result-number.ready { color: #fff; background: linear-gradient(135deg, #24324b, #2f6fed); }

.result-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.detail-multiplier-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.detail-value { padding: 8px; border-radius: 8px; font-weight: 800; text-align: center; }
.positive-text { color: var(--blue); background: var(--blue-soft); }
.negative-text { color: var(--red); background: var(--red-soft); }
.score-input { margin-top: 8px; }

.weight-row {
  display: grid;
  grid-template-columns: auto minmax(100px, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.weighted-score-row,
.single-total-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  gap: 16px;
  margin-top: 18px;
}

.single-total-row {
  align-items: center;
  padding: 13px;
  border-radius: 9px;
  background: #f3f6fb;
  font-weight: 800;
}

.single-total-row span:last-child { text-align: right; }
.score-output { text-align: right; }
.score-output span { font-size: 24px; font-weight: 900; }
.ready-score { color: var(--blue); }

.save-record-button {
  width: 100%;
  min-height: 44px;
  margin-top: 18px;
  border-radius: 9px;
  color: #fff;
  background: var(--blue);
  font-weight: 800;
}

.save-record-button.locked::before { content: "🔒 "; font-size: 12px; }

.history-tools { display: flex; gap: 8px; }
.history-count { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }

.manage-button {
  padding: 8px 13px;
  border: 1px solid #d8dee9;
  border-radius: 8px;
  color: #27364f;
  background: #f9fbfe;
  font-weight: 800;
}

.manage-button.active { color: var(--blue); border-color: var(--blue); background: var(--blue-soft); }
.export-button { color: #fff; border-color: var(--blue); background: var(--blue); }

.history-scroll { margin-top: 16px; overflow-x: auto; }
.history-table { min-width: 820px; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }

.history-row {
  display: grid;
  grid-template-columns: 80px 70px 110px 90px 90px 90px minmax(250px, 1fr);
  align-items: stretch;
  border-bottom: 1px solid var(--line);
}

.history-row.managed { grid-template-columns: 80px 70px 110px 90px 90px 90px minmax(250px, 1fr) 100px; }
.history-row:last-child { border-bottom: 0; }
.history-row > * { display: flex; align-items: center; padding: 10px 8px; border-right: 1px solid var(--line); font-size: 12px; }
.history-row > *:last-child { border-right: 0; }
.history-row-head { color: #fff; background: #24324b; font-weight: 800; }
.history-notes { display: grid !important; align-content: center; gap: 3px; }
.history-actions { display: flex; gap: 5px; }
.history-actions button { padding: 5px 7px; border-radius: 5px; color: var(--blue); background: var(--blue-soft); }
.history-actions .delete { color: var(--red); background: var(--red-soft); }
.history-empty { padding: 44px; color: var(--muted); text-align: center; }

.page-tabs {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(100%, 920px);
  margin: auto;
  padding: 8px 20px calc(8px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  background: rgba(255,255,255,.96);
  box-shadow: 0 -8px 24px rgba(31,42,61,.08);
  backdrop-filter: blur(10px);
}

.page-tab {
  height: 46px;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.page-tab.active { color: var(--blue); background: var(--blue-soft); }

.modal-mask {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(18, 27, 43, .72);
  backdrop-filter: blur(5px);
}

.wheel-panel {
  width: min(100%, 430px);
  padding: 24px 20px 20px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 28px 80px rgba(0,0,0,.3);
  text-align: center;
}

.wheel-title { color: var(--ink); font-size: 21px; font-weight: 900; }
.wheel-subtitle { min-height: 38px; margin: 7px auto 4px; color: var(--muted); font-size: 13px; line-height: 1.45; }

.wheel-stage { position: relative; width: 260px; height: 260px; margin: 8px auto; }

.wheel {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 8px solid #24324b;
  border-radius: 50%;
  box-shadow: 0 12px 25px rgba(31,42,61,.22);
  transition: transform .09s linear;
}

.wheel-slice {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 48px;
  margin-left: -24px;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
  transform-origin: 24px 0;
}

.wheel.special-wheel .wheel-slice { font-size: 9px; }

.wheel-center {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 86px;
  height: 86px;
  padding: 6px;
  border: 7px solid #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  background: #24324b;
  box-shadow: 0 4px 15px rgba(0,0,0,.25);
  font-size: 13px;
  font-weight: 900;
}

.wheel-marker {
  width: 0;
  height: 0;
  margin: -276px auto 246px;
  border-top: 24px solid #e23838;
  border-right: 14px solid transparent;
  border-left: 14px solid transparent;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.25));
}

.special-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  overflow: hidden;
}

.special-overlay::before { position: absolute; inset: 0; content: ""; background: rgba(12,18,29,.78); }
.special-overlay-text { position: relative; z-index: 1; padding: 12px 18px; border-radius: 10px; color: #fff; font-size: 25px; font-weight: 1000; }
.special-good { background: #c69214; }
.special-bad { background: #8b1010; }

.wheel-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.wheel-actions button { min-height: 44px; border-radius: 9px; font-weight: 800; }
.secondary-button { color: #27364f; background: #eef2f8; }
.primary-button { color: #fff; background: var(--blue); }

.toast {
  position: fixed;
  z-index: 100;
  top: 20px;
  left: 50%;
  max-width: calc(100% - 40px);
  padding: 10px 18px;
  border-radius: 999px;
  transform: translate(-50%, -120px);
  color: #fff;
  background: #24324b;
  box-shadow: 0 8px 24px rgba(31,42,61,.25);
  opacity: 0;
  transition: .2s ease;
  pointer-events: none;
}

.toast.show { transform: translate(-50%, 0); opacity: 1; }
.hidden { display: none !important; }

@media (min-width: 760px) {
  .axis-list { grid-template-columns: 1fr 1fr; align-items: start; }
  .record-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
  .record-title { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .page { padding: 16px 12px 100px; }
  .student-panel { grid-template-columns: 1fr; }
  .axis-header { display: block; }
  .axis-values { margin-top: 12px; min-width: 0; }
  .axis-section { padding-inline: 14px; }
  .result-detail { gap: 8px; }
  .weight-row { grid-template-columns: 1fr 1fr; }
  .weight-row input { grid-column: 1 / -1; grid-row: 2; }
  .weight-row span:last-child { text-align: right; }
  .wheel-stage { width: 240px; height: 240px; }
  .wheel-marker { margin-top: -256px; margin-bottom: 226px; }
}
