/* BabelChat: pensato per lo smartphone, funziona anche sul PC. Tema chiaro e scuro. */
:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #eaeef2;
  --text: #13202b;
  --muted: #5b6977;
  --line: #d9e0e6;
  --brand: #0f766e;
  --brand-strong: #0b5f58;
  --brand-ink: #ffffff;
  --brand-soft: #d7f0ec;
  --mine: #0f766e;
  --mine-ink: #ffffff;
  --mine-muted: #c9ece7;
  --theirs: #ffffff;
  --danger: #b42318;
  --danger-soft: #fde7e5;
  --ok: #13703a;
  --ok-soft: #dcf3e4;
  --warn-soft: #fff3cd;
  --warn-ink: #6b4e00;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .07);
  --radius: 18px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", "Noto Sans Ethiopic", "Noto Sans CJK SC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d1318;
    --surface: #151d24;
    --surface-2: #1d2730;
    --text: #e5ecf2;
    --muted: #93a2af;
    --line: #26323d;
    --brand: #2ab3a3;
    --brand-strong: #46c7b8;
    --brand-ink: #032421;
    --brand-soft: #113935;
    --mine: #17796f;
    --mine-ink: #ffffff;
    --mine-muted: #b9e4de;
    --theirs: #1a242d;
    --danger: #ff7b6e;
    --danger-soft: #3a1714;
    --ok: #5fd08b;
    --ok-soft: #12321f;
    --warn-soft: #3a2f0b;
    --warn-ink: #f3d77a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.sprite { position: absolute; }
svg { width: 1.25em; height: 1.25em; flex: none; }
h1, h2 { margin: 0; line-height: 1.2; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 2px; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }
.view { width: 100%; max-width: 640px; margin: 0 auto; }

/* Inizio */
#view-start { padding: max(20px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.brand { display: flex; align-items: center; gap: 14px; padding: 6px 2px 4px; }
.logo { width: 52px; height: 52px; color: var(--brand); }
.brand h1 { font-size: 1.7rem; letter-spacing: -.01em; }
.tagline { margin: 2px 0 0; color: var(--muted); }
.step { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; margin-top: 4px; }
.step svg { color: var(--brand); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0; box-shadow: var(--shadow); }
.card.error { background: var(--danger-soft); border-color: transparent; color: var(--danger); font-weight: 600; box-shadow: none; }
.invite-card { border-color: var(--brand); background: var(--brand-soft); box-shadow: none; }
.invite-card .label { margin: 0 0 8px; font-weight: 600; }
.join-members { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.join-members li { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 999px; padding: 4px 12px 4px 4px; }
/* Bandiere (web/assets/flags.js) */
.flag {
  display: inline-block; flex: none; width: 1.5em; height: 1em; vertical-align: -.12em;
  border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px rgba(0, 0, 0, .14);
}
.flag svg { display: block; width: 100%; height: 100%; }
.flag.mid { width: 33px; height: 22px; border-radius: 4px; }
.flag.big { width: 54px; height: 36px; border-radius: 5px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .14), 0 1px 3px rgba(16, 24, 40, .15); }

/* Scelta della lingua: la bandiera, sotto il nome piccolo */
.lang-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.lang-grid button {
  position: relative; min-height: 88px; padding: 10px 6px 8px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
}
.lang-grid .lang-name { font-size: .82rem; line-height: 1.15; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.lang-grid button:hover { border-color: var(--brand); }
.lang-grid button[aria-checked="true"] { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.lang-grid button[aria-checked="true"] .lang-name { color: var(--text); font-weight: 700; }
.lang-grid button[aria-checked="true"]::after {
  content: "✓"; position: absolute; top: 4px; inset-inline-end: 7px; color: var(--brand-strong); font-weight: 800; font-size: .9rem;
}
.lang-grid.compact { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); margin-top: 10px; }
.lang-grid.compact button { min-height: 76px; }
.lang-grid.compact .flag.big { width: 45px; height: 30px; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.field input, .code-form input {
  min-height: 50px; padding: 10px 14px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface); font-weight: 400; width: 100%;
}
.field input:focus, .code-form input:focus { border-color: var(--brand); outline: none; }

.primary, .secondary, .danger {
  min-height: 48px; padding: 10px 18px; border-radius: 14px; border: 0; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
}
.primary { background: var(--brand); color: var(--brand-ink); }
.primary:hover { background: var(--brand-strong); }
.primary:disabled { opacity: .55; cursor: default; }
.primary.big { min-height: 58px; font-size: 1.1rem; border-radius: 16px; box-shadow: var(--shadow); }
.secondary { background: var(--surface-2); color: var(--text); }
.secondary:hover { background: color-mix(in srgb, var(--surface-2) 80%, var(--text)); }
.danger { background: var(--danger-soft); color: var(--danger); }

.code-box summary { cursor: pointer; color: var(--brand-strong); font-weight: 600; padding: 6px 2px; list-style: none; }
.code-box summary::-webkit-details-marker { display: none; }
.code-box summary::before { content: "＋ "; }
.code-box[open] summary::before { content: "− "; }
.code-form { display: flex; gap: 8px; margin-top: 8px; }
.code-form input { text-transform: uppercase; letter-spacing: .2em; font-weight: 700; }
.code-form button { width: auto; flex: none; }

.privacy { color: var(--muted); font-size: .9rem; text-align: center; margin: 4px 0 0; }

/* Conversazione */
.view.chat { height: 100dvh; display: flex; flex-direction: column; max-width: 760px; background: var(--bg); }
.chat-head {
  display: flex; align-items: center; gap: 8px; padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: relative; z-index: 2;
}
.people { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 4px; text-align: start; border-radius: 12px; }
.people:hover { background: var(--surface-2); }
.avatars { display: flex; flex: none; }
.avatars .avatar + .avatar { margin-inline-start: -10px; }
.people-text { min-width: 0; display: flex; flex-direction: column; }
.people-names { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.people-langs { display: flex; gap: 5px; margin-top: 3px; overflow: hidden; font-size: .9rem; }
.avatar {
  --hue: 170; width: 34px; height: 34px; border-radius: 50%; flex: none; position: relative;
  display: inline-grid; place-items: center; font-weight: 800; font-size: .95rem; color: #fff;
  background: hsl(var(--hue) 55% 42%); border: 2px solid var(--surface);
}
.avatar.off { filter: grayscale(.85); opacity: .7; }
.avatar .dot { position: absolute; inset-inline-end: -2px; bottom: -2px; width: 11px; height: 11px; border-radius: 50%; background: #22c55e; border: 2px solid var(--surface); }
.avatar.off .dot { background: var(--muted); }
.pill {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 14px;
  border-radius: 999px; border: 0; background: var(--brand); color: var(--brand-ink); font-weight: 700;
}
.pill:hover { background: var(--brand-strong); }
.icon-btn { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.banner { background: var(--warn-soft); color: var(--warn-ink); padding: 8px 16px; font-size: .92rem; text-align: center; }

.messages { flex: 1; overflow-y: auto; padding: 16px 12px 8px; display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }
.notice { align-self: center; max-width: 90%; text-align: center; color: var(--muted); font-size: .88rem; background: var(--surface-2); padding: 5px 12px; border-radius: 999px; margin: 6px 0; }
.notice.welcome { background: var(--brand-soft); color: var(--text); border-radius: 14px; padding: 10px 14px; }

.msg { max-width: min(82%, 520px); display: flex; flex-direction: column; gap: 2px; align-self: flex-start; margin-top: 4px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .who { font-size: .8rem; color: var(--muted); padding: 0 10px; display: flex; gap: 6px; align-items: center; }
.msg .who b { color: hsl(var(--hue, 170) 50% 38%); }
@media (prefers-color-scheme: dark) { .msg .who b { color: hsl(var(--hue, 170) 60% 68%); } }
.bubble {
  background: var(--theirs); border: 1px solid var(--line); border-radius: var(--radius); border-start-start-radius: 6px;
  padding: 9px 13px 7px; box-shadow: 0 1px 1px rgba(16, 24, 40, .05); cursor: pointer; text-align: start;
  overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.mine .bubble { background: var(--mine); color: var(--mine-ink); border-color: transparent; border-start-start-radius: var(--radius); border-start-end-radius: 6px; }
.bubble .main { font-size: 1.06rem; }
.bubble .state { display: block; font-size: .82rem; opacity: .75; margin-top: 2px; font-style: italic; }
.bubble .state.bad { color: var(--danger); opacity: 1; font-style: normal; }
.msg.mine .bubble .state.bad { color: #ffd2cc; }
.bubble .extra { display: block; margin-top: 8px; padding-top: 7px; border-top: 1px dashed color-mix(in srgb, currentColor 35%, transparent); font-size: .92rem; opacity: .9; }
.bubble .extra .tag { display: block; font-size: .75rem; font-weight: 700; opacity: .75; }
.bubble .extra .alt { display: block; }
.bubble .extra .alt + .alt { margin-top: 6px; }
.meta { display: flex; align-items: center; gap: 4px; padding: 0 6px; font-size: .75rem; color: var(--muted); }
.meta button { border: 0; background: none; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; padding: 4px 6px; border-radius: 8px; font-size: .78rem; }
.meta button:hover { background: var(--surface-2); color: var(--text); }
.meta button.playing { color: var(--brand-strong); }
.meta svg { width: 1.1em; height: 1.1em; }

.activity { min-height: 22px; padding: 0 18px; font-size: .85rem; color: var(--muted); font-style: italic; }
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; min-height: 46px; max-height: 140px; resize: none; padding: 11px 14px; border-radius: 23px;
  border: 1.5px solid var(--line); background: var(--bg); line-height: 1.35;
}
.composer textarea:focus { outline: none; border-color: var(--brand); }
.round { width: 46px; height: 46px; border-radius: 50%; border: 0; display: grid; place-items: center; flex: none; }
.round svg { width: 22px; height: 22px; }
.round.send { background: var(--brand); color: var(--brand-ink); }
.round.send:disabled { opacity: .5; }
html[dir="rtl"] .round.send svg { transform: scaleX(-1); }
.round.mic { background: var(--surface-2); color: var(--brand-strong); }
.round.attach { background: none; color: var(--muted); width: 40px; }
.round.attach:hover { color: var(--brand-strong); background: var(--surface-2); }

/* Foto, immagini e file nella conversazione */
.bubble.attachment { padding: 4px; cursor: default; white-space: normal; }
.bubble.photo img {
  display: block; width: 260px; max-width: 100%; height: auto; max-height: 340px; object-fit: cover;
  border-radius: 14px; cursor: zoom-in; background: var(--surface-2);
}
.msg.mine .bubble.photo { background: var(--mine); }
.file-card { display: flex; align-items: center; gap: 10px; padding: 6px 4px 6px 8px; min-width: 200px; }
.file-icon { width: 30px; height: 30px; opacity: .85; }
.file-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.file-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: .8rem; opacity: .75; }
.msg.mine .file-card .icon-btn { color: var(--mine-ink); }
.msg.mine .file-card .icon-btn:hover { background: rgba(255, 255, 255, .15); }
.option { justify-content: flex-start; padding-inline: 18px; }
.option svg { color: var(--brand-strong); width: 1.4em; height: 1.4em; }
.sheet.viewer { align-items: center; background: rgba(0, 0, 0, .88); }
.viewer-body { width: 100%; max-width: 900px; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.viewer-body img { max-width: 100%; max-height: calc(100dvh - 120px); object-fit: contain; margin: 0 auto; border-radius: 8px; }
.round.mic.recording { background: var(--danger); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
.round.mic.busy { opacity: .6; pointer-events: none; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent); } 50% { box-shadow: 0 0 0 9px transparent; } }
@media (prefers-reduced-motion: reduce) { .round.mic.recording { animation: none; } }

/* Fine */
.view.ended { padding: 18vh 24px 32px; display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; }
.big-logo { width: 72px; height: 72px; opacity: .85; }
.view.ended .primary { max-width: 360px; }

/* Finestre dal basso */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(5, 12, 18, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet-body {
  width: 100%; max-width: 520px; max-height: 92dvh; overflow-y: auto; background: var(--surface);
  border-radius: 24px 24px 0 0; padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow);
}
@media (min-width: 700px) { .sheet { align-items: center; } .sheet-body { border-radius: 24px; } }
.sheet-body h2 { font-size: 1.25rem; text-align: center; }
.qr-body { align-items: stretch; text-align: center; }
.qr-frame { align-self: center; background: #fff; padding: 8px; border-radius: 18px; box-shadow: var(--shadow); width: min(78vw, 300px); aspect-ratio: 1; }
.qr-frame img { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.qr-code { margin: 0; font-size: 1.9rem; font-weight: 800; letter-spacing: .18em; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); margin: 0; }
.hint { margin: 0; color: var(--muted); font-size: .95rem; }
.joined-note { margin: 0; background: var(--ok-soft); color: var(--ok); border-radius: 12px; padding: 8px 12px; font-weight: 600; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.qr-link { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg); color: var(--muted); font-size: .85rem; text-align: center; }

.member-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.member-list li { display: flex; align-items: center; gap: 12px; padding: 8px 6px; border-radius: 12px; }
.member-list .m-name { font-weight: 700; }
.member-list .m-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }

.switch { display: flex; align-items: center; gap: 12px; padding: 10px 4px; cursor: pointer; font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(18px); }
html[dir="rtl"] .switch input:checked + .track::after { transform: translateX(-18px); }
.switch input:focus-visible + .track { outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 2px; }
.lang-box summary { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; padding: 10px 4px; list-style: none; }
.lang-box summary::-webkit-details-marker { display: none; }
.lang-box summary svg { color: var(--brand); }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; max-width: calc(100vw - 32px);
  box-shadow: var(--shadow); font-size: .95rem; text-align: center;
}
