/*
 * Vibe Coding Simulator · Research engine
 *
 * Palette derivata dal Cluster Lucano Automotive:
 *   ink    #101d74  testo, pulsanti principali
 *   azure  #00acff  tracce dati, focus
 *   teal   #5fc3ac  stato "in esecuzione", tracce dati
 *   ember  #db5111  unico accento caldo (cursore live, errori)
 *   paper  #f6f7fc  fondo
 */

:root {
    --ink: #101d74;
    --ink-deep: #0a1350;
    --ink-soft: #3b4785;
    --muted: #5a6290;
    --azure: #00acff;
    --azure-ink: #006fa6;
    --teal: #5fc3ac;
    --teal-ink: #23705f;
    --ember: #db5111;
    --ember-ink: #a83a07;
    --paper: #f6f7fc;
    --surface: #ffffff;
    --line: #dde1f0;
    --line-strong: #b9c0dc;

    --font-display: 'Bricolage Grotesque', 'Instrument Sans', system-ui, sans-serif;
    --font-body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

    /* scala tipografica 1.25 (terza maggiore) */
    --step--1: 0.8rem;
    --step-0: 1rem;
    --step-1: 1.25rem;
    --step-2: 1.563rem;
    --step-3: 1.953rem;
    --step-4: clamp(2.2rem, 1.6rem + 2.6vw, 3.6rem);
    --step-5: clamp(2.6rem, 1.6rem + 4.4vw, 5.2rem);

    --radius-s: 6px;
    --radius-m: 12px;
    --wrap: 1200px;
    --gutter: clamp(16px, 4vw, 40px);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink-deep);
    font-family: var(--font-body);
    font-size: var(--step-0);
    line-height: 1.55;
    font-feature-settings: 'tnum' 0;
    -webkit-font-smoothing: antialiased;
}

img, svg, canvas, iframe { display: block; max-width: 100%; }

h1, h2, h3, h4 {
    font-family: var(--font-display);
    color: var(--ink);
    line-height: 1.08;
    letter-spacing: -0.02em;
    margin: 0 0 0.5em;
    font-weight: 700;
    font-variation-settings: 'opsz' 96;
    text-wrap: balance;
}
h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-1); letter-spacing: -0.01em; font-variation-settings: 'opsz' 24; }
p { margin: 0 0 1em; max-width: 68ch; }

a { color: var(--ink); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--azure-ink); }

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

.wrap { max-width: var(--wrap); margin-inline: auto; padding-inline: var(--gutter); }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--ink); color: #fff; padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 8px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- Header ------------------------------------------------------------ */

.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.site-header__inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 68px; flex-wrap: wrap; padding-block: 10px; }

.wordmark { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.wordmark__mark { width: 34px; height: 34px; flex: none; }
.wordmark__mark rect { fill: var(--ink); }
.wordmark__mark path { fill: none; stroke: var(--teal); stroke-width: 3; stroke-linecap: round; }
.wordmark__text { font-family: var(--font-display); font-weight: 750; font-size: 1.08rem; line-height: 1.05; letter-spacing: -0.015em; }
.wordmark__text small { display: block; font-family: var(--font-body); font-weight: 500; font-size: 0.78rem; letter-spacing: 0; color: var(--muted); }

.site-nav { display: flex; align-items: center; gap: 4px 18px; flex-wrap: wrap; }
.site-nav a { text-decoration: none; font-weight: 550; color: var(--ink-soft); padding: 6px 0; }
.site-nav a[aria-current='page'] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--teal); }
.site-nav a:hover { color: var(--ink); }
.site-nav .button { color: #fff; padding: 8px 14px; }
.site-nav__quiet { font-weight: 450 !important; }

/* --- Bottoni e form ---------------------------------------------------- */

.button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font: 600 var(--step-0)/1.2 var(--font-body);
    padding: 12px 20px; border-radius: var(--radius-s);
    background: var(--ink); color: #fff; border: 1px solid var(--ink);
    text-decoration: none; cursor: pointer;
    transition: background-color 120ms ease;
}
.button:hover { background: var(--ink-deep); color: #fff; }
.button--ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.button--ghost:hover { background: var(--surface); color: var(--ink); border-color: var(--ink); }
.button--small { padding: 7px 12px; font-size: 0.9rem; }
.button--danger { background: transparent; color: var(--ember-ink); border-color: #efc3ad; }
.button--danger:hover { background: #fff3ed; color: var(--ember-ink); }
.button[disabled] { opacity: 0.5; cursor: not-allowed; }

.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--ink); text-decoration: underline; text-underline-offset: 0.18em; cursor: pointer; }

.form { display: grid; gap: 22px; }
.form label, .form legend { display: block; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.form input[type='text'], .form input[type='email'], .form input[type='password'], .form input[type='search'], .form select, .form textarea {
    width: 100%; font: inherit; color: var(--ink-deep);
    padding: 11px 13px; background: var(--surface);
    border: 1px solid var(--line-strong); border-radius: var(--radius-s);
}
.form textarea { resize: vertical; min-height: 5.5em; line-height: 1.5; }
.form input:focus, .form select:focus, .form textarea:focus { outline: none; border-color: var(--azure-ink); box-shadow: 0 0 0 3px rgba(0, 172, 255, 0.25); }
.form .help-text { color: var(--muted); font-size: 0.9rem; margin-top: 6px; }
.form ul { list-style: none; margin: 6px 0 0; padding: 0; color: var(--ember-ink); font-size: 0.9rem; font-weight: 550; }
.form fieldset { border: 0; padding: 0; margin: 0; }
.form .choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.form input[type='radio'], .form input[type='checkbox'] { accent-color: var(--ink); }
.form input[type='radio'] + label, .form input[type='checkbox'] + label { display: inline; font-weight: 500; margin: 0 16px 0 6px; }
.form__actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

.form-section { display: grid; grid-template-columns: minmax(0, 15rem) minmax(0, 1fr); gap: 12px 40px; padding-block: 28px; border-top: 1px solid var(--line); }
.form-section__intro h2 { font-size: var(--step-1); margin-bottom: 6px; }
.form-section__intro p { color: var(--muted); font-size: 0.95rem; }
.form-section__fields { display: grid; gap: 22px; }
@media (max-width: 760px) { .form-section { grid-template-columns: 1fr; } }

/* --- Messaggi ---------------------------------------------------------- */

.flash { margin: 18px 0 0; padding: 12px 16px; border-radius: var(--radius-s); background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--teal); max-width: none; }
.flash--error { border-left-color: var(--ember); }

.notice { padding: 14px 16px; border-radius: var(--radius-s); background: #eef8f5; border: 1px solid #cbe9e0; color: #1c4d42; font-size: 0.95rem; }
.notice p { margin: 0; }
.notice--warn { background: #fff5ee; border-color: #f2d3c1; color: #6e2c08; }

/* --- Hero (home) ------------------------------------------------------- */

.hero { padding-block: clamp(40px, 7vw, 88px) clamp(40px, 6vw, 72px); }
.hero__grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: clamp(28px, 5vw, 64px); align-items: center; }
.hero h1 { font-size: var(--step-5); font-weight: 760; letter-spacing: -0.022em; line-height: 0.98; margin-bottom: 0.35em; }
.hero__lead { font-size: var(--step-1); color: var(--ink-soft); line-height: 1.45; max-width: 34ch; }
.hero__actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 28px; }
@media (max-width: 900px) { .hero__grid { grid-template-columns: 1fr; } }

/* Il modello dal vivo: l'unico momento "rumoroso" del sito. */
.live-model { margin: 0; min-width: 0; background: var(--ink); color: #dfe5ff; border-radius: var(--radius-m); padding: 18px 18px 16px; }
.live-model__head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.live-model__title { font-family: var(--font-display); font-weight: 650; color: #fff; font-size: 1.05rem; margin: 0; }
.live-model__eq { font-size: 0.85rem; color: #aab4e6; margin: 0; font-style: italic; }
.live-model canvas { width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: var(--radius-s); background: #0c1660; }
.live-model__controls { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px 14px; align-items: center; margin-top: 14px; font-size: 0.92rem; }
.live-model__controls label { color: #fff; font-weight: 550; }
.live-model__controls output { font-variant-numeric: tabular-nums; color: #fff; min-width: 3.2em; text-align: right; }
.live-model input[type='range'] { width: 100%; accent-color: var(--teal); }
.live-model__legend { display: flex; gap: 18px; margin: 10px 0 0; padding: 0; list-style: none; font-size: 0.85rem; color: #c3cbf2; }
.live-model__legend li::before { content: ''; display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 7px; vertical-align: middle; background: var(--swatch); }

/* --- Sezioni ----------------------------------------------------------- */

.section { padding-block: clamp(40px, 6vw, 72px); }
.section + .section { border-top: 1px solid var(--line); }
.section__head { display: flex; justify-content: space-between; align-items: end; gap: 16px 32px; flex-wrap: wrap; margin-bottom: 28px; }
.section__head p { color: var(--muted); margin: 0; }
.section__head h2 { margin-bottom: 6px; }

.page-head { padding-block: clamp(32px, 5vw, 56px) 8px; }
.page-head p { color: var(--ink-soft); font-size: var(--step-1); line-height: 1.45; max-width: 46ch; }

.how { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px; counter-reset: how; padding: 0; margin: 0; list-style: none; }
.how li { counter-increment: how; padding-top: 18px; border-top: 2px solid var(--ink); }
.how li::before { content: counter(how); font-family: var(--font-display); font-weight: 700; font-size: var(--step-2); color: var(--teal-ink); display: block; line-height: 1; margin-bottom: 10px; }
.how h3 { margin-bottom: 6px; }
.how p { color: var(--ink-soft); margin: 0; }
@media (max-width: 760px) { .how { grid-template-columns: 1fr; } }

/* --- Gallery ----------------------------------------------------------- */

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 28px 24px; }

.tile { position: relative; display: flex; flex-direction: column; }
.tile__plate { aspect-ratio: 16 / 10; border-radius: var(--radius-s); overflow: hidden; background: var(--surface); border: 1px solid var(--line); }
.tile__plate canvas { width: 100%; height: 100%; }
.tile__body { padding-top: 12px; }
.tile__meta { display: flex; gap: 6px 12px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.tile h3 { margin-bottom: 4px; font-size: 1.15rem; }
.tile h3 a { text-decoration: none; }
.tile h3 a::after { content: ''; position: absolute; inset: 0; }
.tile:hover .tile__plate { border-color: var(--ink-soft); }
.tile:hover h3 a { text-decoration: underline; }
.tile p { color: var(--ink-soft); font-size: 0.95rem; margin: 0; }

.domain { display: inline-flex; align-items: center; gap: 6px; }
.domain::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--domain-color, var(--line-strong)); }

/* La prima challenge è il riferimento principale: occupa tutta la riga, con il testo accanto. */
.gallery--challenges .tile:first-child { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 12px 32px; align-items: center; }
.gallery--challenges .tile:first-child .tile__plate { aspect-ratio: 21 / 9; }
.gallery--challenges .tile:first-child h3 { font-size: var(--step-2); margin-bottom: 8px; }
.gallery--challenges .tile:first-child p { font-size: var(--step-0); }
@media (max-width: 760px) { .gallery--challenges .tile:first-child { grid-template-columns: 1fr; } }

.empty { padding: 36px 24px; border: 1px dashed var(--line-strong); border-radius: var(--radius-m); text-align: left; }
.empty h3 { margin-bottom: 6px; }
.empty p { color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: end; margin-bottom: 28px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
.filters .form { display: contents; }
.filters label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; color: var(--ink); }
.filters input, .filters select { font: inherit; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-s); background: var(--surface); min-width: 12rem; }
.filters__search { flex: 1 1 14rem; }
.filters__search input { width: 100%; }

/* --- Dettaglio e stage ------------------------------------------------- */

.detail-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px 32px; align-items: end; padding-block: clamp(28px, 4vw, 48px) 20px; }
.detail-head h1 { font-size: var(--step-4); margin-bottom: 8px; }
.detail-head p { color: var(--ink-soft); font-size: var(--step-1); line-height: 1.45; margin: 0; max-width: 52ch; }
.detail-head__meta { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 0.92rem; color: var(--muted); margin-bottom: 12px; }
.detail-head__actions { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 760px) { .detail-head { grid-template-columns: 1fr; } }

.stage { background: var(--ink-deep); border-radius: var(--radius-m); overflow: hidden; border: 1px solid var(--ink-deep); }
.stage__frame { width: 100%; height: min(78vh, 820px); min-height: 460px; border: 0; background: #fff; }
.stage__bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; color: #c7cff5; font-size: 0.88rem; flex-wrap: wrap; }
.stage__bar a, .stage__bar button { color: #fff; }
.stage__bar-actions { display: flex; gap: 16px; }
.stage:fullscreen .stage__frame { height: calc(100vh - 44px); }

.stage__waiting { display: grid; place-content: center; text-align: center; gap: 10px; height: min(60vh, 560px); min-height: 360px; color: #dfe5ff; padding: 24px; }
.stage__waiting h2 { color: #fff; font-size: var(--step-2); margin: 0; }
.stage__waiting p { margin: 0 auto; color: #aab4e6; }
.stage__waiting--failed h2 { color: #ffd6c4; }

.pulse { width: 120px; height: 40px; margin: 0 auto 6px; }
.pulse path { fill: none; stroke: var(--teal); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 160; stroke-dashoffset: 160; animation: trace 1.6s ease-in-out infinite; }
@keyframes trace { to { stroke-dashoffset: -160; } }

.prose { padding-block: 32px 8px; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 32px 56px; }
.prose dl { margin: 0; display: grid; gap: 14px; align-content: start; }
.prose dt { font-weight: 650; color: var(--ink); font-size: 0.92rem; }
.prose dd { margin: 2px 0 0; color: var(--ink-soft); white-space: pre-line; }
@media (max-width: 860px) { .prose { grid-template-columns: 1fr; } }

/* --- Area partner ------------------------------------------------------ */

.dash-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; padding-block: clamp(28px, 4vw, 48px) 24px; }
.dash-head h1 { font-size: var(--step-3); margin-bottom: 4px; }
.dash-head p { color: var(--muted); margin: 0; }

.sim-list { list-style: none; margin: 0 0 48px; padding: 0; border-top: 1px solid var(--line); }
.sim-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 24px; align-items: center; padding: 18px 0; border-bottom: 1px solid var(--line); }
.sim-list h2 { font-size: 1.15rem; margin: 0 0 2px; font-variation-settings: 'opsz' 24; }
.sim-list h2 a { text-decoration: none; }
.sim-list h2 a:hover { text-decoration: underline; }
.sim-list p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 0.82rem; font-weight: 600; background: #eceffa; color: var(--ink-soft); white-space: nowrap; }
.badge--public { background: #e3f4ef; color: var(--teal-ink); }
.badge--running { background: #e2f4fd; color: var(--azure-ink); }
.badge--failed { background: #fdebe2; color: var(--ember-ink); }
.badge--hidden { background: #fdebe2; color: var(--ember-ink); }
.badge-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); gap: 28px; align-items: start; padding-bottom: 56px; }
@media (max-width: 980px) { .workspace { grid-template-columns: 1fr; } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px; }
.panel + .panel { margin-top: 16px; }
.panel h2 { font-size: 1.05rem; margin-bottom: 10px; font-variation-settings: 'opsz' 24; letter-spacing: -0.005em; }
.panel p { font-size: 0.93rem; color: var(--ink-soft); }
.panel .form { gap: 14px; }
.panel .form label { font-size: 0.93rem; }

.visibility { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.visibility p { margin: 0; }

.versions { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.versions li { display: grid; grid-template-columns: 2.2rem minmax(0, 1fr); gap: 2px 10px; padding: 10px 8px; border-radius: var(--radius-s); }
.versions li[aria-current='true'] { background: var(--paper); box-shadow: inset 3px 0 0 var(--ink); }
.versions__n { font-family: var(--font-display); font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.versions__what { font-size: 0.92rem; }
.versions__what a { font-weight: 600; }
.versions__note { grid-column: 2; font-size: 0.85rem; color: var(--muted); }
.versions__actions { grid-column: 2; display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.88rem; margin-top: 4px; }

details.panel summary { cursor: pointer; font-weight: 650; color: var(--ink); }
details.panel[open] summary { margin-bottom: 12px; }

/* --- Login ------------------------------------------------------------- */

.auth { min-height: 62vh; display: grid; place-items: center; padding-block: 48px; }
.auth__box { width: min(100%, 420px); }
.auth__box h1 { font-size: var(--step-3); }
.auth__box > p { color: var(--muted); }

/* --- Footer ------------------------------------------------------------ */

.site-footer { margin-top: 48px; border-top: 1px solid var(--line); background: var(--surface); }
.site-footer__inner { padding-block: 32px; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px 48px; font-size: 0.93rem; color: var(--ink-soft); }
.site-footer__meta { color: var(--muted); }
@media (max-width: 760px) { .site-footer__inner { grid-template-columns: 1fr; } }

/* Colori per ambito: tinte tratte dalla stessa famiglia della palette. */
[data-domain='energia'] { --domain-color: #f0a400; }
[data-domain='biologia'] { --domain-color: #5fc3ac; }
[data-domain='meccatronica'] { --domain-color: #4882e3; }
[data-domain='ambiente'] { --domain-color: #6eaa1f; }
[data-domain='materiali'] { --domain-color: #7639e2; }
[data-domain='mobilita'] { --domain-color: #00acff; }
[data-domain='fisica'] { --domain-color: #101d74; }
[data-domain='chimica'] { --domain-color: #d0021b; }
[data-domain='sicurezza'] { --domain-color: #db5111; }
[data-domain='altro'] { --domain-color: #8a91b4; }

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

/* --- Avvio su richiesta ------------------------------------------------ */

.launcher { position: relative; height: min(60vh, 560px); min-height: 360px; display: grid; }
.launcher__plate { position: absolute; inset: 0; opacity: 0.35; }
.launcher__plate canvas { width: 100%; height: 100%; }
.launcher__body { position: relative; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 24px; text-align: center; }
.launcher__body p { color: #c7cff5; font-size: 0.93rem; max-width: 46ch; margin: 0; }
.launcher__button { background: #fff; color: var(--ink); border-color: #fff; font-size: var(--step-1); padding: 14px 26px; }
.launcher__button:hover { background: var(--paper); color: var(--ink); }
.stage--launcher [hidden] { display: none !important; }

/* --- Controllo automatico e suggerimenti ------------------------------- */

.quality--ok { border-left: 4px solid var(--teal); }
.quality--ko { border-left: 4px solid var(--ember); }
.quality__list { margin: 0 0 12px; padding-left: 18px; font-size: 0.93rem; color: var(--ink-deep); }
.quality__list li + li { margin-top: 4px; }

.hints { margin-bottom: 14px; }
.hints__label { font-size: 0.88rem; margin: 0 0 8px; color: var(--muted); }
.hints__list { display: flex; flex-wrap: wrap; gap: 6px; }
.hints__chip { font: 500 0.85rem/1.2 var(--font-body); padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; }
.hints__chip:hover { border-color: var(--ink); background: var(--paper); }
.launcher__notice { color: #ffd6c4 !important; font-weight: 550; }
