/* ====================================================================
   QuizBlitz – stylesheet
   ==================================================================== */
:root {
  color-scheme: dark;
  --bg:        #0c0d1f;
  --ink:       #ffffff;
  --muted:     #b9badd;
  --card:      rgba(255,255,255,.07);
  --card-2:    rgba(255,255,255,.10);
  --border:    rgba(255,255,255,.14);
  --violet:    #7c3aed;
  --pink:      #ec4899;
  --cyan:      #22d3ee;
  --green:     #22c55e;
  --amber:     #f59e0b;
  --red:       #ef4444;

  /* answer palette (color + shape per index) */
  --a0: #e21b3c;  /* red    triangle */
  --a1: #1368ce;  /* blue   diamond  */
  --a2: #d89e00;  /* gold   circle   */
  --a3: #26890c;  /* green  square   */
  --a4: #8b3fe8;  /* purple pentagon */
  --a5: #ff6b00;  /* orange hexagon  */

  --radius: 18px;
  --shadow: 0 18px 50px rgba(0,0,0,.45);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* animated gradient background + floating blobs */
.bg {
  position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(1100px 800px at 15% -10%, rgba(124,58,237,.55), transparent 60%),
    radial-gradient(1000px 700px at 110% 0%,  rgba(236,72,153,.45), transparent 55%),
    radial-gradient(900px 900px at 50% 120%,  rgba(34,211,238,.30), transparent 60%),
    var(--bg);
}
.bg::before, .bg::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(70px); opacity: .5;
  animation: float 18s ease-in-out infinite;
}
.bg::before { width: 420px; height: 420px; background: #7c3aed; top: 8%; left: 8%; }
.bg::after  { width: 380px; height: 380px; background: #ec4899; bottom: 6%; right: 10%; animation-delay: -8s; }
@keyframes float {
  0%,100% { transform: translate(0,0) scale(1); }
  33%     { transform: translate(40px,-30px) scale(1.1); }
  66%     { transform: translate(-30px,20px) scale(.95); }
}
@media (prefers-reduced-motion: reduce) {
  .bg::before, .bg::after { animation: none; }
}

a { color: #c4b5fd; }
button { font-family: inherit; }

/* ---- layout helpers ---- */
.wrap { min-height: 100dvh; display: flex; flex-direction: column; }
.center { flex: 1; display: grid; place-items: center; padding: 22px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---- brand ---- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 900; letter-spacing: -.5px; }
.brand .bolt { filter: drop-shadow(0 4px 10px rgba(124,58,237,.6)); }
.logo-xl { font-size: clamp(34px, 6vw, 64px); }

/* ---- cards & inputs ---- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); backdrop-filter: blur(12px);
}
.pad { padding: clamp(20px, 4vw, 34px); }
.glass { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); backdrop-filter: blur(12px); }

.field {
  width: 100%; padding: 16px 18px; font-size: 18px; color: #fff;
  background: rgba(0,0,0,.28); border: 2px solid var(--border); border-radius: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.field::placeholder { color: #8e90b8; }
.field:focus { outline: none; border-color: #a78bfa; box-shadow: 0 0 0 4px rgba(167,139,250,.25); }
.field.big { font-size: 30px; text-align: center; letter-spacing: 6px; font-weight: 800; }

label.lbl { display:block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; text-transform: uppercase; letter-spacing: .08em; }

/* ---- buttons ---- */
.btn {
  --grad: linear-gradient(135deg, var(--violet), var(--pink));
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 15px 22px; font-size: 17px; font-weight: 800; color: #fff; cursor: pointer;
  border: 0; border-radius: 14px; background: var(--grad);
  box-shadow: 0 12px 28px rgba(124,58,237,.45); transition: transform .08s, filter .15s, box-shadow .15s;
  user-select: none; text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px) scale(.99); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: grayscale(.3); }
.btn.full { width: 100%; }
.btn.lg { padding: 18px 28px; font-size: 20px; }
.btn.ghost { background: rgba(255,255,255,.08); box-shadow: none; border: 1px solid var(--border); }
.btn.ghost:hover { background: rgba(255,255,255,.14); }
.btn.success { --grad: linear-gradient(135deg, #16a34a, #22c55e); box-shadow: 0 12px 28px rgba(34,197,94,.4); }
.btn.danger  { --grad: linear-gradient(135deg, #dc2626, #f87171); box-shadow: 0 12px 28px rgba(239,68,68,.4); }
.btn.amber   { --grad: linear-gradient(135deg, #d97706, #f59e0b); box-shadow: 0 12px 28px rgba(245,158,11,.4); }

.btn-row { display: flex; gap: 12px; flex-wrap: wrap; }
.iconbtn {
  width: 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; cursor: pointer;
  background: rgba(255,255,255,.08); border: 1px solid var(--border); color: #fff; font-size: 20px;
}
.iconbtn:hover { background: rgba(255,255,255,.16); }

/* ---- toast / errors ---- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: rgba(239,68,68,.95); color: #fff; padding: 13px 18px; border-radius: 12px; font-weight: 700;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 1000;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: rgba(34,197,94,.95); }

/* ====================================================================
   Landing / Join
   ==================================================================== */
.landing { width: 100%; max-width: 460px; text-align: center; }
.landing .tagline { color: var(--muted); margin: 8px 0 26px; font-size: 17px; }
.landing .join-card { margin-bottom: 18px; }
.alt-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.footer-note { color: #7e80a8; font-size: 12.5px; margin-top: 24px; }

/* ====================================================================
   Player view
   ==================================================================== */
.player { width: 100%; max-width: 520px; }
.avatar-bubble {
  width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; font-size: 48px;
  margin: 0 auto 6px; box-shadow: 0 10px 26px rgba(0,0,0,.4); border: 3px solid rgba(255,255,255,.25);
}
.pill { display: inline-block; padding: 6px 14px; border-radius: 999px; background: rgba(255,255,255,.1); border:1px solid var(--border); font-weight: 700; }
.big-status { font-size: clamp(24px, 6vw, 34px); font-weight: 900; text-align: center; }
.sub-status { color: var(--muted); text-align: center; margin-top: 6px; }

.score-chip {
  position: fixed; top: 14px; right: 14px; background: rgba(0,0,0,.35); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 14px; font-weight: 800; display: flex; gap: 8px; align-items: center; backdrop-filter: blur(8px);
}
.name-chip { position: fixed; top: 14px; left: 14px; background: rgba(0,0,0,.35); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 14px; font-weight: 700; display: flex; gap: 8px; align-items: center; backdrop-filter: blur(8px); max-width: 55vw; }
.name-chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* answer grid (player taps these) */
.answers {
  display: grid; gap: 12px; width: 100%;
  grid-template-columns: 1fr 1fr;
}
.answers.cols-1 { grid-template-columns: 1fr; }
.answer {
  position: relative; min-height: 88px; border: 0; border-radius: 16px; cursor: pointer; color: #fff;
  display: flex; align-items: center; gap: 14px; padding: 16px 18px; font-size: 19px; font-weight: 800;
  text-align: left; box-shadow: 0 8px 20px rgba(0,0,0,.35); transition: transform .08s, filter .15s, opacity .2s;
  overflow: hidden;
}
.answer:hover { filter: brightness(1.07); }
.answer:active { transform: scale(.98); }
.answer .shape { flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center; }
.answer .atxt { flex: 1; }
.answer .aimg { width: 54px; height: 54px; object-fit: cover; border-radius: 10px; }
.answer.c0 { background: var(--a0); }
.answer.c1 { background: var(--a1); }
.answer.c2 { background: var(--a2); }
.answer.c3 { background: var(--a3); }
.answer.c4 { background: var(--a4); }
.answer.c5 { background: var(--a5); }
.answer.dim { opacity: .28; filter: grayscale(.4); }
.answer.is-correct { outline: 5px solid #fff; box-shadow: 0 0 0 6px rgba(34,197,94,.6), 0 8px 26px rgba(0,0,0,.4); }
.answer .pick-check { position: absolute; top: 8px; right: 10px; font-size: 22px; opacity: 0; }
.answer.picked .pick-check { opacity: 1; }

/* player result */
.result-screen { text-align: center; }
.result-emoji { font-size: clamp(80px, 22vw, 150px); line-height: 1; animation: pop .35s ease; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0;} 70%{transform: scale(1.12);} 100%{transform: scale(1); opacity:1;} }
.result-title { font-size: clamp(28px, 8vw, 44px); font-weight: 900; margin-top: 6px; }
.points-gain { font-size: clamp(22px, 6vw, 30px); font-weight: 800; color: #fde047; margin-top: 4px; }
.streak-flame { margin-top: 10px; font-weight: 800; color: #fb923c; }

.locked-card { text-align:center; }
.lock-shape { width: 120px; height: 120px; margin: 0 auto 14px; display:grid; place-items:center; border-radius: 24px; }

/* ====================================================================
   Host / Presenter view
   ==================================================================== */
.host { width: 100%; max-width: 1180px; margin: 0 auto; padding: 22px; }
.host-top { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.host-top .brand { font-size: 22px; }
.qcount { background: rgba(0,0,0,.3); border:1px solid var(--border); border-radius: 999px; padding: 8px 16px; font-weight: 800; }
.host-controls { display:flex; gap: 10px; align-items:center; }

/* lobby */
.lobby-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 22px; align-items: stretch; }
@media (max-width: 880px){ .lobby-grid { grid-template-columns: 1fr; } }
.join-panel { text-align: center; display:flex; flex-direction: column; justify-content: center; gap: 16px; }
.join-url { font-size: clamp(16px,2.4vw,22px); color: var(--muted); }
.join-url b { color: #fff; }
.pin-display { font-size: clamp(46px, 9vw, 96px); font-weight: 900; letter-spacing: 10px;
  background: linear-gradient(135deg,#fff,#c4b5fd); -webkit-background-clip: text; background-clip: text; color: transparent; }
.pin-label { text-transform: uppercase; letter-spacing: .25em; color: var(--muted); font-weight: 800; font-size: 14px; }
.qr-box { background:#fff; padding: 18px; border-radius: 22px; display:grid; place-items:center; box-shadow: var(--shadow); }
.qr-box canvas { display:block; width: 100%; height:auto; image-rendering: pixelated; border-radius: 6px; }
.qr-hint { text-align:center; color: var(--muted); margin-top: 10px; font-weight:700; }

.players-bar { display:flex; align-items:center; justify-content: space-between; margin: 22px 0 12px; }
.players-count { font-size: clamp(22px,4vw,34px); font-weight: 900; }
.players-count .num { color:#fde047; }
.player-tiles { display:flex; flex-wrap: wrap; gap: 10px; }
.ptile {
  display:flex; align-items:center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  background: rgba(255,255,255,.1); border:1px solid var(--border); font-weight: 800; animation: tileIn .3s ease;
}
.ptile .av { font-size: 20px; }
@keyframes tileIn { from { transform: scale(.5) translateY(10px); opacity:0;} to { transform:none; opacity:1; } }
.empty-hint { color: var(--muted); padding: 18px; text-align:center; }

/* big question display */
.stage { display:flex; flex-direction: column; gap: 18px; }
.q-headline {
  font-size: clamp(26px, 4.5vw, 50px); font-weight: 900; line-height: 1.12; text-align:center;
  background: rgba(0,0,0,.25); border:1px solid var(--border); border-radius: var(--radius); padding: clamp(18px,3vw,32px);
}
.q-media { display:grid; place-items:center; }
.q-media img { max-height: 38vh; max-width: 100%; border-radius: 16px; box-shadow: var(--shadow); }
.q-meta { display:flex; align-items:center; justify-content: center; gap: 26px; }

/* circular timer */
.timer-ring { position: relative; width: 120px; height: 120px; }
.timer-ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.timer-ring .bg-c { stroke: rgba(255,255,255,.15); }
.timer-ring .fg-c { stroke: #fde047; stroke-linecap: round; transition: stroke-dashoffset .25s linear, stroke .3s; }
.timer-ring .t-num { position:absolute; inset:0; display:grid; place-items:center; font-size: 40px; font-weight: 900; }
.timer-ring.warn .fg-c { stroke: #ef4444; }

.answered-counter { font-size: clamp(20px,3vw,28px); font-weight: 800; }
.answered-counter .num { color:#34d399; }

/* big reading countdown */
.ready-num { font-size: clamp(80px, 18vw, 200px); font-weight: 900; line-height:1;
  background: linear-gradient(135deg,#fff,#fde047); -webkit-background-clip:text; background-clip:text; color:transparent; animation: pop .4s ease; }

/* host answers (4-tile board) */
.board { display:grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.board.cols-1 { grid-template-columns: 1fr; }
.tile {
  position: relative; min-height: clamp(70px, 11vh, 120px); border-radius: 16px; color:#fff;
  display:flex; align-items:center; gap: 14px; padding: 16px 20px; font-size: clamp(18px,2.4vw,28px); font-weight: 800;
  box-shadow: 0 10px 24px rgba(0,0,0,.35); transition: opacity .25s, filter .25s, transform .25s;
}
.tile.c0{background:var(--a0)} .tile.c1{background:var(--a1)} .tile.c2{background:var(--a2)}
.tile.c3{background:var(--a3)} .tile.c4{background:var(--a4)} .tile.c5{background:var(--a5)}
.tile .shape { width: 40px; height: 40px; display:grid; place-items:center; flex:0 0 auto; }
.tile .timg { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.tile .count { margin-left: auto; font-size: 26px; font-weight: 900; background: rgba(0,0,0,.28); padding: 4px 14px; border-radius: 999px; }
.tile.dim { opacity: .25; filter: grayscale(.5); }
.tile.win { outline: 5px solid #fff; transform: scale(1.03); }
.tile .checkmark { position:absolute; top:-12px; right:-12px; width: 40px; height:40px; border-radius:50%; background:#fff; color:#16a34a; display:grid; place-items:center; font-size: 26px; box-shadow: var(--shadow); }

/* distribution bars (reveal) */
.dist { display:flex; align-items:flex-end; gap: 18px; height: 30vh; justify-content:center; padding: 0 10px; }
.bar-col { display:flex; flex-direction:column; align-items:center; gap:8px; flex: 0 1 120px; height:100%; justify-content:flex-end; }
.bar { width: 100%; border-radius: 12px 12px 4px 4px; min-height: 6px; transition: height .6s cubic-bezier(.2,.8,.2,1); position:relative; box-shadow: 0 8px 20px rgba(0,0,0,.3); }
.bar .bcount { position:absolute; top:-26px; left:0; right:0; text-align:center; font-weight:900; font-size: 20px; }
.bar.b0{background:var(--a0)} .bar.b1{background:var(--a1)} .bar.b2{background:var(--a2)}
.bar.b3{background:var(--a3)} .bar.b4{background:var(--a4)} .bar.b5{background:var(--a5)}
.bar-shape { width: 32px; height: 32px; display:grid; place-items:center; }

/* scoreboard */
.leaderboard { display:flex; flex-direction: column; gap: 10px; max-width: 760px; margin: 0 auto; width:100%; }
.lrow {
  display:flex; align-items:center; gap: 14px; padding: 14px 18px; border-radius: 14px;
  background: rgba(255,255,255,.08); border:1px solid var(--border); font-weight: 800; font-size: clamp(16px,2vw,22px);
  animation: slideIn .4s ease backwards;
}
.lrow .rank { width: 38px; height:38px; border-radius:10px; display:grid; place-items:center; background: rgba(0,0,0,.3); font-weight:900; }
.lrow .av { font-size: 26px; }
.lrow .nm { flex:1; overflow:hidden; text-overflow: ellipsis; white-space: nowrap; }
.lrow .sc { color:#fde047; font-variant-numeric: tabular-nums; }
.lrow.top1 { background: linear-gradient(135deg, rgba(245,158,11,.35), rgba(255,255,255,.08)); border-color: rgba(245,158,11,.6); }
.lrow.top2 { background: linear-gradient(135deg, rgba(148,163,184,.3), rgba(255,255,255,.06)); }
.lrow.top3 { background: linear-gradient(135deg, rgba(180,83,9,.3), rgba(255,255,255,.06)); }
@keyframes slideIn { from { transform: translateX(-24px); opacity:0; } to { transform:none; opacity:1; } }

/* podium */
.podium-wrap { text-align:center; }
.podium { display:flex; align-items:flex-end; justify-content:center; gap: clamp(10px,2vw,26px); margin: 24px 0; }
.pod { display:flex; flex-direction:column; align-items:center; gap:10px; width: clamp(90px, 22vw, 200px); animation: rise .6s cubic-bezier(.2,.9,.2,1) backwards; }
@keyframes rise { from { transform: translateY(40px); opacity:0;} to {transform:none; opacity:1;} }
.pod .av { font-size: clamp(38px,8vw,64px); }
.pod .nm { font-weight: 900; font-size: clamp(15px,2vw,22px); max-width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.pod .sc { color:#fde047; font-weight: 800; }
.pod .block { width:100%; border-radius: 14px 14px 0 0; display:grid; place-items:start center; padding-top: 12px; font-size: 40px; font-weight:900;
  box-shadow: inset 0 4px 0 rgba(255,255,255,.25), var(--shadow); }
.pod.p1 .block { height: clamp(150px,28vh,230px); background: linear-gradient(180deg,#fbbf24,#d97706); }
.pod.p2 .block { height: clamp(110px,21vh,180px); background: linear-gradient(180deg,#e5e7eb,#94a3b8); }
.pod.p3 .block { height: clamp(80px,16vh,140px);  background: linear-gradient(180deg,#f59e0b,#b45309); }

/* fullscreen confetti canvas */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; }

/* drag-drop upload */
.dropzone {
  border: 2.5px dashed var(--border); border-radius: var(--radius); padding: 40px 24px; text-align:center;
  color: var(--muted); transition: border-color .2s, background .2s; cursor: pointer;
}
.dropzone.drag { border-color: #a78bfa; background: rgba(167,139,250,.1); color:#fff; }
.dropzone .big { font-size: 22px; font-weight: 800; color:#fff; margin-bottom: 6px; }

/* small helpers */
.muted { color: var(--muted); }
.center-text { text-align:center; }
.mt { margin-top: 14px; } .mt2 { margin-top: 24px; }
.row-between { display:flex; align-items:center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tag { display:inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; background: rgba(255,255,255,.12); }

/* ====================================================================
   Editor
   ==================================================================== */
.editor { max-width: 1100px; margin: 0 auto; padding: 18px; width:100%; }
.ed-top { display:flex; align-items:center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.ed-top .brand { font-size: 20px; }
.ed-grid { display:grid; grid-template-columns: 280px 1fr; gap: 18px; align-items:start; }
@media (max-width: 820px){ .ed-grid { grid-template-columns: 1fr; } }
.q-list { display:flex; flex-direction:column; gap: 10px; }
.q-item { display:flex; gap: 10px; align-items:center; padding: 10px 12px; border-radius: 12px; background: rgba(255,255,255,.06); border:1px solid var(--border); cursor:pointer; }
.q-item.active { border-color:#a78bfa; background: rgba(167,139,250,.16); }
.q-item .qn { width: 26px; height:26px; border-radius:8px; background: rgba(0,0,0,.3); display:grid; place-items:center; font-weight:800; font-size: 13px; flex:0 0 auto; }
.q-item .qt { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:600; font-size: 14px; }
.q-item .badge { font-size: 11px; }
.ed-panel { display:flex; flex-direction:column; gap: 16px; }
.ed-answers { display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px){ .ed-answers { grid-template-columns: 1fr; } }
.ed-answer { border-radius: 14px; padding: 12px; display:flex; flex-direction:column; gap:10px; color:#fff; }
.ed-answer.c0{background:rgba(226,27,60,.9)} .ed-answer.c1{background:rgba(19,104,206,.9)}
.ed-answer.c2{background:rgba(216,158,0,.92)} .ed-answer.c3{background:rgba(38,137,12,.92)}
.ed-answer.c4{background:rgba(139,63,232,.9)} .ed-answer.c5{background:rgba(255,107,0,.9)}
.ed-answer input[type=text] { background: rgba(0,0,0,.25); border:1px solid rgba(255,255,255,.3); color:#fff; padding: 10px 12px; border-radius: 10px; font-size: 15px; width:100%; }
.ed-answer .arow { display:flex; align-items:center; gap: 10px; justify-content: space-between; }
.correct-toggle { display:flex; align-items:center; gap: 8px; font-weight: 800; cursor:pointer; user-select:none; }
.correct-toggle input { width: 20px; height: 20px; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; border:1px solid rgba(255,255,255,.4); }
.field-sm { padding: 9px 12px; font-size: 14px; }
.inline-fields { display:flex; gap: 12px; flex-wrap: wrap; }
.inline-fields > div { flex:1; min-width: 130px; }
select.field { -webkit-appearance:none; appearance:none; }
.imgdrop { font-size: 13px; color: var(--muted); border:1px dashed var(--border); padding: 10px; border-radius: 10px; text-align:center; cursor:pointer; }
.imgdrop.has { color:#fff; }
.cover-prev { max-height: 120px; border-radius: 12px; margin-top: 8px; }
.kbd { font-family: ui-monospace, monospace; background: rgba(0,0,0,.4); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.danger-text { color: #fca5a5; }

/* sound toggle floating */
.sound-fab { position: fixed; bottom: 16px; left: 16px; z-index: 60; }

/* loading spinner */
.spinner { width: 42px; height:42px; border: 4px solid rgba(255,255,255,.2); border-top-color:#fff; border-radius:50%; animation: spin 1s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* connection lost banner */
.conn-lost { position: fixed; top:0; left:0; right:0; background: rgba(239,68,68,.95); color:#fff; text-align:center; padding: 8px; font-weight:800; z-index: 200; }

/* ====================================================================
   Image search + AI wizard (added features)
   ==================================================================== */
.small { font-size: 12.5px; }

/* accent button for the AI wizard */
.btn.ai-btn {
  background: linear-gradient(135deg, var(--violet), var(--pink));
  border: none; color: #fff; font-weight: 800;
}
.btn.ai-btn:hover { filter: brightness(1.08); }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(6,7,18,.66); backdrop-filter: blur(6px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 14px; overflow-y: auto;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 560px; margin: auto;
  background: #15162e; border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; max-height: calc(100vh - 48px);
  animation: pop .18s cubic-bezier(.2,.9,.3,1.2);
}
.modal.wide { max-width: 820px; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 800; font-size: 17px; flex: 1; }
.modal-body { padding: 16px; overflow-y: auto; }

/* ---------- image search ---------- */
.img-search { display: flex; flex-direction: column; gap: 12px; }
.img-search-bar { display: flex; gap: 8px; }
.img-search-bar .field { flex: 1; }
.img-status { color: var(--muted); font-size: 13.5px; min-height: 18px; }
.img-grid-wrap { position: relative; min-height: 120px; }
.img-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}
.img-cell {
  position: relative; padding: 0; border: 2px solid transparent;
  border-radius: 12px; overflow: hidden; cursor: pointer; background: var(--card);
  aspect-ratio: 4 / 3; transition: border-color .12s, transform .12s;
}
.img-cell:hover { transform: translateY(-2px); border-color: var(--cyan); }
.img-cell.sel { border-color: var(--green); }
.img-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-cred {
  position: absolute; left: 0; bottom: 0; font-size: 10px; line-height: 1;
  padding: 3px 6px; background: rgba(0,0,0,.55); color: #fff;
  border-top-right-radius: 8px; pointer-events: none;
}
.img-busy {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center; background: rgba(10,11,26,.7);
  border-radius: 12px; color: #fff; font-weight: 700; z-index: 2;
}
.more-btn { margin-top: 2px; }
.img-attrib { color: var(--muted); font-size: 11.5px; text-align: center; opacity: .85; }

/* ---------- AI wizard ---------- */
.wiz { display: flex; flex-direction: column; gap: 14px; }
.wiz .lbl { display: block; margin-bottom: 5px; }
.field.ta { width: 100%; min-height: 90px; resize: vertical; line-height: 1.45; }
.field.ta.mono, textarea.mono {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 12.5px; white-space: pre; tab-size: 2;
}
.inline-fields { display: flex; gap: 12px; flex-wrap: wrap; }
.inline-fields > div { flex: 1; min-width: 150px; }
.switch-row { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch-row input { width: 18px; height: 18px; accent-color: var(--violet); }
.err-box {
  background: rgba(239,68,68,.14); border: 1px solid rgba(239,68,68,.4);
  color: #ffd9d9; border-radius: 12px; padding: 10px 12px; font-size: 13.5px;
}
.ai-q-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ai-q-text { font-weight: 700; font-size: 15px; }
.ai-img-preview { display: flex; justify-content: center; }
.ai-img-preview .cover-prev { max-height: 180px; }
.result-emoji { font-size: 56px; text-align: center; line-height: 1; }

/* button-row alignment helpers */
.btn-row.end { justify-content: flex-end; }
.btn-row.between { justify-content: space-between; align-items: center; gap: 10px; }
.btn-row.mt { margin-top: 4px; }

@media (max-width: 560px) {
  .img-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .modal-body { padding: 13px; }
}

/* ====================================================================
   Live-game polish: presenter fit, player fill, lobby URL, remote
   ==================================================================== */

/* (#1) Keep the presenter question + answer tiles inside the viewport. */
.stage {
  justify-content: center;
  gap: clamp(8px, 1.8vh, 18px);
  width: 100%; max-width: 1180px; margin: 0 auto;
  min-height: calc(100dvh - 150px);
  max-height: calc(100dvh - 116px);
  overflow: hidden;
}
.stage .q-headline { flex: 0 0 auto; max-height: 42vh; overflow: hidden; }
.q-media { min-height: 0; flex: 0 1 auto; }
.q-media img { max-height: clamp(150px, 30vh, 340px); }
.stage.has-board .q-media img { max-height: clamp(110px, 20vh, 240px); }
.stage .board { min-height: 0; flex: 0 1 auto; }
.stage.has-board .tile { min-height: clamp(50px, 8vh, 104px); }
.q-meta { flex: 0 0 auto; }

/* (#6) Player answers fill the screen; stacked on phones, 2 columns when wide. */
.answer-screen {
  width: 100%; max-width: 720px;
  min-height: calc(100dvh - 44px);
  display: flex; flex-direction: column; gap: 12px;
  padding: 54px 0 14px;
}
.tap-hint { flex: 0 0 auto; }
.answers.fill { flex: 1 1 auto; min-height: 0; grid-auto-rows: 1fr; }
.answer-screen .answer { min-height: 56px; }
.answer .atxt { white-space: normal; overflow-wrap: anywhere; line-height: 1.15; }
@media (orientation: portrait) {
  .answers, .answers.fill { grid-template-columns: 1fr; }
}
@media (orientation: landscape) {
  .answers, .answers.fill { grid-template-columns: 1fr 1fr; }
}

/* (#7) Lobby join panel: one clean URL, kickable player tiles. */
.join-host { font-size: clamp(20px, 3.2vw, 32px); font-weight: 800; color: #fff; word-break: break-all; line-height: 1.1; }
.pin-kicker { text-transform: uppercase; letter-spacing: .2em; color: var(--muted); font-weight: 800; font-size: 12px; margin-top: 4px; }
.ptile { position: relative; }
.ptile .pn { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ptile-kick {
  margin-left: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.16); color: #fff; font-size: 12px; line-height: 1; display: grid; place-items: center;
  opacity: .6; transition: background .15s, opacity .15s;
}
.ptile-kick:hover { background: var(--red); opacity: 1; }

/* (#9) Remote control page. */
.remote { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 14px; }
.rm-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rm-title { font-weight: 900; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rm-state { text-align: center; font-weight: 800; color: var(--muted); background: rgba(0,0,0,.25); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.rm-controls { gap: 10px; }
.rm-roster { background: rgba(255,255,255,.05); border: 1px solid var(--border); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.rm-sub { font-weight: 800; color: var(--muted); font-size: 13px; }
.rm-prow { display: flex; align-items: center; gap: 10px; }
.rm-prow .av { font-size: 22px; }
.rm-prow .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }

/* button size helpers used by the remote + setup dialog */
.btn.xl { font-size: 20px; padding: 18px 20px; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.ghost.danger { background: transparent; color: #fda4af; border: 1px solid rgba(239,68,68,.5); }

/* unsaved-changes indicator (editor) */
.dirty-flag {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  color: #fbbf24; font-weight: 800; font-size: 13px;
  background: rgba(251,191,36,.12); border: 1px solid rgba(251,191,36,.40);
  padding: 6px 12px; border-radius: 999px;
}
.btn.attn { box-shadow: 0 0 0 2px rgba(251,191,36,.55), 0 8px 20px rgba(0,0,0,.35); }

/* ====================================================================
   Presenter: lock to the viewport, never scroll the page (v2)
   ==================================================================== */
.host {
  height: 100dvh; max-height: 100dvh; overflow: hidden;
  display: flex; flex-direction: column;
  padding-top: 12px; padding-bottom: 12px;
}
.host-top { flex: 0 0 auto; margin-bottom: 8px; }
#stage {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; justify-content: center;
  overflow: hidden;
}
/* question views fill the available height and shrink to fit */
#stage > .stage { flex: 1 1 auto; min-height: 0; max-height: 100%; }
/* lobby / scoreboard / podium / upload: centered, scroll only if truly huge */
#stage > .stack, #stage > .podium-wrap { min-height: 0; max-height: 100%; overflow-y: auto; overflow-x: hidden; }

.stage { min-height: 0; max-height: none; gap: clamp(6px, 1.4vh, 16px); justify-content: center; }
.stage .q-headline { flex: 0 1 auto; min-height: 0; max-height: 40vh; overflow: hidden; padding: clamp(10px, 2.2vh, 28px); }
.stage .q-media { flex: 0 1 auto; min-height: 0; }
.stage .q-media img { max-height: min(30vh, 320px); }
.stage .q-meta { flex: 0 0 auto; }
/* during answering/reveal the answer board takes the remaining space and the
   tiles divide it evenly, so nothing ever spills past the screen edge */
.stage.has-board .q-headline { max-height: 26vh; }
.stage.has-board .q-media img { max-height: min(18vh, 220px); }
.stage.has-board .board { flex: 1 1 auto; min-height: 0; grid-auto-rows: 1fr; align-content: stretch; gap: clamp(8px, 1.6vh, 14px); }
.stage.has-board .tile { min-height: 0; overflow: hidden; }

/* index.php: spacing for the inline join error */
#joinErr { margin-top: 10px; }

/* compact icon-only action button (landing page) */
.btn.icon-only { padding-left: 14px; padding-right: 14px; font-size: 1.15em; line-height: 1; }

/* ====================================================================
   iter4 fixes: action row, full-width presenter, narrow remote
   ==================================================================== */
/* keep Präsentieren / Erstellen / Fernsteuerung on ONE row (icon compact) */
.alt-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; }
.alt-actions > .btn { flex: 1 1 auto; }
.alt-actions > .btn.icon-only { flex: 0 0 auto; }

/* presenter uses the FULL screen width; generous side padding means the
   page never scrolls yet no content (incl. badges) gets clipped */
.host { max-width: none; padding: 12px clamp(18px, 3vw, 48px); }
#stage { overflow: visible; }

/* remote: comfortably narrow for a portrait phone, never overflow sideways */
.remote { max-width: 420px; }
.rm-head { min-width: 0; flex-wrap: wrap; }
.rm-title { flex: 1 1 auto; min-width: 0; }
.rm-prow .nm { min-width: 0; }
.remote .btn { white-space: normal; }
.remote { width: 100%; max-width: min(420px, 100%); }
