:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --panel: #ffffff;
  --ink: #17201f;
  --muted: #66726f;
  --line: #d9e3df;
  --brand: #1f766f;
  --brand-dark: #15524d;
  --brand-soft: #e4f2ef;
  --gold: #d49b38;
  --coral: #c95d4f;
  --viewer: #102326;
  --viewer-2: #173438;
  --shadow: 0 16px 42px rgba(20, 54, 54, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(31, 118, 111, 0.08), transparent 32%),
    linear-gradient(315deg, rgba(212, 155, 56, 0.12), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
p,
dl,
dd {
  margin: 0;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: minmax(390px, 52vh) auto;
}

.viewer-section {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 14px 12px;
  background:
    radial-gradient(circle at 20% 0%, rgba(70, 160, 151, 0.3), transparent 32%),
    linear-gradient(145deg, var(--viewer), var(--viewer-2));
  color: #ffffff;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.course-label {
  margin-bottom: 2px;
  color: #a8d9d3;
  font-size: 12px;
}

h1 {
  font-size: 22px;
  font-weight: 760;
  letter-spacing: 0;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: 24px;
  line-height: 1;
}

.viewer-wrap {
  position: relative;
  flex: 1;
  min-height: 270px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(transparent 31px, rgba(255, 255, 255, 0.04) 32px),
    linear-gradient(90deg, transparent 31px, rgba(255, 255, 255, 0.04) 32px),
    #132a2e;
  background-size: 32px 32px;
  box-shadow: var(--shadow);
  touch-action: none;
}

.crystal-viewer {
  width: 100%;
  height: 100%;
  min-height: 270px;
}

.viewer-status,
.element-legend {
  position: absolute;
  max-width: calc(100% - 24px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(12, 27, 30, 0.72);
  color: #eef6f4;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.viewer-status {
  left: 12px;
  bottom: 12px;
  padding: 7px 9px;
  font-size: 12px;
}

.element-legend {
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px;
  font-size: 12px;
}

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

.legend-swatch {
  width: 13px;
  height: 13px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
}

.element-legend.is-hidden {
  display: none;
}

.gesture-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  color: #d7e8e5;
  font-size: 12px;
  text-align: center;
}

.gesture-strip span {
  padding: 7px 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.control-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 14px max(20px, env(safe-area-inset-bottom));
}

.category-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.category-tab,
.structure-tab,
.tool-button,
.future-grid button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
}

.category-tab {
  padding: 10px 8px;
  text-align: left;
}

.category-tab strong,
.category-tab span {
  display: block;
}

.category-tab strong {
  font-size: 14px;
}

.category-tab span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.category-tab.is-active,
.structure-tab.is-active,
.tool-button.is-active {
  border-color: var(--brand);
  background: var(--brand);
  color: #ffffff;
}

.category-tab.is-active span {
  color: #d8f2ed;
}

.structure-tabs,
.toolbar {
  display: grid;
  gap: 8px;
}

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

.system-group {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.system-heading {
  grid-column: 1 / -1;
  margin-top: 4px;
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 760;
}

.structure-tab {
  padding: 8px 6px;
  font-size: 13px;
  font-weight: 680;
}

.concept-flow {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  padding: 14px;
  box-shadow: 0 8px 24px rgba(25, 71, 67, 0.08);
}

.flow-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.flow-heading h2 {
  font-size: 16px;
}

.flow-heading span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.flow-visual {
  display: grid;
  grid-template-columns: 1fr 18px 1fr 18px 1fr 18px 1fr 18px 1fr;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  padding-bottom: 2px;
}

.flow-node {
  position: relative;
  min-height: 72px;
  min-width: 92px;
  overflow: hidden;
  border: 1px solid #d9e3df;
  border-radius: 8px;
  background: #f8fbfa;
  opacity: 0.42;
  transition: opacity 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.flow-node span {
  position: absolute;
  left: 7px;
  bottom: 6px;
  z-index: 2;
  color: #173438;
  font-size: 12px;
  font-weight: 760;
}

.flow-node.is-active {
  border-color: var(--brand);
  opacity: 1;
  transform: translateY(-1px);
}

.flow-arrow {
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, var(--brand), var(--gold));
}

.flow-arrow::after {
  content: "";
  display: block;
  width: 8px;
  height: 8px;
  margin-left: auto;
  transform: translate(1px, -3px) rotate(45deg);
  border-top: 2px solid var(--gold);
  border-right: 2px solid var(--gold);
}

.flow-crystal::before {
  content: "";
  position: absolute;
  inset: 12px;
  background-image: radial-gradient(circle, #4f83d1 0 5px, transparent 6px);
  background-size: 18px 18px;
  transform: skew(-14deg);
}

.flow-points::before,
.flow-lattice::before {
  content: "";
  position: absolute;
  inset: 12px;
  background-image: radial-gradient(circle, #d95d50 0 4px, transparent 5px);
  background-size: 22px 22px;
}

.flow-lattice::after,
.flow-grid::before,
.flow-cell::before {
  content: "";
  position: absolute;
  inset: 13px;
  background:
    linear-gradient(90deg, #517082 1px, transparent 1px),
    linear-gradient(#517082 1px, transparent 1px);
  background-size: 20px 20px;
}

.flow-cell::after {
  content: "";
  position: absolute;
  left: 28px;
  top: 22px;
  width: 36px;
  height: 30px;
  border: 3px solid var(--gold);
  box-shadow: 8px -8px 0 -3px transparent, 8px -8px 0 0 var(--gold);
}

.flow-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.flow-step {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-size: 12px;
}

.flow-step.is-active {
  border-color: var(--gold);
  background: #fff7e8;
  color: #794d11;
  font-weight: 760;
}

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

.tool-button {
  padding: 8px 10px;
}

.knowledge-card,
.future-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(25, 71, 67, 0.08);
}

.knowledge-card {
  padding: 16px;
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.card-heading h2 {
  font-size: 22px;
}

.card-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 760;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 14px 0;
}

.info-grid div {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 10px;
}

dt {
  color: var(--muted);
  font-size: 13px;
}

dd {
  font-weight: 650;
}

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

.study-block h3,
.future-panel h2 {
  margin-bottom: 6px;
  font-size: 15px;
}

.study-block p {
  color: #344541;
  line-height: 1.62;
}

.warning h3 {
  color: var(--coral);
}

.memory-line {
  margin-top: 4px;
  padding: 12px;
  border-radius: 8px;
  background: #fff7e8;
  color: #794d11;
  line-height: 1.55;
  font-weight: 650;
}

.future-panel {
  padding: 14px;
}

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

.future-grid button {
  color: #77817f;
  background: #f2f5f4;
}

@media (min-width: 760px) {
  .app-shell {
    grid-template-columns: minmax(460px, 58vw) minmax(340px, 500px);
    grid-template-rows: 100vh;
  }

  .viewer-section {
    position: relative;
    padding: 22px;
  }

  .control-section {
    height: 100vh;
    overflow: auto;
    padding: 22px;
  }

  .crystal-viewer,
  .viewer-wrap {
    min-height: 520px;
  }

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

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

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

  .flow-visual {
    grid-template-columns: 1fr 22px 1fr 22px 1fr 22px 1fr 22px 1fr;
    overflow: visible;
  }

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