:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --ink: #1c1c1e;
  --muted: #5b5b60;
  --line: #dcdad5;
  --field-line: #c9c7c1;
  --accent: #33566e;
  --accent-dark: #274458;
  --pass: #1e7a34;
  --warn: #96690a;
  --fail: #b3261e;
  --radius: 12px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 20px 4px;
}

.wordmark {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.topbar-note {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 20px 24px;
  align-items: start;
}

.controls, .stage {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

/* Cult UI TextureCard adaptation: 12px radius card, 1px border,
   inset top highlight, and a fine dot texture strip at the top edge. */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: inset 0 1px 0 #ffffff;
}

.texture-card { padding-top: 12px; }

.texture-strip {
  height: 10px;
  border-radius: 6px;
  margin-bottom: 12px;
  background-color: #f1f1ec;
  background-image: radial-gradient(circle, #d5d5cf 1px, transparent 1.4px);
  background-size: 8px 8px;
}

.card h2 {
  font-size: 16px;
  font-weight: 650;
  margin: 0 0 14px;
}

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.field label, .toggle-label {
  display: block;
  font-size: 14px;
  font-weight: 550;
  margin-bottom: 6px;
}

.field .value {
  float: right;
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

input[type="text"], textarea {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--field-line);
  border-radius: 8px;
  padding: 8px 10px;
}

textarea { resize: vertical; }

input[type="file"] {
  font: inherit;
  font-size: 14px;
  max-width: 100%;
}

.field-note {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.color-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--field-line);
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
}

.hex {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.segmented {
  display: flex;
  border: 1px solid var(--field-line);
  border-radius: 9px;
  overflow: hidden;
  margin-bottom: 14px;
}

.seg-btn {
  flex: 1 1 0;
  font: inherit;
  font-size: 14px;
  padding: 8px 4px;
  background: #ffffff;
  color: var(--ink);
  border: 0;
  border-right: 1px solid var(--field-line);
  cursor: pointer;
  min-height: 40px;
}

.seg-btn:last-child { border-right: 0; }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: #ffffff; font-weight: 600; }

.toggle-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toggle-field .toggle-label { margin-bottom: 0; }

/* Watermelon UI Switch adaptation: 52 by 32 pill track, 26px knob inset 3px,
   spring timing on the knob, plain colors only. */
.wm-switch {
  flex: none;
  width: 52px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--field-line);
  background: #e4e4df;
  padding: 0;
  cursor: pointer;
  position: relative;
}

.wm-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid var(--field-line);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.wm-switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.wm-switch[aria-checked="true"] .wm-knob { transform: translateX(20px); border-color: transparent; }

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.btn {
  font: inherit;
  font-size: 15px;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 9px;
  border: 1px solid var(--field-line);
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  text-align: center;
}

.btn:hover { border-color: var(--muted); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.status {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--accent-dark);
  min-height: 1.2em;
}

.error {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--fail);
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.preview-head h2 { margin: 0; }

/* Skiper UI Skiper4 adaptation: segmented pill with a sliding indicator. */
.skiper-toggle {
  position: relative;
  display: inline-flex;
  background: #ecece9;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}

.skiper-indicator {
  position: absolute;
  top: 3px;
  left: 3px;
  height: calc(100% - 6px);
  width: 86px;
  background: #ffffff;
  border: 1px solid var(--field-line);
  border-radius: 999px;
  transition: transform 0.25s ease;
}

.skiper-toggle.show-improved .skiper-indicator { transform: translateX(86px); }

.skiper-btn {
  position: relative;
  z-index: 1;
  width: 86px;
  font: inherit;
  font-size: 13.5px;
  padding: 6px 0;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  min-height: 34px;
}

.skiper-btn.is-active { color: var(--ink); font-weight: 600; }
.skiper-btn:disabled { color: #a3a3a0; cursor: default; }

#lessonCanvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #222222;
}

.note {
  margin: 0 0 12px;
  font-size: 13.5px;
  color: var(--muted);
}

.results { display: flex; flex-direction: column; }

.result-row {
  display: grid;
  grid-template-columns: 92px 1fr 1fr 1.2fr;
  gap: 10px;
  align-items: baseline;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 14.5px;
}

.result-row:first-child { border-top: 0; padding-top: 2px; }
.result-row:last-child { padding-bottom: 0; }

.region { font-weight: 650; }
.metric { color: var(--muted); font-variant-numeric: tabular-nums; }
.metric strong { color: var(--ink); font-weight: 600; }

.status-cell { display: inline-flex; align-items: center; gap: 8px; }

.dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #a3a3a0;
}

.dot.pass { background: var(--pass); }
.dot.warn { background: var(--warn); }
.dot.fail { background: var(--fail); }
.status-pass { color: var(--pass); }
.status-warn { color: var(--warn); }
.status-fail { color: var(--fail); }

.footer {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px 28px;
}

.footer p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 14px 20px; }
  .topbar { padding: 16px 14px 2px; flex-wrap: wrap; gap: 4px 12px; }
  .result-row { grid-template-columns: 84px 1fr 1fr; }
  .status-cell { grid-column: 1 / -1; }
  .btn, .seg-btn { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .wm-knob, .skiper-indicator { transition: none; }
}
