/* ===========================================================
   World Cup 2026 Quiz — Theme & Animations
   Palette: pitch green, trophy gold, host-nation red/blue
   =========================================================== */
:root {
    --green:      #00893d;
    --green-lite: #16b45a;
    --gold:       #ffcb05;
    --gold-deep:  #f5a623;
    --red:        #e11b22;
    --blue:       #0b3d91;
    --ink:        #0a1f14;
    --paper:      #ffffff;
    --muted:      #6b7f74;
    --shadow:     0 12px 40px rgba(0,0,0,.25);
    --radius:     16px;
    --font:       'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--ink);
    min-height: 100vh;
    background: #06301c;
    overflow-x: hidden;
}

/* ---- Animated pitch background ---- */
.pitch-bg {
    position: fixed; inset: 0; z-index: -2;
    background:
        radial-gradient(1200px 600px at 20% -10%, rgba(22,180,90,.55), transparent 60%),
        radial-gradient(1000px 700px at 100% 0%, rgba(11,61,145,.5), transparent 55%),
        radial-gradient(900px 700px at 50% 120%, rgba(225,27,34,.35), transparent 55%),
        linear-gradient(160deg, #073b22 0%, #043019 40%, #052f1c 100%);
    background-color: #052a18;
}
.pitch-bg::before {
    content: ""; position: absolute; inset: -20%;
    background-image:
        repeating-linear-gradient(90deg, rgba(255,255,255,.04) 0 60px, transparent 60px 120px);
    animation: slidefield 18s linear infinite;
}
.pitch-bg::after {
    content: ""; position: absolute; inset: 0;
    background:
        radial-gradient(circle at 50% 50%, transparent 0 120px, rgba(255,255,255,.05) 121px 123px, transparent 124px),
        linear-gradient(transparent 49.6%, rgba(255,255,255,.06) 49.6% 50.4%, transparent 50.4%);
    opacity: .5;
}
@keyframes slidefield { to { transform: translateX(120px); } }
/* Custom full-screen page background image (admin-uploaded): fill the screen, drop the pitch decorations */
.pitch-bg.has-image { background-color: #04160d; }
.pitch-bg.has-image::before, .pitch-bg.has-image::after { display: none; }

/* ---- Top bar ---- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: .7rem 1.4rem; gap: 1rem;
    background: rgba(4,28,17,.82);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid var(--gold);
    position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: #fff; font-weight: 800; letter-spacing: .5px; }
.brand-trophy { font-size: 1.6rem; filter: drop-shadow(0 0 8px var(--gold)); animation: bob 3s ease-in-out infinite; }
.brand .accent { color: var(--gold); }
@keyframes bob { 50% { transform: translateY(-4px) rotate(-6deg); } }
.topnav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topnav a { color: #d7f5e5; text-decoration: none; font-weight: 600; font-size: .92rem; transition: color .2s; }
.topnav a:hover { color: var(--gold); }
.user-chip { background: rgba(255,203,5,.15); color: var(--gold); padding: .25rem .7rem; border-radius: 20px; font-size: .8rem; font-weight: 700; }
.btn-logout { background: var(--red); color: #fff !important; padding: .35rem .8rem; border-radius: 20px; }

.container { max-width: 1080px; margin: 0 auto; padding: 1.6rem 1.2rem 4rem; }
.page-title { color: #fff; font-size: 2rem; margin: .2rem 0 1.2rem; text-shadow: 0 2px 12px rgba(0,0,0,.4); }
.page-title .accent, .accent { color: var(--gold); }

.site-footer { text-align: center; color: #9fd8bb; padding: 1.4rem; font-size: .85rem; display: flex; flex-direction: column; gap: .25rem; align-items: center; }
.footer-brand { color: #cfeede; letter-spacing: .3px; }
.footer-brand strong { color: var(--gold); }

/* ---- Buttons ---- */
.btn { display: inline-block; border: none; cursor: pointer; font-weight: 700; font-size: .95rem;
    padding: .7rem 1.3rem; border-radius: 12px; text-decoration: none; transition: transform .12s, box-shadow .2s; }
.btn:active { transform: scale(.96); }
.btn-primary { background: linear-gradient(135deg, var(--gold), var(--gold-deep)); color: #3a2a00; box-shadow: 0 6px 18px rgba(245,166,35,.4); }
.btn-primary:hover { box-shadow: 0 8px 26px rgba(245,166,35,.6); }
.btn-ghost { background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.25); }
.btn-danger { background: linear-gradient(135deg, #ff4d55, var(--red)); color: #fff; box-shadow: 0 6px 18px rgba(225,27,34,.4); }
.btn-block { width: 100%; }

/* ---- Alerts ---- */
.alert { padding: .8rem 1rem; border-radius: 10px; margin: 0 0 1rem; font-weight: 600; }
.alert.success { background: rgba(22,180,90,.18); color: #b7f5cf; border: 1px solid var(--green-lite); }
.alert.error { background: rgba(225,27,34,.18); color: #ffc9cb; border: 1px solid var(--red); }
.hint { color: var(--muted); font-size: .85rem; }
.panel .hint, .topbar .hint { color: #9fb8ab; }

/* =========================================================
   LOGIN / INSTALL
   ========================================================= */
.login-page, .install-page { display: flex; }
.login-wrap { min-height: 100vh; width: 100%; display: grid; place-items: center; padding: 1.5rem; }
.login-card, .install-card {
    width: 100%; max-width: 400px; background: rgba(255,255,255,.97);
    border-radius: 22px; padding: 2.2rem 2rem; box-shadow: var(--shadow);
    border-top: 6px solid var(--gold); text-align: center;
    animation: popin .5s cubic-bezier(.2,1.2,.3,1);
}
.install-card { max-width: 520px; margin: 6vh auto; text-align: left; }
/* Alerts on the white login/install cards need dark, readable text */
.login-card .alert, .install-card .alert { text-align: left; }
.login-card .alert.error, .install-card .alert.error { background: rgba(225,27,34,.1); color: #d0141a; border-color: #e11b22; }
.login-card .alert.success, .install-card .alert.success { background: rgba(0,137,61,.12); color: #0a7d3f; border-color: var(--green); }
@keyframes popin { from { transform: translateY(20px) scale(.94); opacity: 0; } }
.trophy-big { font-size: 3.4rem; animation: bob 3s ease-in-out infinite; }
.login-logo { display: block; margin: 0 auto .4rem; max-width: 150px; max-height: 130px; width: auto; height: auto;
    object-fit: contain; filter: drop-shadow(0 6px 16px rgba(0,0,0,.25)); animation: popin .5s cubic-bezier(.2,1.2,.3,1); }
.logo-preview { display: flex; align-items: center; gap: .9rem; padding: .8rem 1rem; margin-bottom: 1rem;
    background: #f4f8f6; border: 2px dashed #d6e2db; border-radius: 12px; }
.logo-preview img { max-width: 90px; max-height: 90px; width: auto; height: auto; object-fit: contain; }
.logo-preview .logo-fallback { font-size: 3rem; }
.logo-preview .logo-cap, .bg-preview .logo-cap { color: var(--muted); font-weight: 700; font-size: .85rem; }
.bg-preview { display: flex; align-items: center; gap: .9rem; margin-bottom: 1rem; }
.bg-thumb { width: 160px; height: 96px; border-radius: 12px; flex: 0 0 auto;
    background-size: cover; background-position: center; border: 2px solid #d6e2db;
    display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .8rem;
    text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.bg-thumb-default { background: linear-gradient(160deg, #0b6b3e, #073e25); }
.trophy { font-size: 2.6rem; }
.login-card h1 { margin: .3rem 0 0; font-size: 1.7rem; letter-spacing: 1px; }
.login-card .subtitle { color: var(--muted); margin: .3rem 0 1.3rem; }
.login-card label, .stack-form label { display: block; text-align: left; font-weight: 700; font-size: .82rem; color: #33463c; margin-bottom: .9rem; }
.login-card input, .stack-form input, .stack-form textarea, .stack-form select {
    width: 100%; margin-top: .35rem; padding: .7rem .8rem; border: 2px solid #dfe8e3;
    border-radius: 10px; font-size: 1rem; font-family: inherit; transition: border-color .2s, box-shadow .2s; }
.login-card input:focus, .stack-form input:focus, .stack-form textarea:focus, .stack-form select:focus {
    outline: none; border-color: var(--green-lite); box-shadow: 0 0 0 3px rgba(22,180,90,.18); }
.install-log { list-style: none; padding: 0; }
.install-log li { padding: .3rem 0; }

/* =========================================================
   PLAYER — SCORE STRIP + GRID
   ========================================================= */
.play-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.score-strip { display: flex; gap: .7rem; }
.score-pill { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2); border-radius: 14px;
    padding: .5rem 1rem; text-align: center; color: #fff; min-width: 74px; }
.score-pill.green { background: rgba(22,180,90,.25); border-color: var(--green-lite); }
.score-pill .num { display: block; font-size: 1.5rem; font-weight: 800; color: var(--gold); }
.score-pill.green .num { color: #7dffb0; }
.score-pill .lbl { font-size: .68rem; text-transform: uppercase; letter-spacing: .5px; opacity: .85; }

.grid-board {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 14px; margin-top: 1.6rem;
}
.q-cell {
    position: relative; aspect-ratio: 1 / 1; border: none; cursor: pointer;
    border-radius: 18px; color: #fff; font-family: inherit;
    background: linear-gradient(150deg, #0e5c36, #0a7d47);
    box-shadow: 0 8px 20px rgba(0,0,0,.3), inset 0 2px 0 rgba(255,255,255,.18);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: transform .16s, box-shadow .2s, filter .2s;
    overflow: hidden; animation: cellin .4s backwards;
}
.q-cell::before { /* soccer ball ghost */
    content: "⚽"; position: absolute; right: -8px; bottom: -10px; font-size: 3.2rem; opacity: .12; transform: rotate(-15deg); }
.grid-board .q-cell:nth-child(2n) { animation-delay: .05s; }
.grid-board .q-cell:nth-child(3n) { animation-delay: .1s; }
@keyframes cellin { from { transform: scale(.6); opacity: 0; } }
/* Unanswered cells: white gradient (numbers darkened so they stay readable) */
.q-cell.cell-open {
    background: linear-gradient(160deg, #ffffff, #dfe7e4);
    color: var(--ink);
    box-shadow: 0 8px 20px rgba(0,0,0,.22), inset 0 2px 0 rgba(255,255,255,.9);
}
.q-cell.cell-open .q-num { text-shadow: 0 1px 2px rgba(0,0,0,.12); }
.q-cell.cell-open::before { opacity: .07; }
.q-cell.cell-open:hover { transform: translateY(-5px) scale(1.03); box-shadow: 0 14px 30px rgba(0,0,0,.4); filter: brightness(1.04); }
.q-cell .q-num { font-size: 2.1rem; font-weight: 900; text-shadow: 0 2px 6px rgba(0,0,0,.4); }
.q-cell .q-mark { font-size: 1rem; opacity: .9; margin-top: .1rem; font-weight: 700; }

.q-cell[disabled] { cursor: default; }
.cell-correct { background: linear-gradient(150deg, #12994f, #0b6b38); box-shadow: 0 0 0 3px rgba(125,255,176,.5), 0 8px 20px rgba(0,0,0,.3); }
.cell-wrong   { background: linear-gradient(150deg, #c31d24, #8f1318); box-shadow: 0 0 0 3px rgba(255,120,120,.4), 0 8px 20px rgba(0,0,0,.3); }
.cell-timeout { background: linear-gradient(150deg, #6b7a72, #4b564f); box-shadow: 0 8px 20px rgba(0,0,0,.3); filter: grayscale(.3); }

.empty-note { grid-column: 1/-1; color: #bfe6d2; text-align: center; padding: 2rem; }

/* =========================================================
   QUIZ MODAL
   ========================================================= */
.modal-overlay {
    position: fixed; inset: 0; z-index: 100; display: none;
    align-items: center; justify-content: center; padding: 1rem;
    background: radial-gradient(circle at center, rgba(3,26,15,.7), rgba(2,15,9,.92));
    backdrop-filter: blur(6px);
}
.modal-overlay.open { display: flex; animation: fade .25s; }
@keyframes fade { from { opacity: 0; } }
.modal-card {
    width: 100%; max-width: 620px; border-radius: 24px; padding: 1.6rem 1.6rem 1.8rem;
    color: #fff; position: relative; overflow: hidden;
    background: linear-gradient(160deg, #0b6b3e, #073e25);
    border: 2px solid var(--gold);
    box-shadow: 0 30px 80px rgba(0,0,0,.6);
    animation: modalpop .4s cubic-bezier(.2,1.3,.3,1);
}
@keyframes modalpop { from { transform: scale(.85) translateY(20px); opacity: 0; } }
.modal-card::before { /* world cup glow */
    content: ""; position: absolute; top: -60px; right: -60px; width: 220px; height: 220px;
    background: radial-gradient(circle, rgba(255,203,5,.35), transparent 70%); pointer-events: none;
}
.modal-topline { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.q-badge { background: var(--gold); color: #3a2a00; font-weight: 800; padding: .35rem .9rem; border-radius: 20px; font-size: .9rem; }

/* Timer ring */
.timer-ring { position: relative; width: 72px; height: 72px; }
.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-ring circle { fill: none; stroke-width: 9; }
.ring-bg { stroke: rgba(255,255,255,.15); }
.ring-fg { stroke: var(--green-lite); stroke-linecap: round;
    stroke-dasharray: 327; stroke-dashoffset: 0; transition: stroke-dashoffset 1s linear, stroke .4s; }
.timer-num { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.5rem; font-weight: 900; }
.timer-ring.danger .ring-fg { stroke: var(--red); }
.timer-ring.danger { animation: pulseRed .8s ease-in-out infinite; }
@keyframes pulseRed {
    0%,100% { transform: scale(1);   filter: drop-shadow(0 0 0 rgba(225,27,34,0)); }
    50%     { transform: scale(1.12); filter: drop-shadow(0 0 14px rgba(225,27,34,.9)); }
}

.modal-question { font-size: 1.35rem; font-weight: 700; line-height: 1.4; margin: .4rem 0 1.2rem; min-height: 2.6em; }
/* When a custom background image is set, boost text/chip contrast so it stays readable */
.modal-card.has-bg .modal-question { text-shadow: 0 2px 8px rgba(0,0,0,.8); }
.modal-card.has-bg .opt-btn { background: rgba(0,0,0,.4); border-color: rgba(255,255,255,.4); }
.modal-card.has-bg .opt-btn:not(:disabled):hover { background: rgba(0,0,0,.55); }
.modal-card.has-bg .opt-btn > span:last-child { text-shadow: 0 1px 5px rgba(0,0,0,.85); }
.modal-options { display: grid; gap: .7rem; }
.opt-btn {
    text-align: left; padding: 1rem 1.1rem; border-radius: 14px; cursor: pointer;
    font-size: 1.05rem; font-weight: 600; font-family: inherit; color: #fff;
    background: rgba(255,255,255,.1); border: 2px solid rgba(255,255,255,.22);
    transition: transform .12s, background .2s, border-color .2s;
    display: flex; align-items: center; gap: .8rem;
}
.opt-btn .opt-key { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 8px; background: var(--gold);
    color: #3a2a00; font-weight: 800; display: grid; place-items: center; }
.opt-btn:not(:disabled):hover { background: rgba(255,255,255,.2); border-color: var(--gold); transform: translateX(4px); }
.opt-btn:disabled { cursor: default; }
.opt-btn.correct { background: linear-gradient(135deg, #16b45a, #0b8a41); border-color: #7dffb0; animation: goodpop .5s; }
.opt-btn.correct::after {
    content: "✓"; margin-left: auto; font-size: 1.5rem; font-weight: 900; line-height: 1;
    color: #ffffff; text-shadow: 0 2px 8px rgba(0,0,0,.4);
    animation: tickpop .45s cubic-bezier(.2,1.6,.3,1) both;
}
@keyframes tickpop { 0% { transform: scale(0) rotate(-25deg); opacity: 0; } 60% { transform: scale(1.35) rotate(6deg); } 100% { transform: scale(1) rotate(0); opacity: 1; } }
.opt-btn.wrong   { background: linear-gradient(135deg, #e11b22, #a5141a); border-color: #ff9a9a; animation: shake .5s; }
.opt-btn.dim { opacity: .45; }
@keyframes goodpop { 0% { transform: scale(1);} 40%{ transform: scale(1.05);} 100%{transform: scale(1);} }
@keyframes shake { 10%,90%{transform:translateX(-3px);} 30%,70%{transform:translateX(6px);} 50%{transform:translateX(-8px);} }

.modal-feedback { margin-top: 1.1rem; text-align: center; font-size: 1.15rem; font-weight: 800; min-height: 1.4em; }
.modal-feedback .fb-correct { color: #7dffb0; }
.modal-feedback .fb-wrong { color: #ff9a9a; }
.modal-feedback .fb-timeout { color: #cfd8d2; }
.modal-feedback .correct-answer { display: block; font-size: .95rem; font-weight: 600; color: #fff; margin-top: .3rem; }
.modal-feedback .tap-hint { display:block; font-size:.8rem; font-weight:600; color:#cfe9da; margin-top:.6rem; opacity:.8; }

/* =========================================================
   FX — confetti + big stamp
   ========================================================= */
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 200; overflow: hidden; }
.confetti { position: absolute; width: 10px; height: 14px; top: -20px; opacity: .9;
    animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: 1; } }
.stamp { position: fixed; inset: 0; display: grid; place-items: center; z-index: 210; pointer-events: none; }
.stamp span { font-size: clamp(3rem, 16vw, 9rem); font-weight: 900; animation: stampin .7s cubic-bezier(.2,1.4,.3,1) forwards; text-shadow: 0 8px 30px rgba(0,0,0,.5); }
.stamp.good span { color: #7dffb0; }
.stamp.bad span { color: #ff8a8a; }
.stamp.neutral span { color: #d5ded8; }
@keyframes stampin { 0%{transform:scale(2.4) rotate(-14deg); opacity:0;} 40%{transform:scale(1) rotate(-8deg); opacity:1;} 80%{transform:scale(1) rotate(-8deg); opacity:1;} 100%{opacity:0; transform:scale(1.1) rotate(-8deg);} }

/* =========================================================
   ADMIN
   ========================================================= */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.6rem; }
.stat-card { background: rgba(255,255,255,.96); border-radius: var(--radius); padding: 1.3rem; box-shadow: var(--shadow); border-left: 5px solid var(--gold); }
.stat-num { font-size: 2.4rem; font-weight: 900; color: var(--green); }
.stat-lbl { color: var(--muted); font-weight: 700; font-size: .85rem; }
.stat-card a { display: inline-block; margin-top: .5rem; color: var(--blue); font-weight: 700; text-decoration: none; font-size: .85rem; }
.admin-actions { display: flex; gap: .8rem; flex-wrap: wrap; }

.admin-split { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 1.4rem; align-items: start; }
.panel { background: rgba(255,255,255,.97); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow); }
.panel.narrow { max-width: 480px; }
.panel h2 { margin: 0 0 1rem; color: var(--ink); font-size: 1.2rem; }
.stack-form textarea { resize: vertical; }
.opt-fieldset { border: 2px dashed #d6e2db; border-radius: 12px; padding: .9rem; margin-bottom: 1rem; }
.opt-fieldset legend { font-weight: 800; color: var(--green); padding: 0 .4rem; font-size: .85rem; }
.opt-row { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.opt-row input[type=radio] { width: 20px; height: 20px; accent-color: var(--green); flex: 0 0 auto; }
.opt-row input[type=text] { flex: 1; margin: 0; }
.form-actions { display: flex; gap: .7rem; align-items: center; }
.check-inline { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.check-inline input { width: auto; margin: 0; }
.inline-form { display: flex; gap: .5rem; margin-bottom: .8rem; }
.inline-form input { flex: 1; padding: .55rem .7rem; border: 2px solid #dfe8e3; border-radius: 8px; }

.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th { text-align: left; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .5px; padding: .5rem .5rem; border-bottom: 2px solid #eef3f0; }
.data-table td { padding: .6rem .5rem; border-bottom: 1px solid #eef3f0; vertical-align: middle; }
.data-table .ok { color: var(--green); font-weight: 800; }
.data-table .bad { color: var(--red); font-weight: 800; }
.row-actions { display: flex; gap: .6rem; align-items: center; }
.row-actions a { color: var(--blue); text-decoration: none; font-weight: 700; }
.row-actions form { display: inline; }
.link-danger { background: none; border: none; color: var(--red); cursor: pointer; font-weight: 700; font-family: inherit; font-size: .9rem; padding: 0; }
.tag { background: rgba(11,61,145,.12); color: var(--blue); padding: .2rem .6rem; border-radius: 20px; font-size: .78rem; font-weight: 700; }
.badge { padding: .25rem .7rem; border-radius: 20px; font-size: .75rem; font-weight: 800; color: #fff; }
.b-green { background: var(--green); } .b-red { background: var(--red); } .b-gray { background: #6b7a72; }
.role-list { list-style: none; padding: 0; }
.role-list li { display: flex; justify-content: space-between; align-items: center; padding: .45rem .2rem; border-bottom: 1px solid #eef3f0; }
.nowrap { white-space: nowrap; }

@media (max-width: 760px) {
    .admin-split { grid-template-columns: 1fr; }
    .grid-board { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 10px; }
    .q-cell .q-num { font-size: 1.7rem; }
    .play-header { flex-direction: column; align-items: flex-start; }
}
