:root {
  /* Tutto parte da un solo colore: il blu ciano di TeleMac (--accent).
     Sfondi, superfici e testi sono lo stesso tono, via via più scuri. */
  --bg: #03111a;
  --surface: #0b2331;
  --surface-2: #133247;
  --surface-3: #1f4a63;
  --text: #f3f6f8;
  --text-2: #9eadb7;
  --text-3: #566975;
  --accent: #1ab8ef;
  --accent-rgb: 26, 184, 239;
  --accent-press: #0f9ad0;
  --accent-deep: #0a6e9c;
  --accent-ink: #012332;
  --green: #3ddc97;
  --green-rgb: 61, 220, 151;
  --red: #ff5c6c;
  --yellow: #ffd24a;

  /* Finiture "argento": linee sottili tutte uguali, bordi e riflessi. Ogni
     bordo dell'app usa --line + --hairline, così lo spessore è coerente. */
  --silver: #e4eaee;
  --silver-2: #b7c3cb;
  --silver-3: #7d8d97;
  --hairline: rgba(206, 222, 232, .13);
  --hairline-strong: rgba(222, 234, 241, .24);
  --line: 1px;
  --sheen: inset 0 1px 0 rgba(255, 255, 255, .08);
  --lift: 0 8px 20px -8px rgba(0, 0, 0, .55);
  --surface-grad: linear-gradient(180deg, #11303f 0%, #0a2230 100%);
  --metal-ring: conic-gradient(from 210deg, #f7fafc, #8d9ca6 18%, #e3e9ed 34%, #6c7c86 52%, #f1f5f7 70%, #93a2ac 86%, #f7fafc);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
/* Sugli schermi Retina la linea sottile è davvero mezzo pixel, come in iOS. */
@media (min-resolution: 2dppx) {
  :root { --line: 0.5px; }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Rete di sicurezza: un elemento con [hidden] deve sparire sempre, anche se
   una regola con la stessa specificità (es. una classe che imposta display) lo
   riguarda. */
[hidden] { display: none !important; }

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

html,
body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background:
    radial-gradient(120% 55% at 50% -12%, rgba(var(--accent-rgb), .13), transparent 62%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: none;
}

svg.icon {
  width: 22px;
  height: 22px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
svg.icon.filled {
  fill: currentColor;
  stroke: none;
}

/* ---------- Isola di stato ---------- */

.island-wrap {
  display: flex;
  justify-content: center;
  padding-top: max(6px, var(--safe-t));
  padding-bottom: 4px;
  flex: none;
}
body.island-fixed .island-wrap {
  padding: 0;
  height: 0;
  overflow: visible;
}
/* App aperta dalla schermata Home: l'isola "galleggia", quindi il contenuto
   deve lasciare da solo lo spazio della barra di stato / Dynamic Island. */
body.island-fixed #app { padding-top: var(--safe-t); }

.island {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: #000;
  color: var(--text);
  border-radius: 19px;
  width: 126px;
  height: 37px;
  overflow: hidden;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 590;
  letter-spacing: -0.01em;
  transition: width 350ms cubic-bezier(.2,.8,.2,1), height 350ms cubic-bezier(.2,.8,.2,1),
    border-radius 350ms cubic-bezier(.2,.8,.2,1), background-color 200ms ease;
  padding: 0 14px;
}
body.island-fixed .island {
  position: fixed;
  top: 11px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
}
.island.show {
  width: min(300px, 86vw);
}
/* A riposo l'isola è solo una forma nera (sopra quella vera): il contenuto sparisce. */
.island > * { transition: opacity 180ms ease; }
.island:not(.show) > * { opacity: 0; }
.island.show.tall {
  height: 64px;
  border-radius: 26px;
  white-space: normal;
  text-align: center;
}
@media (prefers-reduced-motion: reduce) {
  .island { transition: none; }
}

.island-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-2);
}
.island[data-tone="ok"] .island-dot { background: var(--green); }
.island[data-tone="warn"] .island-dot { background: var(--yellow); }
.island[data-tone="err"] .island-dot { background: var(--red); }
.island[data-tone="info"] .island-dot { background: var(--accent); }
.island-icon {
  flex: none;
  width: 16px;
  height: 16px;
}
.island-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Struttura generale ---------- */

#app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  padding: 6px 18px calc(10px + var(--safe-b));
  overflow: hidden;
}
.panel.active { display: flex; }

/* ---------- Pannelli Tastiera / Altro (salgono dal basso) ---------- */

.sheet {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  padding-top: max(12px, var(--safe-t));
  transform: translateY(100%);
  visibility: hidden;
  transition: transform 320ms cubic-bezier(.2,.8,.2,1), visibility 0s linear 320ms;
}
.sheet.open {
  transform: none;
  visibility: visible;
  transition: transform 320ms cubic-bezier(.2,.8,.2,1);
}
.sheet-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet.open { transition: none; }
}
.sheet-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 2px 10px;
}
.sheet-header h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; color: var(--silver); }
.sheet-done {
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
  padding: 8px 4px 8px 16px;
}

/* ---------- Telecomando: pulsanti in alto ---------- */

.remote-header {
  flex: none;
  display: flex;
  justify-content: flex-end;
  padding: 2px 0 0;
}
.power-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-grad);
  border: var(--line) solid var(--hairline-strong);
  box-shadow: var(--sheen), var(--lift);
  color: var(--silver-2);
  transition: background-color 150ms ease, color 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
}
.power-btn svg.icon { width: 22px; height: 22px; stroke-width: 2.4; }
.power-btn[aria-checked="true"] {
  color: var(--green);
  border-color: rgba(var(--green-rgb), .6);
  box-shadow: var(--sheen), 0 0 14px rgba(var(--green-rgb), .22);
}
.power-btn:active { transform: scale(.94); }

.top-buttons {
  flex: none;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--btn-gap, 16px) 14px;
  width: 100%;
  max-width: 330px;
  margin: 0 auto var(--pad-gap, 22px);
}
.round-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}
.round-btn-face {
  width: var(--btn-size, 82px);
  height: var(--btn-size, 82px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-grad);
  border: var(--line) solid var(--hairline-strong);
  box-shadow: var(--sheen), var(--lift);
  color: var(--silver);
  transition: background-color 80ms ease, transform 80ms ease, border-color 80ms ease, color 80ms ease;
}
.round-btn-face svg.icon { width: 28px; height: 28px; stroke-width: 1.8; }
.round-btn-face svg.icon.filled { stroke: none; }
.round-btn-label { font-size: 12px; color: var(--text-2); font-weight: 500; letter-spacing: .01em; }
.round-btn.accent-active .round-btn-face,
.round-btn:active .round-btn-face { background: var(--surface-2); transform: scale(0.94); }
.round-btn.accent-active .round-btn-face { color: var(--accent); border-color: rgba(var(--accent-rgb), .55); }

.switch-track {
  flex: none;
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: var(--surface-3);
  border: var(--line) solid var(--hairline);
  position: relative;
  transition: background-color 150ms ease;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffffff, #e3e9ed);
  box-shadow: 0 2px 4px rgba(0,0,0,.3), inset 0 0 0 var(--line) rgba(0,0,0,.08);
  transition: transform 150ms ease;
}

.remote-spacer { flex: 1; min-height: 12px; }

.pad-hint {
  flex: none;
  margin: 0 0 12px;
  text-align: center;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.4;
}

/* ---------- Clickpad ---------- */

.pad-row {
  --pad-size: var(--pad-fit, min(82vw, 42vh, 320px));
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.clickpad {
  width: var(--pad-size);
  height: var(--pad-size);
  border-radius: 50%;
  position: relative;
  /* Anello di metallo sottile (come l'alluminio del Siri Remote) attorno al vetro scuro. */
  border: 1px solid transparent;
  background:
    radial-gradient(circle at 50% 30%, #17394c, #0c2433 62%, #081b27 100%) padding-box,
    var(--metal-ring) border-box;
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, .7), inset 0 1px 0 rgba(255, 255, 255, .06);
  touch-action: none;
  flex: none;
  overflow: hidden;
  transition: box-shadow 150ms ease;
}
/* ---------- Manopola del volume ---------- */

.clickpad.knob { box-shadow: inset 0 0 0 2px var(--accent), 0 0 24px rgba(var(--accent-rgb), .25); }
.pad-zone, .pad-center { transition: opacity 180ms ease, transform 180ms ease; }
.clickpad.knob .pad-zone { opacity: 0; transform: scale(.8); }
.clickpad.knob .pad-center { opacity: 0; }

.knob-face {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transform: scale(.92);
  transition: opacity 180ms ease, transform 260ms cubic-bezier(.2,.8,.2,1);
}
.clickpad.knob .knob-face { opacity: 1; transform: none; }

/* braccio invisibile lungo quanto il raggio: ruotandolo, il puntino gira sull'anello */
.knob-dot-arm {
  position: absolute;
  left: 50%;
  top: 0;
  width: 0;
  height: 50%;
  transform-origin: 50% 100%;
}
.knob-dot {
  position: absolute;
  top: 7%;
  left: -11px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffffff, #dfe7ec);
  box-shadow: 0 0 0 5px rgba(var(--accent-rgb),.35), 0 0 16px rgba(var(--accent-rgb),.8);
}
.knob-center {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--surface-grad);
  border: var(--line) solid var(--hairline-strong);
  box-shadow: var(--sheen);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--accent);
}
.knob-center svg.icon { width: 30px; height: 30px; }
.knob-sign { font-size: 22px; font-weight: 700; line-height: 1; color: var(--text); }
.knob-sign.pop { animation: knob-pop 220ms ease; }
@keyframes knob-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.45); color: var(--accent); }
  100% { transform: scale(1); }
}

/* A puntatore spento il centro del cerchio è "OK". */
.clickpad.pointer-off .pad-center::after {
  content: "OK";
  font-size: 17px;
  font-weight: 600;
  color: var(--text-2);
}

.pad-zone {
  position: absolute;
  color: var(--silver-2);
  display: flex;
  pointer-events: none;
}
.pad-zone svg.icon { width: 24px; height: 24px; stroke-width: 1.8; }
.pad-zone.pad-up { top: 8%; left: 0; right: 0; justify-content: center; }
.pad-zone.pad-down { bottom: 8%; left: 0; right: 0; justify-content: center; }
.pad-zone.pad-left { left: 8%; top: 0; bottom: 0; align-items: center; }
.pad-zone.pad-right { right: 8%; top: 0; bottom: 0; align-items: center; }

.pad-glow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 100ms ease;
  background: conic-gradient(from -45deg,
    rgba(var(--accent-rgb),.5) 0deg 90deg,
    transparent 90deg 360deg);
}
.pad-glow[data-dir="up"] { transform: rotate(0deg); }
.pad-glow[data-dir="right"] { transform: rotate(90deg); }
.pad-glow[data-dir="down"] { transform: rotate(180deg); }
.pad-glow[data-dir="left"] { transform: rotate(270deg); }
.pad-glow.active { opacity: 1; }

.pad-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: linear-gradient(180deg, #15384b, #0e2a3a);
  border: var(--line) solid var(--hairline-strong);
  box-shadow: var(--sheen), 0 6px 16px -6px rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  pointer-events: none;
}
.clickpad.pressed-center .pad-center {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}
.clickpad.dragging .pad-center {
  background: var(--accent-deep);
  color: var(--text);
}

/* ---------- Righe di pulsanti ---------- */

.row {
  flex: none;
  display: flex;
  gap: 10px;
  padding: 5px 0;
}
.row .btn { flex: 1; }

.btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 54px;
  padding: 8px 6px;
  border-radius: 14px;
  background: var(--surface-grad);
  border: var(--line) solid var(--hairline);
  box-shadow: var(--sheen);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
}
.btn:active { background: var(--surface-2); }
.btn.accent-active { color: var(--accent); }
.btn.danger { color: var(--red); }
.btn.wide { flex: 1 1 100%; }
.btn.tall { min-height: 64px; }

/* ---------- Tastiera ---------- */

.keyboard-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 460px;
  width: 100%;
  margin: 0 auto;
  padding-top: 10px;
}

#text-input {
  width: 100%;
  padding: 16px 18px;
  font-size: 18px;
  border-radius: 14px;
  border: var(--line) solid var(--hairline-strong);
  background: var(--surface);
  box-shadow: var(--sheen);
  color: var(--text);
  margin-bottom: 16px;
  outline: none;
}
#text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .18); }
#text-input::placeholder { color: var(--text-2); }

.keyboard-hint {
  color: var(--text-2);
  font-size: 12.5px;
  text-align: center;
  margin: 6px 0 4px;
}

/* ---------- Altro (scorre) ---------- */

.other-stage {
  max-width: 460px;
  width: 100%;
  margin: 0 auto;
  padding-top: 8px;
  padding-bottom: 24px;
}

.group { margin: 4px 0 22px; }
.group h2 {
  font-size: 12.5px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 8px 6px;
  font-weight: 600;
}

.list {
  background: var(--surface);
  border: var(--line) solid var(--hairline);
  box-shadow: var(--sheen);
  border-radius: 14px;
  overflow: hidden;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border-bottom: var(--line) solid var(--hairline);
  color: var(--text);
  font-size: 16px;
  text-align: left;
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--surface-2); }
.list-item svg.icon { width: 20px; height: 20px; color: var(--silver-2); stroke-width: 1.8; flex: none; }
.list-item .list-item-label { flex: 1; }
.list-item.danger { color: var(--red); }
.list-item.danger svg.icon { color: var(--red); }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: var(--line) solid var(--hairline);
  font-size: 15.5px;
}
.list .setting-row:last-child { border-bottom: none; }
.setting-row input[type="range"] { flex: 1; max-width: 170px; accent-color: var(--accent); }
.setting-button {
  width: 100%;
  text-align: left;
  color: var(--accent);
}
.setting-button:active { background: var(--surface-2); }
.setting-hint { color: var(--text-2); font-size: 13px; }

.segmented {
  display: flex;
  border: var(--line) solid var(--hairline);
  background: var(--surface-2);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.segmented button {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 7px;
  color: var(--text-2);
}
.segmented button.active {
  background: linear-gradient(180deg, #f7fafc, #d5dee4);
  color: #0a1f2b;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}

.switch-mini {
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: var(--surface-3);
  border: var(--line) solid var(--hairline);
  position: relative;
  flex: none;
}
.switch-mini .switch-thumb {
  width: 27px;
  height: 27px;
}
.switch-mini[aria-checked="true"] { background: var(--green); }
.switch-mini[aria-checked="true"] .switch-thumb { transform: translateX(20px); }

.about {
  text-align: center;
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.6;
  padding: 6px 0 10px;
}
.about a { color: var(--accent); text-decoration: none; }

/* ---------- Schermo demo ---------- */

.demo-screen {
  flex: none;
  margin-bottom: 10px;
}
.demo-canvas-wrap {
  width: 100%;
  max-width: 230px;
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  background: #020b11;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  border: var(--line) solid var(--hairline-strong);
}

/* La scheda Telecomando, in modalità demo, deve fare spazio allo schermo finto:
   qui restringiamo un po' pad e righe così tutto resta visibile senza scorrere. */
#demo-canvas { width: 100%; height: 100%; display: block; }
.demo-caption {
  margin: 6px 2px 0;
  font-size: 12px;
  color: var(--text-2);
  text-align: center;
  min-height: 15px;
}
.demo-keyboard-box {
  margin-top: 10px;
  padding: 12px 14px;
  border: var(--line) solid var(--hairline);
  background: var(--surface);
  border-radius: 12px;
  font-size: 15px;
  color: var(--text);
  min-height: 22px;
  word-break: break-word;
}
.demo-keyboard-label {
  font-size: 11.5px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 2px 2px 6px;
}

/* ---------- Sovrapposizione di abbinamento ---------- */

.pairing {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: radial-gradient(120% 70% at 50% 0%, #0d3346, var(--bg) 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + var(--safe-t));
  padding-bottom: calc(24px + var(--safe-b));
}
.pairing-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.pairing-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: var(--surface-grad);
  border: var(--line) solid var(--hairline-strong);
  box-shadow: var(--sheen), var(--lift);
  display: flex;
  align-items: center;
  justify-content: center;
}
.pairing-icon svg.icon { width: 30px; height: 30px; color: var(--accent); }
.pairing h1 { font-size: 21px; margin: 0 0 8px; }
.pairing p { color: var(--text-2); font-size: 14px; margin: 0 0 20px; line-height: 1.4; }

.btn-primary {
  width: 100%;
  padding: 15px;
  font-size: 16.5px;
  font-weight: 600;
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 8px 20px -8px rgba(var(--accent-rgb), .6);
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:active { background: var(--accent-press); }
.btn-primary[disabled] { opacity: .5; }

#pair-code {
  width: 100%;
  margin-top: 16px;
  padding: 16px;
  font-size: 30px;
  letter-spacing: 0.35em;
  text-align: center;
  border-radius: 14px;
  border: var(--line) solid var(--hairline-strong);
  background: var(--surface);
  box-shadow: var(--sheen);
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}
#pair-code::placeholder { color: var(--text-3); letter-spacing: 0.2em; }

#pair-error.pairing-error {
  min-height: 18px;
  color: var(--red);
  font-size: 13.5px;
  margin-top: 12px;
}
#pair-status.pairing-status {
  min-height: 18px;
  color: var(--text-2);
  font-size: 13.5px;
  margin-top: 12px;
}
