:root {
  --bg: #ffffff;
  --fg: #000000;
  --muted: #666666;
  --surface-subtle: #f4f4f4;
  --hairline: #d4d4d4;
  --border: #000000;
  --font-sans: "Helvetica Neue", Helvetica, Arial, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  border-radius: 0;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.strong {
  font-weight: 700;
}

.shell {
  width: 100%;
  max-width: 480px;
  min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

@media (min-width: 481px) {
  body {
    background: var(--surface-subtle);
  }
  .shell {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: -2px;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.wordmark {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge[data-state="connected"] {
  background: var(--fg);
  color: var(--bg);
}

.topbar-actions {
  display: flex;
  gap: 6px;
}

.btn {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: opacity 100ms ease-out;
}

.btn:active:not(:disabled) {
  opacity: 0.72;
}

.btn-solid {
  background: var(--fg);
  color: var(--bg);
}

.btn-outline {
  background: var(--bg);
  color: var(--fg);
}

.btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 11px;
}

.full-btn {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
}

/* Banner */
.banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--fg);
  color: var(--bg);
  font-size: 12px;
  line-height: 1.4;
}

.banner[hidden] {
  display: none;
}

.banner-text {
  text-wrap: pretty;
}

.banner-close {
  border: 1px solid var(--bg);
  background: transparent;
  color: var(--bg);
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  line-height: 1;
  font-size: 16px;
  padding: 0;
}

/* Blocks & Labels */
.block {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

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

.label,
.label-head {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--muted);
  text-transform: uppercase;
}

.label-head {
  margin-bottom: 8px;
}

.meta-right {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  gap: 6px;
}

/* Voltage Hero */
.voltage-display {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 8px 0 14px;
}

.voltage-number {
  font-size: clamp(54px, 16vw, 72px);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.voltage-unit {
  font-size: 22px;
  font-weight: 500;
  color: var(--muted);
}

.voltage-controls {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.step-btn {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 26px;
  font-weight: 400;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-btn:active:not(:disabled) {
  background: var(--fg);
  color: var(--bg);
}

.slider-wrap {
  flex: 1;
  min-width: 0;
  padding-top: 12px;
}

.swiss-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.swiss-range::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--fg);
}

.swiss-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -11px;
  background: var(--fg);
  border: 2px solid var(--fg);
}

.swiss-range::-moz-range-track {
  height: 2px;
  background: var(--fg);
}

.swiss-range::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 0;
  background: var(--fg);
  border: 2px solid var(--fg);
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

/* Output Button */
.output-block {
  padding: 12px 14px;
}

.output-btn {
  width: 100%;
  min-height: 64px;
  padding: 10px 14px;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: opacity 100ms ease-out;
}

.output-btn.is-on {
  background: var(--fg);
  color: var(--bg);
}

.output-btn:active:not(:disabled) {
  opacity: 0.78;
}

.output-primary {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.output-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.75;
}

/* Channel & Pedal 2-col */
.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
}

.cell-block {
  padding: 12px 14px;
}

.cell-block:first-child {
  border-right: 1px solid var(--border);
}

.seg-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border);
}

.seg-btn {
  min-height: 44px;
  border: 0;
  background: var(--bg);
  color: var(--fg);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.seg-btn:first-child {
  border-right: 1px solid var(--border);
}

.seg-btn.is-active {
  background: var(--fg);
  color: var(--bg);
}

/* Presets (Are.na grid blocks) */
.presets-block {
  flex: 1;
}

.presets-head {
  margin-bottom: 10px;
}

.btn-mini {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.btn-mini.is-active {
  background: var(--fg);
  color: var(--bg);
}

.save-hint {
  margin-bottom: 10px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  font-size: 11px;
  font-weight: 600;
}

.save-hint[hidden] {
  display: none;
}

.shortcut-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

@media (max-width: 390px) {
  .preset-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.preset-card {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  min-height: 60px;
  padding: 7px 6px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
  text-align: left;
}

.preset-shortcut {
  min-height: 52px;
  padding: 8px 10px;
  flex-direction: row;
  align-items: center;
}

.preset-card.is-active {
  background: var(--fg);
  color: var(--bg);
}

.preset-card.is-save-target {
  border-style: dashed;
}

.preset-idx {
  font-size: 10px;
  opacity: 0.65;
}

.preset-kicker,
.preset-name {
  font-size: 11px;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-val {
  font-size: 11px;
  font-weight: 600;
}

/* Telemetry Footer */
.telemetry-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.tele-cell {
  padding: 10px 12px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tele-cell:last-child {
  border-right: 0;
}

.tele-timer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-icon {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  width: 22px;
  height: 22px;
  padding: 0;
  font-size: 12px;
  line-height: 1;
}

.tele-val {
  font-size: 14px;
  font-weight: 700;
}

/* Dialogs */
.swiss-dialog {
  width: calc(100% - 24px);
  max-width: 440px;
  max-height: 90dvh;
  padding: 0;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--fg);
}

.swiss-dialog-sm {
  max-width: 360px;
}

.swiss-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.dialog-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-wrap: balance;
}

.dialog-body {
  padding: 0;
  overflow-y: auto;
  max-height: calc(90dvh - 58px);
}

.dialog-section {
  padding: 14px;
  border-bottom: 1px solid var(--hairline);
}

.dialog-section:last-child {
  border-bottom: 0;
}

.help-text {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
  text-wrap: pretty;
}

.field-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.swiss-input {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
}

.spaced-top {
  display: block;
  margin-top: 12px;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
}

.check-row input {
  margin-top: 2px;
  width: 16px;
  height: 16px;
  accent-color: #000000;
}

.sub-details {
  margin-top: 12px;
  border: 1px solid var(--hairline);
}

.details-summary {
  padding: 9px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  background: var(--surface-subtle);
}

.details-content {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.name-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.action-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.swiss-dialog-sm .dialog-body {
  padding: 14px;
}

.confirm-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  text-wrap: pretty;
}

.inline-msg {
  font-size: 12px;
  font-weight: 600;
  min-height: 16px;
}

.log-actions {
  display: flex;
  gap: 8px;
}

.ble-log {
  margin: 6px 0 0;
  padding: 8px;
  border: 1px solid var(--hairline);
  background: var(--surface-subtle);
  font-size: 11px;
  line-height: 1.4;
  max-height: 180px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
