:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #5f6f68;
  --line: #d8e2de;
  --panel: #ffffff;
  --soft: #f5faf7;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --blue: #2563eb;
  --warning: #b45309;
  --shadow: 0 16px 40px rgba(23, 33, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--soft);
  color: var(--ink);
  font-family: Arial, "Noto Sans KR", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

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

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 64px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  font-weight: 800;
  text-decoration: none;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.top-nav a {
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}

.top-nav a[aria-current="page"],
.top-nav a:hover {
  background: #e7f5f2;
  color: var(--accent-strong);
}

.intro-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
  gap: 36px;
  align-items: center;
  padding: 56px 28px;
  max-width: 1160px;
  margin: 0 auto;
}

.intro-copy h1 {
  max-width: 720px;
  margin: 0 0 16px;
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.intro-copy p {
  max-width: 680px;
  color: var(--muted);
  font-size: 1.06rem;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.button-row.compact {
  margin-top: 16px;
}

.button,
button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 14px;
  text-decoration: none;
  cursor: pointer;
}

.button.primary,
button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.button:hover,
button:hover {
  border-color: var(--accent);
}

.access-panel,
.feature-card,
.control-panel,
.explain-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.access-panel {
  padding: 22px;
}

.access-panel h2,
.feature-card h2,
.control-panel h1,
.explain-panel h2 {
  margin-top: 0;
}

.qr-placeholder {
  display: grid;
  place-items: center;
  width: 160px;
  height: 160px;
  margin: 16px 0;
  border: 1px dashed var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-weight: 800;
}

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

.content-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 28px 56px;
}

.feature-card {
  padding: 20px;
}

.feature-card p {
  color: var(--muted);
}

.site-footer {
  padding: 24px 28px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.doc-page {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 28px 64px;
}

.doc-section {
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}

.doc-section h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1.08;
}

.doc-section h2 {
  margin-top: 0;
}

.doc-section p,
.doc-section li {
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 300px;
  gap: 16px;
  padding: 20px;
  min-height: calc(100vh - 64px);
}

.app-layout {
  grid-template-columns: 300px minmax(0, 1fr) 300px;
}

body.plot-focus .app-layout {
  grid-template-columns: minmax(0, 1fr);
}

body.plot-focus .control-panel,
body.plot-focus .explain-panel {
  display: none;
}

.control-panel,
.explain-panel {
  padding: 18px;
  align-self: start;
}

.control-panel label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.control-panel select,
.control-panel input,
.control-panel textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
}

.control-panel select,
.control-panel input {
  min-height: 40px;
}

.control-panel input[type="range"] {
  min-height: 28px;
  padding: 0;
  accent-color: var(--accent);
}

.control-panel textarea {
  min-height: 104px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.45;
}

.draw-panel {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.draw-panel canvas {
  width: 100%;
  height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  touch-action: none;
}

.draw-panel button {
  min-height: 36px;
  justify-self: start;
  padding: 7px 10px;
}

.field-help {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
}

.field-error {
  color: #b91c1c;
}

.is-hidden {
  display: none !important;
}

.visual-stage {
  min-width: 0;
}

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

.stage-header h2 {
  margin: 0;
}

.iteration-label {
  margin: 0;
  color: var(--accent-strong);
  font-weight: 800;
}

.stage-tools {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.plot-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.plot-toolbar button {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 0.9rem;
}

.plot-area {
  height: clamp(500px, calc(100vh - 188px), 620px);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

body.plot-focus .plot-area {
  height: clamp(620px, calc(100vh - 150px), 780px);
}

.model-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.model-card {
  min-width: 0;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.model-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 0;
}

.model-card-header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.model-card-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: right;
}

.model-plot {
  height: 210px;
}

.fallback-plot {
  padding: 24px;
}

.metric-list {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.metric-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.metric-list dt {
  color: var(--muted);
  font-weight: 700;
}

.metric-list dd {
  margin: 0;
  font-weight: 800;
}

.plot-caption {
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.mini-plot {
  height: 150px;
  margin-top: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

/* AI4Fluids notebook-style optimization lab */
.optimization-page {
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px;
}

.optimization-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 22px;
  padding: 8px 2px;
}

.optimization-intro h1 {
  max-width: 820px;
  margin: 0;
  font-size: clamp(1.75rem, 3vw, 2.7rem);
  line-height: 1.12;
  letter-spacing: -0.035em;
}

.optimization-intro p:not(.eyebrow) {
  max-width: 760px;
  margin: 12px 0 0;
  color: var(--muted);
}

.logic-flow {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 330px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.logic-flow span:nth-child(odd) {
  padding: 7px 10px;
  border: 1px solid #bddbd5;
  border-radius: 999px;
  background: #eef9f6;
  color: var(--accent-strong);
}

.optimization-layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.lab-controls,
.lab-workspace {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.lab-controls {
  position: sticky;
  top: 84px;
  padding: 20px;
}

.panel-heading h2,
.lab-stage-heading h2 {
  margin: 0;
}

.panel-heading {
  margin-bottom: 20px;
}

.lab-controls label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.lab-controls select,
.lab-controls input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

.lab-run {
  width: 100%;
  margin-top: 2px;
}

.lab-note {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
}

.lab-note strong {
  color: var(--ink);
}

.lab-workspace {
  min-width: 0;
  padding: 18px;
}

.lab-stage-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 10px;
}

.lab-stage-heading h2 {
  font-size: 1.16rem;
}

.lab-status {
  flex: 0 0 auto;
  margin: 0;
  padding: 7px 11px;
  border-radius: 999px;
  background: #e7f5f2;
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 800;
}

.lab-status.is-busy {
  background: #fff7ed;
  color: var(--warning);
}

.lab-plot {
  width: 100%;
  height: clamp(520px, 66vh, 690px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.iteration-player {
  display: grid;
  grid-template-columns: auto auto auto minmax(150px, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
}

.iteration-player button {
  min-height: 36px;
  padding: 6px 11px;
}

.iteration-player input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.iteration-player strong {
  min-width: 92px;
  color: var(--accent-strong);
  font-size: 0.86rem;
  text-align: right;
}

.lab-results {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.lab-results article {
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fcfa;
}

.lab-results span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.lab-results strong {
  display: block;
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lab-log {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.lab-log summary {
  padding: 10px 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 700;
}

.lab-log pre {
  max-height: 240px;
  margin: 0;
  padding: 0 12px 12px;
  overflow: auto;
  color: #30433c;
  font: 0.78rem/1.6 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
}

@media (max-width: 980px) {
  .intro-band,
  .app-shell,
  .app-layout {
    grid-template-columns: 1fr;
  }

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

  .plot-area {
    min-height: 420px;
  }

  .model-panel {
    grid-template-columns: 1fr;
  }

  .optimization-intro {
    align-items: flex-start;
    flex-direction: column;
  }

  .logic-flow {
    justify-content: flex-start;
    min-width: 0;
  }

  .optimization-layout {
    grid-template-columns: 1fr;
  }

  .lab-controls {
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 14px;
  }

  .panel-heading,
  .lab-run,
  .lab-note {
    grid-column: 1 / -1;
  }

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

@media (max-width: 640px) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 18px;
  }

  .intro-band,
  .content-grid,
  .app-shell,
  .optimization-page {
    padding-left: 16px;
    padding-right: 16px;
  }

  .lab-controls {
    display: block;
  }

  .lab-stage-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .lab-plot {
    height: 520px;
  }

  .iteration-player {
    grid-template-columns: repeat(3, 1fr);
  }

  .iteration-player input,
  .iteration-player strong {
    grid-column: 1 / -1;
  }

  .iteration-player strong {
    text-align: left;
  }

  .lab-results {
    grid-template-columns: 1fr;
  }
}
