:root {
  color-scheme: light;
  font-family: Inter, Pretendard, "Noto Sans KR", "Segoe UI", sans-serif;
  font-synthesis: none;
  --panel-bg: rgba(247, 249, 248, 0.94);
  --panel-border: rgba(27, 43, 50, 0.18);
  --ink: #17272e;
  --muted: #66757b;
  --line: rgba(27, 43, 50, 0.12);
  --outside-accent: #0c7c86;
  --structure-accent: #a15f18;
  --active-accent: var(--outside-accent);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #8bc9e3;
  color: var(--ink);
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--active-accent) 76%, white 24%);
  outline-offset: 2px;
}

.model-stage,
#shipScene {
  width: 100%;
  height: 100%;
}

.model-stage {
  position: relative;
  isolation: isolate;
}

#shipScene {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none;
  cursor: grab;
}

#shipScene:active {
  cursor: grabbing;
}

.loading-state {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-content: center;
  gap: 14px;
  background: #d8edf3;
  transition: opacity 320ms ease, visibility 320ms ease;
}

.loading-state.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.loading-state strong {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0;
}

.loading-track {
  width: min(260px, 60vw);
  height: 3px;
  overflow: hidden;
  background: rgba(23, 39, 46, 0.14);
}

.loading-track span {
  display: block;
  width: 12%;
  height: 100%;
  background: var(--outside-accent);
  transition: width 240ms ease;
}

.term-panel {
  position: absolute;
  z-index: 12;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: min(350px, calc(100vw - 36px));
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  background: var(--panel-bg);
  box-shadow: 0 14px 38px rgba(13, 31, 38, 0.17);
}

.term-panel-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 14px 12px 16px;
  border-bottom: 1px solid var(--line);
}

.term-panel-header p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0;
}

.term-panel-header h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.18;
  font-weight: 720;
  letter-spacing: 0;
}

.clear-selection,
.learning-check-button,
.quality-audit-button,
.view-toolbar button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid rgba(27, 43, 50, 0.16);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.clear-selection:hover,
.learning-check-button:hover,
.quality-audit-button:hover,
.view-toolbar button:hover:not(:disabled) {
  border-color: rgba(27, 43, 50, 0.3);
  background: #fff;
}

.clear-selection:disabled,
.view-toolbar button:disabled {
  cursor: default;
  opacity: 0.36;
}

.clear-selection svg,
.learning-check-button svg,
.quality-audit-button svg,
.view-toolbar svg,
.term-tab svg {
  width: 17px;
  height: 17px;
  stroke-width: 1.8;
}

.panel-actions {
  display: flex;
  gap: 6px;
}

.quality-audit-button[aria-pressed="true"],
.learning-check-button[aria-pressed="true"],
.view-toolbar button[aria-pressed="true"] {
  border-color: var(--active-accent);
  background: color-mix(in srgb, var(--active-accent) 12%, white 88%);
  color: var(--active-accent);
}

.term-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}

.term-tab {
  min-width: 0;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid rgba(27, 43, 50, 0.13);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.58);
  font-size: 13px;
  font-weight: 680;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.term-tab:hover {
  background: rgba(255, 255, 255, 0.92);
}

.term-tab.active {
  border-color: var(--active-accent);
  background: var(--active-accent);
  color: #fff;
}

.discipline-filter {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(42, 58, 64, 0.035);
}

.discipline-filter[hidden] {
  display: none;
}

.discipline-button {
  min-width: 0;
  height: 29px;
  padding: 0 3px;
  overflow: hidden;
  border: 0;
  border-right: 1px solid rgba(27, 43, 50, 0.11);
  background: transparent;
  color: #68777d;
  font-size: 10.5px;
  font-weight: 660;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.discipline-button:last-child {
  border-right: 0;
}

.discipline-button:hover {
  color: #273b43;
  background: rgba(255, 255, 255, 0.52);
}

.discipline-button.active {
  color: #7f4b15;
  background: rgba(161, 95, 24, 0.1);
  box-shadow: inset 0 -2px 0 var(--structure-accent);
}

.term-list {
  grid-row: 4;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(23, 39, 46, 0.3) transparent;
}

.term-list[hidden],
.quality-audit[hidden],
.learning-check[hidden] {
  display: none;
}

.quality-audit {
  grid-row: 4;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.learning-check {
  grid-row: 4;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  overscroll-behavior: contain;
}

.quiz-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  color: #65747a;
  font-size: 10px;
}

.quiz-progress output {
  font-family: "Cascadia Mono", "Segoe UI Mono", monospace;
}

.quiz-question {
  margin: 17px 0 14px;
  color: #20343d;
  font-size: 15px;
  line-height: 1.5;
  font-weight: 700;
}

.quiz-choices {
  display: grid;
  gap: 7px;
}

.quiz-choice {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid rgba(27, 43, 50, 0.16);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.66);
  color: #34474e;
  text-align: left;
  cursor: pointer;
}

.quiz-choice:hover:not(:disabled) {
  border-color: rgba(27, 43, 50, 0.34);
  background: #fff;
}

.quiz-choice.correct {
  border-color: #34785a;
  background: #edf7f1;
  color: #235f43;
}

.quiz-choice.wrong {
  border-color: #a8594c;
  background: #fbefed;
  color: #8b3f35;
}

.quiz-feedback {
  min-height: 52px;
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
  color: #5b6a70;
  font-size: 10.5px;
  line-height: 1.5;
}

.quiz-next {
  width: 100%;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  border: 1px solid var(--active-accent);
  border-radius: 5px;
  background: var(--active-accent);
  color: #fff;
  font-weight: 680;
  cursor: pointer;
}

.quiz-next svg {
  width: 15px;
  height: 15px;
}

.audit-intro {
  padding: 12px 15px;
  border-bottom: 1px solid var(--line);
  color: #516168;
  font-size: 10.5px;
  line-height: 1.5;
}

.audit-row {
  border-bottom: 1px solid var(--line);
}

.audit-summary {
  width: 100%;
  min-height: 49px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 16px;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 15px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.audit-summary strong {
  font-size: 12px;
  font-weight: 690;
}

.audit-summary output {
  color: #7f4b15;
  font-family: "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 12px;
  font-weight: 700;
}

.audit-summary svg {
  width: 14px;
  height: 14px;
  transition: transform 160ms ease;
}

.audit-row.active .audit-summary svg {
  transform: rotate(180deg);
}

.audit-meter {
  height: 2px;
  margin: 0 15px;
  background: rgba(27, 43, 50, 0.1);
}

.audit-meter span {
  display: block;
  height: 100%;
  background: #8d673e;
}

.audit-detail {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 180ms ease;
}

.audit-detail > div {
  overflow: hidden;
}

.audit-row.active .audit-detail {
  grid-template-rows: 1fr;
}

.audit-gates {
  margin: 0;
  padding: 8px 15px 12px;
  list-style: none;
}

.audit-gates li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 4px 0;
  color: #637178;
  font-size: 10px;
  line-height: 1.35;
}

.audit-gates output {
  font-family: "Cascadia Mono", "Segoe UI Mono", monospace;
}

.term-row {
  border-bottom: 1px solid var(--line);
  background: transparent;
  transition: background 180ms ease;
}

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

.term-row.active {
  background: color-mix(in srgb, var(--active-accent) 8%, white 92%);
}

.term-summary {
  width: 100%;
  min-height: 45px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 18px;
  align-items: center;
  gap: 10px;
  padding: 9px 12px 9px 15px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.term-summary:hover {
  background: rgba(255, 255, 255, 0.48);
}

.term-summary strong {
  min-width: 0;
  overflow: hidden;
  color: #20343d;
  font-size: 13px;
  line-height: 1.2;
  font-weight: 690;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.term-summary small {
  color: #5e6d73;
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}

.term-summary svg {
  width: 15px;
  height: 15px;
  color: #78868b;
  transition: transform 180ms ease;
}

.term-row.active .term-summary svg {
  transform: rotate(180deg);
}

.term-detail {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 190ms ease;
}

.term-detail > div {
  overflow: hidden;
}

.term-row.active .term-detail {
  grid-template-rows: 1fr;
}

.term-detail p {
  margin: 0;
  padding: 0 34px 13px 15px;
  color: #516168;
  font-size: 11.5px;
  line-height: 1.55;
}

.term-evidence {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 9px;
  margin: 0 34px 8px 15px;
  color: #6b777c;
  font-size: 9px;
  line-height: 1.4;
}

.term-evidence a {
  color: #355c68;
  text-decoration: underline;
  text-decoration-color: rgba(53, 92, 104, 0.35);
  text-underline-offset: 2px;
}

.system-sequence {
  margin: 0 34px 8px 15px;
  padding: 7px 0;
  overflow-wrap: anywhere;
  border-top: 1px solid rgba(27, 43, 50, 0.09);
  border-bottom: 1px solid rgba(27, 43, 50, 0.09);
  color: #42585f;
  font-family: "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 8.5px;
  line-height: 1.55;
}

.term-code {
  display: block;
  margin: 0 34px 6px 15px;
  color: #7a6250;
  font-family: "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 9.5px;
  line-height: 1.3;
}

.model-provenance {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  padding: 9px 14px 10px;
  border-top: 1px solid var(--line);
  color: #748187;
  font-size: 9px;
  line-height: 1.4;
}

.view-toolbar {
  position: absolute;
  z-index: 10;
  left: 18px;
  bottom: 18px;
  display: flex;
  gap: 6px;
}

.selection-layer {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
}

.connector-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  color: var(--active-accent);
  opacity: 0;
  transition: opacity 150ms ease;
}

.selection-layer.visible .connector-svg {
  opacity: 1;
}

.connector-svg line {
  stroke: currentColor;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.connector-svg circle {
  fill: #fff;
  stroke: currentColor;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.active-callout {
  position: absolute;
  min-width: 128px;
  max-width: 210px;
  padding: 9px 11px;
  border: 1px solid color-mix(in srgb, var(--active-accent) 68%, white 32%);
  border-radius: 5px;
  background: rgba(251, 252, 251, 0.94);
  box-shadow: 0 9px 25px rgba(15, 28, 33, 0.16);
  transform: translate(-50%, -100%);
}

.active-callout strong,
.active-callout span {
  display: block;
}

.active-callout strong {
  color: #1e3037;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 720;
}

.active-callout span {
  margin-top: 3px;
  color: #65747a;
  font-size: 10px;
}

body[data-mode="structure"] {
  --active-accent: var(--structure-accent);
  background: #e2e8e6;
}

body[data-model-error] .loading-track {
  display: none;
}

@media (max-width: 760px) {
  .term-panel {
    top: auto;
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    max-height: 43vh;
  }

  .term-panel-header {
    min-height: 58px;
    padding: 10px 10px 9px 13px;
  }

  .term-panel-header h1 {
    font-size: 15px;
  }

  .term-tabs {
    padding: 6px;
  }

  .term-tab {
    height: 36px;
  }

  .discipline-filter {
    padding: 5px 6px;
  }

  .discipline-button {
    height: 27px;
    font-size: 10px;
  }

  .view-toolbar {
    top: 10px;
    bottom: auto;
    left: 10px;
  }

  .active-callout {
    max-width: 160px;
  }
}

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