:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --border: #30363d;
  --accent: #14b8a6;
  --text-primary: #e6edf3;
  --text-secondary: #7d8590;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 40px;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

a.icon-btn {
  text-decoration: none;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

/* ── Main ── */
.app-main {
  padding: 16px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Meter ── */
.meter-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 20px 18px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.level-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
  height: 80px;
  overflow: hidden;
}

.level-value {
  font-size: 18px;
  font-weight: 500;
  line-height: 1;
  color: var(--text-secondary);
}

.level-value--active {
  font-size: 72px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -3px;
  color: var(--text-primary);
}

.level-unit {
  font-size: 18px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 4px;
}

.meter-bar-wrap {
  margin-bottom: 10px;
}

.meter-bar {
  width: 100%;
  height: 24px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green) 0%, var(--yellow) 60%, var(--red) 100%);
  transition: width 0.12s ease-out;
  border-radius: 12px;
}

.meter-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  padding: 0 2px;
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.level-chart {
  display: block;
  width: 100%;
  height: 56px;
  margin-top: 12px;
  border-radius: 6px;
}

.peak-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.peak-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  font-weight: 600;
}

.peak-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--yellow);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
}

/* ── Monitor section ── */
.monitor-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.monitor-active-row {
  display: flex;
  gap: 8px;
}

.monitor-active-row .btn {
  width: auto;
  flex: 1;
}


/* ── Buttons ── */
.btn {
  width: 100%;
  padding: 15px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: -0.2px;
}

.btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.btn-start {
  background: var(--green);
  color: #fff;
}

.btn-stop {
  background: var(--red);
  color: #fff;
}

.btn-save {
  background: var(--accent);
  color: #fff;
  flex: 1;
  border-radius: var(--radius);
  padding: 15px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-save:active {
  transform: scale(0.98);
}

.btn-save:disabled,
.btn-save-delay:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.btn-save-delay {
  flex: 1;
  border-radius: var(--radius);
  padding: 15px;
  font-size: 16px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-save-delay:hover {
  background: var(--surface);
}

.btn-save-delay:active {
  transform: scale(0.98);
}


/* ── Controls sections ── */
.controls-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  font-weight: 600;
}

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

.control-label {
  font-size: 15px;
  color: var(--text-primary);
  flex-shrink: 0;
}

/* ── Freq viz strip ── */
.freq-stepper-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.freq-viz {
  display: flex;
  justify-content: space-between;
}

.freq-viz-label {
  font-size: 9px;
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1;
  transition: color 0.15s, font-weight 0.15s;
  user-select: none;
  transform: rotate(-45deg);
  display: inline-block;
  padding-bottom: 6px;
}

.freq-viz-label.active {
  color: var(--accent);
  font-weight: 700;
}

/* ── Stepper ── */
.stepper {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.stepper-btn {
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s;
  touch-action: manipulation;
}

.stepper-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.stepper-btn:active {
  background: rgba(255, 255, 255, 0.14);
}

.stepper-select {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  width: 100px;
  padding: 0 2px;
  appearance: none;
  cursor: pointer;
  height: 40px;
}

.stepper-select option {
  background: var(--surface);
  color: var(--text-primary);
}

/* ── Text inputs ── */
.text-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 15px;
  padding: 10px 12px;
  width: 160px;
  transition: border-color 0.15s;
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
}

input[type="date"].text-input {
  color-scheme: dark;
}

/* ── Results table ── */
.results-title {
  margin-top: 4px;
}

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
}

.results-table th {
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 7px 6px;
  text-align: center;
  font-weight: 600;
}

.results-table th:first-child {
  text-align: left;
  padding-left: 8px;
}

.results-table td {
  padding: 7px 6px;
  text-align: center;
  border-top: 1px solid var(--border);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.results-table td:first-child {
  text-align: left;
  padding-left: 8px;
  color: var(--text-secondary);
  font-size: 11px;
}

.results-table tbody tr:hover {
  background: var(--surface-2);
}

.row-delete-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.row-delete-btn:hover {
  color: var(--red);
  background: rgba(248, 81, 73, 0.12);
}

/* ── Instructions popover ── */
#instructions {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  max-width: 380px;
  width: 90vw;
  padding: 0;
}

#instructions_content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.instructions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#instructions_content h2 {
  font-size: 17px;
  font-weight: 700;
}

#instructions_content p {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-secondary);
}

#instructions_content strong {
  color: var(--text-primary);
}

#instructions_content em {
  font-style: italic;
}
