:root {
  --fondo: #f5f2ec;          /* the warm white behind the card */
  --carta: #fffdf9;
  --bordo: rgba(40, 30, 20, 0.07);
  --linea: #ebe6de;
  --testo: #1b1916;
  --testo-2: #6f6a62;
  --testo-3: #a9a399;
  --accento: #d0532a;        /* the one accent: terracotta, the needle, the converted value, the approx sign */
  --accento-tenue: #fbe9e1;
  --freddo: #5b8fb8;         /* the cold end of the ruler, only for Temp */
  --caldo: #d0532a;          /* the warm end of the ruler, only for Temp */
  --tacca: #c9c3b8;          /* the ticks */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--fondo);
  color: var(--testo);
  font-family: "Mona Sans Variable", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.stage {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(10px, 3vh, 28px) 16px;
  background: radial-gradient(120% 80% at 50% 0%, #faf8f4 0%, var(--fondo) 60%);
}

/* ---- the card ---- */
.card {
  position: relative;
  width: min(360px, 100%);
  background: var(--carta);
  border-radius: 22px;
  padding: clamp(12px, 3.4vh, 20px) clamp(14px, 4.5vw, 20px) clamp(12px, 3vh, 18px);
  box-shadow:
    0 0 0 1px var(--bordo),
    0 1px 1px rgba(40, 28, 16, 0.04),
    0 4px 10px -4px rgba(40, 28, 16, 0.06),
    0 22px 44px -22px rgba(40, 28, 16, 0.2);
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 2.4vh, 14px);
}
.card::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 30%);
  mask: linear-gradient(#000, #000) content-box exclude, linear-gradient(#000, #000);
  padding: 1px;
}

.head { display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 620; letter-spacing: -0.01em; font-stretch: 112%; }
.brand svg { width: 17px; height: 17px; fill: none; stroke: var(--accento); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.head__title { font-size: 12px; font-weight: 480; color: var(--testo-3); letter-spacing: 0.01em; }

/* ---- the segmented control ---- */
.seg {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  border-radius: 12px;
  background: #f3efe8;
  box-shadow: inset 0 0 0 1px rgba(40, 30, 20, 0.04), inset 0 1px 2px rgba(40, 30, 20, 0.05);
}
.seg__pill {
  position: absolute; left: 0; top: 3px; bottom: 3px; width: 0;
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 0 0 0.5px rgba(40, 30, 20, 0.08), 0 1px 2px rgba(40, 30, 20, 0.08), 0 3px 8px -3px rgba(40, 30, 20, 0.14);
}
.seg__btn {
  position: relative; z-index: 1;
  height: clamp(28px, 7.4vh, 32px);
  font-size: 13px; font-weight: 520; color: var(--testo-2);
  font-stretch: 100%;
  transition: color 0.25s ease;
}
.seg__btn[aria-selected="true"] { color: var(--testo); }
@media (hover: hover) { .seg__btn:hover { color: var(--testo); } }
.seg__btn:focus-visible { outline: 2px solid var(--accento); outline-offset: -2px; border-radius: 9px; }

/* ---- the two rows ---- */
.rows { position: relative; display: flex; flex-direction: column; }
.row {
  position: relative;
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: clamp(4px, 1.4vh, 10px) 2px;
  will-change: transform;
}
.row__num { display: inline-flex; align-items: baseline; gap: 6px; min-width: 0; }
.row .roll {
  font-size: clamp(32px, min(11vw, 9vh), 50px);
  font-weight: 560;
  letter-spacing: -0.035em;
  font-stretch: 100%;
}
.row__sym { font-size: clamp(14px, 3.6vh, 18px); font-weight: 520; color: var(--testo-2); letter-spacing: -0.01em; }
.row__name { font-size: 12px; font-weight: 480; color: var(--testo-3); white-space: nowrap; }
.row--to .roll { color: var(--accento); }
.row--to .row__sym { color: color-mix(in srgb, var(--accento) 70%, #fff); }
.rows__rule { height: 1px; background: var(--linea); margin: 0 2px; }

.swap {
  position: absolute; left: 50%; top: 50%;
  width: 34px; height: 34px; margin: -17px 0 0 -17px;
  display: grid; place-items: center;
  border-radius: 50%;
}
.swap__bg {
  position: absolute; inset: 0; border-radius: 50%;
  background: var(--carta);
  box-shadow: 0 0 0 1px var(--linea), 0 2px 6px -2px rgba(40, 28, 16, 0.14);
}
.swap__ic { position: relative; width: 17px; height: 17px; fill: none; stroke: var(--testo); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.swap:focus-visible { outline: 2px solid var(--accento); outline-offset: 2px; }

/* ---- the ruler ---- */
.ruler {
  position: relative;
  height: clamp(50px, 12.5vh, 64px);
  border-radius: 12px;
  background: linear-gradient(180deg, #faf7f2, #fffdf9);
  box-shadow: inset 0 0 0 1px rgba(40, 30, 20, 0.05);
  cursor: grab;
  touch-action: pan-y;
  user-select: none; -webkit-user-select: none;
  outline: none;
}
.ruler:focus-visible { box-shadow: inset 0 0 0 1px rgba(40, 30, 20, 0.05), 0 0 0 2px var(--accento-tenue), 0 0 0 3px var(--accento); }
.ruler.is-down { cursor: grabbing; }
.ruler__tint { position: absolute; inset: 0; border-radius: inherit; opacity: 0; pointer-events: none; }
.ruler__win {
  position: absolute; inset: 0; overflow: hidden; border-radius: inherit;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 22%, #000 78%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 22%, #000 78%, transparent 100%);
}
.ruler__strip { position: absolute; left: 0; top: 0; height: 100%; overflow: visible; will-change: transform; }
.ruler__strip line { stroke: var(--tacca); stroke-width: 1; stroke-linecap: round; }
.ruler__strip line.mj { stroke: #b3ac9f; }
.ruler__strip line.lb { stroke: #8f887b; stroke-width: 1.2; }
.ruler__strip text { fill: var(--testo-3); font-size: 9.5px; font-weight: 520; text-anchor: middle; font-family: inherit; }
.ruler.is-temp .ruler__strip line { stroke: url(#uc-heat); }
.ruler.is-temp .ruler__strip text { fill: url(#uc-heat); }

.needle {
  position: absolute; left: 50%; top: 6px; bottom: 16px; width: 2px; margin-left: -1px;
  border-radius: 1px; background: var(--accento);
  transform-origin: 50% 0;
  box-shadow: 0 0 0 2px rgba(255, 253, 249, 0.9);
  pointer-events: none;
}
.needle__cap {
  position: absolute; left: 50%; top: -4px; width: 8px; height: 5px; margin-left: -4px;
  background: var(--accento);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

/* ---- the hint ---- */
.hint {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 18px; overflow: hidden;
  font-size: 12.5px; font-weight: 470; color: var(--testo-2);
}
.hint__approx { color: var(--accento); font-weight: 600; }
.hint__txt { display: inline-block; white-space: nowrap; }

/* ---- the drawn pointer of the self-running preview ---- */
.ptr {
  position: fixed; left: 0; top: 0; width: 22px; height: 22px; z-index: 5;
  pointer-events: none; opacity: 0;
  fill: var(--testo); stroke: #fff; stroke-width: 1.4; stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.18));
  transform-origin: 5px 3px;
}

/* ---- rolling digits ---- */
.roll { display: inline-flex; align-items: flex-start; height: 1.08em; line-height: 1.08em; overflow: hidden; }
.roll .s, .roll .d { display: block; height: 1.08em; }
.roll .d { overflow: hidden; }
.roll .d__col { display: block; }
.roll .d__col > span { display: block; height: 1.08em; text-align: center; }

@media (max-height: 440px) {
  .head { display: none; }
}
@media (max-width: 340px) {
  .row__name { display: none; }
}
