:root {
  --soil: #5B3A29;
  --olive: #6B7F2A;
  --wheat: #E9D8A6;
  --cream: #FBF7EF;
  --tomato: #D9502B;
  --sky: #4A8FA3;
  --ink: #3A2519;
  --radius: 14px;
  --maxw: 480px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #E4DCC8;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

#app {
  position: relative;
  max-width: var(--maxw);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--cream);
  overflow: hidden;
  box-shadow: 0 0 30px rgba(91, 58, 41, 0.15);
}

[hidden] { display: none !important; }
em { font-style: normal; opacity: 0.7; font-weight: 400; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  user-select: none;
  -webkit-user-select: none;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border: 2px solid var(--soil);
  border-radius: 12px;
  background: var(--cream);
  color: var(--soil);
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); background: var(--wheat); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.icon { padding: 0; width: 44px; font-size: 20px; border-color: transparent; background: transparent; }
.btn.icon:active { background: rgba(91, 58, 41, 0.08); }
.btn.primary { background: var(--tomato); border-color: var(--tomato); color: #fff; }
.btn.primary:active { background: #B8411F; }
.btn.olive { background: var(--olive); border-color: var(--olive); color: #fff; }
.btn.big { width: 100%; min-height: 52px; font-size: 18px; }
.btn:focus-visible, .slider:focus-visible, .place:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  padding: calc(4px + env(safe-area-inset-top)) 8px 4px 12px;
  background: var(--olive);
  color: var(--cream);
  flex: none;
}
.topbar .btn.icon { color: var(--cream); }
.topbar .title { flex: 1; font-weight: 800; font-size: 20px; letter-spacing: 0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title.small { font-size: 15px; }
.coins {
  background: var(--cream);
  color: var(--soil);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 16px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.coins.bump { animation: bump 0.3s ease-out; }
@keyframes bump { 50% { transform: scale(1.18); } }

/* ---------------------------------------------------------------- map */
.map { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.map-art { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.places { position: absolute; inset: 0; }
.place {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 120px;
  padding: 8px 10px;
  border: 3px solid var(--soil);
  border-radius: 16px;
  background: var(--cream);
  color: var(--soil);
  font: inherit;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(91, 58, 41, 0.35);
}
.place:active { transform: translate(-50%, -48%); box-shadow: 0 2px 0 rgba(91, 58, 41, 0.35); }
.place-icon { font-size: 30px; line-height: 1.1; }
.place-name { font-weight: 800; font-size: 15px; }
.place-lock { font-size: 12px; }
.place.locked { opacity: 0.6; filter: grayscale(1); border-style: dashed; box-shadow: none; cursor: default; }
.place.locked:active { transform: translate(-50%, -50%); }
#place-weigh { animation: glow 2.2s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 4px 0 rgba(91, 58, 41, 0.35), 0 0 0 7px rgba(217, 80, 43, 0.25); } }

.map-player { flex: none; padding: 8px 14px 0; font-size: 14px; text-align: center; min-height: 26px; }
.bottombar { flex: none; display: flex; gap: 8px; padding: 8px 12px 12px; }
.bottombar .btn:not(.icon) { flex: 1; }
.bottombar .btn.icon { border-color: var(--soil); }

/* ---------------------------------------------------------------- weighing station */
.bubble {
  flex: none;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 8px 10px 4px;
  padding: 8px 10px;
  background: #fff;
  border: 2px solid var(--wheat);
  border-radius: var(--radius);
}
.bubble-face { font-size: 30px; line-height: 1; flex: none; }
.bubble-body { min-width: 0; }
.bubble-who { font-size: 12px; font-weight: 700; color: var(--olive); }
.bubble-text { font-size: 14.5px; line-height: 1.3; }
.bubble-sub { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.bubble-sub:empty { display: none; }
.chip { font-size: 11.5px; background: var(--cream); border: 1px solid var(--wheat); border-radius: 999px; padding: 2px 7px; }

.plot-wrap { flex: 1 1 45%; min-height: 110px; padding: 0 6px; }
.scene-wrap { flex: 0 0 auto; height: clamp(96px, 16dvh, 140px); cursor: pointer; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.info-row {
  flex: none;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 12px;
  font-size: 13px;
  font-weight: 600;
  background: var(--wheat);
  font-variant-numeric: tabular-nums;
}

.bottom { flex: none; padding: 6px 12px 10px; }
.controls { display: flex; flex-direction: column; gap: 4px; }
.slider-row { display: flex; flex-direction: column; }
.slider-label { font-size: 14px; font-weight: 700; margin-left: 2px; }
.slider-box { display: flex; align-items: center; gap: 6px; }
.slider-end { width: 26px; height: 26px; flex: none; fill: none; stroke: var(--soil); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0.7; }

.slider { position: relative; flex: 1; height: 48px; touch-action: none; cursor: pointer; }
.slider-track {
  position: absolute; left: 0; right: 0; top: 50%; height: 10px; transform: translateY(-50%);
  border-radius: 999px; background: var(--wheat); border: 1px solid rgba(91, 58, 41, 0.25);
}
.slider-thumb {
  position: absolute; top: 50%; width: 40px; height: 40px; transform: translate(-50%, -50%);
  border-radius: 50%; background: var(--tomato); border: 4px solid #fff;
  box-shadow: 0 2px 5px rgba(91, 58, 41, 0.35);
  transition: transform 0.1s;
}
.slider.active .slider-thumb { transform: translate(-50%, -50%) scale(1.12); }
.slider.disabled { opacity: 0.4; cursor: default; }

.controls .btn.big { margin-top: 4px; }
.lock-row { display: flex; gap: 8px; }
/* drag mode: no sliders, a hint and the words pendenza / intercetta instead */
.controls.drag .slider-row { display: none; }
.drag-info { padding: 2px 2px 4px; }
.drag-hint { font-size: 14px; font-weight: 700; }
.drag-words { font-size: 13px; margin-top: 3px; line-height: 1.35; }
.drag-words b { color: var(--tomato); }
/* scanner 100: sliders move by themselves; keep them readable and say so */
.controls.smart .slider.disabled { opacity: 0.9; }
.controls.smart .slider-label::after { content: ' · automatico 🤖'; color: var(--olive); font-weight: 700; }
.lock-row .btn.big { flex: 1; min-width: 0; padding: 0 8px; font-size: 17px; }

.result { display: flex; flex-direction: column; gap: 5px; }
.result-head { display: flex; justify-content: space-between; align-items: center; }
.result-title { font-size: 20px; font-weight: 800; }
.result-coins { font-size: 24px; font-weight: 900; color: var(--soil); font-variant-numeric: tabular-nums; }
.result-coins.pop { animation: bump 0.25s ease-out; }
.result-label { font-size: 13px; font-weight: 600; }
.bar-row { display: grid; grid-template-columns: 52% 1fr; align-items: center; gap: 6px; font-size: 12.5px; }
.bar-name { line-height: 1.15; }
.bar-name .swatch { margin-right: 5px; vertical-align: middle; }
.bar { height: 14px; background: rgba(91, 58, 41, 0.08); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; width: 0; border-radius: 999px; transition: width 0.6s ease-out; }
.bar-fill.me, .swatch.me { background: var(--tomato); }
.bar-fill.best, .swatch.best { background: var(--olive); }
.swatch { display: inline-block; flex: none; width: 14px; height: 4px; border-radius: 2px; }
.result-note { font-size: 12.5px; line-height: 1.3; min-height: 2.6em; }

/* ---------------------------------------------------------------- sheet (shop, leaderboard, settings) */
.sheet { position: absolute; inset: 0; background: rgba(58, 37, 25, 0.45); display: flex; align-items: flex-end; z-index: 10; }
.sheet-panel {
  width: 100%; max-height: 92%; display: flex; flex-direction: column;
  background: var(--cream); border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom);
  animation: slideup 0.2s ease-out;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; padding: 8px 8px 0 16px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 20px; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 4px 14px 16px; touch-action: pan-y; }
.sheet-note { font-size: 13px; opacity: 0.8; margin: 4px 0 10px; line-height: 1.35; }

.shop-item { background: #fff; border: 2px solid var(--wheat); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
.shop-top { display: flex; align-items: center; gap: 10px; }
.shop-icon { font-size: 30px; }
.shop-name { font-weight: 800; font-size: 17px; }
.shop-desc { font-size: 13px; line-height: 1.3; margin: 4px 0 6px; }
.shop-effect { font-size: 13px; font-weight: 600; color: var(--olive); margin-bottom: 8px; }
.pips { display: flex; gap: 3px; margin: 2px 0 8px; }
.pip { flex: 1; height: 8px; border-radius: 3px; background: var(--wheat); }
.pip.on { background: var(--olive); }
.shop-item .btn { width: 100%; }
.preview-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
canvas.preview { flex: 1; min-width: 0; height: 84px; background: #F4ECD8; border-radius: 10px; touch-action: auto; }
.preview-arrow { font-size: 18px; color: var(--olive); flex: none; }

.tabs { display: flex; gap: 6px; margin: 6px 0 10px; }
.tabs .btn { flex: 1; }
.tabs .btn[aria-selected="true"] { background: var(--soil); color: var(--cream); }
.tabs.three .btn { min-width: 0; padding: 0 4px; font-size: 14px; }
.board { list-style: none; margin: 0; padding: 0; }
.board li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: #fff; margin-bottom: 6px; font-size: 15px; }
.board li.me { border: 2px solid var(--tomato); }
.board .rank { font-weight: 800; width: 2ch; text-align: right; }
.board .who { flex: 1; }
.board .val { font-weight: 800; font-variant-numeric: tabular-nums; }
.banner { background: var(--wheat); border-radius: 12px; padding: 8px 12px; font-size: 13.5px; margin-bottom: 10px; }

.settings-row { background: #fff; border-radius: var(--radius); padding: 12px; margin-bottom: 10px; font-size: 14px; line-height: 1.4; }
.settings-row .btn { margin-top: 8px; width: 100%; }
.btn.danger { border-color: var(--tomato); color: var(--tomato); }
.choice-row { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.settings-row .choice-row .btn { margin-top: 0; text-align: left; font-size: 15px; }
.btn.choice[aria-checked="true"] { background: var(--olive); border-color: var(--olive); color: #fff; }

/* ---------------------------------------------------------------- modal */
.modal { position: absolute; inset: 0; background: rgba(58, 37, 25, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal-panel { width: 100%; max-width: 420px; max-height: 92%; overflow-y: auto; background: var(--cream); border-radius: 20px; padding: 18px 16px 14px; animation: slideup 0.2s ease-out; }
.modal-body h2 { margin: 0 0 8px; font-size: 22px; }
.modal-body p { margin: 6px 0; font-size: 15px; line-height: 1.4; }
.modal-body ol { padding-left: 20px; margin: 6px 0; }
.modal-body li { margin: 6px 0; font-size: 14.5px; line-height: 1.4; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.modal-actions .btn { width: 100%; }
.name-choice { width: 100%; text-align: left; font-size: 17px; margin: 5px 0; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.stat { background: #fff; border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12.5px; }

.toast {
  position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--soil); color: var(--cream); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; z-index: 30; max-width: 90%; text-align: center; pointer-events: none;
}

/* ---------------------------------------------------------------- map: Lo smistamento */
.place-svg { display: block; height: 36px; line-height: 0; }
#place-lab .place-name, #place-lab .place-lock { white-space: nowrap; }
.place-svg svg { display: block; }
.place-lock svg, .coin-ic { vertical-align: -3px; }
.place.locked.buyable { opacity: 0.92; filter: none; }
#place-sort:not(.locked) { animation: glow 2.2s ease-in-out infinite; animation-delay: 1.1s; }

/* ---------------------------------------------------------------- sorting station (minigame 2) */
.topbar .btn.icon svg { display: block; margin: auto; }
.coin-ic-slot { display: inline-block; line-height: 0; vertical-align: -3px; }
.s-levelbar { flex: none; display: flex; gap: 8px; align-items: center; padding: 6px 10px 4px; }
.s-levels { flex: none; display: flex; align-items: center; gap: 5px; padding: 0 9px; font-size: 15px; font-variant-numeric: tabular-nums; }
.s-levels svg { display: block; }
.s-level-text { min-width: 0; }
.s-level-title { font-weight: 800; font-size: 15px; }
.s-story { font-size: 12.5px; line-height: 1.3; }
.s-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain; touch-action: pan-y; padding: 0 0 6px; position: relative;
}
.s-caption { font-size: 12.5px; line-height: 1.3; padding: 2px 12px 4px; }
.s-svg { display: block; width: 100%; height: auto; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.s-svg text { font-family: inherit; }
.s-gate { cursor: pointer; }
.s-gate .box { fill: var(--cream); stroke: var(--soil); stroke-width: 2.5; transition: stroke 0.1s, fill 0.1s; }
.s-gate.filled .box { fill: #fff; }
.s-gate .qmark { font-size: 26px; font-weight: 800; fill: var(--soil); }
.s-gate.empty .box { stroke: var(--tomato); stroke-dasharray: 5 4; animation: gatepulse 1.6s ease-in-out infinite; }
@keyframes gatepulse { 50% { fill: #F6E3D6; } }
.s-gate .f-yes, .s-gate .f-no { display: none; }
.s-gate.lit-yes .f-yes, .s-gate.lit-no .f-no { display: inline; }
.s-gate.lit-yes .box { stroke: var(--olive); stroke-width: 4; fill: #EEF2DC; }
.s-gate.lit-no .box { stroke: var(--soil); stroke-width: 4; fill: var(--wheat); }
.s-gate.wrong-q .box { stroke: var(--tomato); stroke-width: 4.5; fill: #FBE1D6; stroke-dasharray: none; }
.s-gate .badge { font-size: 13px; font-weight: 800; fill: #fff; }
.s-item { cursor: pointer; }
.s-item.gone { opacity: 0.22; }
.s-item .ring, .s-pile .ring { display: none; }
.s-item.wrong .ring, .s-pile.wrong .ring { display: inline; }
.s-pile.hidden { display: none; }
.s-pile { cursor: pointer; }

.s-bottom { flex: none; padding: 6px 12px 10px; border-top: 2px solid var(--wheat); background: var(--cream); }
.s-result { min-height: 40px; display: flex; flex-direction: column; gap: 3px; font-size: 13.5px; line-height: 1.3; }
.s-result .btn { align-self: flex-start; margin-top: 2px; }
.s-msg svg { vertical-align: -4px; }
.s-acc { display: flex; flex-direction: column; gap: 3px; }
.s-accbar { display: block; height: 10px; border-radius: 999px; background: rgba(91, 58, 41, 0.1); overflow: hidden; }
.s-accbar span { display: block; height: 100%; background: var(--tomato); border-radius: 999px; transition: width 0.5s ease-out; }
.s-accbar span.full { background: var(--olive); }
.s-pay { color: var(--soil); font-size: 16px; white-space: nowrap; }
.s-actions { display: flex; gap: 8px; margin-top: 6px; }
.s-actions .btn.big { flex: 1; min-width: 0; padding: 0 8px; font-size: 16.5px; }
#s-deliver.ready { animation: glow 1.8s ease-in-out infinite; }
.s-tg.drive-in { animation: drivein 0.7s cubic-bezier(.2,.7,.3,1) both; }
@keyframes drivein { from { transform: translateX(-460px); } }

.s-card {
  position: absolute; left: 8px; right: 8px; bottom: 132px; z-index: 5;
  background: #fff; border: 2px solid var(--soil); border-radius: var(--radius);
  padding: 8px 10px 10px; box-shadow: 0 6px 18px rgba(58, 37, 25, 0.25); max-height: 45%; overflow-y: auto;
  animation: slideup 0.15s ease-out;
}
.s-card-x { position: absolute; right: 2px; top: 2px; }
.s-card-top { display: flex; gap: 8px; align-items: flex-start; padding-right: 40px; }
.s-card-top > svg { flex: none; }
.s-card-title { font-weight: 800; font-size: 14px; margin-bottom: 4px; }
.s-feats { display: flex; flex-wrap: wrap; gap: 4px; }
.s-feat { display: inline-flex; align-items: center; gap: 1px; padding: 1px 4px 1px 2px; border: 1px solid var(--wheat); border-radius: 8px; background: var(--cream); }
.s-feat.unknown { opacity: 0.45; }
.s-label { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 6px; font-size: 13.5px; font-weight: 700; }
.s-label svg.lbl { vertical-align: middle; background: var(--cream); border: 1px solid var(--wheat); border-radius: 6px; }
.s-wrong { color: var(--tomato); display: inline-flex; align-items: center; gap: 4px; }
.s-card .s-msg { font-size: 12.5px; margin-top: 4px; }

.s-palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 7px; margin: 4px 0 10px; }
.s-q { height: 54px; padding: 0; display: flex; align-items: center; justify-content: center; background: #fff; border-color: var(--wheat); }
.s-q svg { display: block; }
.s-q.on { border-color: var(--olive); border-width: 3px; background: #EEF2DC; }
.s-locked svg { vertical-align: middle; }
svg.dim { opacity: 0.4; }
.s-pal-actions { display: flex; flex-direction: column; gap: 8px; }
.s-pal-actions .btn { display: flex; align-items: center; justify-content: center; gap: 6px; }
.s-pal-actions .btn svg { flex: none; }

.s-levels-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.s-lv { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 4px; min-height: 86px; background: #fff; border-color: var(--wheat); font-weight: 600; }
.s-lv.on { border-color: var(--tomato); border-width: 3px; }
.s-lv.closed { opacity: 0.5; }
.s-lv-no { font-size: 20px; font-weight: 900; }
.s-lv-t { font-size: 12px; line-height: 1.15; text-align: center; }
.s-lv-g { font-size: 11px; opacity: 0.7; font-weight: 500; }
.s-lv-b { min-height: 20px; display: flex; align-items: center; gap: 2px; }
.shop-svg { flex: none; }

@media (max-height: 700px) {
  .s-story { font-size: 12px; }
  .s-levelbar { padding-top: 4px; padding-bottom: 2px; }
  .s-result { min-height: 34px; font-size: 13px; }
  .s-bottom { padding-top: 4px; padding-bottom: 6px; }
  .s-card { bottom: 118px; }
}

/* ---------------------------------------------------------------- lab (minigame 3) */
#place-lab:not(.locked) { animation: glow 2.2s ease-in-out infinite; animation-delay: 0.6s; }
.l-levels-ic { display: inline-block; line-height: 0; }
.l-restart { flex: none; margin-left: auto; border-color: var(--wheat) !important; }
.l-restart svg { display: block; margin: auto; }
.l-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain; touch-action: pan-y; padding: 2px 0 8px; position: relative;
}
.l-legend { display: flex; flex-wrap: wrap; gap: 0 9px; font-size: 12.5px; font-weight: 700; margin-top: 1px; }
.l-leg { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
svg.l-shape { display: inline-block; flex: none; vertical-align: -2px; }
.l-field-wrap { padding: 0 6px; height: 280px; }
.l-field-wrap canvas { touch-action: pan-y; }
.l-tree { display: block; width: 100%; height: auto; margin-top: 4px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.l-tree text { font-family: inherit; }
.l-node, .l-leaf { cursor: pointer; }
.l-node .box { fill: #fff; stroke: var(--soil); stroke-width: 2.5; }
.l-node .qmark { font-size: 24px; font-weight: 800; fill: var(--soil); }
.l-node .num { font-size: 11px; font-weight: 800; fill: #fff; }
.l-node.empty .box { fill: var(--cream); stroke: var(--tomato); stroke-dasharray: 5 4; animation: gatepulse 1.6s ease-in-out infinite; }

/* score: two bars (training, test) */
.l-score { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.l-shead { font-size: 12px; font-weight: 700; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.l-srow { display: flex; align-items: center; gap: 6px; min-height: 24px; }
.l-srow > svg { flex: none; }
.l-slab { flex: none; width: 104px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.l-srow .s-accbar { flex: 1; position: relative; overflow: visible; }
.l-srow .s-accbar > span { border-radius: 999px; }
.s-accbar.pass > span { background: var(--olive); }
.s-accbar.fail > span { background: var(--tomato); }
.s-accbar.off { opacity: 0.5; }
.l-best { position: absolute; top: -4px; width: 3px; height: 18px; margin-left: -1.5px; background: var(--olive); border-radius: 2px; box-shadow: 0 0 0 1.5px #fff; }
.l-num { flex: none; min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; }
.l-pay { flex: none; min-width: 66px; margin-left: 4px; display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.l-coins { font-size: 16px; white-space: nowrap; }
.l-coins.pop { animation: bump 0.25s ease-out; }
.l-coins svg, .l-pay svg { vertical-align: -3px; }
#l-next.ready { animation: glow 1.8s ease-in-out infinite; }

/* node pop-up */
.l-pop { position: absolute; inset: 0; z-index: 6; background: rgba(58, 37, 25, 0.45); display: flex; align-items: flex-end; justify-content: center; touch-action: none; }
.l-card {
  width: calc(100% - 12px); max-height: calc(100% - 12px); margin: 0 6px calc(6px + env(safe-area-inset-bottom));
  overflow-y: auto; overscroll-behavior: contain; background: var(--cream); border: 2px solid var(--soil);
  border-radius: var(--radius); padding: 4px 10px 10px; box-shadow: 0 6px 18px rgba(58, 37, 25, 0.3);
  animation: slideup 0.15s ease-out;
}
.l-card-head { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.l-card-head .btn.icon { margin-left: auto; }
.l-card-head .btn.icon svg { display: block; margin: auto; }
.l-pop-n, .l-pop-ok { display: inline-flex; align-items: center; gap: 3px; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.l-pop-n svg, .l-pop-ok svg { flex: none; }
.l-pop-canvas { display: block; width: 100%; height: 280px; touch-action: none; background: var(--cream); }
.l-sides { display: flex; flex-direction: column; gap: 5px; margin-top: 4px; }
.l-side { display: flex; align-items: center; gap: 4px; }
.l-side-pic { flex: none; margin-right: 2px; }
.l-pick {
  position: relative; flex: 1 1 0; min-width: 0; max-width: 56px; height: 44px; padding: 0;
  display: flex; align-items: center; justify-content: center; background: #fff; border-color: var(--wheat);
}
.l-pick.on { border-color: var(--cc, var(--soil)); border-width: 3px; background: color-mix(in srgb, var(--cc, #5B3A29) 16%, white); }
.l-pick.plus.on { --cc: var(--soil); }
.l-pick svg { display: block; }
.l-pick-n { position: absolute; right: 3px; bottom: 1px; font-size: 10px; font-weight: 700; opacity: 0.6; font-variant-numeric: tabular-nums; }
.l-pop-actions { display: flex; gap: 6px; margin-top: 8px; }
.l-pop-actions .btn { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 0 8px; }
.l-pop-actions .btn svg { flex: none; }
.l-hint, .l-del { flex: none; min-width: 56px; font-size: 14px; }
.l-apply { flex: 1; min-height: 50px; font-size: 18px; }
.l-confirm { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 20px; font-weight: 800; padding: 8px 0 0; }
.l-confirm-n { font-size: 26px; color: var(--tomato); }
.l-lv-dots { display: flex; gap: 2px; justify-content: center; }

@media (max-height: 700px) {
  .l-pop-actions { margin-top: 5px; }
  .l-pick { height: 42px; }
  .l-apply { min-height: 46px; }
}

/* ---------------------------------------------------------------- small / short screens */
@media (max-height: 700px) {
  .bubble { margin-top: 4px; padding: 5px 8px; }
  .bubble-text { font-size: 13.5px; }
  .bubble-face { font-size: 24px; }
  .slider { height: 44px; }
  .slider-thumb { width: 36px; height: 36px; }
  .bottom { padding-top: 4px; padding-bottom: 6px; }
  .chip { font-size: 11px; padding: 1px 6px; }
  .bubble-sub { margin-top: 2px; }
  .slider-label { font-size: 13px; }
  .result { gap: 3px; }
  .result-title { font-size: 18px; }
  .result-coins { font-size: 21px; }
  .btn.big { min-height: 46px; }
}
@media (max-width: 380px) {
  #screen-sort .topbar .title, #screen-lab .topbar .title { display: none; }
  #screen-sort .topbar .coins, #screen-lab .topbar .coins { margin-left: auto; }
  .info-row { font-size: 12px; padding: 3px 8px; }
  .info-row span { white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
