:root {
  --bg: #0e1318;
  --surface: #161e27;
  --surface-alt: #1d2834;
  --border: #283647;
  --text: #e8eef5;
  --muted: #8c9bb0;
  --accent: #4fd1c5;
  --accent-dark: #143537;
  --danger: #f27474;
  --danger-bg: #3a1d22;
  --ok: #5dd39e;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

#content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(16px + env(safe-area-inset-top)) 16px 20px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

#nav {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
}

.nav-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 4px;
  border-radius: 10px;
  cursor: pointer;
}

.nav-btn.active {
  background: var(--accent-dark);
  color: var(--accent);
  font-weight: 700;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

.subtitle.accent {
  color: var(--accent);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.muted {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}

.mono {
  font-family: var(--mono);
}

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

.row-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.scroll-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 10px;
  scrollbar-width: none;
}

.scroll-row::-webkit-scrollbar {
  display: none;
}

.grow {
  flex: 1;
  min-width: 0;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.val-readout {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
}

.btn {
  border: none;
  border-radius: 10px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  padding: 10px 15px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #091416;
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(242, 116, 116, 0.35);
}

.pill {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 18px;
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.pill.active {
  background: var(--accent);
  color: #091416;
  border-color: transparent;
}

.pill.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: transparent;
}

.curve-canvas {
  width: 100%;
  display: block;
  touch-action: pan-y;
  cursor: crosshair;
}

.field {
  margin-bottom: 10px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type="text"],
input[type="number"],
input[type="url"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--sans);
  font-size: 16px; /* >= 16px prevents iOS Safari auto-zoom */
}

textarea {
  min-height: 76px;
  font-family: var(--mono);
  font-size: 13px;
}

.swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.swatch.selected {
  border-color: #ffffff;
  transform: scale(1.08);
}

.list-item {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 14.5px;
  cursor: pointer;
}

.check-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.badge-ok {
  color: var(--ok);
  font-size: 12px;
  font-weight: 700;
}

.badge-muted {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.safety-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin: 6px 0 12px;
}

/* Modal sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 9, 13, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 12px;
}

@media (min-width: 600px) {
  .modal-backdrop {
    align-items: center;
  }
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 540px;
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(74px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  background: #233142;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
