:root {
  --ink: #1a2433;
  --muted: #5a6a7d;
  --paper: #f3efe6;
  --panel: rgba(255, 252, 246, 0.92);
  --line: #c8bba8;
  --accent: #0d6e6e;
  --accent-deep: #084848;
  --warn: #b33a3a;
  --ok: #1f7a3f;
  --stage: #e8f0f2;
  --shadow: 0 12px 40px rgba(26, 36, 51, 0.12);
  --radius: 14px;
  --font-ui: "Noto Sans TC", sans-serif;
  --font-brand: "Space Grotesk", "Noto Sans TC", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  color: var(--ink);
  background: #0f2a2e;
}

.lab-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 10% 0%, #1a5c5c 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 20%, #3d4a1f 0%, transparent 45%),
    linear-gradient(165deg, #0f2a2e 0%, #1c3d42 45%, #243528 100%);
}

.lab-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.08;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.35) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, black, transparent 85%);
}

.lab-header {
  padding: 1.4rem 1.5rem 0.6rem;
  max-width: 1200px;
  margin: 0 auto;
}

.brand {
  margin: 0;
  font-family: var(--font-brand);
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #f4f1e8;
}

.tagline {
  margin: 0.25rem 0 0;
  color: #b7c9c8;
  font-size: 0.95rem;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: 1200px;
  margin: 0.8rem auto 0;
  padding: 0 1.5rem;
}

.tab {
  font-family: var(--font-ui);
  font-size: 0.92rem;
  border: 1px solid rgba(244, 241, 232, 0.25);
  background: rgba(15, 42, 46, 0.45);
  color: #d7e4e2;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}

.tab:hover {
  border-color: rgba(244, 241, 232, 0.55);
  transform: translateY(-1px);
}

.tab.active {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
  font-weight: 700;
}

.panels {
  max-width: 1200px;
  margin: 1rem auto 2rem;
  padding: 0 1.5rem;
}

.panel {
  display: grid;
  grid-template-columns: minmax(220px, 260px) 1fr;
  gap: 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 620px;
}

.panel[hidden] {
  display: none !important;
}

.controls {
  padding: 1.25rem 1.1rem;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #fffdf8 0%, #f0ebe0 100%);
}

.controls h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-family: var(--font-brand);
}

.controls label {
  display: block;
  font-size: 0.86rem;
  color: var(--muted);
  margin-bottom: 0.85rem;
}

.controls input[type="number"],
.controls select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

.controls input[type="range"] {
  display: block;
  width: 100%;
  margin-top: 0.45rem;
}

.btn-primary {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.btn-primary:hover {
  background: var(--accent-deep);
  transform: translateY(-1px);
}

.hint, .status {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
  margin: 1rem 0 0;
}

/* 預留判定文字高度，避免 SUCCESS/FAILED 出現時撐高左側造成右側畫布跳動 */
#kinematics-status {
  min-height: 2.6em;
  margin-top: 0.75rem;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.3;
}

.status.ok { color: var(--ok); font-weight: 700; }
.status.fail { color: var(--warn); font-weight: 700; }

.stage {
  position: relative;
  background:
    radial-gradient(circle at 80% 10%, rgba(13, 110, 110, 0.08), transparent 40%),
    var(--stage);
  display: flex;
  align-items: flex-start; /* 固定靠上，避免面板高度變化時畫布垂直重置中 */
  justify-content: center;
  padding: 0.75rem;
  min-height: 560px;
}

.stage-split {
  flex-direction: column;
  gap: 0.5rem;
  min-height: 580px;
}

.stage canvas {
  width: 100%;
  height: auto;
  max-height: 560px;
  background: #f7fbfc;
  border: 1px solid #c5d4d8;
  border-radius: 10px;
  display: block;
}

.stage-split canvas {
  max-height: 220px;
}

.stage-split #mechanics-geo {
  max-height: 260px;
}

.stage-note {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.stage-kin {
  flex-direction: column;
  align-items: stretch;
}

.stage-kin canvas {
  max-height: 520px;
}

.kin-result {
  position: absolute;
  top: 1rem;
  left: 1.25rem;
  margin: 0;
  font-family: var(--font-brand);
  font-size: 1.35rem;
  font-weight: 700;
  pointer-events: none;
  min-height: 1.4em;
  z-index: 2;
}

.kin-result.ok { color: var(--ok); }
.kin-result.fail { color: var(--warn); }

@media (max-width: 860px) {
  .panel {
    grid-template-columns: 1fr;
    min-height: unset;
  }

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

  .stage {
    min-height: 420px;
  }
}
