:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --ink: #1d2522;
  --label: #25302c;
  --muted: #6c7973;
  --subtle: #84918b;
  --line: #d9ded6;
  --panel: #ffffff;
  --accent: #146b63;
  --accent-2: #b7442e;
  --guide: #7f8f88;
  --rack: #3f628d;
  --shadow: 0 18px 45px rgba(35, 45, 41, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 2.4vw, 2.35rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: 1rem;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.94);
}

.actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.actions button {
  background: var(--accent-2);
}

.download-target {
  min-width: 150px;
  margin: 0;
  gap: 5px;
  color: var(--label);
  font-size: 0.82rem;
}

.download-target select {
  min-height: 40px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  align-items: start;
  gap: 18px;
  padding: 16px clamp(16px, 3vw, 34px);
}

.panel,
.preview {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 108px);
  overflow: auto;
  display: grid;
  gap: 18px;
  padding: 18px;
}

.controls section + section {
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--label);
  font-size: 0.95rem;
  font-weight: 700;
}

.hint {
  color: var(--subtle);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.55;
}

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

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(20, 107, 99, 0.22);
  outline-offset: 2px;
}

.check {
  grid-template-columns: 20px 1fr;
  align-items: center;
  color: var(--ink);
}

.check input {
  min-height: auto;
}

.check .hint {
  grid-column: 2;
}

.is-hidden {
  display: none;
}

.readout dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.readout div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

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

.readout dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.preview {
  position: sticky;
  top: 14px;
  height: calc(100vh - 108px);
  min-height: 560px;
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr);
  overflow: hidden;
}

.canvas-toolbar {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.canvas-toolbar span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.88rem;
}

#resetView {
  background: #eef3f1;
  color: var(--accent);
  border-color: #c8d8d4;
}

#gearSvg {
  width: 100%;
  height: 100%;
  min-height: 420px;
  background:
    linear-gradient(#eef1ec 1px, transparent 1px),
    linear-gradient(90deg, #eef1ec 1px, transparent 1px);
  background-size: 24px 24px;
}

.gear-body {
  fill: rgba(20, 107, 99, 0.16);
  stroke: var(--accent);
  stroke-width: 0.45;
  vector-effect: non-scaling-stroke;
}

.internal-body {
  fill: rgba(183, 68, 46, 0.14);
  stroke: var(--accent-2);
}

.bore {
  fill: var(--panel);
  stroke: var(--accent);
  stroke-width: 0.45;
  vector-effect: non-scaling-stroke;
}

.guide {
  fill: none;
  stroke: var(--guide);
  stroke-dasharray: 4 3;
  stroke-width: 0.35;
  vector-effect: non-scaling-stroke;
}

.rack {
  fill: rgba(63, 98, 141, 0.14);
  stroke: var(--rack);
  stroke-width: 0.45;
  vector-effect: non-scaling-stroke;
}

footer {
  padding: 0 clamp(16px, 3vw, 34px) 24px;
  color: var(--muted);
}

footer p {
  max-width: 820px;
  margin-bottom: 0;
  line-height: 1.7;
}

footer p span {
  display: block;
}

@media (max-width: 860px) {
  .topbar,
  .canvas-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    justify-content: flex-start;
  }

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

  .controls,
  .preview {
    position: static;
    max-height: none;
  }

  .preview {
    order: -1;
    height: min(66vh, 560px);
    min-height: 360px;
  }

  #gearSvg {
    min-height: 320px;
  }
}
