:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --accent: #2563eb;
  --danger: #dc2626;
  --border: #d9dce1;
  --stage: #111214;
  --bar: #1f2226;
  --bar-text: #e8eaed;
  --bar-button: #33373d;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --card: #1f2226;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --border: #33373d;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.card {
  max-width: 360px;
  margin: 12vh auto 0;
  padding: 28px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
@media (max-width: 420px) {
  .card { margin: 6vh 16px 0; padding: 22px; }
}
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card p { margin: 0 0 20px; }
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input {
  padding: 10px 12px;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button, .button {
  display: inline-block;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: .6; cursor: progress; }
button.danger { background: var(--danger); }
button.secondary, .button.secondary { color: var(--text); background: transparent; border: 1px solid var(--border); }
#install-btn { width: 100%; margin-top: 12px; }
.status { min-height: 1.4em; margin: 16px 0 0 !important; font-size: 14px; }
.status.error { color: var(--danger); }

/* ---- visualizzatore ---- */
#viewer { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--stage); }
#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  padding-top: max(6px, env(safe-area-inset-top));
  color: var(--bar-text);
  background: var(--bar);
  font-size: 13px;
}
#toolbar button, #toolbar select { padding: 5px 10px; font-size: 13px; }
#toolbar button:not(.danger) { background: var(--bar-button); }
#toolbar select { color: var(--bar-text); background: var(--bar-button); border: 1px solid #44484f; border-radius: 8px; }
#toolbar .muted { color: #9aa0a6; }
#toolbar button.on { background: var(--accent); }
.spacer { flex: 1; }
@media (max-width: 600px) {
  #toolbar { gap: 6px; padding-left: 8px; padding-right: 8px; }
  #stats, #fullscreen-btn { display: none; }
  #peer-name { max-width: 22vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #toolbar select { max-width: 30vw; }
  #toolbar button, #toolbar select { padding: 5px 8px; }
}
@media (max-width: 480px) {
  #peer-name { display: none; }
}

#keys { padding: 6px 8px; background: var(--bar); border-top: 1px solid #33373d; }
#text-input { width: 100%; margin-bottom: 6px; padding: 8px 10px; color: var(--bar-text); background: #111214;
  border-color: #44484f; }
.keyrow { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.keyrow button { flex: none; padding: 7px 11px; font-size: 13px; color: var(--bar-text); background: var(--bar-button); }
.keyrow button.on { background: var(--accent); }

#stage { position: relative; flex: 1; min-height: 0; display: flex; overflow: hidden; touch-action: none; }
#screen { width: 100%; height: 100%; object-fit: contain; outline: none; cursor: default;
  transform-origin: 0 0; touch-action: none; user-select: none; -webkit-user-select: none; }
#viewer:fullscreen #toolbar { display: none; }
/* freccia della modalità touchpad: la punta (in alto a sinistra) è il punto del clic */
#cursor { position: absolute; left: -2px; top: -1px; width: 26px; height: 26px; pointer-events: none; z-index: 2;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M2 1 L2 19 L7 14.5 L10.5 22 L13.5 20.6 L10 13.3 L16.5 13.3 Z' fill='white' stroke='black' stroke-width='1.5' stroke-linejoin='round'/></svg>") no-repeat 0 0 / contain; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5)); }
#drop-hint { position: absolute; inset: 16px; display: grid; place-items: center; color: #fff; font-size: 18px;
  border: 3px dashed #93b4f5; border-radius: 12px; background: rgba(37, 99, 235, .25); pointer-events: none; }

/* ---- file ---- */
#files {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  color: var(--text);
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, .25);
  z-index: 5;
}
.files-head, .files-nav, .files-actions { display: flex; align-items: center; gap: 8px; }
.files-head button, .files-nav button, .files-actions button, .files-actions .button { padding: 6px 10px; font-size: 13px; }
#files-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; direction: rtl; text-align: left; }
#files-list { flex: 1; min-height: 120px; margin: 0; padding: 0; overflow-y: auto; list-style: none;
  border: 1px solid var(--border); border-radius: 8px; }
#files-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border);
  cursor: pointer; font-size: 14px; }
#files-list li:last-child { border-bottom: 0; }
#files-list li.selected { background: rgba(37, 99, 235, .15); }
#files-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#files-list .size { color: var(--muted); font-size: 12px; }
#files-info { margin: 0; font-size: 12px; }
#transfers { flex: none; margin: 0; padding: 0; list-style: none; max-height: 30vh; overflow-y: auto; font-size: 13px; }
#transfers li { padding: 6px 0; border-top: 1px solid var(--border); }
#transfers progress { width: 100%; height: 8px; }
