/* Palette (grayscale): #f8f9fa #e9ecef #dee2e6 #ced4da #adb5bd #6c757d #495057 #343a40 #212529 */
:root {
  color-scheme: light;
  --bg: #e9ecef;
  --panel: #f8f9fa;
  --panel-alt: #dee2e6;
  --border: #ced4da;
  --text: #212529;
  --text-muted: #6c757d;
  --accent: #495057;
  --accent-contrast: #f8f9fa;
  --input-bg: #f8f9fa;
  --preview-surface: #dee2e6;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #212529;
  --panel: #343a40;
  --panel-alt: #495057;
  --border: #6c757d;
  --text: #f8f9fa;
  --text-muted: #adb5bd;
  --accent: #adb5bd;
  --accent-contrast: #212529;
  --input-bg: #343a40;
  --preview-surface: #343a40;
}

html[data-theme="oled"] {
  color-scheme: dark;
  --bg: #000000;
  --panel: color-mix(in srgb, #212529 60%, black);
  --panel-alt: color-mix(in srgb, #343a40 55%, black);
  --border: color-mix(in srgb, #495057 45%, black);
  --text: #f8f9fa;
  --text-muted: #adb5bd;
  --accent: #adb5bd;
  --accent-contrast: #000000;
  --input-bg: color-mix(in srgb, #212529 40%, black);
  --preview-surface: color-mix(in srgb, #212529 50%, black);
}

* { box-sizing: border-box; }

body, input, select, button {
  font-family: sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.5rem 2rem 0.5rem;
}

.app-header h1 { margin: 0 0 0.25rem; font-size: 1.5rem; letter-spacing: -0.01em; }
.subtitle { margin: 0; color: var(--text-muted); }

.theme-toggle {
  display: flex;
  gap: 0.2rem;
  padding: 0.2rem;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex: 0 0 auto;
}

.theme-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.theme-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 480px) 1fr;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
  align-items: start;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 1rem;
}

legend { padding: 0 0.5rem; font-weight: 600; }

label {
  display: block;
  font-size: 0.9rem;
  margin: 0.4rem 0;
}

input, select {
  width: 100%;
  padding: 0.35rem 0.5rem;
  margin-top: 0.2rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.95rem;
  background: var(--input-bg);
  color: var(--text);
}

input[type="radio"], input[type="checkbox"] {
  width: auto;
  margin: 0 0.35rem 0 0;
}

fieldset label:has(input[type="radio"]) {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  margin-right: 1rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.hint { font-size: 0.8rem; color: var(--text-muted); margin: 0.4rem 0 0; }

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  font-size: 0.75rem;
  font-style: normal;
  font-weight: 700;
  line-height: 1;
  color: var(--text-muted);
  border: 1px solid var(--text-muted);
  border-radius: 50%;
  cursor: help;
  vertical-align: middle;
}

th .info-icon, legend .info-icon { margin-left: 0.15rem; }

.field-row {
  display: flex;
  align-items: stretch;
}

.field-row input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.unit-label {
  display: flex;
  align-items: center;
  padding: 0 0.5rem;
  margin-top: 0.2rem;
  border: 1px solid var(--border);
  border-left: none;
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  background: var(--panel-alt);
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.color-row {
  display: flex;
  gap: 0.4rem;
  align-items: stretch;
}

.color-row input[type="color"] {
  width: 2.4rem;
  padding: 0.15rem;
  flex: 0 0 auto;
}

.color-row input[type="text"] {
  flex: 1 1 auto;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
}

.tick-fields {
  margin-top: 0.6rem;
  padding: 0.6rem 0.75rem;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.calibration-option {
  padding: 0.6rem 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.option-label {
  margin: 0 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.or-divider {
  display: flex;
  align-items: center;
  margin: 0.6rem 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.or-divider::before, .or-divider::after {
  content: '';
  flex: 1 1 auto;
  border-top: 1px solid var(--border);
}

.or-divider span {
  padding: 0 0.6rem;
}

table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
th, td { padding: 0.25rem; text-align: left; }
td input { width: 100%; }

button {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

button.secondary, button[data-role="remove"] {
  background: transparent;
  color: var(--text);
}

.actions { display: flex; gap: 0.5rem; margin: 1rem 0; }

.tape-preview {
  display: flex;
  justify-content: center;
  padding: 1rem;
  background: var(--preview-surface);
  border-radius: 6px;
  overflow: auto;
}

.tape-preview svg { max-height: 70vh; }

#statsContent { font-size: 0.85rem; }
#statsContent table { width: 100%; }
#statsContent th, #statsContent td { border-bottom: 1px solid var(--border); }

.stats-advanced {
  margin-top: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.stats-advanced summary { font-weight: 700; cursor: pointer; }
.stats-advanced table { margin-top: 0.4rem; margin-bottom: 0.75rem; }

@media print {
  body * { visibility: hidden; }
}
