/* =============================================================================
 * app.css — layout e componenti.
 *
 * Ordine: reset, guscio, tipografia, moduli d'inserimento, componenti, ruota,
 * schermate, foglio dal basso, tab bar. Le classi seguono il blocco a cui
 * appartengono (`.wheel-*`, `.sheet-*`, `.meter-*`): non ci sono selettori di
 * tipo che possano collidere con quelli di un altro blocco.
 * ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* L'altezza la detta Telegram, non il browser.
   `--tg-vh-stable` la scrive js/tg.js dal viewportStableHeight del client;
   `100vh` resta come ripiego fuori da Telegram, dove è il valore giusto.
   `100dvh` copre i browser mobili con la barra degli indirizzi che si ritrae. */
body {
  height: var(--tg-vh-stable, 100dvh);
  min-height: var(--tg-vh-stable, 100vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;              /* scorre #app, non la pagina */
}

button, input { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* --- guscio ---------------------------------------------------------------- */

#app {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-top) + 8px) var(--pad) calc(var(--tab-h) + var(--safe-bottom) + 24px);
}

.screen { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 26px; }

/* --- tipografia ------------------------------------------------------------ */

.scr-head { padding-top: 6px; }
.scr-title { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 4px; }
.scr-sub { margin: 0; color: var(--text-dim); font-size: 14px; }

.sec { display: flex; flex-direction: column; gap: 10px; }
.sec-title {
  font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-faint); margin: 0;
}
.sec-note { margin: -4px 0 0; font-size: 13px; color: var(--text-dim); }

.hint { margin: 2px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--text-faint); }

.notice {
  margin: 0; padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--warn-soft); color: var(--warn);
  font-size: 13px; line-height: 1.45;
}

.disclaimer {
  margin: 8px 0 0; padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 11px; line-height: 1.5; color: var(--text-faint); text-align: center;
}

/* --- moduli d'inserimento --------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: 12px; }

.input {
  width: 100%;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  transition: border-color .15s, background .15s;
}
.input::placeholder { color: var(--text-faint); }
.input:focus { outline: none; border-color: var(--accent); background: var(--surface-2); }
.input:disabled { opacity: .4; }

.input-num { text-align: center; font-family: var(--font-num); letter-spacing: .04em; }

.field-row { display: flex; gap: 8px; align-items: center; }
.field-row .input-num { flex: 1; min-width: 0; }
.field-row.disabled { opacity: .4; pointer-events: none; }
.field-row .sep { color: var(--text-faint); font-family: var(--font-num); }

.check { display: flex; align-items: center; gap: 9px; font-size: 14px; color: var(--text-dim); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.form-errors { display: flex; flex-direction: column; gap: 6px; }
.form-errors .err { margin: 0; font-size: 13px; color: var(--neg); }
.form-errors .warn { margin: 0; font-size: 13px; color: var(--warn); }

.link { color: var(--accent); text-decoration: underline; padding: 0; font-size: inherit; }

/* ricerca città */
.city-results {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm); overflow: hidden; max-height: 260px; overflow-y: auto;
}
.city-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border);
}
.city-item:last-child { border-bottom: none; }
.city-item:hover, .city-item:focus-visible { background: var(--surface-2); }
.city-name { font-size: 15px; }
.city-country { font-size: 11px; color: var(--text-faint); font-family: var(--font-num); }
.city-none { padding: 14px; font-size: 13.5px; color: var(--text-dim); }

.city-picked { margin-top: 2px; }
.pill {
  display: inline-block; padding: 6px 11px; border-radius: 100px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-family: var(--font-num);
}

/* --- pulsanti ---------------------------------------------------------------- */

.btn {
  padding: 13px 18px; border-radius: var(--r-sm);
  font-size: 15px; font-weight: 600;
  transition: transform .1s, opacity .15s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; }

.btn-primary { background: var(--grad); color: #150F00; box-shadow: var(--glow); }
html.theme-light .btn-primary { color: #FFF; }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--neg-soft); color: var(--neg); }

.btn-star { display: inline-flex; align-items: center; justify-content: center; gap: 2px; }
.star { color: #FFD84D; }

/* Il pulsante di ripiego serve solo fuori da Telegram, dove non c'è MainButton */
.fallback-submit { display: none; }
html.no-tg .fallback-submit { display: block; }

/* --- righe e liste ----------------------------------------------------------- */

.row {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
}
.row-tap { cursor: pointer; }
.row-tap:hover { background: var(--surface-2); }
.row-label { flex: 1; font-size: 14.5px; }
.row-value { font-size: 14px; color: var(--text-dim); font-family: var(--font-num); text-align: right; }
.row-value.dim { color: var(--text-faint); font-size: 12.5px; }
.row-chevron { color: var(--text-faint); font-size: 20px; line-height: 1; }

.body-list { display: flex; flex-direction: column; gap: 1px; background: var(--border); border-radius: var(--r-sm); overflow: hidden; }
.body-row {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 14px; background: var(--surface); cursor: pointer;
}
.body-row:hover { background: var(--surface-2); }
.body-glyph { font-family: var(--font-glyph); font-size: 18px; color: var(--accent); width: 22px; text-align: center; }
.body-name { flex: 1; font-size: 14.5px; }
.body-pos { font-family: var(--font-num); font-size: 13px; color: var(--text-dim); display: inline-flex; gap: 5px; align-items: baseline; }
.body-house { font-family: var(--font-num); font-size: 11px; color: var(--text-faint); min-width: 22px; text-align: right; }
.retro { color: var(--warn); font-size: 12px; }

/* --- i tre pilastri ---------------------------------------------------------- */

.pillars { display: flex; flex-direction: column; gap: 10px; }
.pillar {
  padding: 16px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--border);
  position: relative; overflow: hidden;
}
.pillar-glyph {
  position: absolute; top: -6px; right: 8px;
  font-family: var(--font-glyph); font-size: 56px; line-height: 1;
  color: var(--accent); opacity: .09; pointer-events: none;
}
.pillar-title { margin: 0 0 6px; font-size: 15px; font-weight: 700; color: var(--accent); }
.pillar-text { margin: 0; font-size: 14.5px; line-height: 1.55; color: var(--text-dim); }

/* --- aspetti ------------------------------------------------------------------ */

.aspect-list { display: flex; flex-direction: column; gap: 8px; }
.aspect {
  padding: 13px 15px; border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--text-faint);
}
.aspect-armonico { border-left-color: var(--pos); }
.aspect-teso { border-left-color: var(--neg); }
.aspect-neutro { border-left-color: var(--accent); }
.aspect-head { display: flex; align-items: baseline; gap: 10px; }
.aspect-title { margin: 0; font-size: 14px; font-weight: 600; flex: 1; }
.aspect-orb { font-family: var(--font-num); font-size: 11.5px; color: var(--text-faint); }
.aspect-text { margin: 6px 0 0; font-size: 13.5px; line-height: 1.5; color: var(--text-dim); }

/* --- ruota dello zodiaco ------------------------------------------------------- */

.wheel-box { display: flex; justify-content: center; padding: 4px 0; }
.wheel { width: 100%; max-width: 370px; height: auto; display: block; }

.w-disc { fill: var(--surface); }
.w-ring { fill: none; stroke: var(--border-str); stroke-width: 1; }
.w-sign-div { stroke: var(--border-str); stroke-width: .8; }
.w-sign-band { opacity: .17; }
.w-sign-glyph { font-family: var(--font-glyph); font-size: 13px; fill: var(--text-dim); }
.w-cusp { stroke: var(--border-str); stroke-width: .8; stroke-dasharray: 2 3; }
.w-cusp-angle { stroke: var(--accent); stroke-width: 1.4; stroke-dasharray: none; opacity: .75; }
.w-house-num { font-family: var(--font-num); font-size: 8px; fill: var(--text-faint); }
.w-angle-label { font-family: var(--font-num); font-size: 8.5px; fill: var(--accent); letter-spacing: .05em; }
.w-tick { stroke: var(--text-faint); stroke-width: .7; opacity: .55; }
.w-aspect { stroke-linecap: round; }
.w-body { cursor: pointer; }
.w-body-bg { fill: var(--surface); stroke: var(--border); stroke-width: 1; }
.w-body:hover .w-body-bg, .w-body:focus-visible .w-body-bg { stroke: var(--accent); }
.w-body-glyph { font-family: var(--font-glyph); font-size: 14px; fill: var(--text); }
.w-retro { font-family: var(--font-num); font-size: 7px; fill: var(--warn); }
.w-outer-glyph { fill: var(--accent-2); font-size: 13px; }

/* --- confronto ------------------------------------------------------------------ */

.seg {
  display: flex; gap: 3px; padding: 3px;
  background: var(--surface-2); border-radius: 100px;
}
.seg-item {
  flex: 1; padding: 9px 8px; border-radius: 100px;
  font-size: 13.5px; font-weight: 600; color: var(--text-dim);
  transition: background .15s, color .15s;
}
.seg-item.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-soft); }

.people { display: flex; flex-direction: column; gap: 8px; }
.person {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 14px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
}
.person:hover { background: var(--surface-2); }
.person-score {
  width: 44px; height: 44px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  font-family: var(--font-num); font-size: 16px; font-weight: 700;
}
.person-body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.person-name { font-size: 15px; font-weight: 600; }
.person-sub { font-size: 12px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.match-actions { display: flex; flex-direction: column; gap: 8px; }

.score-card {
  padding: 26px 20px; border-radius: var(--r-lg); text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}
.score-dial { display: flex; align-items: baseline; justify-content: center; gap: 2px; margin-bottom: 8px; }
.score-num { font-family: var(--font-num); font-size: 54px; font-weight: 700; line-height: 1; color: var(--accent); }
.score-of { font-family: var(--font-num); font-size: 16px; color: var(--text-faint); }
.score-title { margin: 0 0 8px; font-size: 19px; font-weight: 700; }
.score-text { margin: 0; font-size: 14px; line-height: 1.55; color: var(--text-dim); }

.meters { display: flex; flex-direction: column; gap: 16px; }
.meter-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.meter-label { font-size: 14px; font-weight: 600; }
.meter-value { font-family: var(--font-num); font-size: 14px; color: var(--text-dim); }
.meter-track { height: 6px; border-radius: 100px; background: var(--surface-2); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 100px; transition: width .5s cubic-bezier(.4, 0, .2, 1); }
.meter-note { margin: 7px 0 0; font-size: 13px; line-height: 1.45; color: var(--text-dim); }

/* --- oggi ---------------------------------------------------------------------- */

.today-card {
  padding: 20px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--border);
  position: relative; overflow: hidden;
}
.today-card::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(120% 80% at 100% 0%, var(--accent-soft), transparent 60%);
  pointer-events: none;
}
.today-date { margin: 0 0 6px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-faint); }
.today-headline { margin: 0 0 10px; font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.today-text { margin: 0; font-size: 14.5px; line-height: 1.6; color: var(--text-dim); }

.transit-list { display: flex; flex-direction: column; gap: 1px; background: var(--border); border-radius: var(--r-sm); overflow: hidden; }
.transit {
  display: flex; align-items: baseline; gap: 8px;
  padding: 11px 14px; background: var(--surface); font-size: 13.5px;
  border-left: 3px solid var(--text-faint);
}
.transit-armonico { border-left-color: var(--pos); }
.transit-teso { border-left-color: var(--neg); }
.transit-neutro { border-left-color: var(--accent); }
.transit-body { font-weight: 600; }
.transit-asp { color: var(--text-dim); flex: 1; }
.transit-orb { font-family: var(--font-num); font-size: 11.5px; color: var(--text-faint); }

/* --- blocco a pagamento --------------------------------------------------------- */

.locked {
  position: relative; overflow: hidden;
  padding: 24px 20px; border-radius: var(--r-lg); text-align: center;
  background: var(--surface); border: 1px solid var(--border-str);
}
.locked-glow {
  position: absolute; inset: -50% -20% auto; height: 160px;
  background: radial-gradient(60% 100% at 50% 0%, var(--accent-soft), transparent 70%);
  pointer-events: none;
}
.locked-title { margin: 0 0 6px; font-size: 17px; font-weight: 700; }
.locked-desc { margin: 0 0 16px; font-size: 13.5px; line-height: 1.5; color: var(--text-dim); }

/* Le altre vie per aprire lo stesso contenuto: presenti e sobrie. Devono
   leggersi senza rubare il gesto alla principale — sono un'alternativa, non
   una seconda offerta che mette in dubbio la prima. */
.locked-altri {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
}
.locked-alt {
  background: none; border: 0; padding: 4px;
  font: inherit; font-size: 13px; color: var(--text-dim);
  cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
.locked-alt:hover { color: var(--text); }
.locked-alt .star { text-decoration: none; color: var(--accent); }

/* --- stati vuoti e scheletri ------------------------------------------------------ */

.empty { padding: 40px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-icon { font-family: var(--font-glyph); font-size: 34px; color: var(--accent); opacity: .5; }
.empty-title { margin: 0; font-size: 17px; font-weight: 700; }
.empty-text { margin: 0 0 8px; font-size: 14px; color: var(--text-dim); max-width: 34ch; line-height: 1.5; }

.skel { display: flex; flex-direction: column; gap: 9px; }
.skel-line { height: 12px; border-radius: 6px; background: var(--surface-2); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* --- onboarding -------------------------------------------------------------------- */

.ob-head { text-align: center; padding: 18px 0 6px; }
.ob-mark { font-family: var(--font-glyph); font-size: 34px; color: var(--accent); margin-bottom: 10px; }
.ob-title { margin: 0 0 6px; font-size: 27px; font-weight: 700; letter-spacing: -.02em; }
.ob-sub { margin: 0; font-size: 14px; color: var(--text-dim); }

/* --- foglio dal basso --------------------------------------------------------------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .55);
  opacity: 0; transition: opacity .2s;
}
.sheet-backdrop.open { opacity: 1; }

.sheet-panel {
  width: 100%; max-width: 560px; max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  border-top: 1px solid var(--border-str);
  transform: translateY(100%); transition: transform .25s cubic-bezier(.3, 1, .5, 1);
  padding-bottom: var(--safe-bottom);
}
.sheet-backdrop.open .sheet-panel { transform: translateY(0); }

.sheet-head { display: flex; align-items: center; gap: 12px; padding: 18px var(--pad) 12px; }
.sheet-title { flex: 1; margin: 0; font-size: 18px; font-weight: 700; }
.sheet-x { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); color: var(--text-dim); font-size: 14px; }
.sheet-body { padding: 0 var(--pad) 16px; overflow-y: auto; font-size: 14.5px; line-height: 1.6; color: var(--text-dim); }
.sheet-body p { margin: 0 0 11px; }
.sheet-body p:last-child { margin-bottom: 0; }
.sheet-lead { color: var(--accent); font-family: var(--font-num); font-size: 13px; }
.sheet-foot { display: flex; gap: 8px; padding: 12px var(--pad) 18px; border-top: 1px solid var(--border); }
.sheet-foot .btn { flex: 1; }

.invite-link {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; margin: 12px 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
}
.invite-link code {
  flex: 1; min-width: 0; font-family: var(--font-num); font-size: 11.5px;
  color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- toast ------------------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-bottom) + 16px);
  transform: translate(-50%, 20px); z-index: 100;
  max-width: min(88vw, 420px);
  padding: 12px 18px; border-radius: 100px;
  background: var(--surface-2); border: 1px solid var(--border-str);
  color: var(--text); font-size: 13.5px; text-align: center;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast-in { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--neg-soft); border-color: var(--neg); color: var(--neg); }

/* --- tab bar ------------------------------------------------------------------------- */

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
}
#tabs[hidden] { display: none; }

.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-faint); transition: color .15s;
}
.tab.active { color: var(--accent); }
.tab-glyph { font-family: var(--font-glyph); font-size: 19px; line-height: 1; }
.tab-label { font-size: 10.5px; font-weight: 600; letter-spacing: .02em; }

/* Persona il cui tema non è calcolabile: si segnala da sola, senza portarsi
   dietro il resto della lista. */
.person-broken { opacity: .8; }
.person-score-broken { background: var(--neg-soft); color: var(--neg); }

/* --- tendine della data ----------------------------------------------------
 * Il mese è più largo degli altri due perché contiene una parola intera
 * («settembre», «September»): dando a tutti la stessa larghezza il mese si
 * troncherebbe proprio nella lingua in cui i nomi sono lunghi.
 *
 * appearance:none toglie la freccia di sistema, che su Android è enorme e non
 * si accorda col resto; la freccia la disegna il background come SVG inline —
 * un file esterno sarebbe una richiesta in più per un triangolo.
 * ------------------------------------------------------------------------ */

.field-data { display: flex; gap: 8px; }
/* Le tre larghezze non sono uguali perché i contenuti non lo sono: il giorno
   deve contenere la parola «Giorno» (più lunga di «31»), il mese «settembre» o
   «September», l'anno quattro cifre. Con un terzo ciascuno il giorno usciva
   troncato in «Gio...». */
.field-data .sel-gg { flex: 0 1 27%; min-width: 0; }
.field-data .sel-mm { flex: 1 1 41%; min-width: 0; }
.field-data .sel-aa { flex: 0 1 32%; min-width: 0; }

.input-sel {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 26px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239D9AB4' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  text-overflow: ellipsis;
  cursor: pointer;
}

/* Il segnaposto («Giorno», «Mese», «Anno») e un option disabilitato: finché è
   selezionato il campo deve leggersi come vuoto, non come un valore scelto. */
.input-sel:invalid,
.input-sel option[value=""] { color: var(--text-faint); }

.input-sel:disabled { opacity: .45; cursor: default; }

/* Su iOS il menu di sistema usa il colore di sfondo dell'option, non quello
   del select: senza questo le voci escono bianche su bianco in tema chiaro. */
.input-sel option { background: var(--surface); color: var(--text); }

@media (max-width: 340px) {
  .field-data { gap: 6px; }
  .input-sel { padding-right: 22px; background-position: right 6px center; }
}
