:root {
  --bg: #f6f2e9;
  --surface: #fffdfa;
  --surface-strong: #ffffff;
  --ink: #1d2926;
  --muted: #68746f;
  --line: #e5ddd0;
  --teal: #1d756f;
  --teal-dark: #155955;
  --teal-soft: #dcefeb;
  --amber: #c9822b;
  --amber-soft: #f7e2c2;
  --green: #2f8d5b;
  --shadow: 0 18px 48px rgba(34, 45, 40, 0.1);
  --radius: 8px;
  --bottom-nav: 78px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(246, 242, 233, 0.78), rgba(246, 242, 233, 1)),
    repeating-linear-gradient(90deg, rgba(29, 117, 111, 0.04) 0 1px, transparent 1px 96px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 18px 16px calc(var(--bottom-nav) + 22px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: env(safe-area-inset-top) 0 16px;
}

.topbar h1,
.summary-copy h2,
.section-heading h2,
.detail-dialog h2,
.empty-state h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
  line-height: 1.15;
}

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

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  color: var(--teal-dark);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 24px rgba(34, 45, 40, 0.08);
}

.main-layout {
  display: grid;
  gap: 14px;
}

.summary-panel,
.tools-panel,
.content-panel {
  background: rgba(255, 253, 250, 0.92);
  border: 1px solid rgba(229, 221, 208, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.summary-panel {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  overflow: hidden;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(220, 239, 235, 0.95), rgba(255, 253, 250, 0.88) 48%, rgba(247, 226, 194, 0.58)),
    var(--surface);
}

.summary-copy {
  min-width: 0;
}

.summary-copy h2 {
  max-width: 14em;
  font-size: 22px;
  line-height: 1.25;
}

.summary-copy p {
  margin: 9px 0 0;
  max-width: 32em;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.pill,
.count-badge,
.level-badge,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill {
  margin-bottom: 10px;
  color: var(--teal-dark);
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(29, 117, 111, 0.16);
}

.summary-meter {
  display: grid;
  place-items: center;
  flex: 0 0 88px;
}

.meter-ring {
  --progress: 0%;
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--surface) 0 55%, transparent 56%),
    conic-gradient(var(--teal) var(--progress), rgba(29, 117, 111, 0.14) 0);
}

.meter-ring span {
  font-weight: 800;
  color: var(--teal-dark);
}

.tools-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 46px;
  padding: 0 12px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.search-field input {
  min-width: 0;
  width: 100%;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
}

.course-tabs,
.level-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.course-tabs::-webkit-scrollbar,
.level-tabs::-webkit-scrollbar {
  display: none;
}

.tab-button,
.chip,
.ghost-button,
.primary-button,
.secondary-button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.tab-button,
.chip {
  flex: 0 0 auto;
  padding: 8px 12px;
  color: var(--muted);
  background: var(--surface-strong);
}

.tab-button.is-active,
.chip.is-active {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal);
}

.content-panel {
  min-height: 340px;
  padding: 16px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-heading h2 {
  font-size: 20px;
}

.count-badge {
  color: var(--amber);
  background: var(--amber-soft);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 14px;
}

.ghost-button,
.secondary-button {
  color: var(--teal-dark);
  background: #fff;
}

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

.cards-list {
  display: grid;
  gap: 10px;
}

.knowledge-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  min-width: 0;
}

.card-title h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.card-title p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.star-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.star-button.is-active {
  color: #fff;
  background: var(--amber);
  border-color: var(--amber);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.level-badge {
  color: var(--teal-dark);
  background: var(--teal-soft);
}

.status-badge {
  color: var(--muted);
  background: #f5f1ea;
}

.status-badge.is-learning {
  color: var(--amber);
  background: var(--amber-soft);
}

.status-badge.is-done {
  color: var(--green);
  background: #dff1e6;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.card-actions button {
  min-height: 38px;
}

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

.empty-state h3 {
  color: var(--ink);
  font-size: 18px;
}

.course-progress {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.progress-row {
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.progress-row-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  font-size: 14px;
  font-weight: 700;
}

.progress-track {
  height: 9px;
  overflow: hidden;
  background: #ece5da;
  border-radius: 999px;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--green));
  border-radius: inherit;
}

.progress-small {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  min-height: var(--bottom-nav);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 250, 0.92);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.nav-item {
  display: grid;
  place-items: center;
  gap: 3px;
  min-width: 0;
  min-height: 54px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  font-size: 12px;
}

.nav-item svg {
  width: 19px;
  height: 19px;
}

.nav-item.is-active {
  color: var(--teal-dark);
  background: var(--teal-soft);
}

.detail-dialog {
  width: min(92vw, 560px);
  padding: 0;
  background: transparent;
  border: 0;
}

.detail-dialog::backdrop {
  background: rgba(24, 31, 29, 0.32);
  backdrop-filter: blur(5px);
}

.dialog-card {
  position: relative;
  display: grid;
  gap: 14px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.detail-dialog h2 {
  max-width: calc(100% - 48px);
  font-size: 22px;
  line-height: 1.35;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.detail-block {
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.detail-block h3 {
  margin: 0 0 7px;
  font-size: 14px;
}

.detail-block p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

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

[hidden] {
  display: none !important;
}

@media (hover: hover) {
  .tab-button:hover,
  .chip:hover,
  .ghost-button:hover,
  .secondary-button:hover,
  .icon-button:hover,
  .star-button:hover,
  .nav-item:hover {
    transform: translateY(-1px);
  }
}

@media (min-width: 760px) {
  .app-shell {
    padding: 26px 24px calc(var(--bottom-nav) + 26px);
  }

  .main-layout {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    align-items: start;
  }

  .summary-panel,
  .tools-panel {
    grid-column: 1;
  }

  .content-panel {
    grid-column: 2;
    grid-row: 1 / span 2;
    min-height: 680px;
  }

  .summary-panel {
    display: grid;
  }

  .summary-meter {
    justify-self: start;
  }

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

  .bottom-nav {
    right: auto;
    bottom: 18px;
    left: 24px;
    width: min(430px, calc(100% - 48px));
    margin: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
}

@media (min-width: 1080px) {
  .cards-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .calc-intro {
    grid-column: 1 / -1;
  }
}

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

/* Example Display */
.example-question {
  margin-bottom: 10px;
  padding: 10px;
  background: var(--amber-soft);
  border-radius: 4px;
  border-left: 3px solid var(--amber);
  font-size: 14px;
  line-height: 1.5;
}

.example-answer {
  padding: 10px;
  background: var(--teal-soft);
  border-radius: 4px;
  border-left: 3px solid var(--teal);
  font-size: 14px;
  line-height: 1.5;
}

/* Calculator Widget */
.calc-tools {
  display: grid;
  grid-column: 1 / -1;
  gap: 12px;
}

.calc-intro {
  padding: 14px;
  background: linear-gradient(135deg, var(--teal-soft), rgba(255, 253, 250, 0.96));
  border: 1px solid rgba(29, 117, 111, 0.18);
  border-radius: var(--radius);
}

.calc-intro h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.calc-intro p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.calc-widget {
  margin-top: 12px;
  padding: 16px;
  background: var(--teal-soft);
  border-radius: var(--radius);
  border: 1px solid var(--teal);
}

.calc-tool-card .calc-widget {
  margin-top: 0;
  background: #fff;
  border-color: var(--line);
}

.calc-title {
  margin: 0 0 4px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--teal-dark);
}

.calc-formula {
  margin: 0 0 12px 0;
  font-size: 13px;
  color: var(--muted);
  font-family: "SF Mono", Monaco, Consolas, monospace;
}

.calc-inputs {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.calc-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.calc-field label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.calc-field input {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 14px;
  background: var(--surface);
}

.calc-field input:focus {
  outline: 2px solid var(--teal);
  outline-offset: -1px;
}

.calc-btn {
  width: 100%;
  padding: 10px;
  background: var(--teal);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.calc-btn:hover {
  background: var(--teal-dark);
}

.calc-btn:active {
  transform: scale(0.98);
}

.calc-result {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface);
  border-radius: 4px;
  border: 1px solid var(--line);
}

.calc-result:empty {
  display: none;
}

.calc-result-item {
  padding: 4px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}

.calc-result-item:last-child {
  border-bottom: none;
}

.calc-label {
  color: var(--muted);
  font-weight: 500;
}

.calc-value {
  color: var(--ink);
  font-weight: 600;
  font-family: "SF Mono", Monaco, Consolas, monospace;
}

.calc-error {
  padding: 8px;
  background: #fee;
  color: #c33;
  border-radius: 4px;
  font-size: 13px;
}
