:root {
  color-scheme: dark;
  --bg: #101412;
  --panel: #18211d;
  --panel-2: #202b25;
  --ink: #f5f1e8;
  --muted: #aeb9af;
  --line: #33423a;
  --accent: #f2b84b;
  --accent-2: #48d19a;
  --danger: #ef705d;
  --track: #111816;
  --switch: #e9e1d1;
  --switch-on: #54d28f;
  --shadow: rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(242, 184, 75, 0.13), transparent 36%),
    radial-gradient(circle at 85% 18%, rgba(72, 209, 154, 0.16), transparent 30%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(760px, calc(100% - 20px));
  min-height: 100vh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 0 max(18px, env(safe-area-inset-bottom));
  display: block;
}

.workbench {
  border: 1px solid var(--line);
  background: rgba(24, 33, 29, 0.9);
  box-shadow: 0 22px 55px var(--shadow);
  border-radius: 8px;
  padding: clamp(14px, 4vw, 24px);
}

.topbar {
  display: grid;
  gap: 14px;
}

.brand-block {
  min-width: 0;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.brand-logo {
  width: 58px;
  height: 58px;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.38));
}

.eyebrow,
.readout-label,
.summary-cell span,
.field span,
legend {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 13vw, 4.8rem);
  line-height: 0.9;
}

.readout {
  width: 100%;
}

.decimal-control {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  gap: 8px;
}

.decimal-control input {
  min-width: 0;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #0f1714;
  font-size: max(1.55rem, 16px);
  font-weight: 800;
  text-align: center;
}

.step-button,
.reset-button {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel-2);
  cursor: pointer;
}

.step-button {
  display: grid;
  place-items: center;
  font-size: 1.12rem;
}

.step-button:hover,
.reset-button:hover,
.segmented span:hover {
  border-color: var(--accent);
}

.settings-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 23, 20, 0.76);
}

.settings-panel summary {
  min-height: 52px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 0 14px;
  cursor: pointer;
  list-style: none;
}

.settings-panel summary::-webkit-details-marker {
  display: none;
}

.settings-panel summary::after {
  content: "▼";
  justify-self: end;
  color: var(--accent);
  font-size: 0.85rem;
  transition: transform 160ms ease;
}

.settings-panel[open] summary::after {
  transform: rotate(180deg);
}

.settings-panel summary span {
  font-weight: 900;
}

.settings-panel summary strong {
  min-width: 0;
  justify-self: end;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-grid {
  display: grid;
  gap: 12px;
  padding: 0 14px 14px;
}

.machine {
  margin-top: 16px;
  border-radius: 8px;
  border: 1px solid #27342f;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04), transparent 14%, transparent 86%, rgba(255, 255, 255, 0.04)),
    #141b18;
  padding: 18px;
}

.chip-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--track);
}

.chip-header span {
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
}

.dip-body {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(var(--switches), minmax(56px, 1fr));
  gap: 10px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.switch-wrap {
  min-width: 56px;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 6px;
  justify-items: center;
  scroll-snap-align: center;
}

.switch-label {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr 1fr;
  align-items: center;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.switch-label span {
  writing-mode: horizontal-tb;
}

.dip-switch {
  width: 100%;
  min-width: 42px;
  aspect-ratio: 0.58;
  border: 1px solid #394b43;
  border-radius: 6px;
  padding: 7px;
  background:
    linear-gradient(#26322d, #111816),
    var(--track);
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 6px;
  cursor: pointer;
  box-shadow: inset 0 0 0 2px #0b100e;
  touch-action: manipulation;
}

.dip-switch::before,
.dip-switch::after {
  content: "";
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
}

.dip-switch .paddle {
  grid-row: 2;
  border-radius: 4px;
  background: linear-gradient(180deg, #fff7e7, var(--switch));
  box-shadow: 0 3px 9px rgba(0, 0, 0, 0.45);
}

.dip-switch.is-up .paddle {
  grid-row: 1;
}

.dip-switch.is-one .paddle {
  background: linear-gradient(180deg, #d8ffe7, var(--switch-on));
}

.dip-switch:focus-visible,
.step-button:focus-visible,
.reset-button:focus-visible,
input:focus-visible,
select:focus-visible,
.segmented input:focus-visible + span {
  outline: 3px solid rgba(242, 184, 75, 0.75);
  outline-offset: 3px;
}

.bit-scale {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(var(--switches), minmax(56px, 1fr));
  gap: 10px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.bit-scale span {
  min-width: 56px;
  text-align: center;
}

.summary-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.summary-cell {
  min-width: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 20, 0.88);
  padding: 12px;
}

.summary-cell strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 1.05rem;
}

.field,
fieldset {
  display: grid;
  gap: 8px;
  margin: 0;
}

fieldset {
  border: 0;
  padding: 0;
}

select {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #0f1714;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.segmented span {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  padding: 0 10px;
  color: var(--muted);
  background: #111816;
  cursor: pointer;
  font-weight: 800;
}

.segmented input:checked + span {
  color: #111816;
  border-color: var(--accent-2);
  background: var(--accent-2);
}

.reset-button {
  width: 100%;
  font-weight: 900;
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 28px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) 320px;
    align-items: start;
  }

  .brand-block {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .brand-logo {
    width: 74px;
    height: 74px;
  }

  .settings-grid {
    grid-template-columns: 180px 1fr 1fr 120px;
    align-items: end;
  }

  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .app-shell {
    width: 100%;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .workbench {
    min-height: 100vh;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    padding-right: 10px;
    padding-left: 10px;
  }

  .machine {
    padding: 10px;
  }

  .chip-header span {
    padding: 5px 8px;
    font-size: 0.7rem;
  }

  .dip-body,
  .bit-scale {
    grid-template-columns: repeat(var(--switches), minmax(0, 1fr));
    gap: 4px;
    overflow-x: visible;
  }

  .dip-body.allow-scroll,
  .bit-scale.allow-scroll {
    grid-template-columns: repeat(var(--switches), minmax(30px, 1fr));
    overflow-x: auto;
  }

  .switch-wrap {
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }

  .switch-label {
    display: none;
  }

  .dip-switch {
    min-width: 0;
    min-height: 62px;
    padding: 4px;
    gap: 3px;
  }

  .bit-scale span {
    min-width: 0;
    font-size: 0.7rem;
  }

  .bit-scale.allow-scroll span {
    min-width: 30px;
  }

  .settings-panel summary {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .settings-panel summary strong {
    font-size: 0.74rem;
  }

  .brand-block {
    grid-template-columns: 50px minmax(0, 1fr);
    gap: 10px;
  }

  .brand-logo {
    width: 50px;
    height: 50px;
  }

  h1 {
    font-size: clamp(2rem, 15vw, 3.6rem);
  }
}
