* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #ff9c41; --secondary: #2a3744; --accent: #ff9c41;
    --bg1: #0f151c; --bg2: #1b2530;
    --card-bg: rgba(18,26,34,0.92); --card-border: #223040;
    --text: #e8edf2; --muted: #8ea0ad;
    --input-bg: #1b2530;
    --bull: #4ade80; --hit: #fbbf24; --miss: #6b7280; --bad: #f87171;
    --tile-empty: rgba(255,255,255,0.04); --tile-border: #2a3744;
    --key-bg: #223040;
}
body.light {
    --bg1: #eef1f4; --bg2: #e3e8ee;
    --card-bg: rgba(255,255,255,0.78); --card-border: rgba(0,0,0,0.08);
    --text: #15202b; --muted: rgba(21,32,43,0.65); --input-bg: rgba(255,255,255,0.9);
    --bull: #16a34a; --hit: #d97706; --miss: #9ca3af; --bad: #dc2626;
    --tile-empty: rgba(0,0,0,0.03); --tile-border: rgba(0,0,0,0.18);
    --key-bg: rgba(0,0,0,0.08);
}
body {
    font-family: 'Segoe UI', 'Rubik', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg1), var(--bg2)); color: var(--text);
    min-height: 100vh; line-height: 1.6; transition: background .5s;
}

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.2rem; background: rgba(0,0,0,0.25); backdrop-filter: blur(12px); }
.topbar .back { color: var(--text); text-decoration: none; font-weight: 600; opacity: .9; }
.topbar .title { font-weight: 700; font-size: 1.15rem; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.icon-btn { background: rgba(255,255,255,0.2); border: none; color: var(--text); font-size: 1.1rem; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; transition: transform .2s; }
.icon-btn:active { transform: scale(0.9); }
.exit-btn { background: rgba(248,113,113,0.22); color: var(--text); border: 1px solid rgba(248,113,113,0.5); border-radius: 999px; padding: .4rem .8rem; font-size: .85rem; font-weight: 700; cursor: pointer; font-family: inherit; }
.exit-btn:hover { background: rgba(248,113,113,0.35); }

#app { max-width: 520px; margin: 0 auto; padding: 1.2rem 1rem 2rem; position: relative; }
.screen { display: none; animation: fadeIn .45s ease; }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

.card { background: var(--card-bg); backdrop-filter: blur(14px); border: 1px solid var(--card-border); border-radius: 22px; padding: 1.6rem 1.2rem; box-shadow: 0 18px 50px rgba(0,0,0,0.22); }
.center { text-align: center; }
.game-logo { font-size: 2.6rem; letter-spacing: 2px; margin-bottom: .3rem; }
h2 { font-size: 1.5rem; margin-bottom: .4rem; }
.subtitle { color: var(--muted); margin-bottom: 1.2rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; width: 100%; padding: .9rem 1.3rem; border: none; border-radius: 14px; font-size: 1.05rem; font-weight: 700; cursor: pointer; font-family: inherit; transition: transform .15s, box-shadow .25s, background .25s, opacity .2s; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: #fff; color: var(--primary); box-shadow: 0 10px 26px rgba(0,0,0,0.22); }
body.light .btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: rgba(255,255,255,0.2); color: var(--text); border: 1px solid var(--card-border); }
.btn-danger { background: #ef4444; color: #fff; }
.btn-small { width: auto; padding: .5rem 1rem; font-size: .9rem; }
.btn-stack { display: flex; flex-direction: column; gap: .7rem; margin-top: 1rem; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; margin-top: 1rem; font-size: .95rem; font-family: inherit; text-decoration: underline; }

.text-input { width: 100%; padding: .9rem 1rem; border-radius: 12px; border: 1px solid var(--card-border); background: var(--input-bg); color: var(--text); font-size: 1.1rem; font-family: inherit; text-align: center; }
.code-input { letter-spacing: .5rem; font-size: 1.8rem; font-weight: 700; }
.text-input::placeholder { color: var(--muted); letter-spacing: normal; }
.error { color: var(--bad); min-height: 1.4rem; font-weight: 600; }

.code-box { display: flex; flex-direction: column; align-items: center; gap: 1rem; margin: 1.2rem 0; }
.code-box .two { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.room-code { font-size: 3rem; font-weight: 800; letter-spacing: .6rem; direction: ltr; background: rgba(0,0,0,0.2); padding: .6rem 1.4rem; border-radius: 16px; }
.waiting-line { display: flex; align-items: center; justify-content: center; gap: .7rem; color: var(--muted); margin-top: 1.2rem; }
.spinner { width: 20px; height: 20px; border: 3px solid rgba(255,255,255,0.3); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.game-head { display: flex; align-items: center; justify-content: center; gap: .8rem; flex-wrap: wrap; margin-bottom: .2rem; }
.round-badge { font-size: 1.3rem; font-weight: 800; }
.round-badge b { color: var(--accent); }
.series-badge { background: rgba(255,255,255,0.16); border: 1px solid var(--card-border); border-radius: 999px; padding: .2rem .7rem; font-size: .85rem; font-weight: 700; }

/* Board of tiles — RTL so position 1 is on the right (Hebrew reads right-to-left) */
.board { display: grid; gap: 6px; justify-content: center; margin: 1rem auto; direction: rtl; }
.board-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.tile {
    width: 52px; height: 52px; display: flex; align-items: center; justify-content: center;
    font-size: 1.7rem; font-weight: 800; border-radius: 8px;
    border: 2px solid var(--tile-border); background: var(--tile-empty); color: var(--text);
    text-transform: none; transition: transform .12s;
}
.tile.filled { border-color: var(--muted); animation: pop .12s ease; }
.tile.bull { background: var(--bull); border-color: var(--bull); color: #06210f; }
.tile.hit { background: var(--hit); border-color: var(--hit); color: #2a1a00; }
.tile.miss { background: var(--miss); border-color: var(--miss); color: #fff; }
.board-row.reveal .tile { animation: flip .5s ease both; }
.board-row.reveal .tile:nth-child(2) { animation-delay: .1s; }
.board-row.reveal .tile:nth-child(3) { animation-delay: .2s; }
.board-row.reveal .tile:nth-child(4) { animation-delay: .3s; }
.board-row.reveal .tile:nth-child(5) { animation-delay: .4s; }
@keyframes pop { 0% { transform: scale(0.9); } 100% { transform: scale(1); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }

/* Hebrew on-screen keyboard */
.keyboard { display: flex; flex-direction: column; gap: 6px; margin-top: 1.1rem; }
.kb-row { display: flex; justify-content: center; gap: 5px; }
.key {
    min-width: 30px; height: 48px; padding: 0 .35rem; border: none; border-radius: 7px;
    background: var(--key-bg); color: var(--text); font-size: 1.1rem; font-weight: 700;
    font-family: inherit; cursor: pointer; flex: 1; max-width: 42px; transition: transform .1s, background .2s;
}
.key:active { transform: scale(0.92); }
.key.wide { flex: 1.6; max-width: 74px; font-size: .95rem; }
.key.bull { background: var(--bull); color: #06210f; }
.key.hit { background: var(--hit); color: #2a1a00; }
.key.miss { background: var(--miss); color: #fff; opacity: .85; }

/* Reveal + over */
.reveal { display: flex; gap: 1rem; justify-content: center; margin: 1.2rem 0; flex-wrap: wrap; }
.reveal-item { background: rgba(0,0,0,0.18); border-radius: 14px; padding: 1rem 1.4rem; }
.reveal-label { display: block; color: var(--muted); font-size: .85rem; margin-bottom: .3rem; }
.reveal-num { font-size: 1.8rem; font-weight: 800; letter-spacing: .3rem; }
.result-emoji { font-size: 4rem; animation: popbig .6s ease; }
@keyframes popbig { 0% { transform: scale(0); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }
.series-line { color: var(--muted); font-weight: 700; margin-bottom: .6rem; font-size: 1.05rem; }
.rematch-note { color: var(--accent); font-weight: 600; margin-bottom: .6rem; }

.countdown-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; z-index: 500; }
.countdown-num { font-size: 8rem; font-weight: 900; color: #fff; animation: cd 1s ease infinite; }
@keyframes cd { 0% { transform: scale(0.5); opacity: 0; } 40% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.4); opacity: 0; } }

.banner { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.8); color: #fff; padding: .8rem 1.4rem; border-radius: 12px; z-index: 600; font-weight: 600; text-align: center; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 700; padding: 1rem; }
.modal-card { background: linear-gradient(135deg, var(--bg1), var(--bg2)); border: 1px solid var(--card-border); border-radius: 20px; padding: 2rem; max-width: 460px; }
.modal-card h2 { margin-bottom: 1rem; }
.modal-card p { margin-bottom: .8rem; }
.modal-card ul { margin: 0 1.4rem 1rem; list-style: none; }
.modal-card li { margin-bottom: .4rem; }
#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 800; }

/* pending (submitted, awaiting reveal) row — keep the word visible */
.board-row.pending .tile.filled { border-color: var(--accent); border-style: dashed; opacity: .9; animation: pendPulse 1.2s ease-in-out infinite; }
@keyframes pendPulse { 0%,100% { opacity: .95; } 50% { opacity: .55; } }

/* round timer + participants */
.timer { font-weight: 800; font-size: 1.05rem; background: rgba(0,0,0,0.18); padding: .2rem .6rem; border-radius: 999px; direction: ltr; }
.timer.low { color: var(--bad); animation: warnBlink 1s ease infinite; }
@keyframes warnBlink { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
.participants-btn { background: rgba(255,255,255,0.18); border: 1px solid var(--card-border); color: var(--text); border-radius: 999px; padding: .25rem .7rem; font-size: .9rem; font-weight: 700; cursor: pointer; font-family: inherit; }

/* players lists (lobby + participants) */
.players-list { display: flex; flex-direction: column; gap: .35rem; margin: .3rem 0 1rem; max-height: 240px; overflow-y: auto; }
.pl-row { display: flex; justify-content: space-between; align-items: center; gap: .6rem; background: rgba(255,255,255,0.1); border: 1px solid var(--card-border); border-radius: 10px; padding: .5rem .9rem; font-weight: 600; }
.pl-row.off { opacity: .55; }

/* leaderboard */
.race-over { margin: 1rem 0; }
.leaderboard { display: flex; flex-direction: column; gap: .4rem; margin-top: 1rem; text-align: right; }
.lb-row { display: grid; grid-template-columns: 2rem 1fr auto; gap: .6rem; align-items: center; background: rgba(255,255,255,0.1); border: 1px solid var(--card-border); border-radius: 10px; padding: .5rem .8rem; }
.lb-row.winner { background: rgba(74,222,128,0.25); border-color: var(--bull); }
.lb-pos { font-weight: 800; text-align: center; }
.lb-name { font-weight: 700; }
.lb-solved { color: var(--muted); font-size: .9rem; }

.hidden { display: none !important; }

@media (max-width: 430px) {
    .tile { width: 46px; height: 46px; font-size: 1.5rem; }
    .key { height: 44px; font-size: 1rem; }
    .game-logo { font-size: 2.1rem; }
}
