:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1f2937;
  background: #eef1f5;
  --border: #d7dce2;
  --panel: #ffffff;
  --muted: #667085;
  --blue: #2563eb;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: #eef1f5; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button { border: 1px solid #1d4ed8; background: var(--blue); color: white; border-radius: .5rem; padding: .42rem .65rem; }
button.secondary { background: white; color: #344054; border-color: var(--border); }
button.icon-button { border: 0; background: transparent; color: #667085; font-size: 1.5rem; padding: .1rem .4rem; }

.app { min-height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .7rem 1rem; background: #fff; border-bottom: 1px solid var(--border); }
.topbar h1 { margin: 0; font-size: 1.22rem; }
.topbar p { margin: .12rem 0 0; color: var(--muted); font-size: .82rem; }
.top-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.language-switcher { display: inline-flex; gap: .15rem; align-items: center; }
.language-button { border: 1px solid var(--border); background: white; color: #344054; border-radius: .45rem; padding: .2rem .32rem; font-size: .95rem; line-height: 1; min-width: 2rem; }
.language-button.active { border-color: #93c5fd; background: #eff6ff; box-shadow: inset 0 0 0 1px #bfdbfe; }
.language-button:focus-visible { outline: 2px solid #60a5fa; outline-offset: 1px; }

.main-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: .75rem; padding: .75rem; }
.main-layout.with-saved { grid-template-columns: minmax(0, 1fr) 300px; }
.content { min-width: 0; }
.hidden { display: none !important; }

.canvas-card { height: var(--canvas-height, clamp(360px, 70vh, 820px)); border: 1px solid var(--border); border-radius: .75rem; background: #fff; overflow: hidden; box-shadow: 0 1px 2px rgba(16,24,40,.05); }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.controls { margin-top: .55rem; padding: .65rem .75rem; background: #fff; border: 1px solid var(--border); border-radius: .75rem; display: flex; flex-direction: column; gap: .55rem; }
.row { display: flex; align-items: center; gap: .5rem; }
.row.wrap { flex-wrap: wrap; row-gap: .35rem; }
.row label, .row strong { font-size: .88rem; }
.grow { flex: 1; min-width: 140px; }
.small-number { width: 92px; }
select, input[type="number"] { min-height: 2.15rem; border: 1px solid var(--border); border-radius: .45rem; background: #fff; padding: .3rem .45rem; }
.check { display: inline-flex; align-items: center; gap: .3rem; font-weight: 450 !important; }
.numeric-readout { width: 3.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.heighway-inline {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  flex: 1 1 240px;
  min-width: 210px;
  white-space: nowrap;
}
.heighway-inline.hidden { display: none; }
.heighway-slider {
  width: auto;
  flex: 1 1 auto;
  min-width: 120px;
}
.heighway-inline .numeric-readout { width: 2rem; text-align: right; }
.hint { color: var(--muted); font-size: .78rem; margin-top: -.3rem; }
.epicycle-row { border-top: 1px solid var(--border); padding-top: .55rem; }

.saved-panel { background: #fff; border: 1px solid var(--border); border-radius: .75rem; display: flex; flex-direction: column; max-height: calc(100vh - 2rem); overflow: hidden; }
.saved-panel.hidden { display: none; }
.saved-header { display: flex; justify-content: space-between; gap: .5rem; padding: .9rem; border-bottom: 1px solid var(--border); }
.saved-header h2 { margin: 0; font-size: 1rem; }
.saved-header p { margin: .2rem 0 0; color: var(--muted); font-size: .78rem; }
.saved-list { flex: 1; overflow: auto; padding: .65rem; }
.saved-empty { color: var(--muted); font-size: .88rem; padding: .5rem; }
.saved-item { padding: .65rem; border: 1px solid var(--border); border-radius: .55rem; margin-bottom: .5rem; }
.saved-item.selected { outline: 2px solid #93c5fd; }
.saved-name { font-weight: 650; overflow-wrap: anywhere; }
.saved-meta { color: var(--muted); font-size: .76rem; margin-top: .2rem; }
.saved-actions { display: flex; gap: .35rem; margin-top: .55rem; }
.saved-actions button { font-size: .78rem; padding: .35rem .5rem; }
.saved-panel > button:last-child { margin: .65rem; }

.dialog-card { min-width: min(90vw, 360px); padding: .2rem; display: flex; flex-direction: column; gap: .7rem; }
.dialog-card h2 { margin: 0; font-size: 1.05rem; }
.dialog-card input { border: 1px solid var(--border); border-radius: .45rem; padding: .55rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; }
dialog { border: 0; border-radius: .75rem; padding: 1rem; box-shadow: 0 12px 40px rgba(16,24,40,.2); }
dialog::backdrop { background: rgba(16,24,40,.35); }

@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .main-layout.with-saved { grid-template-columns: minmax(0, 1fr); }
  .saved-panel { max-height: 420px; }
}
