/* Bevel gear generator - page styling.
   The palette matches the desktop program's drawings so the same colour means
   the same member everywhere: pinion blue, wheel rust, pitch line green. */

:root {
  --pinion: #2f6fb0;
  --wheel: #b0562f;
  --pitch: #1f9d55;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1e2227;
  --muted: #6b7278;
  --line: #dcdfe4;
  --accent: #2f6fb0;
  --warn: #b03030;
  --mono: "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --panel: #1c2026;
    --ink: #e6e8ea;
    --muted: #9aa2ab;
    --line: #2c323a;
    --pinion: #5c9ee0;
    --wheel: #d98055;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  font: 14px/1.45 system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand p {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}

.build-stamp { font-family: var(--mono); opacity: 0.75; }

.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

/* ------------------------------------------------------------------ main */

main {
  display: grid;
  grid-template-columns: 402px 1fr;
  min-height: 0;
}

.form {
  overflow-y: auto;
  padding: 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 6px;
  margin: 0 0 14px;
  padding: 10px 12px 12px;
}

legend {
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.row {
  display: grid;
  grid-template-columns: 1fr 170px;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}

.row > span:first-child { cursor: help; }

.check {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
}

.check.inline { margin-bottom: 0; }
.check span { cursor: help; }

input[type="number"], select {
  width: 100%;
  padding: 4px 6px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}

input[type="number"]:disabled {
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 88%, var(--muted));
}

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.optional { display: grid; grid-template-columns: 1fr; gap: 3px; }
.optional .auto {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
}

.hint {
  margin: -3px 0 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}

button {
  padding: 5px 11px;
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { color: var(--muted); cursor: default; }

button.primary {
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-color: transparent;
  padding: 7px 16px;
}

button.primary:disabled { background: var(--muted); }

button.accent {
  font-weight: 600;
  color: var(--accent);
  border-color: var(--accent);
}

button.accent:disabled { color: var(--muted); border-color: var(--line); }

/* ----------------------------------------------------------------- views */

.views {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  min-width: 0;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 12px 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.tab {
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 5px 5px 0 0;
  color: var(--muted);
  background: none;
  margin-bottom: -1px;
}

.tab.active {
  color: var(--ink);
  background: var(--bg);
  border-color: var(--line);
  font-weight: 600;
}

.view { display: none; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.view.active { display: grid; }

.view-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 12px;
  font-size: 12px;
  border-bottom: 1px solid var(--line);
}

.view-bar select { width: auto; }
.view-bar label { display: flex; align-items: center; gap: 6px; }
.grow { flex: 1; }
.muted { color: var(--muted); }
#mesh-info.stale { color: var(--warn); }

.canvas-wrap { position: relative; min-height: 0; }
.canvas-wrap canvas { display: block; width: 100%; height: 100%; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--bg);
}

/* `display: flex` above would otherwise beat the user agent's [hidden] rule
   and the overlay would stay on top of the finished model. */
.overlay[hidden] { display: none; }

.overlay p { margin: 0; }

/* --------------------------------------------------------------- results */

.results {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  /* Drag the top edge to trade table height against drawing height, the way
     the desktop's splitter does. */
  height: 260px;
  min-height: 96px;
  max-height: 62vh;
  resize: vertical;
  overflow: hidden;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.table-wrap { overflow: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-weight: 600;
  padding: 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

/* The value column holds preformatted, right-aligned numbers, so let it take
   exactly the width its content needs and give the rest to the source. */
thead th:nth-child(2) { text-align: right; }
th:nth-child(2), td:nth-child(2) { width: 1%; white-space: pre; }

tbody td { padding: 3px 12px; border-bottom: 1px solid var(--bg); }
tbody tr:nth-child(even) { background: color-mix(in srgb, var(--panel) 94%, var(--ink)); }
tbody td:nth-child(2) {
  font-family: var(--mono);
  text-align: right;
  white-space: pre;
}
tbody td:nth-child(3) { color: var(--muted); font-size: 11.5px; }
tbody tr.group td { font-weight: 600; color: var(--muted); background: none; }

.messages {
  margin: 0;
  padding: 8px 12px;
  max-height: 104px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: pre-wrap;
  border-top: 1px solid var(--line);
}

.messages.bad { color: var(--warn); }

/* ------------------------------------------------------------- actionbar */

.actionbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 18px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.actionbar label.inline { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.actionbar input[type="number"] { width: 62px; }

.status { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.progress { display: flex; align-items: center; gap: 9px; cursor: help; }
/* Same trap as the overlay: `display: flex` beats the user agent's
   [hidden] rule, so an idle 0% bar sat under the button. */
.progress[hidden] { display: none; }

.progress-track {
  width: 220px;
  height: 8px;
  overflow: hidden;
  background: var(--line);
  border-radius: 4px;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  /* Slightly slower than the 800 ms poll, so the bar creeps between answers
     instead of stepping. */
  transition: width 0.9s linear;
}

.progress-percent {
  min-width: 38px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ------------------------------------------------------------- downloads */

.downloads {
  position: fixed;
  right: 18px;
  bottom: 62px;
  width: 380px;
  max-height: 60vh;
  overflow: auto;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}

.downloads .close {
  position: absolute;
  top: 6px;
  right: 8px;
  padding: 1px 7px;
  font-size: 16px;
  line-height: 1.2;
  color: var(--muted);
  background: none;
  border: none;
}

.downloads h2 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.downloads ul { list-style: none; margin: 0; padding: 0; }
.downloads li { display: flex; align-items: baseline; gap: 8px; padding: 3px 0; font-size: 12.5px; }
.downloads li a { color: var(--accent); font-family: var(--mono); }
.downloads li.step a { font-weight: 700; }
.downloads li .size { margin-left: auto; color: var(--muted); font-size: 11px; }
.downloads details { margin-top: 10px; font-size: 12px; }
.downloads pre {
  max-height: 300px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 11px;
  white-space: pre;
}

/* ----------------------------------------------------------------- tooltip */

.tip {
  position: fixed;
  z-index: 50;
  max-width: 360px;
  padding: 9px 11px;
  font-size: 12px;
  line-height: 1.42;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

/* ------------------------------------------------------------- signing in */

.whoami {
  align-self: center;
  margin-right: 6px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.whoami::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--pitch);
  vertical-align: 1px;
}

.whoami[hidden] { display: none; }

.auth-note { font-size: 12px; color: var(--muted); }
.auth-note[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.45);
}

.modal[hidden] { display: none; }

.modal-card {
  width: 100%;
  max-width: 440px;
  padding: 22px 24px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.modal-card h2 { margin: 0 0 10px; font-size: 16px; }
.modal-card p { margin: 0 0 10px; font-size: 13px; line-height: 1.5; }
.modal-card p.muted { font-size: 12.5px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}
