:root {
  --ink: #23324a;
  --ink-2: #51607a;
  --ink-3: #7d8aa1;
  --paper: #fffdf8;
  --paper-2: #f6f1e7;
  --line: #e6dccb;
  --shadow: 0 1px 0 rgba(35, 50, 74, .06), 0 8px 24px rgba(35, 50, 74, .12);
  --accent: #e0875a;
  --ok: #3f9a5a;
  --warn: #d9822b;
  --bad: #c9474b;
  --radius: 16px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --gutter: max(12px, env(safe-area-inset-left));
}
:root[data-sky="night"] {
  --ink: #eef1f8;
  --ink-2: #c3cbe0;
  --ink-3: #8f9ab6;
  --paper: #1d2438;
  --paper-2: #262f48;
  --line: #36405e;
  --shadow: 0 1px 0 rgba(0, 0, 0, .2), 0 10px 28px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bfe3f2; color: var(--ink); font-family: var(--font); -webkit-font-smoothing: antialiased; }
:root[data-sky="night"] body { background: #16203a; }
button, input { font: inherit; color: inherit; }
h1, h2, p { margin: 0; }

#scene { position: fixed; inset: 0; touch-action: none; }
#scene canvas { display: block; outline: none; }

.hud { position: fixed; z-index: 10; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-top { top: max(12px, env(safe-area-inset-top)); left: var(--gutter); right: var(--gutter); display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }

.brand { display: flex; align-items: center; gap: 10px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px 8px 10px; box-shadow: var(--shadow); }
.brand-mark { font-size: 26px; line-height: 1; }
.brand h1 { font-size: 18px; font-weight: 800; letter-spacing: .2px; }
.tagline { font-size: 12px; color: var(--ink-2); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow); white-space: nowrap; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.chip .dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(63, 154, 90, .18); }
.chip.warn { border-color: #f0c08e; }
.chip.warn .dot { background: var(--warn); }

.toolbar { display: flex; gap: 8px; margin-left: auto; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow); cursor: pointer; font-size: 18px; line-height: 1; transition: transform 120ms ease-out, background 120ms ease-out; }
.icon-btn:hover { background: var(--paper-2); }
.icon-btn:active { transform: scale(.96); }
.icon-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
:focus-visible { outline: 3px solid #5b8def; outline-offset: 2px; }

/* pannello attività */
.panel { position: fixed; z-index: 9; right: var(--gutter); top: 76px; bottom: 16px; width: 340px; display: flex; flex-direction: column; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; transition: transform 240ms cubic-bezier(.2, .8, .2, 1); }
.panel-handle { display: none; }
.panel-body { overflow-y: auto; padding: 14px 14px 18px; display: flex; flex-direction: column; gap: 18px; overscroll-behavior: contain; }
.panel h2 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-3); margin-bottom: 8px; }
.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.task { display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center; padding: 10px; border-radius: 12px; background: var(--paper-2); border: 1px solid transparent; cursor: pointer; text-align: left; width: 100%; }
.task:hover { border-color: var(--line); }
.task .ava { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; background: #fff; border: 3px solid var(--accent); }
.task .t { font-weight: 700; font-size: 14px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.task .s { font-size: 12px; color: var(--ink-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task .meta { font-size: 12px; color: var(--ink-3); text-align: right; display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
.task.waiting { border-color: #f0c08e; background: #fff4e6; }
:root[data-sky="night"] .task.waiting { background: #3a3020; }
.task-list.done .task { opacity: .8; }
.empty { font-size: 13px; color: var(--ink-2); padding: 10px 12px; border: 1px dashed var(--line); border-radius: 12px; }
.legend ul { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 4px; flex: none; }

/* scheda dettaglio */
.inspector { position: fixed; z-index: 11; left: var(--gutter); bottom: 16px; width: min(380px, calc(100vw - 24px)); max-height: calc(100vh - 110px); overflow-y: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; animation: rise 200ms cubic-bezier(.2, .8, .2, 1); }
.inspector .close { position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; font-size: 14px; box-shadow: none; }
.inspector h3 { margin: 0 40px 4px 0; font-size: 18px; font-weight: 800; }
.inspector .sub { color: var(--ink-2); font-size: 13px; margin-bottom: 10px; }
.inspector p { font-size: 14px; line-height: 1.45; color: var(--ink-2); margin-bottom: 10px; }
.inspector dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; margin: 8px 0 12px; }
.inspector dt { color: var(--ink-3); }
.inspector dd { margin: 0; font-weight: 600; word-break: break-word; }
.inspector .howto { background: var(--paper-2); border-radius: 12px; padding: 10px 12px; font-size: 13px; line-height: 1.45; }
.inspector code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: rgba(125, 138, 161, .16); padding: 1px 5px; border-radius: 6px; }
.inspector .members { list-style: none; padding: 0; margin: 8px 0 12px; display: flex; flex-direction: column; gap: 6px; }
.inspector .members li { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--paper-2); }
.badge.working { background: #e5f4e9; color: #23683a; }
.badge.waiting { background: #fff0dc; color: #9a5512; }
.badge.done { background: #e8eefb; color: #2f4f9a; }
.badge.failed, .badge.stopped { background: #fbe7e7; color: #9a2f33; }
:root[data-sky="night"] .badge { background: rgba(255, 255, 255, .08); color: var(--ink); }

/* etichette 3D (CSS2D) */
.lbl { pointer-events: none; user-select: none; font-family: var(--font); transform-origin: 50% 100%; }
.sign { padding: 5px 11px; border-radius: 999px; background: rgba(255, 253, 248, .94); border: 2px solid var(--c, #ccc); font-size: 13px; font-weight: 800; color: #23324a; white-space: nowrap; box-shadow: 0 4px 10px rgba(35, 50, 74, .15); display: flex; gap: 6px; align-items: center; }
.sign .n { font-size: 11px; font-weight: 800; background: var(--c); color: #fff; border-radius: 999px; padding: 1px 7px; }
.sign.small { font-size: 11px; padding: 3px 8px; }
.bubble { position: relative; max-width: 190px; padding: 5px 9px; border-radius: 12px; background: #fff; color: #23324a; font-size: 12px; font-weight: 700; line-height: 1.25; box-shadow: 0 4px 10px rgba(35, 50, 74, .18); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: pop 220ms cubic-bezier(.2, 1.4, .4, 1); }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -5px; width: 10px; height: 10px; background: inherit; transform: translateX(-50%) rotate(45deg); }
.bubble.ask { background: #ffe9c7; }
.bubble.done { background: #dff3e4; }
.bubble.failed { background: #fbe0e0; }
.bubble.dim { opacity: .82; font-weight: 600; }
.tag { font-size: 10px; font-weight: 800; color: #23324a; background: rgba(255, 255, 255, .85); padding: 1px 6px; border-radius: 999px; white-space: nowrap; }
.hide-far .tag.far { display: none; }

/* toast */
.toasts { position: fixed; z-index: 12; left: 50%; transform: translateX(-50%); top: 80px; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(420px, calc(100vw - 24px)); }
.toast { background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 600; animation: rise 220ms cubic-bezier(.2, .8, .2, 1); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast.out { opacity: 0; transition: opacity 300ms ease-in; }

/* login */
dialog { border: 1px solid var(--line); border-radius: 20px; padding: 0; background: var(--paper); color: var(--ink); box-shadow: var(--shadow); width: min(380px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(20, 30, 50, .35); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 8px; }
dialog h2 { font-size: 18px; font-weight: 800; }
.muted { color: var(--ink-2); font-size: 13px; line-height: 1.4; margin-bottom: 6px; }
dialog label { font-size: 13px; font-weight: 700; }
dialog input { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper-2); padding: 0 12px; font-size: 16px; }
.form-error { color: var(--bad); font-size: 13px; min-height: 18px; }
.row { display: flex; justify-content: flex-end; gap: 8px; }
.btn { height: 40px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); font-weight: 700; cursor: pointer; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.ghost { background: transparent; }

.loading { position: fixed; inset: 0; display: grid; place-content: center; grid-auto-flow: column; gap: 10px; align-items: center; z-index: 20; background: #bfe3f2; font-weight: 700; color: #23324a; transition: opacity 400ms ease-out; }
.loading.gone { opacity: 0; pointer-events: none; }
.loading .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); animation: bob 700ms ease-in-out infinite alternate; }
.noscript { position: fixed; inset: 0; display: grid; place-content: center; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.toasts .toast { animation-name: rise; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes bob { from { transform: translateY(-4px); } to { transform: translateY(4px); } }

/* telefono: pannello come foglio dal basso */
@media (max-width: 760px) {
  .brand { padding: 6px 10px 6px 8px; }
  .brand h1 { font-size: 16px; }
  .tagline { display: none; }
  .chips { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; padding-bottom: 4px; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { height: 30px; font-size: 12px; }
  .icon-btn { width: 44px; height: 44px; }
  .panel { left: 0; right: 0; top: auto; bottom: 0; width: auto; height: min(62vh, 520px); border-radius: 20px 20px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
  .panel.collapsed { transform: translateY(calc(100% - 56px - env(safe-area-inset-bottom))); }
  .panel-handle { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; height: 56px; padding: 8px 16px; border: 0; background: transparent; cursor: pointer; font-weight: 700; font-size: 14px; flex: none; }
  .panel-handle .grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); }
  .panel-body h2:first-of-type { display: none; }
  .inspector { bottom: calc(68px + env(safe-area-inset-bottom)); left: 12px; right: 12px; width: auto; max-height: 52vh; }
  .toasts { top: 120px; }
  .legend ul { grid-template-columns: 1fr; }
}
@media (min-width: 761px) and (max-width: 1100px) {
  .panel { width: 300px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
.bubble.icon { padding: 3px 6px; font-size: 14px; border-radius: 999px; }
@media (max-width: 760px) {
  .hide-far .sign .nm { display: none; }
  .hide-far .sign { padding: 4px 7px; font-size: 15px; }
  .hide-far .tag { display: none; }
}
