/* Incastro, direzione Aurora. Token da .context/design/brief.md */
@font-face { font-family: "IBM Plex Sans Condensed"; font-weight: 600; font-style: normal; font-display: swap; src: url("../fonts/IBMPlexSansCondensed-SemiBold.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/IBMPlexSans-Regular.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 500; font-style: normal; font-display: swap; src: url("../fonts/IBMPlexSans-Medium.ttf") format("truetype"); }

/* Colori registrati: la tinta dell'aurora si può animare */
@property --a1 { syntax: "<color>"; inherits: true; initial-value: #5EF2D6; }
@property --a2 { syntax: "<color>"; inherits: true; initial-value: #4FB8FF; }
@property --a3 { syntax: "<color>"; inherits: true; initial-value: #5EF2D6; }

:root {
  --notte: #0E1430; --pozzo: #121A3D; --pannello: #19214A;
  --testo: #EEF1FF; --tenue: #A3ABD6;
  --verde: #5EF2D6; --viola: #8A7CFF; --rosa: #FF7AC6; --oro: #F5B92E;
  --linea: rgba(238, 241, 255, .12);
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --num: "IBM Plex Sans Condensed", "IBM Plex Sans", system-ui, sans-serif;
  --sa-t: env(safe-area-inset-top, 0px); --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px); --sa-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
html { background: var(--notte); height: 100%; }
body {
  height: 100%; overflow: hidden; font: 400 16px/1.45 var(--font); color: var(--testo);
  --a1: #5EF2D6; --a2: #4FB8FF; --a3: #5EF2D6;
  background:
    radial-gradient(55% 38% at 50% -4%, color-mix(in srgb, var(--a1) 38%, transparent), transparent 72%),
    radial-gradient(40% 34% at 82% 8%, color-mix(in srgb, var(--a2) 40%, transparent), transparent 70%),
    radial-gradient(38% 30% at 16% 14%, color-mix(in srgb, var(--a3) 22%, transparent), transparent 70%),
    var(--notte);
  background-attachment: fixed;
  transition: --a1 1.2s ease, --a2 1.2s ease, --a3 1.2s ease;
  -webkit-tap-highlight-color: transparent;
}
body[data-world="alba"] { --a1: #FF7AC6; --a2: #FFB38A; --a3: #FF7AC6; }
body[data-world="corrente"] { --a1: #5EF2D6; --a2: #4FB8FF; --a3: #5EF2D6; }
body[data-world="tempesta"] { --a1: #8A7CFF; --a2: #FF5FD2; --a3: #8A7CFF; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--verde); outline-offset: 3px; }

/* Schermate */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain;
  padding: max(16px, var(--sa-t)) max(16px, var(--sa-r)) max(16px, var(--sa-b)) max(16px, var(--sa-l)); }
.screen:not([hidden]) { animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; } }
.col { width: min(100%, 420px); margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.col.wide { width: min(100%, 760px); }
.col.center { margin-block: auto; }
.col .col { width: 100%; }

h1, h2 { font-family: var(--num); font-weight: 600; letter-spacing: -.01em; line-height: 1.1; }
h1 { font-size: 34px; }
h2 { font-size: 20px; }
.title { font-size: 60px; text-align: center; letter-spacing: -.02em; }
.lead { color: var(--tenue); }
.label { color: var(--tenue); font-size: 14px; margin-bottom: 8px; font-weight: 500; }
.best { text-align: center; color: var(--tenue); margin-top: -8px; }
.best b { font: 600 20px var(--num); color: var(--testo); font-variant-numeric: tabular-nums; margin-left: 4px; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.panel { border-radius: 14px; background: rgba(25, 33, 74, .72); border: 1px solid var(--linea); padding: 12px 14px 14px; }

/* Pulsanti */
.btn { font: 500 16px/1.2 var(--font); min-height: 48px; padding: 12px 20px; border-radius: 12px; cursor: pointer;
  color: var(--testo); background: rgba(255, 255, 255, .06); border: 1px solid var(--linea);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .12); }
.btn.primary { background: var(--verde); border-color: var(--verde); color: var(--notte); font-weight: 500; }
.btn.primary:hover { background: #8BF6E3; }
.btn.ghost { background: transparent; border-color: transparent; padding-inline: 8px 12px; }
.back svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.subhead { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.subhead h1 { font-size: 26px; }
.subhead .back { margin-left: -8px; }

/* Logo */
.logo { display: grid; grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(2, 40px); gap: 4px; justify-content: center; }
.b { position: relative; border-radius: 20%; background: linear-gradient(135deg, var(--ba), var(--bb) 55%); box-shadow: 0 0 22px -2px var(--bb);
  animation: drop .55s cubic-bezier(.3, 1.4, .5, 1) both; animation-delay: calc(var(--i) * 110ms); }
/* ritardi a cascata senza attributi style inline (CSP style-src 'self') */
.b, .star { --i: 0; } .b:nth-child(2), .star:nth-child(2) { --i: 1; } .b:nth-child(3), .star:nth-child(3) { --i: 2; } .b:nth-child(4) { --i: 3; }
.b::after { content: ""; position: absolute; left: 20%; top: 15%; width: 60%; height: 14%; border-radius: 99px; background: rgba(255, 255, 255, .42); }
.b-t { --ba: #E4D4FF; --bb: #9B6BFF; grid-column: 2; grid-row: 1; }
.b-i { --ba: #B8FAFF; --bb: #2FC9E8; grid-column: 1; grid-row: 2; }
.b-s { --ba: #FFC4D2; --bb: #F2466E; grid-column: 2; grid-row: 2; }
.b-l { --ba: #FFDDB8; --bb: #FF8A3D; grid-column: 3; grid-row: 2; }
@keyframes drop { from { transform: translateY(-120px); opacity: 0; } 60% { opacity: 1; } }

/* Scelta livello */
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.lv { font: 600 20px var(--num); min-height: 48px; border-radius: 12px; cursor: pointer; color: var(--testo);
  background: rgba(255, 255, 255, .06); border: 1px solid var(--linea); font-variant-numeric: tabular-nums; }
.lv:hover { background: rgba(255, 255, 255, .12); }
.lv[aria-checked="true"] { background: var(--verde); border-color: var(--verde); color: var(--notte); }

/* Mappa */
.worlds { display: grid; gap: 16px; }
.world h2 { margin-bottom: 8px; }
.stages { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stage { width: 100%; text-align: left; font: 400 14px/1.3 var(--font); color: var(--testo); cursor: pointer; min-height: 72px;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--linea); background: rgba(25, 33, 74, .72);
  display: grid; gap: 2px; align-content: start; }
.stage:hover:not(:disabled) { background: rgba(255, 255, 255, .12); }
.stage .n { font: 600 20px var(--num); }
.stage .g { color: var(--tenue); }
.stage:disabled { cursor: default; opacity: 1; color: var(--tenue); }
.stage .lock { display: flex; align-items: center; gap: 6px; color: var(--tenue); }
.stage .lock svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stars { display: inline-flex; gap: 2px; margin-top: 2px; }
.star { width: 20px; height: 20px; fill: none; stroke: var(--tenue); stroke-width: 1.6; stroke-linejoin: round; }
.star.on { fill: var(--oro); stroke: var(--oro); }
@media (min-width: 768px) { .worlds { grid-template-columns: repeat(3, 1fr); align-items: start; } .col.wide { width: min(100%, 960px); } .stages { grid-template-columns: 1fr; } }

/* Record */
.records { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.records th { font-weight: 500; font-size: 14px; color: var(--tenue); text-align: right; padding: 6px 8px; }
.records td { padding: 10px 8px; text-align: right; border-top: 1px solid var(--linea); }
.records th:first-child, .records td:first-child { text-align: left; font: 600 18px var(--num); }
.records td:nth-child(2) { font: 600 18px var(--num); }
.records th:last-child, .records td:last-child { color: var(--tenue); font-size: 14px; }
.empty { text-align: center; padding: 32px 16px; }
.empty p { margin-bottom: 16px; }
.empty .btn { margin-inline: auto; }

/* Impostazioni */
.rows { padding: 4px 14px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 56px; }
.row + .row { border-top: 1px solid var(--linea); }
.switch { position: relative; width: 56px; height: 32px; border-radius: 16px; border: 1px solid var(--linea); cursor: pointer; flex: none;
  background: rgba(255, 255, 255, .1); }
.switch span { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--testo); }
.switch[aria-checked="true"] { background: var(--verde); border-color: var(--verde); }
.switch[aria-checked="true"] span { left: 27px; background: var(--notte); }
.switch::after { content: ""; position: absolute; inset: -7px -1px; } /* area tattile 44 px senza cambiare la grafica */
.col > h2 { margin-top: 8px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; align-items: center; }
.keys dt { font-weight: 500; }
.keys dd { color: var(--tenue); }
kbd { font: 500 13px var(--font); display: inline-block; min-width: 26px; padding: 2px 7px; text-align: center; border-radius: 6px;
  background: rgba(255, 255, 255, .08); border: 1px solid var(--linea); }

/* Partita */
.screen.game { padding: 0; overflow: hidden; }
.app { height: 100dvh; display: grid; grid-template-rows: auto 1fr;
  padding: max(18px, var(--sa-t)) max(28px, var(--sa-r)) max(24px, var(--sa-b)) max(28px, var(--sa-l)); }
.gbar { display: flex; align-items: center; gap: 16px; }
.mark { font: 600 26px/1 var(--num); letter-spacing: -.01em; }
.mark span { display: inline-block; width: .5em; height: .5em; border-radius: 3px; margin-right: 8px;
  background: linear-gradient(135deg, var(--verde), var(--viola)); box-shadow: 0 0 14px var(--verde); }
.context { margin-left: auto; color: var(--tenue); font-size: 15px; }
.context b { color: var(--testo); font: 600 18px var(--num); font-variant-numeric: tabular-nums; margin-left: 6px; }
.actions { display: flex; gap: 8px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--linea); background: rgba(255, 255, 255, .05);
  color: var(--testo); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
.icon-btn svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.icon-btn[aria-pressed="true"] .slash, .icon-btn[aria-pressed="false"] .waves { display: none; }

.play { --wh: min(calc(100dvh - 140px - var(--sa-t) - var(--sa-b)), 760px);
  display: grid; min-height: 0; justify-content: center; gap: 18px 32px; padding-top: 16px;
  grid-template-columns: 190px auto 190px; }
.side { display: flex; flex-direction: column; gap: 18px; align-self: start; min-width: 0; }
.wellbox { width: calc(var(--wh) / 2); height: var(--wh); }
.well { position: relative; width: 100%; height: 100%; border-radius: 16px; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  background: var(--pozzo); border: 1px solid var(--linea);
  box-shadow: 0 0 0 6px rgba(255, 255, 255, .02), 0 30px 80px -20px color-mix(in srgb, var(--a1) 28%, transparent); }
.well canvas { width: 100%; height: 100%; display: block; }
.panel h2 { font: 500 14px var(--font); color: var(--tenue); margin-bottom: 6px; letter-spacing: 0; }
.hold canvas { width: 100%; height: 70px; display: block; }
.next canvas { width: 100%; height: 62px; display: block; }
.next canvas:first-of-type { height: 78px; }
.statlist { display: grid; gap: 16px; align-content: start; padding-top: 8px; }
.stat dt { font-size: 14px; color: var(--tenue); }
.stat dd { font: 600 30px/1.1 var(--num); font-variant-numeric: tabular-nums; }
.stat.big dd { font-size: 44px; }
.stat.big dd.small { font-size: 30px; }
.stat dd.urgent { color: var(--rosa); }
.progress { padding-top: 8px; }
.progress p { font-size: 14px; color: var(--tenue); margin-bottom: 8px; }
.track { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.track i { display: block; width: 0; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--verde), var(--viola)); box-shadow: 0 0 12px var(--verde); }

.alert { position: absolute; left: 0; right: 0; top: 26%; margin-inline: auto; width: max-content; max-width: 92%; pointer-events: none;
  font: 600 34px/1.1 var(--num); text-align: center; padding: 10px 18px; border-radius: 14px; opacity: 0;
  background: rgba(14, 20, 48, .85); border: 1px solid var(--linea); box-shadow: 0 0 30px -4px var(--verde); }
.alert.show { opacity: 1; }

.guide { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 14px; text-align: center;
  background: rgba(14, 20, 48, .88); color: var(--testo); border: 0; font: 500 18px/1.3 var(--font); padding: 16px; cursor: pointer; }
.g-title { font: 600 26px var(--num); }
.g-ok { color: var(--verde); margin-top: 8px; }

/* Overlay */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(14, 20, 48, .72); backdrop-filter: blur(6px); }
.overlay:not([hidden]) { animation: fade .18s ease-out; }
.dialog { width: min(100%, 360px); background: var(--pannello); border: 1px solid var(--linea); border-radius: 14px; padding: 24px; display: grid; gap: 16px; text-align: center;
  box-shadow: 0 30px 80px -20px color-mix(in srgb, var(--a1) 30%, transparent); }
.dialog h2 { font-size: 34px; }
.badge { color: var(--notte); background: var(--verde); border-radius: 99px; padding: 6px 14px; font-weight: 500; justify-self: center; }
.sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sum dt { color: var(--tenue); font-size: 14px; }
.sum dd { font: 600 26px/1.1 var(--num); font-variant-numeric: tabular-nums; }
.stagename { color: var(--tenue); margin-top: -8px; }
#r-stars { display: flex; justify-content: center; min-height: 52px; }
#r-stars .star { width: 48px; height: 48px; }
#r-stars .stars { gap: 8px; }
.stars.anim .star.on { animation: pop .4s cubic-bezier(.3, 1.5, .5, 1) both; animation-delay: calc(var(--i) * 350ms + 250ms); }
@keyframes pop { from { transform: scale(0); opacity: 0; } }

/* Telefono */
@media (max-width: 767px) {
  .title { font-size: 44px; }
  .app { padding: max(10px, var(--sa-t)) max(12px, var(--sa-r)) max(12px, var(--sa-b)) max(12px, var(--sa-l)); }
  .mark { font-size: 20px; } .context { font-size: 13px; } .context b { font-size: 15px; }
  .play { grid-template-columns: 84px minmax(0, 1fr) 84px; grid-template-rows: auto auto minmax(0, 1fr); gap: 10px; padding-top: 10px; justify-content: stretch;
    grid-template-areas: "hold stats next" "hold prog next" "well well well"; }
  .side { display: contents; }
  .hold { grid-area: hold; align-self: start; } .next { grid-area: next; align-self: start; }
  .statlist { grid-area: stats; } .progress { grid-area: prog; }
  .wellbox { grid-area: well; width: 100%; height: 100%; min-height: 0; container-type: size; display: grid; place-items: center; }
  .well { width: min(100cqw, 50cqh); height: min(100cqh, 200cqw); border-radius: 12px; }
  .statlist { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 6px; padding-top: 0; align-content: start; }
  .progress { padding-top: 0; }
  .progress p { font-size: 12px; margin-bottom: 4px; white-space: nowrap; }
  .track { height: 6px; }
  .panel { padding: 8px; border-radius: 12px; } .panel h2 { font-size: 12px; margin-bottom: 2px; }
  .hold canvas { height: 46px; } .next canvas, .next canvas:first-of-type { height: 28px; }
  .stat dt { font-size: 12px; line-height: 1.2; } .stat dd { font-size: 20px; }
  .stat.big { grid-column: 1 / -1; } .stat.big dd { font-size: 30px; } .stat.big dd.small { font-size: 22px; }
  .alert { font-size: 26px; }
  .guide { font-size: 16px; gap: 10px; }
  .dialog { padding: 20px; }
}

/* Animazioni ridotte: sistema o impostazione */
html[data-reduced="1"] body { transition: none; }
html[data-reduced="1"] .b, html[data-reduced="1"] .screen, html[data-reduced="1"] .overlay,
html[data-reduced="1"] .stars.anim .star.on { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
  body { transition: none; }
  .b, .screen, .overlay, .stars.anim .star.on { animation: none !important; }
}
