:root {
  --bg: #0F3D2E;
  --bg-raised: #164E3B;
  --stage: #121714;
  --ink: #F6F1E4;
  --ink-soft: #D8E3CE;
  --gold: #E5B242;
  --gold-hi: #F0C156;
  --on-gold: #0B2A1F;
  --line: rgba(216, 227, 206, 0.22);
  --bar-h: 56px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}

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

html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--stage);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

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

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- Header ---------- */
.bar {
  position: fixed; inset: 0 0 auto 0; z-index: 10;
  height: var(--bar-h);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 0 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bar__logo { width: auto; height: 34px; flex: none; }
.bar__title {
  margin: 0; min-width: 0;
  font: 700 17px/1.1 var(--font-display); letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar__title-sub { color: var(--gold); font-weight: 600; }
.bar__center { display: flex; align-items: center; gap: 8px; }
.bar__end { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.bar__meta { min-width: 92px; font: 500 12px/1 var(--font-mono); color: var(--ink-soft); white-space: nowrap; }

.seg { display: inline-flex; gap: 2px; padding: 3px; background: rgba(0, 0, 0, .22); border: 1px solid var(--line); border-radius: 10px; }
.seg__btn, .tool {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 11px;
  border: 0; border-radius: 7px; cursor: pointer;
  font: 600 13px/1 var(--font-body); white-space: nowrap; text-decoration: none;
}
.seg__btn { background: transparent; color: var(--ink-soft); }
.seg__btn:hover { background: rgba(246, 241, 228, .08); color: var(--ink); }
.seg__btn[aria-pressed="true"] { background: var(--gold); color: var(--on-gold); }
.tool { background: var(--bg-raised); color: var(--ink); border: 1px solid var(--line); height: 36px; }
.tool:hover { background: #1D6049; color: var(--ink); }
.tool[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); }
.tool:disabled { opacity: .4; cursor: not-allowed; }
.tool[hidden] { display: none; }
.tool--primary { background: var(--gold); color: var(--on-gold); border-color: var(--gold); }
.tool--primary:hover { background: var(--gold-hi); color: var(--on-gold); }
.seg__btn svg, .tool svg {
  width: 17px; height: 17px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* QR popover (API popover nativa: Esc e clic fuori la chiudono) */
.qr-pop {
  position: fixed; inset: auto; top: calc(var(--bar-h) + 8px); right: 14px; margin: 0;
  width: 232px; padding: 18px;
  background: var(--ink); color: var(--on-gold);
  border: 0; border-radius: 14px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .5);
  text-align: center;
}
.qr-pop img { width: 180px; height: 180px; margin: 0 auto; image-rendering: pixelated; }
.qr-pop__title { margin: 12px 0 2px; font: 700 15px/1.3 var(--font-display); color: var(--bg); }
.qr-pop__url { margin: 0; font: 500 11px/1.4 var(--font-mono); color: #365446; }

/* Header stretto (768–1180px): via i testi, restano icone e tooltip */
@media (max-width: 1280px) { .bar__title-sub { display: none; } }
@media (max-width: 1100px) {
  .seg__label, .tool__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .bar__meta { display: none; }
}
@media (max-width: 860px) { .bar__title { display: none; } }

/* ---------- Stage ---------- */
.stage {
  position: fixed; inset: var(--bar-h) 0 0 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  overflow: hidden;
  background: radial-gradient(ellipse 70% 60% at 50% 45%, #1b221e 0%, var(--stage) 70%);
}

.slot { position: relative; flex: none; }
.device { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.device__body {
  position: relative;
  background: linear-gradient(145deg, #2a2f2d, #121514);
  box-shadow: inset 0 0 0 2px #3b413e, 0 0 0 1px rgba(0, 0, 0, .5), 0 40px 80px rgba(0, 0, 0, .5);
}
.device__screen { position: relative; overflow: hidden; background: var(--bg); }
.device__screen iframe { display: block; width: 100%; height: 100%; border: 0; background: var(--bg); }

.device--smartphone .device__body { padding: 14px; border-radius: 58px; }
.device--smartphone .device__screen { border-radius: 44px; }
.device--smartphone .device__body::before {
  content: ""; position: absolute; z-index: 3; pointer-events: none;
  width: 110px; height: 30px; border-radius: 20px; background: #050606;
  top: 26px; left: 50%; transform: translateX(-50%);
}
.device--smartphone[data-orientation="landscape"] .device__body::before {
  width: 30px; height: 110px; top: 50%; left: 26px; transform: translateY(-50%);
}

.device--tablet .device__body { padding: 24px; border-radius: 40px; }
.device--tablet .device__screen { border-radius: 16px; }
.device--tablet .device__body::before {
  content: ""; position: absolute; z-index: 3; width: 9px; height: 9px; border-radius: 50%;
  background: #0b0d0c; box-shadow: inset 0 0 0 2px #1d2321;
  top: 8px; left: 50%; transform: translateX(-50%);
}
.device--tablet[data-orientation="landscape"] .device__body::before { top: 50%; left: 8px; transform: translateY(-50%); }

.device--desktop .device__body { padding: 18px 18px 46px; border-radius: 18px; }
.device--desktop .device__screen { border-radius: 4px; }
.device--desktop .device__body::after {
  content: ""; position: absolute; left: 50%; bottom: 16px; width: 12px; height: 12px;
  transform: translateX(-50%); border-radius: 50%; background: #3b413e;
}
.device__stand { display: none; }
.device--desktop .device__stand { display: block; position: relative; height: 120px; }
.device--desktop .device__stand::before {
  content: ""; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  width: 180px; height: 96px;
  background: linear-gradient(90deg, #1b1f1d, #343a37 50%, #1b1f1d);
  clip-path: polygon(14% 0, 86% 0, 100% 100%, 0 100%);
}
.device--desktop .device__stand::after {
  content: ""; position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 420px; height: 24px; border-radius: 6px 6px 12px 12px;
  background: linear-gradient(180deg, #3b413e, #1b1f1d);
}

/* Schermo intero: l'iframe occupa tutta l'area sotto l'header, senza cornice */
.stage.is-fill { padding: 0; }
.stage.is-fill .slot { width: 100% !important; height: 100% !important; }
.device--fill { position: static; width: 100%; height: 100%; transform: none !important; }
.device--fill .device__body { padding: 0; border-radius: 0; box-shadow: none; background: none; width: 100%; height: 100%; }
.device--fill .device__screen { width: 100% !important; height: 100% !important; border-radius: 0; }

@media (prefers-reduced-motion: no-preference) {
  .device:not(.device--fill) { transition: transform .3s cubic-bezier(.2, .7, .2, 1); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
