:root {
  --bg: #ffffff;
  --ink: #111111;
  --ink-soft: #6f6f6f;
  --ink-faint: #b8b8b8;
  --rule: #ebebeb;
  --hit: rgba(0, 0, 0, 0.04);
  --hit-strong: rgba(0, 0, 0, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
[data-theme="dark"] {
  --bg: #0a0a0a;
  --ink: #f5f5f5;
  --ink-soft: #8a8a8a;
  --ink-faint: #4a4a4a;
  --rule: #1f1f1f;
  --hit: rgba(255, 255, 255, 0.05);
  --hit-strong: rgba(255, 255, 255, 0.1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body, #app {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11", "tnum";
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

/* ---------- shell ---------- */
/* Portrait (default): the top bar is a narrow left sidebar rather than a
   horizontal strip — keeps it easy to see/reach with one hand and doesn't
   eat into the panels' vertical space. */
.app {
  height: 100%;
  display: flex;
  flex-direction: row;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ---------- topbar ---------- */
.topbar {
  flex: 0 0 auto;
  order: 2;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  gap: 14px;
  width: 64px;
  height: auto;
  padding: 14px 8px;
  border-right: none;
  border-left: 1px solid var(--rule);
  background: var(--bg);
}
.brand {
  display: flex; flex-direction: column; align-items: center;
}
.mfg-indicator { text-align: center; line-height: 1.3; }
.topbar-actions { display: flex; flex-direction: column; gap: 10px; align-items: center; margin-top: auto; }

.mfg-stepper { display: flex; flex-direction: column; gap: 1px; border: 1px solid var(--rule); border-radius: 10px; padding: 1px; margin-bottom: 4px; color: var(--ink-faint); }
.mfg-stepper.on { color: var(--ink); border-color: var(--ink); }
.mfg-step { width: 32px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: inherit; transition: background 100ms ease; }
.mfg-step:active:not(:disabled) { background: var(--hit); }
.mfg-step:disabled { opacity: 0.3; cursor: not-allowed; }
.mfg-count { display: inline-flex; align-items: center; gap: 5px; padding: 3px 0; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.tb-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: grid; place-items: center;
  color: var(--ink-soft);
  transition: background 100ms ease, color 100ms ease;
}
.tb-btn:active { background: var(--hit); color: var(--ink); }
.tb-btn:disabled { color: var(--ink-faint); cursor: not-allowed; }
.tb-btn:disabled:active { background: transparent; }
.tb-btn.on { color: var(--ink); background: var(--hit-strong); }

/* :hover only on devices that genuinely have one (mouse/trackpad) — on
   touch, :hover has no real "leave" event to clear it, so it was getting
   stuck "on" after a tap instead of releasing like :active correctly does. */
@media (hover: hover) {
  .mfg-step:hover:not(:disabled) { background: var(--hit); }
  .tb-btn:hover { background: var(--hit); color: var(--ink); }
  .tb-btn:disabled:hover { background: transparent; }
}

.app-version {
  font-size: 9px;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

/* ---------- panels ---------- */
.panels {
  flex: 1 1 auto;
  order: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Landscape / wide: back to the original horizontal top bar — there's
   enough width for the panels to sit side by side without needing the
   sidebar's vertical space savings. */
@media (min-width: 720px) and (orientation: landscape) {
  .app { flex-direction: column; }
  .topbar {
    order: 0;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 0;
    width: auto;
    height: 48px;
    padding: 10px 14px;
    border-left: none;
    border-bottom: 1px solid var(--rule);
  }
  .brand { flex-direction: row; }
  .mfg-indicator { text-align: left; }
  .topbar-actions { flex-direction: row; gap: 2px; margin-top: 0; }
  .mfg-stepper { flex-direction: row; margin-right: 4px; margin-bottom: 0; }
  .mfg-step { width: 28px; height: 32px; }
  .mfg-count { padding: 0 3px; }
  .panels { order: 0; flex-direction: row; min-width: 0; }
}

.panel {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--rule);
  overflow: hidden;
}
.panel:last-child { border-bottom: none; }
@media (min-width: 720px) and (orientation: landscape) {
  .panel { border-bottom: none; border-right: 1px solid var(--rule); }
  .panel:last-child { border-right: none; }
}

/* ---- panel internal grid: top row split L/R, bottom row full ---- */
.row {
  display: flex;
  min-height: 0;
  flex: 1 1 0;
}
.row.top { flex: 1.2 1 0; }
.row.bot { flex: 1 1 0; }

.zone {
  flex: 1 1 0;
  position: relative;
  background: transparent;
  color: inherit;
  border: none;
  cursor: pointer;
  transition: background 100ms ease;
  overflow: hidden;
  text-align: left;
}
.zone:active { background: var(--hit); }
.zone.holding { background: var(--hit-strong); }
.zone[aria-disabled="true"] { opacity: 0.35; cursor: not-allowed; }
.zone[aria-disabled="true"]:active { background: transparent; }

/* internal dividers between zones */
.row.top .zone.add { border-right: 1px solid var(--rule); }
.row.bot { border-top: 1px solid var(--rule); }

/* zone hint labels — small, in safe corners away from center */
.hint {
  position: absolute;
  display: flex; align-items: center; gap: 6px;
  color: var(--ink-faint);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  pointer-events: none;
}
.hint svg { display: block; }
.zone.add .hint { top: 14px; left: 16px; }
.zone.tap .hint { top: 14px; right: 16px; flex-direction: row-reverse; }
.zone.rem .hint { bottom: 14px; left: 50%; transform: translateX(-50%); }

/* center label — token name + big counter, sits over the rows but doesn't catch taps */
.panel-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  padding: 20px 16px 18px;
  z-index: 1;
}
.panel-name {
  font-size: clamp(26px, 4.4vh, 38px);
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  display: flex; align-items: center; gap: 12px;
}
.panel-name svg { color: var(--ink); flex: 0 0 auto; }
.num-stack {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.panel-num {
  font-size: clamp(64px, 15vh, 128px);
  line-height: 0.9;
  font-weight: 600;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  transition: transform 160ms cubic-bezier(.5,.1,.2,1.4);
}
.panel-num.bump { transform: scale(1.06); }
.panel-tapped {
  font-size: clamp(24px, 6vh, 48px);
  line-height: 0.9;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.panel-tapped svg { display: block; }
.panel-tapped b {
  color: var(--ink);
  font-weight: 600;
}
.panel-tapped.zero { color: var(--ink-faint); }
.panel-tapped.zero b { color: var(--ink-faint); font-weight: 400; }

/* number pop on change */
@keyframes flash {
  0% { background: var(--hit-strong); }
  100% { background: transparent; }
}
.zone.flash { animation: flash 380ms ease-out; }

/* sheet — info popover */
.sheet-mask {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: grid; place-items: end center;
  z-index: 100;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  animation: fadein 160ms ease-out;
}
.sheet-mask[hidden] { display: none; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  background: var(--bg);
  border-radius: 16px;
  max-width: 460px;
  width: 100%;
  padding: 20px 22px 22px;
  color: var(--ink);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  animation: rise 220ms cubic-bezier(.2,.7,.2,1);
  /* scroll inside the sheet on short screens so "Got it" stays reachable */
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
}
@keyframes rise { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet h2 {
  font-size: 16px;
  margin: 0 0 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sheet ul {
  list-style: none;
  padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 12px;
}
.sheet li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.sheet li b { color: var(--ink); font-weight: 600; }
.sheet li .sheet-icon {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--hit);
  display: grid; place-items: center;
  color: var(--ink);
  flex: 0 0 28px;
}
.sheet-close {
  width: 100%;
  margin-top: 18px;
  padding: 12px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
}

/* shy tiny label in topbar — manufactor "on" indicator */
.mfg-indicator {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.mfg-indicator[hidden] { display: none; }
