: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);
}

.mobile-sheet-rail,
.term-search {
  display: none;
}

.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,
.education-guide-link,
.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,
.education-guide-link: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,
.education-guide-link 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;
}

.education-guide-link {
  color: inherit;
  text-decoration: none;
}

.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-empty {
  display: grid;
  min-height: 120px;
  place-items: center;
  padding: 24px;
  color: #6b777c;
  font-size: 12px;
}

.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: 48px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(72px, 112px) 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;
  color: #20343d;
  font-size: 13px;
  line-height: 1.2;
  font-weight: 690;
  overflow-wrap: anywhere;
}

.term-summary small {
  color: #5e6d73;
  font-size: 11px;
  line-height: 1.2;
  overflow-wrap: anywhere;
  text-align: right;
}

.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;
}

.model-provenance a {
  color: inherit;
  text-underline-offset: 2px;
}

.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), (max-height: 600px) and (max-width: 960px) {
  .term-panel {
    top: auto;
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    height: 76px;
    max-height: none;
    grid-template-rows: auto auto auto auto auto minmax(0, 1fr);
    border-radius: 7px;
    transition: height 220ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .term-panel[data-sheet-state="browse"] {
    height: min(50dvh, 440px);
  }

  .term-panel[data-sheet-state="full"] {
    height: min(82dvh, 720px);
  }

  .mobile-sheet-rail {
    grid-row: 1;
    min-width: 0;
    min-height: 67px;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 7px 4px 8px;
    border-bottom: 1px solid var(--line);
    background: rgba(249, 251, 250, 0.96);
  }

  .mobile-sheet-toggle {
    position: relative;
    min-width: 0;
    min-height: 58px;
    display: grid;
    flex: 1 1 auto;
    grid-template-columns: minmax(0, 1fr) 22px;
    align-items: center;
    gap: 8px;
    padding: 13px 8px 6px 7px;
    border: 0;
    background: transparent;
    color: #20343d;
    cursor: pointer;
    touch-action: none;
  }

  .mobile-sheet-toggle:focus {
    outline: none;
  }

  .mobile-sheet-toggle:focus-visible {
    outline: 1px solid color-mix(in srgb, var(--active-accent) 76%, white 24%);
    outline-offset: -1px;
  }

  .mobile-sheet-grip {
    position: absolute;
    top: 3px;
    left: 50%;
    width: 34px;
    height: 3px;
    border-radius: 2px;
    background: rgba(41, 57, 64, 0.28);
    transform: translateX(-50%);
  }

  .mobile-sheet-copy {
    min-width: 0;
    display: grid;
    gap: 2px;
    text-align: left;
  }

  .mobile-sheet-copy small {
    overflow: hidden;
    color: #738087;
    font-size: 9.5px;
    font-weight: 680;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-sheet-copy strong {
    display: -webkit-box;
    overflow: hidden;
    color: #20343d;
    font-size: 13px;
    line-height: 1.15;
    font-weight: 720;
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .mobile-sheet-toggle > svg {
    width: 18px;
    height: 18px;
    transition: transform 180ms ease;
  }

  .term-panel[data-sheet-state="full"] .mobile-sheet-toggle > svg {
    transform: rotate(180deg);
  }

  .mobile-education-guide,
  .mobile-clear-selection {
    width: 42px;
    height: 42px;
    display: inline-grid;
    flex: 0 0 auto;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(27, 43, 50, 0.14);
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.78);
    color: #52636a;
    cursor: pointer;
  }

  .mobile-education-guide {
    text-decoration: none;
  }

  .mobile-education-guide:hover {
    border-color: rgba(11, 133, 136, 0.42);
    color: var(--outside-accent);
  }

  .mobile-clear-selection[hidden] {
    display: none;
  }

  .mobile-education-guide svg,
  .mobile-clear-selection svg {
    width: 17px;
    height: 17px;
  }

  .term-panel[data-sheet-state="peek"] > :not(.mobile-sheet-rail) {
    display: none;
  }

  .term-panel[data-sheet-state="browse"] .term-panel-header,
  .model-provenance {
    display: none;
  }

  .term-panel-header {
    grid-row: 2;
    min-height: 44px;
    padding: 4px 7px 4px 12px;
  }

  .term-panel-header p {
    display: none;
  }

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

  .term-panel-header .education-guide-link,
  .term-panel-header .learning-check-button,
  .term-panel-header .quality-audit-button {
    width: 40px;
    height: 40px;
  }

  .term-panel-header .clear-selection {
    display: none;
  }

  .term-tabs {
    grid-row: 3;
    gap: 4px;
    padding: 5px 6px;
  }

  .term-tab {
    height: 44px;
  }

  .discipline-filter {
    grid-row: 4;
    display: flex;
    gap: 4px;
    padding: 5px 6px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .discipline-filter::-webkit-scrollbar {
    display: none;
  }

  .discipline-button {
    min-width: 64px;
    height: 40px;
    flex: 1 0 auto;
    padding: 0 9px;
    border: 1px solid rgba(27, 43, 50, 0.11);
    border-radius: 4px;
    font-size: 10.5px;
  }

  .discipline-button:last-child {
    border-right: 1px solid rgba(27, 43, 50, 0.11);
  }

  .term-search {
    grid-row: 5;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 7px;
    border-bottom: 1px solid var(--line);
  }

  .term-search label {
    min-width: 0;
    height: 44px;
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 7px;
    padding: 0 10px;
    border: 1px solid rgba(27, 43, 50, 0.14);
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.72);
  }

  .term-search label svg {
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
    color: #6b797f;
  }

  .term-search input {
    min-width: 0;
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: #20343d;
    font: inherit;
    font-size: 12px;
  }

  .term-search input::-webkit-search-cancel-button {
    display: none;
    -webkit-appearance: none;
  }

  .term-search > button {
    width: 44px;
    height: 44px;
    display: inline-grid;
    flex: 0 0 auto;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(27, 43, 50, 0.14);
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.72);
    color: #5f6f75;
  }

  .term-search > button[hidden] {
    display: none;
  }

  .term-search > button svg {
    width: 16px;
    height: 16px;
  }

  .term-list,
  .quality-audit,
  .learning-check {
    grid-row: 6;
  }

  .term-summary {
    min-height: 56px;
    grid-template-columns: minmax(0, 1fr) minmax(68px, 108px) 18px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .term-panel[data-sheet-state="browse"] .term-row.active .term-detail {
    grid-template-rows: 0fr;
  }

  .term-panel[data-sheet-state="browse"] .term-row.active .term-summary svg {
    transform: none;
  }

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

  .view-toolbar button {
    width: 42px;
    height: 42px;
  }

  .active-callout,
  .selection-layer.mobile-marker .connector-svg line {
    display: none;
  }

  .selection-layer.mobile-marker .connector-svg circle {
    fill: color-mix(in srgb, var(--active-accent) 22%, white 78%);
    stroke-width: 2.5;
  }
}

@media (max-width: 960px) and (max-height: 600px) and (orientation: landscape) {
  .term-panel[data-sheet-state="browse"],
  .term-panel[data-sheet-state="full"] {
    top: 8px;
    right: 8px;
    bottom: 8px;
    left: auto;
    width: min(360px, 48vw);
    height: auto;
  }

  .term-panel[data-sheet-state="peek"] {
    right: 8px;
    left: auto;
    width: min(320px, 48vw);
  }
}

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