:root {
  --bg: #0d0b08;
  --panel: #1a1611;
  --panel-2: #14100b;
  --line: #332a1c;
  --line-soft: #241d13;
  --gold: #c9a227;
  --gold-bright: #e8c65a;
  --gold-deep: #8a6a12;
  --ink: #f3ead7;
  --muted: #9c8f78;
  --danger: #c05248;
  --radius: 18px;
  --note-dot: #a78bfa;
  --bookmark-dot: #f2c94c;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% 0%, #1d170e 0%, transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* ---------- rotator ---------- */

/* Nel fullscreen alcuni browser Android aggiornano il viewport in ritardo:
   le dimensioni in pixel (--app-w/--app-h) arrivano dal JS e sono più
   affidabili delle unità vw/dvh in quella transizione. */
#rotator {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--app-w, 100vw);
  height: var(--app-h, 100dvh);
  overflow-x: hidden;
  overflow-y: auto;
  transform-origin: top left;
  transform: none;
  -webkit-overflow-scrolling: touch;
}

/* Ancorato in alto a sinistra: in fullscreen il centro del viewport può
   essere calcolato su misure sbagliate, l'origine no. */
#rotator[data-rotation="90"] {
  width: var(--app-h, 100dvh);
  height: var(--app-w, 100vw);
  transform: rotate(90deg) translateY(-100%);
}

#rotator:not([data-rotation="0"]) .app {
  --rot-safe: max(
    env(safe-area-inset-top),
    env(safe-area-inset-right),
    env(safe-area-inset-bottom),
    env(safe-area-inset-left)
  );
  padding: calc(var(--rot-safe) + 10px) calc(var(--rot-safe) + 12px);
}

:root:fullscreen,
:root:-webkit-full-screen {
  background:
    radial-gradient(120% 80% at 50% 0%, #1d170e 0%, transparent 60%),
    var(--bg);
}

[hidden] {
  display: none !important;
}

body.modal-open {
  overflow: hidden;
}

body.modal-open #rotator {
  overflow: hidden;
}

.app {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px calc(env(safe-area-inset-bottom) + 10px);
}

/* ---------- icone (Radix, file SVG in root) ---------- */

.icon-mask {
  display: inline-block;
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  background-color: currentColor;
  -webkit-mask-image: var(--icon);
  mask-image: var(--icon);
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

.icon-bookmark {
  --icon: url("./bookmark.svg");
}

.step-bookmark[aria-pressed="true"] .icon-bookmark {
  --icon: url("./bookmark-filled.svg");
}

.icon-pencil {
  --icon: url("./pencil-1.svg");
}

.icon-trash {
  --icon: url("./trash.svg");
}

.icon-rotate {
  --icon: url("./reload.svg");
}

.icon-undo {
  --icon: url("./reset.svg");
}

.icon-restart {
  --icon: url("./update.svg");
}

.icon-close {
  --icon: url("./cross-2.svg");
}

.icon-plus {
  --icon: url("./plus.svg");
}

.icon-fullscreen {
  --icon: url("./enter-full-screen.svg");
}

.icon-action[aria-pressed="true"] .icon-fullscreen {
  --icon: url("./exit-full-screen.svg");
}

/* ---------- header ---------- */

.top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 30px;
}

.top-actions {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.icon-action {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  font-family: inherit;
  color: var(--gold);
  background: transparent;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.icon-action .icon-mask {
  width: 17px;
  height: 17px;
  display: block;
}

.icon-action:active {
  background: #1b1610;
}

.icon-action:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.icon-action[aria-pressed="true"] {
  color: var(--gold-bright);
  border-color: var(--gold-deep);
  background: rgba(201, 162, 39, 0.12);
}

.lang-toggle {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
}

.brand {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
  white-space: nowrap;
}

.brand-version {
  margin-left: 6px;
  font-size: 0.58rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: #6f6552;
}

.brand-mark {
  color: var(--gold);
}

.wake {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 4px 9px;
  font-family: inherit;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  cursor: pointer;
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
}

.wake:active {
  background: #19140d;
}

.wake:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.wake span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wake-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: #4a4234;
}

.wake[data-state="on"] {
  color: var(--gold-bright);
  border-color: #4b3d18;
}

.wake[data-state="on"] .wake-dot {
  background: var(--gold-bright);
  box-shadow: 0 0 8px rgba(232, 198, 90, 0.8);
}

.wake[data-state="off"] {
  color: #8a7f6a;
}

.wake[data-state="unsupported"] .wake-dot {
  background: var(--danger);
}

.wake[data-state="unsupported"] {
  cursor: default;
}

/* ---------- counters ---------- */

.counters {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* I giocatori partecipano alla stessa griglia dei contatori:
   su tablet si dispongono in riga e vanno a capo da soli. */
.players {
  display: contents;
}

.tablet .step-pill {
  flex-direction: column;
  gap: 0;
  height: 48px;
  padding: 3px 2px 4px;
}

.tablet .step-pill-num {
  font-size: 0.98rem;
  line-height: 1.1;
}

.tablet .step-pill-name {
  display: block;
  max-width: 100%;
  font-size: 0.55rem;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tablet .step-bookmark {
  width: 36px;
  height: 36px;
}

.tablet .step-bookmark .icon-mask {
  width: 16px;
  height: 16px;
}

.tablet .counters {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px 8px;
  background: linear-gradient(180deg, #1c1710, var(--panel-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.counter-player {
  position: relative;
}

.player-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  min-width: 0;
}

.player-caption {
  display: none;
  font-size: 0.5rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #6f6552;
}

.tablet .player-caption {
  display: block;
}

.player-name {
  max-width: 100%;
  padding: 0 8px;
  overflow: hidden;
  font-family: inherit;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: default;
}

.player-name:disabled {
  opacity: 1; /* resta leggibile: è un'etichetta, non un controllo spento */
}

.tablet .player-name {
  padding: 0 24px;
  font-size: 0.72rem;
  cursor: pointer;
  text-decoration: underline dotted rgba(201, 162, 39, 0.5);
  text-underline-offset: 3px;
}

.tablet .player-name:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
  border-radius: 6px;
}

.player-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1;
  color: #7d7060;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.player-remove[hidden] {
  display: none;
}

.player-remove .icon-mask {
  width: 11px;
  height: 11px;
}

.player-remove:active {
  color: #ff8b7e;
  background: #221a13;
}

/* Tile per aggiungere un giocatore (solo tablet, sotto i 4). */
.counter-add {
  justify-content: center;
  gap: 4px;
  min-height: 78px;
  font-family: inherit;
  color: var(--muted);
  background: transparent;
  border: 1px dashed #3d321f;
  cursor: pointer;
}

.counter-add:active {
  background: #17130d;
}

.counter-add .add-mark {
  width: 22px;
  height: 22px;
  color: var(--gold);
}

.counter-add .add-label {
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
}

/* Tablet: card più strette, numeri proporzionati. */
.tablet .counter-value {
  font-size: clamp(1.7rem, 3.4vw, 2.4rem);
}

.tablet .counter-value.long {
  font-size: clamp(1.3rem, 2.6vw, 1.9rem);
}

.tablet .step {
  flex-basis: 38px;
}

.tablet .edit-hint {
  font-size: 0.55rem;
}

.counter-label {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.counter-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  margin-top: 4px;
}

.counter-value {
  flex: 1 1 auto;
  min-width: 0;
  font-size: clamp(1.9rem, 9vw, 2.9rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--ink);
  text-align: center;
}

.counter-value.long {
  font-size: clamp(1.4rem, 6.4vw, 2.1rem);
}

.counter-value.alert {
  color: #ff6b5e;
  text-shadow: 0 0 16px rgba(224, 90, 78, 0.35);
}

.counter.needs-setup {
  border-color: #6d5720;
}

/* Badge sempre visibile, anche quando il suggerimento testuale è nascosto
   nelle altezze compatte. */
.counter.needs-setup::before {
  content: "!";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 17px;
  height: 17px;
  display: grid;
  place-items: center;
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1;
  color: #1a1408;
  background: linear-gradient(180deg, #f4dd8c, #c8a233);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(232, 198, 90, 0.55);
}

.counter.needs-setup .edit-hint {
  margin-top: 3px;
  padding: 1px 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #1a1408;
  background: linear-gradient(180deg, #f0d878, #c8a233);
  border-radius: 999px;
  box-shadow: 0 0 12px rgba(232, 198, 90, 0.28);
}

/* Con altezze compatte il suggerimento resta visibile se serve impostare. */
.compact-height .counter.needs-setup .edit-hint,
.very-short .counter.needs-setup .edit-hint {
  display: inline-block;
}

.counter.needs-setup .value-btn {
  border-bottom-color: rgba(232, 198, 90, 0.8);
}

/* Ripple riavviabile: lo attiva il JS (primo avvio, nuova partita, nuovo
   giocatore) e può ripartire anche se la card era già in promemoria. */
.counter.threat-pulse {
  animation: threat-card 0.9s ease-in-out 4;
}

.counter.threat-pulse .counter-value {
  animation: threat-hint 0.9s ease-in-out 4;
}

@keyframes threat-card {
  0%,
  100% {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04),
      0 0 0 1px rgba(232, 198, 90, 0.18);
    transform: scale(1);
  }
  45% {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04),
      0 0 0 3px rgba(232, 198, 90, 0.85), 0 0 34px rgba(232, 198, 90, 0.45);
    transform: scale(1.015);
  }
}

@keyframes threat-hint {
  0%,
  100% {
    color: inherit;
    transform: scale(1);
    text-shadow: 0 0 0 rgba(232, 198, 90, 0);
  }
  45% {
    color: #ffeaa6;
    transform: scale(1.12);
    text-shadow: 0 0 22px rgba(232, 198, 90, 0.95);
  }
}

.value-btn.alert {
  border-bottom-color: rgba(255, 107, 94, 0.65);
}

.value-btn {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
  border-bottom: 1px dashed rgba(201, 162, 39, 0.45);
}

.value-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
  border-radius: 6px;
}

.edit-hint {
  min-height: 1em;
  margin-top: 3px;
  font-size: 0.6rem;
  letter-spacing: 0.02em;
  color: #6f6552;
  text-align: center;
}

.step {
  flex: 0 0 40px;
  height: 54px;
  display: grid;
  place-items: center;
  padding: 0;
  font-family: inherit;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--gold-bright);
  background: linear-gradient(180deg, #241d13, #1a150e);
  border: 1px solid var(--line);
  border-radius: 13px;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.12s ease;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.step:active {
  transform: scale(0.94);
  background: #2c2417;
}

.step:disabled {
  opacity: 0.28;
  pointer-events: none;
}

.step:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

@keyframes pop {
  0% {
    transform: scale(1);
    color: var(--gold-bright);
  }
  55% {
    transform: scale(1.14);
  }
  100% {
    transform: scale(1);
  }
}

.pop {
  animation: pop 0.26s ease-out;
}

/* Effetto visivo quando la risoluzione dell'impresa aumenta la Minaccia. */
@keyframes threat-hit {
  0% {
    box-shadow: 0 0 0 0 rgba(192, 82, 72, 0);
    transform: translateX(0);
  }
  20% {
    box-shadow: 0 0 0 3px rgba(192, 82, 72, 0.55);
    transform: translateX(-2px);
  }
  45% {
    transform: translateX(2px);
  }
  70% {
    box-shadow: 0 0 0 5px rgba(192, 82, 72, 0);
    transform: translateX(-1px);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(192, 82, 72, 0);
    transform: translateX(0);
  }
}

.threat-hit {
  animation: threat-hit 0.55s ease-out;
}

.threat-float {
  position: absolute;
  bottom: 2px;
  left: 50%;
  z-index: 2;
  padding: 1px 7px;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.35;
  color: #ff8b7e;
  background: rgba(20, 14, 10, 0.92);
  border: 1px solid rgba(192, 82, 72, 0.6);
  border-radius: 999px;
  pointer-events: none;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  animation: threat-float 0.9s ease-out forwards;
}

@keyframes threat-float {
  0% {
    opacity: 0;
    transform: translate(-50%, 6px) scale(0.9);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -18px) scale(1.05);
  }
}

@media (prefers-reduced-motion: reduce) {
  .threat-hit {
    animation: none;
  }

  .threat-float {
    animation: none;
    opacity: 1;
    transform: translate(-50%, -24px);
  }
}

/* ---------- phases ---------- */

.phase {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 12px;
  min-height: 0;
}

.stepper {
  display: flex;
  gap: 5px;
}

.step-pill {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #6f6552;
  background: #15110c;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.step-pill-num {
  line-height: 1;
}

/* Su telefono il nome della fase resta nascosto: c'è solo il numero. */
.step-pill-name {
  display: none;
}

.step-pill:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.step-pill.done {
  color: #8f7a3f;
  border-color: #3b3120;
}

.step-pill.current {
  color: #1a1408;
  background: linear-gradient(180deg, #eccd63, #b8912a);
  border-color: #f2da8a;
  box-shadow: 0 0 18px rgba(201, 162, 39, 0.22);
}

/* Note in viola (in alto a destra), segnalibro in giallo (in basso a
   destra): restano distinguibili anche sulla pillola corrente dorata. */
.step-pill.has-notes::before,
.step-pill.has-bookmark::after {
  content: "";
  position: absolute;
  right: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  box-shadow: 0 0 6px currentColor, 0 0 0 1px rgba(13, 11, 8, 0.6);
}

.step-pill.has-notes::before {
  top: 5px;
  color: var(--note-dot);
  background: var(--note-dot);
}

.step-pill.has-bookmark::after {
  bottom: 5px;
  color: var(--bookmark-dot);
  background: var(--bookmark-dot);
}

.phase-card {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  text-align: center;
  padding: 2px 4px 6px;
  scrollbar-width: thin;
  scrollbar-color: #40361f transparent;
}

.phase-eyebrow {
  margin: 0;
  font-size: 0.66rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.phase-name {
  margin: 2px 0 6px;
  font-size: clamp(1.55rem, 8vw, 2.35rem);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gold-bright);
}

/* ---------- passi, finestre di azione e note ---------- */

.step-list {
  --step-indent: 50px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 4px;
  text-align: left;
}

.step-block {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 2px;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s ease;
}

.step-block:active {
  background: rgba(201, 162, 39, 0.08);
}

/* Riga con il segnalibro: barra dorata e sfondo tenue. */
.step-block.bookmarked {
  background: linear-gradient(90deg, rgba(242, 201, 76, 0.1), transparent 72%);
  box-shadow: inset 2px 0 0 var(--bookmark-dot);
  border-radius: 0 8px 8px 0;
}

.step-bookmark {
  flex: 0 0 auto;
  align-self: flex-start;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  margin: -3px -2px -3px 0;
  padding: 0;
  color: #8d7f63;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.85;
  transition: color 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}

.step-bookmark .icon-mask {
  width: 15px;
  height: 15px;
  display: block;
}

.step-bookmark:active {
  background: rgba(201, 162, 39, 0.14);
}

.step-bookmark:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.step-bookmark[aria-pressed="true"] {
  color: var(--bookmark-dot);
  opacity: 1;
  background: rgba(242, 201, 76, 0.12);
}

.step-num {
  flex: 0 0 auto;
  min-width: 40px;
  padding-top: 0.12em;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  text-align: right;
}

.step-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.step-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.32;
  color: #dcd0b8;
  overflow-wrap: anywhere;
}

.action-window {
  margin: 3px 0;
  padding: 3px 10px 3px var(--step-indent, 50px);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-align: left;
  color: #cf8d84;
  background: rgba(168, 67, 58, 0.1);
  box-shadow: inset 3px 0 0 #a8433a;
  border-radius: 0 6px 6px 0;
}

.process-btn {
  padding: 3px 10px;
  font-family: inherit;
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffd9d2;
  background: rgba(168, 67, 58, 0.22);
  border: 1px solid #7a3a33;
  border-radius: 999px;
  cursor: pointer;
}

.process-btn:active {
  background: rgba(168, 67, 58, 0.4);
}

.process-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.quest-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #e8e2c8;
  background: rgba(201, 162, 39, 0.16);
  border-color: #8a6f2a;
}

.quest-btn:active {
  background: rgba(201, 162, 39, 0.32);
}

.quest-btn-icon {
  width: 14px;
  height: 14px;
  display: block;
  border-radius: 50%;
}

.gap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 0 0 2px 48px;
}

.gap-notes {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.player-note {
  display: block;
  width: 100%;
  padding: 6px 9px;
  font-family: inherit;
  font-size: 0.8rem;
  line-height: 1.3;
  text-align: left;
  color: #eedfff;
  background: rgba(112, 74, 160, 0.16);
  border: 1px solid rgba(150, 108, 205, 0.4);
  border-left: 3px solid #a878e0;
  border-radius: 8px;
  cursor: pointer;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.player-note:active {
  background: rgba(112, 74, 160, 0.3);
}

.player-note:focus-visible {
  outline: 2px solid #b98bea;
  outline-offset: 2px;
}

.gap-add {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  font-family: inherit;
  font-size: 0.8rem;
  line-height: 1;
  color: #6f6552;
  background: transparent;
  border: 1px dashed #3a2f1e;
  border-radius: 50%;
  cursor: pointer;
}

.gap-add .icon-mask {
  width: 13px;
  height: 13px;
}

.gap-add:active {
  color: var(--gold-bright);
  border-color: var(--gold-deep);
}

.gap-add:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---------- next ---------- */

.next {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 16px;
  font-family: inherit;
  color: #191307;
  background: linear-gradient(180deg, #eccd63, #b8912a);
  border: 1px solid #f0d878;
  border-radius: 20px;
  box-shadow: 0 5px 0 #6d5510, 0 10px 26px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}

.next:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #6d5510, 0 4px 12px rgba(0, 0, 0, 0.4);
}

.next:focus-visible {
  outline: 2px solid #fff2bf;
  outline-offset: 3px;
}

.next-main {
  font-size: clamp(1.35rem, 6.4vw, 1.85rem);
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  padding-left: 0.24em;
}

.next-hint {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.72;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- footer ---------- */

.bottom {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

.bottom button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  cursor: pointer;
  overflow: hidden;
}

.bottom button .icon-mask {
  width: 14px;
  height: 14px;
}

.bottom button:active {
  background: #16120c;
}

.bottom button:disabled {
  opacity: 0.32;
  pointer-events: none;
}

.bottom button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

#undoLabel {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  top: var(--vv-top, 0px);
  left: 0;
  width: 100%;
  height: var(--vv-h, 100dvh);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(18px, 6vh) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(5, 4, 3, 0.72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* Con l'interfaccia ruotata gli assi sono scambiati: l'overlay deve
   coprire l'area visibile sopra la tastiera nel sistema ruotato. */
#rotator[data-rotation="90"] .overlay {
  top: 0;
  left: var(--vv-top, 0px);
  width: var(--vv-h, 100dvh);
  height: 100%;
}

.panel {
  flex: 0 1 auto;
  min-height: 0;
  width: min(360px, 100%);
  padding: 20px;
  background: linear-gradient(180deg, #201a12, #14100b);
  border: 1px solid #3d321f;
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold-bright);
}

.panel-sub {
  margin: 0 0 14px;
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--muted);
}

.num-input {
  width: 100%;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--ink);
  background: #0e0c09;
  border: 1px solid #4b3d18;
  border-radius: 12px;
}

.num-input:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.text-input {
  width: 100%;
  padding: 12px;
  font-family: inherit;
  font-size: 1.15rem;
  color: var(--ink);
  background: #0e0c09;
  border: 1px solid #4b3d18;
  border-radius: 12px;
}

.text-input:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.panel-actions button {
  flex: 1;
  min-height: 46px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  border-radius: 12px;
  cursor: pointer;
}

.ghost {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}

.primary {
  color: #191307;
  background: linear-gradient(180deg, #eccd63, #b8912a);
  border: 1px solid #f0d878;
}

.primary.danger {
  color: #fdeee9;
  background: linear-gradient(180deg, #a4433a, #7d2f28);
  border-color: #c05248;
}

.panel-actions button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---------- notes sheet ---------- */

.panel-notes {
  width: min(420px, 100%);
  max-height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel-head h2 {
  overflow-wrap: anywhere;
}

#notesTitle {
  font-size: 1rem;
  letter-spacing: 0.04em;
}

/* ---------- process sheet ---------- */

.panel-process {
  width: min(520px, 100%);
  max-height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#processTitle {
  font-size: 1rem;
  letter-spacing: 0.04em;
}

.process-steps {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin-top: 4px;
  padding-right: 2px;
  -webkit-overflow-scrolling: touch;
}

.process-steps .action-window {
  margin: 2px 0;
}

/* ---------- risoluzione dell'impresa ---------- */

.panel-quest {
  width: min(420px, 100%);
}

#questTitle {
  font-size: 1rem;
  letter-spacing: 0.04em;
}

.quest-field {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  gap: 4px 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line-soft);
}

.quest-field:first-of-type {
  border-top: 0;
  padding-top: 2px;
}

.quest-token {
  grid-row: 1 / span 2;
  width: 30px;
  height: 30px;
  display: block;
  border-radius: 50%;
}

.quest-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.quest-stepper {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.quest-stepper .step {
  flex: 0 0 38px;
  height: 44px;
  font-size: 1.35rem;
  border-radius: 10px;
  touch-action: manipulation;
}

.quest-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  padding: 0 8px;
  font-family: inherit;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--ink);
  background: #0e0c09;
  border: 1px solid #4b3d18;
  border-radius: 10px;
  -moz-appearance: textfield;
}

.quest-input:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.quest-input:disabled {
  opacity: 0.62;
}

.quest-result {
  margin-top: 12px;
}

.quest-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(74, 110, 54, 0.18);
  border: 1px solid #4c6a3a;
  border-radius: 14px;
}

.quest-token-progress {
  width: 32px;
  height: 32px;
}

.quest-progress-label {
  flex: 1 1 auto;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #b9cf9b;
}

.quest-progress-value {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: #d7e8b8;
}

.quest-raise {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #ffe0d9;
  background: linear-gradient(180deg, #a4433a, #7d2f28);
  border: 1px solid #c05248;
  border-radius: 14px;
  cursor: pointer;
}

.quest-raise .quest-token {
  width: 26px;
  height: 26px;
}

.quest-raise:active {
  background: linear-gradient(180deg, #b74d43, #8c352d);
}

.quest-raise:disabled {
  opacity: 0.55;
  cursor: default;
}

.quest-raise:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.quest-done {
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.quest-done:active {
  background: #1c1710;
}

.quest-done:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.quest-lock {
  margin: 10px 0 0;
  font-size: 0.78rem;
  line-height: 1.35;
  text-align: center;
  color: var(--muted);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-head h2 {
  margin: 0;
}

.icon-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.icon-btn .icon-mask {
  width: 15px;
  height: 15px;
}

.icon-btn:active {
  background: #1c1710;
}

.icon-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.notes-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0;
  padding-right: 2px;
  -webkit-overflow-scrolling: touch;
}

.notes-list,
.process-steps {
  scrollbar-width: thin;
  scrollbar-color: #40361f transparent;
}

.notes-list::-webkit-scrollbar,
.process-steps::-webkit-scrollbar {
  width: 6px;
}

.notes-list::-webkit-scrollbar-track,
.process-steps::-webkit-scrollbar-track {
  background: transparent;
}

.notes-list::-webkit-scrollbar-thumb,
.process-steps::-webkit-scrollbar-thumb {
  background: #40361f;
  border-radius: 3px;
}

.note-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  background: #0f0c08;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
}

.note-row.confirming {
  border-color: #5a2d28;
}

.note-text {
  flex: 1 1 140px;
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.35;
  color: #e2d7c1;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.note-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.note-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  font-family: inherit;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  cursor: pointer;
}

.note-icon .icon-mask {
  width: 16px;
  height: 16px;
  display: block;
}

.note-icon:active {
  background: #1b1610;
}

.note-icon:focus-visible,
.note-text-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.note-edit {
  flex: 1 1 100%;
  min-height: 64px;
  max-height: 180px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.84rem;
  line-height: 1.35;
  color: var(--ink);
  background: #0b0906;
  border: 1px solid #4b3d18;
  border-radius: 8px;
  resize: vertical;
}

.note-edit:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.note-text-btn {
  min-height: 32px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.note-text-btn.primary-mini {
  color: #191307;
  background: linear-gradient(180deg, #eccd63, #b8912a);
  border-color: #f0d878;
}

.note-text-btn.danger {
  color: #fdeee9;
  background: linear-gradient(180deg, #a4433a, #7d2f28);
  border-color: #c05248;
}

.notes-empty {
  margin: 16px 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}

.notes-composer {
  flex: 0 0 auto;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.notes-input {
  width: 100%;
  min-height: 58px;
  max-height: 160px;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--ink);
  background: #0e0c09;
  border: 1px solid #3a2f1c;
  border-radius: 10px;
  resize: vertical;
}

.notes-input:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

.char-count {
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  color: #6f6552;
}

.composer-row .primary {
  min-width: 110px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
}

.composer-row .primary:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- small / short layouts (classi impostate da app.js) ---------- */

/* Il nome lungo dell'app chiede spazio: sotto i 380 px si compatta. */
.tight-head .brand {
  font-size: 0.68rem;
}

.tight-head .brand-version {
  margin-left: 4px;
  font-size: 0.55rem;
}

.narrow .app {
  padding-left: 10px;
  padding-right: 10px;
}

.narrow .top {
  gap: 6px;
}

.narrow .top-actions {
  gap: 4px;
}

.narrow .brand-version {
  display: none;
}

.narrow .brand {
  font-size: 0.6rem;
  letter-spacing: 0.06em;
}

.narrow .icon-action {
  width: 29px;
  height: 29px;
}

.narrow .icon-action .icon-mask {
  width: 15px;
  height: 15px;
}

.narrow .wake {
  gap: 5px;
  padding: 4px 7px;
  font-size: 0.56rem;
}

.narrow .counters {
  gap: 8px;
}

.narrow .counter {
  padding: 8px 5px 7px;
}

.narrow .step {
  flex-basis: 36px;
  height: 50px;
  font-size: 1.45rem;
}

.narrow .step-pill {
  font-size: 0.85rem;
}

.narrow .edit-hint {
  font-size: 0.55rem;
}

.compact-height .app {
  gap: 8px;
}

.compact-height .counter {
  padding: 6px 8px;
}

.compact-height .step {
  height: 46px;
}

.compact-height .edit-hint {
  display: none;
}

.compact-height .phase {
  gap: 6px;
}

.compact-height .step-pill {
  height: 34px;
}

.tablet.compact-height .step-pill {
  height: 40px;
}

.tablet.compact-height .step-pill-name {
  font-size: 0.48rem;
}

.compact-height .phase-name {
  margin-bottom: 2px;
}

.compact-height .step-text {
  font-size: 0.82rem;
}

.compact-height .step-block {
  padding: 3px 2px;
}

.compact-height .action-window {
  padding: 4px 8px 4px var(--step-indent, 50px);
}

.compact-height .next {
  padding: 8px 16px;
}

/* Landscape e altezze ridotte: chrome compatto ma fermo (stepper e AVANTI
   sempre visibili); scorre soltanto il contenuto della fase. */
.very-short .app {
  gap: 6px;
  padding-top: calc(env(safe-area-inset-top) + 6px);
  padding-bottom: calc(env(safe-area-inset-bottom) + 6px);
}

.very-short .top {
  min-height: 28px;
}

.very-short .counters {
  gap: 8px;
}

.very-short .counter {
  padding: 4px 6px 5px;
}

.very-short .counter-label {
  font-size: 0.55rem;
  letter-spacing: 0.14em;
}

.very-short .counter-row {
  margin-top: 2px;
}

.very-short .counter-value {
  font-size: 1.6rem;
}

.very-short .counter-value.long {
  font-size: 1.15rem;
}

.very-short .step {
  flex-basis: 34px;
  height: 38px;
  font-size: 1.25rem;
}

.very-short .edit-hint {
  display: none;
}

.very-short .stepper {
  gap: 4px;
}

.very-short .step-pill {
  height: 30px;
  font-size: 0.82rem;
}

.very-short .step-pill-name {
  display: none;
}

.very-short .step-bookmark {
  width: 26px;
  height: 26px;
  margin: -2px -2px -2px 0;
}

.very-short .step-bookmark .icon-mask {
  width: 13px;
  height: 13px;
}

.very-short .phase {
  gap: 6px;
}

.very-short .phase-card {
  padding: 0 4px;
}

.very-short .phase-eyebrow {
  display: none;
}

.very-short .phase-name {
  margin: 0 0 3px;
  font-size: 1.2rem;
}

.very-short .step-list {
  margin-top: 2px;
  --step-indent: 42px;
}

.very-short .step-text {
  font-size: 0.78rem;
  line-height: 1.25;
}

.very-short .step-block {
  gap: 6px;
  padding: 2px;
}

.very-short .step-num {
  min-width: 34px;
  font-size: 0.64rem;
}

.very-short .gap {
  padding-left: 40px;
}

.very-short .action-window {
  padding: 3px 8px 3px var(--step-indent, 42px);
  font-size: 0.56rem;
}

.very-short .player-note {
  padding: 4px 7px;
  font-size: 0.72rem;
}

.very-short .gap-add {
  width: 21px;
  height: 21px;
}

.very-short .next {
  padding: 6px 12px;
  border-radius: 14px;
}

.very-short .next-main {
  font-size: 1.25rem;
}

.very-short .next-hint {
  font-size: 0.6rem;
}

.very-short .bottom button {
  min-height: 36px;
  padding: 5px 8px;
  font-size: 0.72rem;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
