:root {
  --panel: #FBF7F0; --ink: #24170F; --muted: #6E5B4C; --recess: #EFE6D8;
  --tick: #A18F7F; --band: #BFAF9D; --knob: #24170F; --knurl: #4A3527;
  --knob-text: #FBF7F0; --knob-muted: #C9B8A6; --accent: #8B4319; --on-accent: #FFFFFF;
  --g-track: #CFC2B1; --g-band: #9C8873; --bean-edge: transparent;
  --logo-gear: #24170F; --logo-center: #FBF7F0;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --panel: #1A110C; --ink: #F3E9DA; --muted: #BBA792; --recess: #2C1E16;
  --tick: #7D6A5A; --band: #5E4B3C; --knob: #3A281D; --knurl: #5E4B3C;
  --knob-text: #F3E9DA; --knob-muted: #C9B8A6; --accent: #C9722F; --on-accent: #1A110C;
  --g-track: #4F3D30; --g-band: #8A7560; --bean-edge: #A87A52;
  --logo-gear: #F3E9DA; --logo-center: #1A110C;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--panel); overscroll-behavior: none; }
body {
  color: var(--ink);
  font-family: 'Barlow Semi Condensed', -apple-system, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
button, select { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
h1, h2, p { margin: 0; }

#app {
  height: 100vh; height: 100dvh;
  max-width: 480px; margin: 0 auto;
  padding: max(env(safe-area-inset-top), 10px) 20px max(env(safe-area-inset-bottom), 16px);
  display: flex; flex-direction: column; gap: 10px; overflow: hidden;
}

/* Phone turned sideways: swap the app's width and height and turn it back upright. */
:root[data-rotate], :root[data-rotate] body { overflow: hidden; }
:root[data-rotate] #app {
  position: fixed; left: 0; top: 0; margin: 0; max-width: none;
  width: 100vh; width: 100dvh; height: 100vw; height: 100dvw;
  padding-top: max(env(safe-area-inset-left), env(safe-area-inset-right), 10px);
  padding-bottom: max(env(safe-area-inset-left), env(safe-area-inset-right), 16px);
  transform-origin: 0 0;
}
:root[data-rotate="ccw"] #app { transform: translateY(100vh) rotate(-90deg); transform: translateY(100dvh) rotate(-90deg); }
:root[data-rotate="cw"] #app { transform: translateX(100vw) rotate(90deg); transform: translateX(100dvw) rotate(90deg); }

.head { display: flex; align-items: center; justify-content: space-between; height: 44px; flex: none; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand svg { display: block; flex: none; }
.brand h1 { font-size: 26px; font-weight: 700; letter-spacing: .01em; }
.brand h1 span { color: var(--accent); }
.head h1 { font-size: 22px; font-weight: 600; }
.brand h1 { font-size: 26px; }
.icon-btn { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; flex: none; }
.icon-btn.left { margin-left: -10px; }
.icon-btn.right { margin-right: -10px; }
.spacer { width: 34px; }

.tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 14px; background: var(--recess); flex: none; }
.tab { height: 58px; border-radius: 11px; font-size: 13px; font-weight: 600; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.tab.on, .opt.on { background: var(--knob); color: var(--knob-text); }
:root[data-theme="dark"] .tab.on, :root[data-theme="dark"] .opt.on { background: var(--ink); color: var(--panel); }

.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: space-evenly; }
.readouts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); text-align: center; flex: none; }
.readout-col { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.ro-label { font-size: 13px; font-weight: 700; letter-spacing: .14em; line-height: 16px; }
.ro-val { font-size: 42px; font-weight: 500; line-height: 44px; }
.ro-unit { height: 44px; display: flex; align-items: center; justify-content: center; padding: 0 8px; font-size: 14px; font-weight: 500; }
.ro-unit.fixed { color: var(--muted); }
.ro-pill { padding: 2px 8px; border: 1px solid var(--muted); border-radius: 11px; display: flex; align-items: center; gap: 4px; line-height: 16px; }
.stage.compact .ro-label { line-height: 14px; }
.stage.compact .ro-val { font-size: 36px; line-height: 38px; }
.gears { position: relative; flex: none; align-self: center; }
.gear { position: absolute; top: 0; border-radius: 50%; touch-action: none; cursor: ns-resize; -webkit-touch-callout: none; }
.gear input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.gear-face, .gear-face * { pointer-events: none; }
.gear-face svg { display: block; overflow: visible; }
.g-turn { transition: transform .12s linear; }
.g-body { fill: var(--logo-gear); }
.g-win { fill: var(--panel); }
.g-ring { stroke: var(--logo-gear); }
.gear-pm { position: absolute; display: flex; gap: 8px; }
.round-btn { width: 44px; height: 44px; border-radius: 22px; background: var(--recess); display: flex; align-items: center; justify-content: center; }
#gear-beans .f-base { fill: #3E1F0E; }
.f-g1 { fill: #6B3212; }
.f-g2 { fill: #8B4319; }
.f-g3 { fill: #A9652F; }
#gear-water .f-base { fill: #2F7F94; }
.f-shade { fill: #236779; }
.f-surface { fill: none; stroke: #8FD3DF; stroke-width: 2; }
.gear-hint { flex: none; text-align: center; font-size: 14px; line-height: 18px; color: var(--muted); }
.stage.compact .gear-hint { display: none; }
.grind-panel { flex: none; border-radius: 14px; background: var(--recess); padding: 6px 12px 2px; }
.g-head { height: 20px; display: flex; justify-content: space-between; align-items: baseline; line-height: 20px; }
.g-name { font-size: 15px; font-weight: 700; }
.g-sub { font-size: 13px; color: var(--muted); }
.g-row { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 3px; }
.g-seg { height: 44px; display: flex; align-items: center; justify-content: center; }
.g-seg span { display: block; width: 100%; height: 10px; border-radius: 5px; background: var(--g-track); }
.g-seg.band span { background: var(--g-band); }
.g-seg.on span { height: 22px; background: var(--accent); }
.face svg { overflow: visible; }
.face, .face * { pointer-events: none; }
.face { position: absolute; inset: 0; }
.face svg { display: block; width: 100%; height: 100%; overflow: visible; }
.s-minor { stroke: var(--tick); stroke-width: 1.2; }
.s-major { stroke: var(--ink); stroke-width: 1.8; }
.s-track { stroke: var(--recess); stroke-width: 3; stroke-linecap: round; }
.s-band { stroke: var(--band); stroke-width: 7; stroke-linecap: round; }
.s-arc, .s-ind { stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }
.f-knob { fill: var(--knob); }
.s-knurl { stroke: var(--knurl); stroke-width: 4; stroke-dasharray: 1.6 3.4; }
.scale { position: absolute; transform: translate(-50%, -50%); font-weight: 500; color: var(--muted); }
.readout { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--knob-text); }
.val { font-weight: 500; line-height: 1; }
.unit { margin-top: 3px; padding: 1px 6px; border: 1px solid transparent; border-radius: 9px; display: flex; align-items: center; gap: 3px; font-weight: 500; line-height: 1.2; color: var(--knob-muted); }
.unit.tappable { border-color: var(--knurl); }
.dial-label { position: absolute; left: 0; right: 0; text-align: center; font-weight: 700; letter-spacing: .14em; }
.dial-sub { position: absolute; text-align: center; }
.sub1 { font-weight: 600; line-height: 18px; white-space: nowrap; }
.sub2 { color: var(--muted); line-height: 17px; white-space: nowrap; }

.strip { display: flex; gap: 8px; flex: none; }
.cell { height: 60px; border-radius: 14px; background: var(--recess); display: flex; flex-direction: column; align-items: center; justify-content: center; width: 78px; flex: none; text-align: center; }
.cell.ratio { flex: 1; min-width: 0; flex-direction: row; justify-content: space-between; padding: 0 4px; }
.cell small { display: block; font-size: 12px; font-weight: 500; line-height: 16px; color: var(--muted); }
.cell b { display: block; font-size: 22px; font-weight: 600; line-height: 26px; }

.primary { height: 56px; flex: none; border-radius: 16px; background: var(--accent); color: var(--on-accent); font-size: 20px; font-weight: 600; }
.primary.dark { background: var(--knob); color: var(--knob-text); }
.auto-note { height: 56px; flex: none; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 16px; font-weight: 500; color: var(--muted); }

.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 8px 4px; border-radius: 14px; background: var(--recess); text-align: center; flex: none; }
.summary small { display: block; font-size: 12px; font-weight: 500; line-height: 16px; color: var(--muted); }
.summary b { display: block; font-size: 18px; font-weight: 600; line-height: 22px; white-space: nowrap; }
.clock-wrap { display: flex; justify-content: center; flex: none; }
.clock { position: relative; }
.now { text-align: center; flex: none; }
.now b { display: block; font-size: 30px; font-weight: 600; line-height: 36px; }
.now span { font-size: 15px; line-height: 20px; color: var(--muted); }
.steps { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.step { height: 40px; flex: none; padding: 0 12px; border-radius: 10px; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; font-size: 16px; }
.step.done { color: var(--muted); }
.step.cur { background: var(--recess); font-weight: 600; }

.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 6px; margin-bottom: calc(-1 * max(env(safe-area-inset-bottom), 16px)); padding-bottom: max(env(safe-area-inset-bottom), 16px); }
.section { margin: 8px 0 0 2px; font-size: 13px; font-weight: 700; letter-spacing: .12em; color: var(--muted); }
.card { border-radius: 14px; background: var(--recess); overflow: hidden; flex: none; }
.row { min-height: 52px; padding: 0 4px 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 17px; font-weight: 500; }
.card > * + * { border-top: 1px solid var(--panel); }
.opts { display: flex; gap: 2px; }
.opt { min-width: 44px; height: 44px; padding: 0 8px; border-radius: 10px; font-size: 15px; font-weight: 600; }
.link-row { width: 100%; min-height: 52px; padding: 6px 10px 6px 14px; text-align: left; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 17px; font-weight: 500; }
.link-row span span { display: block; line-height: 22px; }
.link-row .small { font-size: 14px; font-weight: 400; line-height: 18px; color: var(--muted); }
select { height: 44px; border: 0; background: transparent; font-size: 15px; font-weight: 600; margin-right: 6px; }
.text-btn { min-height: 44px; flex: none; font-size: 16px; font-weight: 600; text-decoration: underline; }
.lead { margin: 0 2px; font-size: 15px; line-height: 20px; color: var(--muted); flex: none; }
.def-row { min-height: 76px; }
.def-row .small { font-size: 13px; font-weight: 400; line-height: 17px; color: var(--muted); }
.def-row .name { line-height: 22px; }
.stepper { display: flex; align-items: center; flex: none; }
.stepper b { width: 76px; text-align: center; font-size: 21px; font-weight: 600; white-space: nowrap; }
.readonly { padding-right: 44px; flex: none; }
.readonly b { display: block; width: 76px; text-align: center; font-size: 21px; font-weight: 600; white-space: nowrap; }

.intro { margin: 0 2px 4px; font-size: 16px; line-height: 22px; flex: none; }
.src { padding: 10px 14px; }
.src div:first-child { display: flex; justify-content: space-between; gap: 12px; font-size: 17px; font-weight: 600; line-height: 22px; }
.src div:last-child { font-size: 14px; line-height: 19px; color: var(--muted); }
.prose { padding: 12px 14px; font-size: 15px; line-height: 21px; }
.prose p + p { margin-top: 8px; }
.notice { margin-top: 10px; border: 1.5px solid var(--ink); border-radius: 14px; padding: 12px 14px; flex: none; }
.notice h2 { margin-bottom: 4px; font-size: 17px; font-weight: 700; line-height: 22px; }
.notice p { font-size: 15px; line-height: 21px; }
.ext { min-height: 44px; flex: none; display: flex; align-items: center; justify-content: center; color: var(--ink); font-size: 16px; font-weight: 600; }
