/* ------------------------------------------------------------------
   Design "Quaderno scuro" (chosen 2026-10-08): dark navy background,
   thin blue-grey lines to separate the parts, ochre only for details.
   The app is always dark. All colours are defined here once.
   ------------------------------------------------------------------ */
:root {
  --bg: #161c26;          /* page background */
  --surface: #1d2532;     /* tile, panels, menu */
  --ink: #e8ecf2;         /* main text */
  --muted: #8e9aab;       /* secondary text, Resetta */
  --line: #6f8bb5;        /* lines, borders, draw button */
  --line-ink: #10151d;    /* icon on the draw button */
  --ochre: #d4a853;       /* small accents only */
  --off: #39424f;         /* disabled / excluded */
  --gap: clamp(12px, 4dvh, 36px); /* main vertical spacing */
  color-scheme: dark;
}

/* ------------------------------------------------------------------
   Base
   ------------------------------------------------------------------ */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* One column filling the screen, from top to bottom:
   range, tile, draw button, status box, switch, Resetta. */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px max(16px, env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------------
   1. Range "DA | A", underlined, with a dashed divider
   ------------------------------------------------------------------ */
.range {
  display: flex;
  border-bottom: 1.5px solid var(--line);
  padding-bottom: 14px;
}

.range-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.range-item + .range-item { border-left: 1.5px dashed var(--line); }

.range-label {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ochre);
}

.range-value,
.range-input {
  min-width: 96px;
  min-height: 56px;
  font-size: 2.4rem;
  font-weight: 600;
  text-align: center;
  border-radius: 10px;
}

.range-value {
  background: transparent;
  border: 2px dashed transparent;
  padding: 0 12px;
}
/* Dashed outline hints that the number can be tapped and changed. */
.range-value:hover,
.range-value:focus-visible { border-color: var(--muted); outline: none; }

.range-input {
  width: 120px;
  background: var(--surface);
  color: var(--ink);
  border: 2px solid var(--ochre);
  padding: 0 8px;
}

/* ------------------------------------------------------------------
   2. Drawn number as a flat tile.
   Same space above and below the tile; the hint sits inside the space
   below, so it never moves the rest of the screen. Sizes and gaps use
   dvh (screen height) so that everything fits without scrolling.
   ------------------------------------------------------------------ */
.result {
  position: relative;
  display: flex;
  justify-content: center;
  margin: var(--gap) 0;
}

.result-number {
  width: min(64vw, 260px, 30dvh);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 28px;
  font-size: min(8.5rem, 15dvh, 30vw);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
/* Longer numbers get smaller so they stay inside the tile. */
.result-number.digits-3 { font-size: min(6rem, 10.5dvh, 21vw); }
.result-number.digits-4 { font-size: min(4.6rem, 8dvh, 16vw); }
/* Before the first draw: a faded "?". */
.result-number.empty { color: var(--off); }

.result-hint {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 6px 0 0;
  font-size: 0.95rem;
  color: var(--muted);
  text-align: center;
}

/* ------------------------------------------------------------------
   3. Draw button: wide, centred, ochre offset shadow
   ------------------------------------------------------------------ */
.draw-btn {
  align-self: center;
  width: 72%;
  height: clamp(56px, 9dvh, 76px);
  margin-bottom: var(--gap);
  border: none;
  border-radius: 10px;
  background: var(--line);
  color: var(--line-ink);
  display: grid;
  place-items: center;
  box-shadow: 5px 5px 0 var(--ochre);
  transition: transform 0.08s, box-shadow 0.08s;
}
/* Pressed: the button "sinks" onto its shadow. */
.draw-btn:active {
  transform: translate(3px, 3px);
  box-shadow: 2px 2px 0 var(--ochre);
}
.draw-btn:disabled {
  background: var(--off);
  color: var(--muted);
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------
   4. Status box (mode, counter, ⋮ menu) with an ochre band on the left
   ------------------------------------------------------------------ */
.status-box {
  position: relative;
  display: flex;
  align-items: center;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  padding: 14px 8px 14px 56px; /* left padding balances the ⋮ button */
  margin-bottom: 14px;
}
.status-box::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: var(--ochre);
  border-radius: 4px 0 0 4px;
}

.status-text {
  flex: 1;
  text-align: center;
}

.status-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
}

.status-counter {
  margin: 6px 0 0;
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.menu-btn {
  width: 48px;
  height: 48px;
  border: none;
  background: transparent;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.menu-btn svg { fill: currentColor; }
.menu-btn:active { background: var(--surface); }

.menu {
  position: absolute;
  right: 8px;
  bottom: calc(100% - 8px);
  z-index: 5;
  display: flex;
  flex-direction: column;
  min-width: 210px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.4);
  overflow: hidden;
}
.menu[hidden] { display: none; }
.menu button {
  min-height: 52px;
  padding: 0 18px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 1.05rem;
}
.menu button + button { border-top: 1px solid var(--off); }
.menu button:active { background: var(--bg); }

/* ------------------------------------------------------------------
   5. Switch "Consenti ripetizione", between two lines.
   The real checkbox is invisible; .switch draws the track and knob.
   ------------------------------------------------------------------ */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 48px;
  padding: 6px 0;
  margin-bottom: var(--gap);
  border-top: 1.5px solid var(--line);
  border-bottom: 1.5px solid var(--line);
  font-size: 1.15rem;
  cursor: pointer;
  user-select: none;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch {
  position: relative;
  width: 58px;
  height: 32px;
  border: 2px solid var(--muted);
  border-radius: 999px;
  transition: background 0.15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  background: var(--bg);
  transition: transform 0.15s;
}
.switch-row input:checked + .switch { background: var(--ochre); border-color: var(--ochre); }
.switch-row input:checked + .switch::after { transform: translateX(26px); border-color: var(--ochre); }
.switch-row input:focus-visible + .switch { outline: 3px solid var(--line); outline-offset: 3px; }

/* ------------------------------------------------------------------
   6. Resetta (and the other secondary buttons)
   ------------------------------------------------------------------ */
.reset-btn,
.primary-btn {
  min-height: 44px;
  padding: 0 28px;
  border-radius: 6px;
  font-size: 1rem;
}
.reset-btn {
  border: 1.5px solid var(--muted);
  background: transparent;
  color: var(--muted);
}
.reset-btn:active { background: var(--surface); }
#resetBtn { align-self: center; }

.primary-btn {
  border: 1.5px solid var(--line);
  background: var(--line);
  color: var(--line-ink);
  font-weight: 600;
}

/* Short screens: slightly smaller range and status box. */
@media (max-height: 760px) {
  .app { padding-top: max(12px, env(safe-area-inset-top)); }
  .range { padding-bottom: 8px; }
  .range-value, .range-input { min-height: 44px; font-size: 2rem; }
  .status-box { padding-top: 8px; padding-bottom: 8px; margin-bottom: 10px; }
  .status-counter { margin-top: 2px; font-size: 1.3rem; }
  .switch-row { min-height: 44px; padding: 2px 0; }
}

/* ------------------------------------------------------------------
   Panels (<dialog>): history, exclusions, confirmation
   ------------------------------------------------------------------ */
.panel {
  width: min(520px, calc(100vw - 32px));
  max-height: 80dvh;
  padding: 0;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}
.panel[open] { display: flex; flex-direction: column; }
.panel::backdrop { background: rgb(0 0 0 / 0.6); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 8px 8px 20px;
  border-bottom: 1.5px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 1.2rem; }

.close-btn {
  width: 48px;
  height: 48px;
  border: none;
  background: transparent;
  font-size: 1.3rem;
}

.panel-note,
.panel-empty {
  margin: 12px 20px;
  color: var(--muted);
}

.panel-foot {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 20px 20px;
}

.history-list {
  margin: 0;
  padding: 4px 20px 16px;
  overflow-y: auto;
  list-style: none;
}
.history-list li {
  display: flex;
  justify-content: space-between;
  padding: 10px 4px;
  border-bottom: 1px dashed var(--off);
  font-size: 1.15rem;
}
.history-list .ord { color: var(--muted); }
.history-list .num { font-weight: 700; font-variant-numeric: tabular-nums; }

.exclude-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 8px;
  padding: 0 20px;
  overflow-y: auto;
}
.exclude-grid button {
  min-height: 48px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: transparent;
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.exclude-grid button[aria-pressed="true"] {
  background: var(--off);
  border-color: var(--off);
  color: var(--muted);
  text-decoration: line-through;
}

.confirm p {
  margin: 24px 20px 4px;
  font-size: 1.1rem;
  line-height: 1.4;
}

/* ------------------------------------------------------------------
   Toast (short message at the bottom)
   ------------------------------------------------------------------ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  border-radius: 8px;
  border: 1.5px solid var(--ochre);
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  z-index: 20;
}
.toast[hidden] { display: none; }
