:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --panel-bg: #ffffff;
  --line: #c4d9e9;
  --line-strong: #8ec4e6;
  --text: #204172;
  --muted: #1e6da9;
  --accent: #1e6da9;
  --brand-green: #13ce74;
  --ink-strong: #06371f;
  --header-h: 72px;
  --footer-h: 38px;
  --shadow-soft: 0 12px 28px -24px rgba(32, 65, 114, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.top-banner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: transparent;
  overflow: hidden;
}

.brand-mark-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.brand-title {
  margin: 0;
  font-size: 1.01rem;
  font-weight: 700;
  line-height: 1.2;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: var(--muted);
}

.home-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
}

.home-link-icon {
  width: 15px;
  height: 15px;
  display: block;
}

.home-link:hover {
  border-color: var(--line-strong);
  text-decoration: none;
}

.app-shell {
  margin: 12px;
  height: calc(100vh - var(--header-h) - var(--footer-h) - 24px);
  min-height: 620px;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.control-panel {
  border-right: 1px solid var(--line);
  background: var(--panel-bg);
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.panel-expand-btn {
  display: none;
  width: 48px;
  margin: 12px auto;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 10px 0;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-direction: column;
}

.panel-expand-icon {
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
}

.panel-expand-text {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 11px;
  text-transform: uppercase;
}

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

.panel-kicker {
  margin: 0 0 3px;
  font-size: 0.73rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.03rem;
  line-height: 1.2;
}

.icon-btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.panel-body {
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
}

.panel-actions {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  gap: 8px;
  padding-bottom: 12px;
  margin-bottom: 2px;
  background: linear-gradient(
    180deg,
    rgba(238, 245, 251, 0.98) 0%,
    rgba(238, 245, 251, 0.9) 82%,
    rgba(238, 245, 251, 0) 100%
  );
}

.panel-tip {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.group {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
  margin-bottom: 12px;
}

.group-title {
  width: 100%;
  border: none;
  background: var(--surface);
  color: var(--text);
  font-size: 0.89rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  text-align: left;
  cursor: pointer;
  padding: 12px 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.group-title::after {
  content: "+";
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}

.group.is-open .group-title::after {
  content: "-";
}

.group-title:hover {
  background: #f3f8fd;
}

.group-content {
  display: none;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.group.is-open .group-content {
  display: block;
}

.group-intro {
  margin: 0 0 10px;
  font-size: 0.77rem;
  line-height: 1.4;
  color: var(--muted);
}

fieldset {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px;
  background: var(--surface);
}

fieldset:last-child {
  margin-bottom: 0;
}

legend {
  font-size: 0.78rem;
  color: var(--text);
  font-weight: 650;
  padding: 0 6px;
}

label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.78rem;
  color: var(--text);
  font-weight: 600;
}

fieldset p {
  margin: 8px 0 5px;
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 600;
}

.assumption-note {
  margin: 2px 0 8px;
  font-size: 0.74rem;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.4;
}

.managed-by-trajectory p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.hidden-trajectory-inputs {
  display: none;
}

input[type="number"],
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  padding: 9px 10px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input[type="number"] {
  margin-bottom: 9px;
}

input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30, 109, 169, 0.16);
}

.trajectory-editor {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  padding: 11px;
  margin-bottom: 10px;
}

.trajectory-editor h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--text);
  padding-right: 150px;
}

.trajectory-editor-copy {
  margin: 4px 0 9px;
  font-size: 0.76rem;
  color: var(--muted);
  padding-right: 150px;
}

.chart-export-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.trajectory-editor > .chart-export-row {
  position: absolute;
  top: 11px;
  right: 11px;
  margin-top: 0;
  z-index: 2;
}

.export-csv-btn {
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.75rem;
  line-height: 1;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 7px 10px;
  cursor: pointer;
  transition: border-color 0.16s ease, color 0.16s ease, background-color 0.16s ease;
}

.export-csv-btn:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.export-csv-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30, 109, 169, 0.16);
}

.trajectory-canvas-wrap {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f3f8fd;
  padding: 8px;
  height: 208px;
}

.trajectory-canvas {
  width: 100% !important;
  height: 100% !important;
  cursor: grab;
}

.trajectory-canvas.dragging {
  cursor: grabbing;
}

.trajectory-hint {
  margin: 8px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}

.btn {
  border-radius: 11px;
  border: 1px solid transparent;
  padding: 10px 12px;
  font-size: 0.86rem;
  font-weight: 650;
  cursor: pointer;
}

.btn-primary {
  background: #204172;
  color: #fff;
  border-color: #204172;
}

.btn-primary:hover {
  background: #1e6da9;
  border-color: #1e6da9;
}

.btn-ghost {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--accent);
}

.workspace {
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.workspace-header h1 {
  margin: 0;
  font-size: clamp(1.05rem, 1.45vw, 1.4rem);
  line-height: 1.2;
  color: var(--text);
}

.workspace-header p {
  margin: 4px 0 0;
  max-width: 62ch;
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.45;
}

.view-toggle {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.view-tab {
  border: 1px solid transparent;
  border-radius: 999px;
  background: #eaf3fb;
  color: var(--text);
  padding: 7px 12px;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
}

.view-tab:hover {
  background: #dff2ea;
}

.view-tab.is-active {
  background: #204172;
  color: #fff;
}

.subview-toolbar {
  margin-top: 10px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.subview-toolbar label {
  margin: 0;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.scenario-summary {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.77rem;
  color: var(--muted);
}

.chart-card {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chart-head {
  display: grid;
  gap: 3px;
  padding: 2px 170px 0 2px;
}

.chart-card > .chart-export-row {
  position: absolute;
  top: 10px;
  right: 12px;
  margin-top: 0;
  z-index: 2;
}

.chart-head-rule {
  width: 44px;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, #204172 0%, #1e6da9 52%, #13ce74 100%);
}

.chart-head h2 {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.2;
  color: var(--ink-strong);
  font-weight: 700;
}

.chart-head p {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.35;
  color: var(--muted);
}

#chartCanvas {
  width: 100% !important;
  height: 100% !important;
  min-height: 280px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  padding: 2px 2px 0;
}

.chart-legend-item {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.2;
}

.chart-legend-item.is-hidden {
  color: #8badc5;
}

.chart-legend-swatch {
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  display: inline-block;
}

.app-shell.panel-collapsed {
  grid-template-columns: 68px minmax(0, 1fr);
}

.app-shell.panel-collapsed .panel-head,
.app-shell.panel-collapsed .panel-body {
  display: none;
}

.app-shell.panel-collapsed .panel-expand-btn {
  display: flex;
}

.footer-strip {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface);
  font-size: 0.76rem;
}

.footer-strip strong {
  color: var(--accent);
}

.footer-strip a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.footer-strip a:hover {
  text-decoration: underline;
}

.tippy-box[data-theme~="light-border"] {
  border-radius: 10px;
  border: 1px solid #89e7ba;
  background: #06371f;
  color: #ffffff;
  box-shadow: 0 10px 28px -22px rgba(6, 55, 31, 0.72);
}

.tippy-box[data-theme~="light-border"] .tippy-content {
  color: inherit;
  font-size: 12px;
  line-height: 1.35;
}

.tippy-box[data-theme~="light-border"] > .tippy-arrow::before {
  color: #06371f;
}

@media (max-width: 1360px) {
  .app-shell {
    grid-template-columns: 332px minmax(0, 1fr);
  }
}

@media (max-width: 1024px) {
  .top-banner {
    height: auto;
    padding: 12px;
    flex-wrap: wrap;
  }

  .app-shell {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .panel-head {
    padding: 13px;
  }

  .panel-body {
    max-height: 480px;
  }

  .workspace {
    min-height: 70vh;
  }

  .subview-toolbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .subview-toolbar label {
    margin-bottom: -2px;
  }

  .app-shell.panel-collapsed {
    grid-template-columns: 1fr;
  }

  .app-shell.panel-collapsed .panel-head,
  .app-shell.panel-collapsed .panel-body {
    display: flex;
  }

  .app-shell.panel-collapsed .panel-head {
    justify-content: space-between;
  }

  .app-shell.panel-collapsed .panel-body {
    display: block;
  }

  .app-shell.panel-collapsed .panel-expand-btn {
    display: none;
  }

  #panelCollapseBtn {
    display: none;
  }
}

@media (max-width: 680px) {
  .home-link {
    padding: 8px 11px;
    font-size: 0.86rem;
  }

  .workspace {
    padding: 14px;
  }

  .chart-card {
    padding: 10px;
    min-height: 370px;
  }

  .chart-head {
    padding-right: 138px;
  }

  .trajectory-editor h3,
  .trajectory-editor-copy {
    padding-right: 128px;
  }

  .footer-strip {
    padding: 0 8px;
    text-align: center;
  }
}
