:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --surface-soft: #f9f9fb;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.08);
  --soft-shadow: 0 8px 28px rgba(0, 0, 0, 0.06);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.12);
  --good: #248a3d;
  --good-soft: rgba(52, 199, 89, 0.14);
  --bad: #c9342f;
  --bad-soft: rgba(255, 59, 48, 0.12);
  --warn: #a86600;
  --warn-soft: rgba(255, 159, 10, 0.18);
  --purple: #6e5bd7;
  --radius: 24px;
  --radius-sm: 16px;
  --tap: 46px;
  --max: 1220px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101012;
  --surface: rgba(30, 30, 34, 0.78);
  --surface-solid: #1d1d21;
  --surface-soft: #26262b;
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --line: rgba(255, 255, 255, 0.1);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
  --soft-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  --accent-soft: rgba(10, 132, 255, 0.18);
  --good-soft: rgba(52, 199, 89, 0.18);
  --bad-soft: rgba(255, 69, 58, 0.17);
  --warn-soft: rgba(255, 159, 10, 0.2);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 18% -10%, rgba(10, 132, 255, 0.12), transparent 30%),
    radial-gradient(circle at 92% 0%, rgba(110, 91, 215, 0.11), transparent 28%),
    var(--bg);
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 72px;
  padding: max(12px, env(safe-area-inset-top)) clamp(16px, 3vw, 32px) 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(22px) saturate(1.25);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(145deg, #111827, #3b4350);
  color: #fff;
  font-size: 13px;
  font-weight: 760;
  box-shadow: var(--soft-shadow);
}

:root[data-theme="dark"] .brand-mark {
  background: linear-gradient(145deg, #f5f5f7, #aeb4c1);
  color: #111;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.1;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  margin: 0 auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-solid) 58%, transparent);
  overflow-x: auto;
  scrollbar-width: none;
}

.nav::-webkit-scrollbar {
  display: none;
}

.nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.nav a.active {
  color: var(--text);
  background: var(--surface-solid);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08);
}

.icon-button,
.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: var(--tap);
  border: 0;
  border-radius: 999px;
  padding: 0 18px;
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.icon-button:active,
.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.danger-button:active,
.option-button:active {
  transform: scale(0.98);
}

.icon-button {
  width: var(--tap);
  padding: 0;
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: var(--soft-shadow);
}

.primary-button {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(10, 132, 255, 0.25);
}

.secondary-button {
  background: var(--surface-solid);
  color: var(--text);
  border: 1px solid var(--line);
}

.ghost-button {
  background: transparent;
  color: var(--accent);
}

.danger-button {
  background: var(--bad-soft);
  color: var(--bad);
}

.app {
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 64px;
}

.page {
  display: grid;
  gap: 24px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.55fr);
  gap: 24px;
  align-items: stretch;
}

.panel,
.metric-card,
.question-panel,
.control-panel,
.result-panel,
.loading-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.08);
}

.panel,
.question-panel,
.control-panel,
.result-panel,
.loading-panel {
  padding: clamp(20px, 3vw, 32px);
  transform-origin: 50% 18px;
}

.loading-panel {
  max-width: 720px;
  margin: 10vh auto;
  text-align: center;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 14px;
  font-size: clamp(34px, 5vw, 68px);
  line-height: 1.03;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 16px;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.12;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 10px;
  font-size: 20px;
}

.lead {
  color: var(--muted);
  font-size: clamp(16px, 2vw, 20px);
  line-height: 1.6;
}

.subtle {
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.metrics {
  grid-template-columns: repeat(6, minmax(140px, 1fr));
}

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

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric-card {
  min-height: 132px;
  padding: 18px;
}

.metric-card .value {
  margin: 10px 0 6px;
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 780;
  line-height: 1;
}

.metric-card .label {
  color: var(--muted);
  font-size: 14px;
}

.progress-list {
  display: grid;
  gap: 14px;
}

.chapter-row {
  display: grid;
  grid-template-columns: 150px minmax(120px, 1fr) 58px;
  gap: 14px;
  align-items: center;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 14%, transparent);
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--purple));
}

.task-list,
.plain-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.task-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

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

.task-title {
  font-weight: 760;
}

.pill,
.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tag.good {
  background: var(--good-soft);
  color: var(--good);
}

.tag.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.tag.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.tag.accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.tag.final {
  background: color-mix(in srgb, var(--good) 18%, transparent);
  color: var(--good);
}

.tag.command {
  background: color-mix(in srgb, var(--purple) 16%, transparent);
  color: var(--purple);
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
  align-items: end;
}

.control {
  display: grid;
  gap: 8px;
}

.control label,
.check-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select,
input[type="number"],
textarea {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 14px;
  background: var(--surface-solid);
  color: var(--text);
}

textarea {
  min-height: 110px;
  padding: 14px;
  resize: vertical;
}

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

.check-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-solid);
}

.check-chip input {
  width: 18px;
  height: 18px;
}

.question-panel {
  display: grid;
  gap: 18px;
}

.question-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.question-title {
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1.25;
  margin: 0;
}

.options {
  display: grid;
  gap: 12px;
}

.option-button {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: var(--surface-solid);
  color: var(--text);
  text-align: left;
  touch-action: manipulation;
}

.option-key {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 800;
}

.option-button.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.option-button.correct {
  border-color: color-mix(in srgb, var(--good) 42%, transparent);
  background: var(--good-soft);
}

.option-button.wrong {
  border-color: color-mix(in srgb, var(--bad) 45%, transparent);
  background: var(--bad-soft);
}

.feedback {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 18px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  overflow: hidden;
  animation: feedbackIn 0.24s ease both;
}

.feedback.correct {
  background: var(--good-soft);
}

.feedback.wrong {
  background: var(--bad-soft);
}

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

.details {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

details summary {
  min-height: 38px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

pre.source-json {
  max-height: 260px;
  overflow: auto;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface-soft);
  white-space: pre-wrap;
  word-break: break-word;
}

.command-block {
  overflow: auto;
  margin: 8px 0 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-solid) 72%, var(--surface-soft));
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.answer-steps {
  line-height: 1.75;
  white-space: pre-wrap;
}

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

.settings-metrics .metric-card {
  min-height: 104px;
}

.score-point {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.score-point:last-child {
  border-bottom: 0;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-soft);
}

.segmented button {
  min-height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  color: var(--text);
  background: var(--surface-solid);
  box-shadow: var(--soft-shadow);
}

.table-like {
  display: grid;
  gap: 10px;
}

.row-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 68px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

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

.empty {
  padding: 32px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 99;
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 32px));
  padding: 13px 18px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
  color: var(--text);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.penguin-pop {
  position: fixed;
  right: clamp(18px, 4vw, 42px);
  bottom: clamp(18px, 5vw, 46px);
  z-index: 110;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(360px, calc(100% - 32px));
  padding: 12px 16px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-solid) 92%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.2);
  animation: penguinToast 2.3s ease both;
}

.penguin {
  position: relative;
  width: 54px;
  height: 62px;
  flex: 0 0 auto;
  border-radius: 48% 48% 44% 44%;
  background: #20242b;
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.16);
  animation: penguinBounce 0.72s ease-in-out 2;
}

.penguin-belly {
  position: absolute;
  left: 11px;
  top: 20px;
  width: 32px;
  height: 34px;
  border-radius: 50% 50% 45% 45%;
  background: #ffffff;
}

.penguin-eye {
  position: absolute;
  top: 16px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ffffff;
}

.penguin-eye.left { left: 19px; }
.penguin-eye.right { right: 19px; }

.penguin-beak {
  position: absolute;
  left: 23px;
  top: 23px;
  width: 9px;
  height: 7px;
  border-radius: 60% 60% 70% 70%;
  background: #ffb340;
}

.penguin-wing {
  position: absolute;
  top: 28px;
  width: 14px;
  height: 26px;
  border-radius: 999px;
  background: #20242b;
  transform-origin: top center;
}

.penguin-wing.left {
  left: -6px;
  transform: rotate(28deg);
  animation: wingLeft 0.48s ease-in-out 3;
}

.penguin-wing.right {
  right: -6px;
  transform: rotate(-28deg);
  animation: wingRight 0.48s ease-in-out 3;
}

.penguin-foot {
  position: absolute;
  bottom: -3px;
  width: 16px;
  height: 7px;
  border-radius: 999px;
  background: #ffb340;
}

.penguin-foot.left { left: 10px; }
.penguin-foot.right { right: 10px; }

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .nav {
    order: 3;
    width: 100%;
    justify-content: flex-start;
  }

  .hero,
  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .grid.metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

@media (max-width: 720px) {
  .app {
    width: min(100% - 20px, var(--max));
    padding-top: 18px;
  }

  .brand small {
    display: none;
  }

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

  .metric-card {
    min-height: 112px;
  }

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

  .chapter-row,
  .row-card,
  .task-item,
  .score-point {
    grid-template-columns: 1fr;
  }

  .segmented {
    width: 100%;
  }

  .actions > * {
    flex: 1 1 160px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .page,
  .question-panel,
  .panel {
    animation: rise 0.32s cubic-bezier(.2, .7, .2, 1) both;
  }

  @keyframes rise {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes feedbackIn {
    from {
      opacity: 0;
      max-height: 0;
      transform: translateY(-4px);
    }
    to {
      opacity: 1;
      max-height: 420px;
      transform: translateY(0);
    }
  }

  @keyframes penguinToast {
    0% {
      opacity: 0;
      transform: translateY(18px) scale(.96);
    }
    12%,
    78% {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
    100% {
      opacity: 0;
      transform: translateY(10px) scale(.98);
    }
  }

  @keyframes penguinBounce {
    0%,
    100% { transform: translateY(0) rotate(0); }
    45% { transform: translateY(-6px) rotate(-2deg); }
    70% { transform: translateY(1px) rotate(2deg); }
  }

  @keyframes wingLeft {
    0%,
    100% { transform: rotate(28deg); }
    50% { transform: rotate(58deg); }
  }

  @keyframes wingRight {
    0%,
    100% { transform: rotate(-28deg); }
    50% { transform: rotate(-58deg); }
  }
}

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