:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-soft: #f7f9fc;
  --ink: #101827;
  --muted: #606b7b;
  --line: #dbe3ee;
  --line-strong: #c9d3df;
  --accent: #15527c;
  --accent-dark: #0f3d5d;
  --green: #0f766e;
  --red: #b42318;
  --amber: #a16207;
  --shadow: 0 12px 28px rgba(17, 24, 39, 0.07);
  --shadow-soft: 0 6px 18px rgba(17, 24, 39, 0.045);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f8fafc 0%, var(--bg) 100%);
  color: var(--ink);
  font-family:
    Inter, "Source Sans 3", ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

.topbar {
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  align-items: center;
  gap: 18px;
  padding: 0 2px 20px;
  border-bottom: 1px solid var(--line);
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.42rem, 2.05vw, 2.28rem);
  line-height: 1.12;
  text-align: center;
  font-weight: 600;
  color: #0f172a;
}

h2 {
  font-size: 0.82rem;
  line-height: 1.2;
  text-transform: uppercase;
  color: #334155;
  font-weight: 750;
  margin: 18px 0 10px;
}

.nav-link,
.primary-action,
.ghost-button,
.preset-button,
.path-button,
.icon-button {
  min-height: 36px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  cursor: pointer;
  font-weight: 700;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.primary-action {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  white-space: nowrap;
  box-shadow: 0 8px 18px rgba(21, 82, 124, 0.18);
}

.primary-action:disabled {
  opacity: 0.6;
  cursor: wait;
}

.ghost-button:disabled,
.preset-button:disabled,
.path-button:disabled,
.icon-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.primary-action:not(:disabled):hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  transform: translateY(-1px);
}

.nav-link:hover,
.ghost-button:hover,
.preset-button:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-soft);
}

.nav-link-wide {
  min-height: 42px;
  padding: 0 18px;
  font-size: 0.98rem;
  white-space: nowrap;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.status-strip > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 15px;
  box-shadow: var(--shadow-soft);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.status-strip strong {
  display: block;
  margin-top: 4px;
  font-size: 1.35rem;
  line-height: 1;
}

.workspace {
  display: grid;
  grid-template-columns: 382px minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  height: clamp(760px, calc(100vh - 212px), 980px);
}

.control-panel,
.plot-panel,
.robot-stage,
.sketch-stage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  padding: 16px;
  position: sticky;
  top: 12px;
  height: 100%;
  max-height: none;
  overflow: auto;
}

.visual-panel {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  min-height: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-head h2 {
  margin: 0;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
  margin: 13px 0;
}

.preset-button.active,
.path-button.active {
  border-color: var(--accent);
  background: #edf6fb;
  color: var(--accent-dark);
  box-shadow: inset 0 0 0 1px rgba(21, 82, 124, 0.08);
}

.field,
.toggle-row {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  margin-top: 10px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

input[type="number"],
input[type="range"] {
  width: 100%;
}

input[type="range"],
input[type="checkbox"] {
  accent-color: var(--accent);
}

input[type="number"] {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 8px;
  background: #ffffff;
  color: var(--ink);
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

input[type="number"] {
  appearance: textfield;
}

input[type="number"]:focus,
input[type="range"]:focus {
  outline: 2px solid rgba(22, 78, 122, 0.22);
  outline-offset: 1px;
}

input[type="number"]:disabled {
  background: #eef2f7;
  color: #94a3b8;
  cursor: not-allowed;
}

.toggle-row {
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 36px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  margin-top: 14px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.input-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.78rem;
}

.input-table th {
  height: 28px;
  color: var(--muted);
  background: var(--panel-soft);
  font-weight: 800;
}

.input-table td,
.input-table th {
  border-bottom: 1px solid var(--line);
  padding: 3px;
  text-align: center;
}

.input-table tr:last-child td {
  border-bottom: 0;
}

.input-table input {
  height: 28px;
  min-width: 64px;
  padding: 0 5px;
  text-align: right;
}

.visual-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.94fr) minmax(520px, 1.06fr);
  gap: 14px;
  align-items: stretch;
  height: 100%;
  min-height: 0;
}

.motion-column {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(220px, 0.42fr);
  gap: 12px;
  min-height: 0;
}

.robot-stage,
.sketch-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  min-height: 0;
}

.stage-toolbar,
.sketch-toolbar {
  display: grid;
  grid-template-columns: 78px 86px 1fr 78px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.sketch-toolbar {
  grid-template-columns: minmax(160px, 1fr) 74px 74px;
}

.planning-action {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 42px;
}

.speed-select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 750;
  padding: 0 8px;
}

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

#time-readout {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  text-align: right;
}

#robot-canvas {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  background: #fbfcfe;
}

#sketch-canvas {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  background: #fbfcfe;
  cursor: crosshair;
  touch-action: none;
}

.plot-stack {
  display: grid;
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 8px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding-right: 2px;
}

.plot-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 9px;
  min-height: 0;
}

.plot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 8px;
}

.plot-panel h2 {
  margin: 0 0 8px;
  font-size: 0.76rem;
}

.plot-head h2 {
  margin: 0;
  min-width: 0;
}

.constraint-status {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.62rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.constraint-status.within-limit {
  border-color: rgba(15, 118, 110, 0.32);
  background: rgba(15, 118, 110, 0.08);
  color: #0f6b64;
}

.constraint-status.exceeds-limit {
  border-color: rgba(180, 35, 24, 0.38);
  background: rgba(180, 35, 24, 0.09);
  color: #a11f16;
}

.constraint-status.not-enforced,
.constraint-status.pending {
  border-color: rgba(100, 116, 139, 0.28);
  background: rgba(100, 116, 139, 0.07);
  color: #59677a;
}

.compact-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.plot-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: crosshair;
  touch-action: none;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(440px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #ffffff;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.28);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
  font-size: 0.88rem;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 1280px) and (max-width: 1324px) {
  .workspace {
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 12px;
  }

  .visual-grid {
    grid-template-columns: minmax(344px, 0.94fr) minmax(520px, 1.06fr);
    gap: 12px;
  }
}

@media (max-width: 1279px) {
  .workspace,
  .visual-grid {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .control-panel {
    position: static;
    height: auto;
    max-height: none;
  }

  .motion-column {
    grid-template-rows: auto auto;
  }

  #robot-canvas {
    height: auto;
    aspect-ratio: 1.18 / 1;
  }

  #sketch-canvas {
    height: auto;
    aspect-ratio: 2.2 / 1;
  }

  .plot-stack {
    height: auto;
    overflow: visible;
  }

  .plot-canvas {
    height: 150px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 16px, 1480px);
    padding-top: 14px;
  }

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

  h1 {
    text-align: left;
  }

  .status-strip {
    grid-template-columns: 1fr 1fr;
  }

  .two-col,
  .stage-toolbar,
  .sketch-toolbar {
    grid-template-columns: 1fr;
  }
}
