/* Mini-sito questionario - stile neutro, monocromatico, mobile-first */
@font-face { font-family: 'IBM Plex Mono'; font-weight: 400; font-style: normal; font-display: swap; src: url('../assets/fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-weight: 500; font-style: normal; font-display: swap; src: url('../assets/fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-weight: 600; font-style: normal; font-display: swap; src: url('../assets/fonts/ibm-plex-mono-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-weight: 700; font-style: normal; font-display: swap; src: url('../assets/fonts/ibm-plex-mono-latin-700-normal.woff2') format('woff2'); }

:root {
  --bg: #fafaf8; --card: #ffffff; --ink: #1b1b1b; --muted: #5d5d5d; --line: #d9d9d4; --line-strong: #1b1b1b;
  --accent: #1b1b1b; --accent-ink: #ffffff; --sel: #ececE6;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 17px; line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; }
.brand { font-family: var(--mono); font-weight: 600; font-size: 14px; letter-spacing: .02em; }
.code-badge { font-family: var(--mono); font-size: 13px; padding: 2px 10px; border: 1px solid var(--line-strong); border-radius: 999px; }
.progress { height: 3px; background: var(--line); }
#progress-bar { height: 3px; width: 0; background: var(--ink); transition: width .25s; }
main#app { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px 14px 90px; outline: none; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.sync { position: fixed; left: 0; right: 0; bottom: 0; text-align: center; font-size: 13px; color: var(--muted); background: var(--bg); padding: 0; }
.sync:not(:empty) { padding: 8px 12px; border-top: 1px solid var(--line); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 16px; }
.card.wide { max-width: 1100px; }
.center { text-align: center; }
.screen-title { font-family: var(--mono); font-size: 20px; margin: 0 0 12px; line-height: 1.3; }
.screen-title.big { font-size: 24px; }
.question { font-size: 18px; font-weight: 600; margin: 14px 0 12px; }
.big-text { font-size: 20px; }
.protocol-text { padding: 12px 14px; background: var(--sel); border-radius: 8px; }
.notice { font-size: 15px; color: var(--muted); }
.hint { font-size: 14px; color: var(--muted); margin: 6px 0; }
.link { color: var(--ink); text-underline-offset: 3px; }
.practice-tag { display: inline-block; font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; border: 1px solid var(--line-strong); border-radius: 999px; padding: 1px 10px; margin: 0 0 8px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.btn { appearance: none; font: inherit; font-weight: 600; border-radius: var(--radius); border: 1.5px solid var(--accent); padding: 12px 22px; cursor: pointer; min-height: 48px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: transparent; color: var(--ink); }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 15px; }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn:focus-visible, .option:focus-visible, .scale-btn:focus-visible, .dim-item:focus-visible { outline: 3px solid #4a7dff; outline-offset: 2px; }

.options { display: flex; flex-direction: column; gap: 10px; margin: 8px 0; }
.options-inline { flex-direction: row; flex-wrap: wrap; }
.options-inline .option { flex: 1 1 auto; min-width: 120px; text-align: center; justify-content: center; }
.option { appearance: none; font: inherit; text-align: left; background: var(--card); color: var(--ink); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 13px 14px; min-height: 52px; cursor: pointer; display: flex; align-items: center; }
.option:hover:not(:disabled) { border-color: var(--line-strong); }
.option.selected { border-color: var(--line-strong); background: var(--sel); box-shadow: inset 0 0 0 1px var(--line-strong); font-weight: 600; }
.option:disabled { cursor: default; }
.option-nc { border-style: dashed; margin-top: 6px; color: #333; }
.debug-key { outline: 2px dashed #8a5cf6; outline-offset: 2px; }

.plate { margin: 0 0 14px; text-align: center; }
.plate img { width: 100%; max-width: 600px; height: auto; object-fit: contain; display: inline-block; -webkit-user-drag: none; user-select: none; }
.stimulus { margin: 6px 0 14px; text-align: center; padding: 16px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.stimulus img { max-width: 100%; -webkit-user-drag: none; user-select: none; }
.c4-plates { display: flex; flex-direction: column; gap: 14px; margin-bottom: 8px; }
.c4-plate { position: relative; margin: 0; padding: 10px 10px 10px 44px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; text-align: left; }
.c4-plate img { width: 100%; max-width: 600px; }
.c4-letter { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-family: var(--mono); font-weight: 700; font-size: 22px; }

.scale-wrap { margin: 6px 0 14px; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.scale-btn { appearance: none; font: inherit; font-weight: 600; height: 52px; border-radius: var(--radius); border: 1.5px solid var(--line); background: var(--card); cursor: pointer; }
.scale-btn.selected { background: var(--ink); color: #fff; border-color: var(--ink); }
.scale-labels { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.q-block { margin-bottom: 18px; }

.field { width: 100%; font: inherit; padding: 12px; border: 1.5px solid var(--line-strong); border-radius: var(--radius); background: #fff; color: var(--ink); }
.area { resize: vertical; min-height: 110px; }
.field-label { display: block; font-weight: 600; margin: 12px 0 4px; }
.field-label .field { margin-top: 4px; font-weight: 400; }
.form-error { color: #8a1c1c; font-weight: 600; min-height: 1.4em; }
.feedback { font-weight: 600; min-height: 1.4em; margin: 12px 0 0; padding: 0; }
.feedback:not(:empty) { padding: 10px 12px; background: var(--sel); border-radius: 8px; border-left: 4px solid var(--ink); }

.code-box { display: flex; gap: 18px; flex-wrap: wrap; margin: 14px 0; }
.code-box div { border: 1.5px solid var(--line-strong); border-radius: var(--radius); padding: 10px 18px; text-align: center; min-width: 120px; }
.code-box dt { font-size: 13px; color: var(--muted); }
.code-box dd { margin: 0; font-family: var(--mono); font-size: 28px; font-weight: 700; letter-spacing: .06em; }
.code-line { font-size: 18px; }

/* familiarizzazione */
.fam-structure { padding: 12px 14px; background: var(--sel); border-radius: 8px; }
.fam-group h3 { font-family: var(--mono); font-size: 16px; margin: 20px 0 6px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.fam-group dl { margin: 0; }
.fam-item { margin: 10px 0; }
.fam-item dt { font-weight: 700; }
.fam-item dd { margin: 2px 0 0; color: #333; }

/* legenda ricostruita (font IBM Plex Mono locale) */
.legend { display: grid; grid-template-columns: 1fr; gap: 12px 40px; font-family: var(--mono); margin: 14px 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
@media (min-width: 700px) { .legend { grid-template-columns: 1fr 1fr; } }
.lg-h { font-size: 16px; font-weight: 700; margin: 4px 0 8px; }
.lg-list { list-style: none; padding: 0; margin: 0 0 14px; }
.lg-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 18px; margin: 8px 0; }
.lg-icon { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: flex-start; min-width: 64px; }
.lg-icon-state { min-width: 78px; }
.lg-icon-resp { min-width: 32px; justify-content: center; align-items: center; }
.lg-wide { min-width: 201px; }
.lg-img-proc { width: 63px; height: 63px; }
.lg-img-wide { width: 201px; height: 63px; max-width: none; }
.lg-img-resp { width: 22px; height: 22px; }
.lg-img-media { width: 38px; height: 38px; }
.lg-img { display: block; }
.lg-crop { display: inline-block; background-repeat: no-repeat; flex: 0 0 auto; }
.lg-label { font-size: 16px; line-height: 1.3; }
.lg-note { font-family: var(--sans); font-size: 14px; color: var(--muted); margin: 0 0 8px; }
.lg-media { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 8px 18px; }
.lg-media li { display: flex; align-items: center; gap: 8px; }
.legend-toggle { margin-top: 12px; }
.legend-panel { margin-top: 10px; overflow-x: auto; }
.legend-panel[hidden] { display: none; }

/* prova dimensionale */
.dim-list { display: flex; flex-direction: row; flex-wrap: wrap; gap: 12px; align-items: flex-start; margin: 12px 0; max-width: 100%; }
.dim-item { appearance: none; font: inherit; background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.dim-item:hover { border-color: var(--line-strong); }
.dim-pct { font-family: var(--mono); font-weight: 700; font-size: 14px; }
.dim-item img { display: block; height: auto; -webkit-user-drag: none; }
.gate { text-align: center; padding: 28px 8px; }
.gate-icon { font-size: 64px; line-height: 1; margin-bottom: 8px; animation: spin 2.4s ease-in-out infinite; }
@keyframes spin { 0%, 60% { transform: rotate(0); } 100% { transform: rotate(90deg); } }

/* overlay & debug */
.overlay { position: fixed; inset: 0; background: rgba(20,20,20,.55); z-index: 30; display: flex; align-items: flex-start; justify-content: center; padding: 20px 12px; overflow: auto; }
.overlay .card { width: 100%; max-width: 560px; }
.overlay .card.wide { max-width: 1100px; }
.debug-bar { position: fixed; right: 8px; bottom: 8px; z-index: 20; background: #1b1b1b; color: #fff; border-radius: 10px; padding: 6px; display: flex; flex-wrap: wrap; gap: 6px; max-width: calc(100vw - 16px); align-items: center; font-family: var(--mono); font-size: 12px; }
.dbg-label { padding: 0 6px; }
.dbg-btn { font: inherit; background: #333; color: #fff; border: 1px solid #666; border-radius: 6px; padding: 5px 9px; cursor: pointer; }
.table-scroll { overflow: auto; max-height: 60vh; }
.tbl { border-collapse: collapse; font-size: 12px; width: 100%; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 4px 6px; text-align: left; vertical-align: top; }
.tbl tr.current { background: #fff3c4; }

@media (max-width: 480px) {
  body { font-size: 16px; }
  .card { padding: 14px 12px; }
  .screen-title.big { font-size: 21px; }
  .btn { width: 100%; }
  .actions { flex-direction: column-reverse; }
  .options-inline .option { min-width: 0; flex: 1 1 28%; }
}

.screen-title.sub { font-size: 18px; margin-top: 22px; }
.welcome-list { padding-left: 22px; margin: 6px 0 14px; }
.welcome-list li { margin: 6px 0; }

.top-right { display: flex; align-items: center; gap: 10px; }
.lang-switch { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.lang-switch[hidden] { display: none; }
.lang-btn { font-family: var(--mono); font-size: 12px; padding: 3px 10px; border: 0; background: transparent; color: var(--ink); cursor: pointer; min-height: 28px; }
.lang-btn.on { background: var(--ink); color: #fff; }
