:root {
  --bg: #0b0d1a;
  --bg2: #141733;
  --panel: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.09);
  --text: #ece9f7;
  --muted: #9a97b5;
  --gold: #f5e6b8;
  --accent: #8b7cf6;
  --accent2: #6d5ce8;
  --ok: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --sun: #f59e0b;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(120% 60% at 50% -10%, #241d58 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior-y: none;
}
input { -webkit-user-select: text; user-select: text; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; padding-bottom: calc(24px + var(--safe-b)); }
main { padding: 12px 16px 24px; }
h1, h3, h4, h5 { margin: 0; }
h1 { font-family: Cinzel, Georgia, serif; font-size: 44px; letter-spacing: 6px; text-align: center; color: var(--gold); }
h3 { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
h4 { font-size: 14px; margin-bottom: 8px; }
h5 { font-size: 13px; margin: 14px 0 8px; color: var(--muted); font-weight: 600; display: flex; gap: 8px; align-items: center; }
small { color: var(--muted); font-weight: 400; }
code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.tiny { font-size: 12.5px; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; }
.row.wrap { flex-wrap: wrap; }
.warn-t { color: var(--warn); }

/* ---------- header / tabs ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: rgba(11, 13, 26, 0.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.top-l { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.top-l b { font-family: Cinzel, Georgia, serif; letter-spacing: 2px; color: var(--gold); }
.top-r { display: flex; gap: 6px; align-items: center; }
.tabs { display: flex; gap: 4px; padding: 8px 16px 0; position: sticky; top: calc(53px + var(--safe-t)); z-index: 19; background: rgba(11,13,26,.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); padding: 10px 4px; font: 600 13.5px Inter, sans-serif; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-color: var(--accent); }

/* ---------- elementi ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: rgba(255,255,255,.07); color: var(--text);
  font: 600 15px Inter, sans-serif; padding: 12px 16px; border-radius: 12px; cursor: pointer;
  transition: transform .08s, background .2s, opacity .2s;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent2)); border-color: transparent; color: #fff; }
.btn.ok { background: rgba(52, 211, 153, .16); border-color: rgba(52, 211, 153, .5); color: #a7f3d0; }
.btn.danger { background: #b91c1c; border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 8px 12px; font-size: 13.5px; border-radius: 10px; }
.btn.xs { padding: 4px 9px; font-size: 12.5px; border-radius: 8px; }
.btn.wide { width: 100%; }
.btn.big { padding: 16px; font-size: 16px; border-radius: 14px; }
.btn.sun { background: linear-gradient(180deg, #fbbf24, #d97706); color: #2a1600; border: 0; margin-top: 14px; }
.btn.moonb { background: linear-gradient(180deg, #4f46e5, #312e81); color: #fff; border: 0; margin-top: 14px; }
.btn.undo { background: rgba(139, 124, 246, .18); border-color: rgba(139, 124, 246, .45); }

input {
  width: 100%; background: rgba(0,0,0,.25); border: 1px solid var(--line); color: var(--text);
  font: 500 17px Inter, sans-serif; padding: 13px 14px; border-radius: 12px; outline: none;
}
input:focus { border-color: var(--accent); }
.code-in { text-transform: uppercase; letter-spacing: 8px; font-weight: 700; text-align: center; font-size: 22px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: rgba(255,255,255,.08); color: var(--muted); white-space: nowrap; }
.tag.ok { background: rgba(52,211,153,.15); color: #6ee7b7; }
.tag.warn { background: rgba(251,191,36,.15); color: #fcd34d; }
.pill { font-size: 12.5px; font-weight: 700; padding: 4px 10px; border-radius: 99px; }
.pill.night { background: rgba(99,102,241,.25); color: #c7d2fe; }
.pill.day { background: rgba(245,158,11,.22); color: #fde68a; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 6px 10px; border-radius: 99px; background: rgba(255,255,255,.07); font-size: 13.5px; }

.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; border: 1px solid var(--line); }
.banner.warn { background: rgba(251,191,36,.1); border-color: rgba(251,191,36,.35); }
.banner.warn.sm { font-size: 12.5px; padding: 8px 10px; margin: 8px 0; }
.banner.dead { background: rgba(248,113,113,.1); border-color: rgba(248,113,113,.35); text-align: center; }
.banner.end { text-align: center; background: linear-gradient(180deg, rgba(139,124,246,.2), rgba(139,124,246,.05)); border-color: rgba(139,124,246,.4); font-size: 16px; }
.big-emoji { font-size: 44px; line-height: 1.2; }

/* ---------- home ---------- */
.home { padding-top: calc(36px + var(--safe-t)); }
.home .panel { margin-top: 14px; }
.logo { position: relative; width: 120px; height: 120px; margin: 0 auto 6px; display: grid; place-items: center; }
.logo span { position: relative; font-size: 54px; filter: drop-shadow(0 4px 12px rgba(0,0,0,.6)); }
.moon { width: 60px; height: 60px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fffbe8, var(--gold) 55%, #cdb77a); box-shadow: 0 0 40px rgba(245,230,184,.5); }
.moon.big { position: absolute; width: 110px; height: 110px; opacity: .9; }
.or { text-align: center; margin: 16px 0; color: var(--muted); font-size: 13px; position: relative; }
.or::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--line); }
.or span { position: relative; background: var(--bg); padding: 0 10px; }
.home > .tiny { margin-top: 24px; }

/* ---------- lobby ---------- */
.codebox { text-align: center; padding: 14px; margin-bottom: 12px; border-radius: var(--radius); background: linear-gradient(180deg, rgba(245,230,184,.12), rgba(245,230,184,.03)); border: 1px dashed rgba(245,230,184,.4); cursor: pointer; }
.codebox b { display: block; font-family: Cinzel, Georgia, serif; font-size: 44px; letter-spacing: 12px; color: var(--gold); margin: 2px 0 0 12px; }
.codebox small { display: block; font-size: 12px; }
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.plist li:last-child { border-bottom: 0; }
.plist li.me .pn { color: var(--gold); }
.plist li.dead .pn { text-decoration: line-through; opacity: .5; }
.pn { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pn small { font-weight: 500; }
.x { background: none; border: 0; color: var(--muted); font-size: 16px; padding: 4px 8px; cursor: pointer; }

.roles-ed { list-style: none; margin: 0; padding: 0; }
.roles-ed li { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); opacity: .7; }
.roles-ed li.on { opacity: 1; }
.roles-ed li:last-child { border-bottom: 0; }
.roles-ed .re { font-size: 24px; text-align: center; }
.roles-ed .rn { font-weight: 600; min-width: 0; }
.roles-ed .rn small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 11.5px; line-height: 1.35; margin-top: 2px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper b { min-width: 22px; text-align: center; font-size: 16px; }
.stepper button { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.07); color: var(--text); font-size: 20px; line-height: 1; cursor: pointer; }
.stepper button:disabled { opacity: .3; }
.roles-ed.locked { opacity: .6; }
.sticky-bottom { position: sticky; bottom: 0; padding: 12px 0 calc(8px + var(--safe-b)); background: linear-gradient(0deg, var(--bg) 88%, transparent); }
.count-line { text-align: center; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.count-line.ok { color: var(--ok); }
.count-line.bad { color: var(--warn); }

/* ---------- carta ---------- */
.reveal { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: calc(100dvh - 70px); }
.hint-line { color: var(--muted); max-width: 320px; margin: 18px auto 0; min-height: 3em; }
.card-wrap { perspective: 1200px; width: min(78vw, 300px); margin: 8px auto; }
.card-wrap.small { width: min(74vw, 280px); }
.card { aspect-ratio: 5 / 7.4; cursor: pointer; }
.card-inner { position: relative; width: 100%; height: 100%; transition: transform .7s cubic-bezier(.3,.9,.3,1.15); transform-style: preserve-3d; }
.card.up .card-inner { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; border-radius: 18px; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; display: flex; flex-direction: column; align-items: center; box-shadow: 0 18px 50px rgba(0,0,0,.55); }
.face.back {
  border: 2px solid rgba(245,230,184,.55);
  background:
    repeating-linear-gradient(45deg, rgba(245,230,184,.06) 0 2px, transparent 2px 14px),
    repeating-linear-gradient(-45deg, rgba(245,230,184,.06) 0 2px, transparent 2px 14px),
    radial-gradient(circle at 50% 40%, #2c2470, #0f0c2a 75%);
  justify-content: center;
}
.back-art { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.back-art .moon { width: 70px; height: 70px; }
.card-wrap.small .back-art .moon { width: 48px; height: 48px; }
.back-title { font-family: Cinzel, Georgia, serif; font-weight: 800; letter-spacing: 6px; color: var(--gold); font-size: 22px; }
.face .hint { position: absolute; bottom: 12px; font-size: 11.5px; color: rgba(245,230,184,.7); letter-spacing: .5px; }
.face.front {
  transform: rotateY(180deg);
  background: radial-gradient(circle at 50% 25%, var(--c1), var(--c2) 80%);
  border: 2px solid rgba(255,255,255,.25);
  padding: 22px 16px 34px; text-align: center;
}
.role-emoji { font-size: 84px; line-height: 1.1; margin-top: 4px; filter: drop-shadow(0 6px 16px rgba(0,0,0,.5)); }
.role-name { font-family: Cinzel, Georgia, serif; font-size: 26px; font-weight: 800; color: #fff; margin-top: 8px; letter-spacing: 1px; }
.role-team { font-size: 11.5px; text-transform: uppercase; letter-spacing: 1.5px; color: rgba(255,255,255,.7); margin-top: 2px; }
.role-desc { font-size: 13.5px; line-height: 1.45; color: rgba(255,255,255,.92); margin: 12px 0 0; overflow-y: auto; }
.card-wrap.small .role-emoji { font-size: 50px; }
.card-wrap.small .role-name { font-size: 19px; }
.card-wrap.small .role-desc { font-size: 12.5px; margin-top: 6px; }
.card-wrap.small .face.front { padding: 14px 10px 28px; }

/* ---------- ruota ---------- */
.wheel-stage { display: flex; flex-direction: column; align-items: center; animation: wheelOut 4.3s forwards; }
.wheel-box { position: relative; width: min(80vw, 320px); aspect-ratio: 1; }
.pointer { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); z-index: 2; width: 0; height: 0; border-left: 14px solid transparent; border-right: 14px solid transparent; border-top: 26px solid var(--gold); filter: drop-shadow(0 3px 4px rgba(0,0,0,.6)); }
.wheel { position: absolute; inset: 0; border-radius: 50%; border: 5px solid var(--gold); box-shadow: 0 0 60px rgba(139,124,246,.4), inset 0 0 30px rgba(0,0,0,.5); animation: spin 4.3s cubic-bezier(.12,.6,.2,1) forwards; }
.wl { position: absolute; inset: 0; }
.wl span { position: absolute; left: 50%; top: 7%; transform: translateX(-50%); font-size: 30px; }
.hub { position: absolute; inset: 38%; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #2c2470, #0f0c2a); border: 3px solid var(--gold); display: grid; place-items: center; font-family: Cinzel, serif; font-size: 26px; color: var(--gold); }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(var(--end)); } }
@keyframes wheelOut { 0%, 72% { opacity: 1; transform: scale(1); filter: blur(0); } 100% { opacity: 0; transform: scale(.6); filter: blur(8px); } }

/* ---------- overlay ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.cd { background: rgba(5, 6, 15, .94); }
.cd-num { font-family: Cinzel, Georgia, serif; font-size: 140px; font-weight: 800; color: var(--gold); text-shadow: 0 0 60px rgba(245,230,184,.6); animation: pop 1s ease-out; }
.cd-sub { color: var(--muted); margin-top: 10px; letter-spacing: 1px; }
@keyframes pop { 0% { transform: scale(2); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 100% { transform: scale(.85); opacity: .8; } }
.modal-bg { background: rgba(0,0,0,.6); padding: 16px; animation: fade .15s; }
.modal { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 18px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal p { margin: 0 0 18px; font-size: 16px; line-height: 1.5; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 120; background: #26234a; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- master ---------- */
.gm { padding-top: 12px; }
.cycle { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; background: var(--panel); overflow: hidden; }
.cycle.cur.night { border-color: rgba(129,140,248,.5); background: linear-gradient(180deg, rgba(79,70,229,.12), rgba(79,70,229,.03)); }
.cycle.cur.day { border-color: rgba(245,158,11,.45); background: linear-gradient(180deg, rgba(245,158,11,.1), rgba(245,158,11,.02)); }
.cycle > :not(.cyc-head) { margin-left: 12px; margin-right: 12px; }
.cycle > :last-child { margin-bottom: 12px; }
.cycle > .btn.wide { width: calc(100% - 24px); }
.cyc-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; font-weight: 700; cursor: pointer; }
.cyc-head span:first-child { flex: 1; }
.chev { color: var(--muted); width: 14px; text-align: center; }
.steps { list-style: none; padding: 0; margin: 0 12px; }
.step { border-top: 1px solid var(--line); }
.step-row { display: grid; grid-template-columns: 18px 28px auto 1fr; align-items: center; gap: 6px; padding: 10px 0; cursor: pointer; }
.step .st { color: var(--muted); font-size: 13px; text-align: center; }
.step.done .st { color: var(--ok); }
.step.open .st { color: var(--accent); }
.step .se { font-size: 20px; text-align: center; }
.step .sn { font-weight: 600; white-space: nowrap; }
.step .sv { text-align: right; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step.done .sv { color: var(--text); }
.step.deadrole .sn { opacity: .55; }
.step-panel { background: rgba(0,0,0,.2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 0 0 12px; }
.step-panel.hunter { border-color: rgba(251,191,36,.4); margin-top: 10px; }
.prompt { margin: 0 0 4px; font-weight: 600; }
.step-panel > .tiny { margin: 0 0 10px; }
.result { padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.06); margin: 6px 0 10px; font-size: 15px; }
.result.bad { background: rgba(248,113,113,.15); color: #fecaca; }
.result.good { background: rgba(52,211,153,.12); color: #a7f3d0; }
.tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.tgt { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 6px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.06); color: var(--text); font: 600 13.5px Inter, sans-serif; cursor: pointer; min-width: 0; }
.tgt .te { font-size: 18px; line-height: 1.1; }
.tgt .tn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tgt .tw { position: absolute; top: 3px; right: 6px; color: var(--warn); font-size: 12px; }
.tgt.sel { background: linear-gradient(180deg, var(--accent), var(--accent2)); border-color: transparent; color: #fff; }
.tgt.dead { opacity: .45; }
.tgt.warn:not(.sel) { border-color: rgba(251,191,36,.35); }
.tgt.none { justify-content: center; color: var(--muted); }
.tgt.none.sel { color: #fff; }
.deadpick { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.deadpick summary { cursor: pointer; padding: 4px 0; }
.deadpick .tgrid { margin-top: 6px; }
.dawn, .announce, .reveal-box { border-top: 1px dashed var(--line); padding-top: 12px; margin-top: 4px; }
.dawn .plist li, .announce .plist li { padding: 6px 0; }
.dawn > .btn { margin-top: 8px; }
.dawn .step-panel { margin-top: 8px; }
.notes { margin: 0 0 6px; padding-left: 0; list-style: none; font-size: 13px; color: #a7f3d0; }
.reveal-box p { margin: 0 0 10px; color: var(--muted); }
.announce p { margin: 0 0 8px; }
.info { font-size: 14px; margin: 10px 0; }
.hist { list-style: none; padding: 0; margin: 0; }
.hist li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.hist li .btn { flex-shrink: 0; }
.end-pick { text-align: center; margin: 18px 0; }
.end-pick .row { justify-content: center; }

@media (min-width: 700px) {
  body { font-size: 15.5px; }
}

/* ---------- regole ---------- */
.rules .rl { margin: 0; padding-left: 18px; }
.rules .rl li { margin: 6px 0; }
.rules .order { margin: 0; padding-left: 22px; columns: 2; column-gap: 16px; }
.rules .order li { margin: 3px 0; break-inside: avoid; }
.rules .order small { display: block; font-size: 11px; }
.rules-h { font-family: Cinzel, Georgia, serif; color: var(--gold); font-size: 20px; margin: 22px 2px 10px; letter-spacing: 1px; }
.role-card { display: grid; grid-template-columns: 64px 1fr; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.rc-art { width: 64px; height: 88px; border-radius: 10px; display: grid; place-items: center; font-size: 34px; background: radial-gradient(circle at 50% 30%, var(--c1), var(--c2) 85%); border: 1px solid rgba(255,255,255,.2); box-shadow: 0 6px 16px rgba(0,0,0,.4); }
.rc-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 16px; }
.rc-body p { margin: 6px 0 0; font-size: 13.5px; line-height: 1.45; }
.rc-body .rc-win { color: var(--gold); font-size: 12.5px; }
.role-win { font-size: 11.5px; color: rgba(255,255,255,.75); margin: 8px 0 0; }
.card-wrap.small .role-win { font-size: 10.5px; margin-top: 4px; }
.chips.pick .chip { border: 1px solid var(--line); color: var(--text); font: 600 13px Inter, sans-serif; cursor: pointer; }
.chips.pick .chip.sel { background: linear-gradient(180deg, var(--accent), var(--accent2)); border-color: transparent; color: #fff; }
.top-r .btn + .btn { margin-left: 2px; }
