* { 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;
    --good: #4ade80;
    --bad: #f87171;
}

body.light {
    --bg1: #eef1f4;
    --bg2: #e3e8ee;
    --card-bg: rgba(255,255,255,0.9);
    --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);
    --good: #16a34a;
    --bad: #dc2626;
}

body {
    font-family: 'Segoe UI', 'Rubik', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg1) 0%, var(--bg2) 100%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    transition: background .5s;
}

/* Topbar */
.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 .back:hover { opacity: 1; }
.topbar .title { font-weight: 700; font-size: 1.15rem; }
.theme-toggle { 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; }
.theme-toggle:active { transform: scale(0.9); }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.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; transition: background .2s, transform .15s;
}
.exit-btn:hover { background: rgba(248,113,113,0.35); }
.exit-btn:active { transform: scale(0.94); }
.btn-danger { background: #ef4444; color: #fff; box-shadow: 0 10px 26px rgba(239,68,68,0.35); }
.btn-danger:hover { background: #dc2626; transform: translateY(-2px); }

#app { max-width: 560px; margin: 0 auto; padding: 1.5rem 1rem 4rem; position: relative; }

/* Screens + fade transitions */
.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: 2rem 1.6rem; box-shadow: 0 18px 50px rgba(0,0,0,0.22);
}
.center { text-align: center; }

.game-logo { font-size: 2.6rem; letter-spacing: 1px; margin-bottom: .3rem; text-shadow: 0 6px 24px rgba(0,0,0,0.25); }
h2 { font-size: 1.6rem; margin-bottom: .4rem; }
.subtitle { color: var(--muted); margin-bottom: 1.4rem; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    width: 100%; padding: .95rem 1.4rem; 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-primary:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(0,0,0,0.3); }
.btn-secondary { background: rgba(255,255,255,0.2); color: var(--text); border: 1px solid var(--card-border); }
.btn-secondary:hover { background: rgba(255,255,255,0.3); }
.btn-small { width: auto; padding: .5rem 1rem; font-size: .9rem; }
.btn-stack { display: flex; flex-direction: column; gap: .8rem; 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; }

/* Inputs */
.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; }

.digit-inputs { display: flex; gap: .7rem; justify-content: center; margin: 1.2rem 0; direction: ltr; }
.digit {
    width: 58px; height: 66px; text-align: center; font-size: 2rem; font-weight: 800;
    border-radius: 14px; border: 2px solid var(--card-border); background: var(--input-bg);
    color: var(--text); font-family: inherit; transition: border-color .2s, transform .15s;
}
.digit:focus { outline: none; border-color: var(--accent); transform: scale(1.05); }

/* Live checks */
.checks { list-style: none; text-align: right; max-width: 260px; margin: 0 auto 1.3rem; }
.checks li { padding: .3rem 0; color: var(--muted); transition: color .3s; }
.checks li::before { content: "○ "; }
.checks li.ok { color: var(--good); }
.checks li.ok::before { content: "✅ "; }

.error { color: var(--bad); min-height: 1.4rem; font-weight: 600; }

/* Room code */
.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 */
.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 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Game */
.round-badge { text-align: center; font-size: 1.5rem; font-weight: 800; margin-bottom: .3rem; }
.round-badge span { color: var(--accent); }
.series-badge {
    display: inline-block; margin: 0 auto .5rem; text-align: center;
    background: rgba(255,255,255,0.16); border: 1px solid var(--card-border);
    border-radius: 999px; padding: .2rem .8rem; font-size: .85rem; font-weight: 700;
    letter-spacing: .04rem; align-self: center;
}
.series-badge { display: block; width: fit-content; margin-inline: auto; }
.series-line { color: var(--muted); font-weight: 700; margin-bottom: .6rem; font-size: 1.05rem; }

/* History table */
.history { margin-top: 1.6rem; }
.history h3 { text-align: center; margin-bottom: .7rem; font-size: 1.1rem; }
.history table { width: 100%; border-collapse: collapse; }
.history th, .history td { padding: .6rem; text-align: center; border-bottom: 1px solid var(--card-border); }
.history th { color: var(--muted); font-weight: 600; font-size: .9rem; }
.history td { font-size: 1.15rem; font-weight: 700; }
.history td.guess { letter-spacing: .25rem; direction: ltr; }
.history .bull { color: var(--good); }
.history .hit { color: var(--accent); }
@keyframes rowIn { from { background: rgba(240,147,251,0.45); transform: scale(1.02); } to { background: transparent; transform: scale(1); } }
.history tr.new { animation: rowIn 1.4s ease; }

/* Game status row: my hidden secret + opponent threat meter */
.game-status { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin: .2rem 0 1rem; flex-wrap: wrap; }
.mini-toggle {
    background: #1b2530; color: var(--text);
    border: 1px solid var(--card-border); border-radius: 999px;
    padding: .35rem .8rem; font-size: .85rem; font-weight: 600;
    cursor: pointer; font-family: inherit; transition: background .2s, transform .15s;
}
.mini-toggle:hover { background: rgba(255,255,255,0.24); }
.mini-toggle:active { transform: scale(0.95); }
.mini-toggle b { letter-spacing: .18rem; direction: ltr; display: inline-block; }
.threat { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); }
.threat-dots { display: flex; gap: .28rem; }
.threat-dots span {
    width: 13px; height: 13px; border-radius: 50%;
    background: rgba(255,255,255,0.18); border: 1px solid var(--card-border);
    transition: background .3s, box-shadow .3s, transform .2s;
}
.threat-dots span.on { background: var(--accent); border-color: transparent; }
.threat.high .threat-dots span.on { background: var(--bad); box-shadow: 0 0 9px var(--bad); animation: threatPulse 0.9s ease infinite; }
@keyframes threatPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.25); } }
.threat-warn { text-align: center; color: var(--bad); font-weight: 800; margin: -.4rem 0 .9rem; animation: warnBlink 1s ease infinite; }
@keyframes warnBlink { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

/* Peek at opponent board */
.peek-toggle {
    display: block; margin: 0 0 .6rem auto;
    background: rgba(255,255,255,0.18); color: var(--text);
    border: 1px solid var(--card-border); border-radius: 999px;
    padding: .4rem .9rem; font-size: .85rem; font-weight: 600;
    cursor: pointer; font-family: inherit; transition: background .2s, transform .15s;
}
.peek-toggle:hover { background: rgba(255,255,255,0.28); }
.peek-toggle:active { transform: scale(0.95); }
.peek-toggle.on { background: var(--accent); color: #1e1b4b; }
.opp-history { margin-top: 1.2rem; border-top: 1px dashed var(--card-border); padding-top: 1rem; }
.opp-history .opp-hint { text-align: center; color: var(--muted); font-size: .85rem; margin-top: -.4rem; margin-bottom: .6rem; }
.opp-empty { text-align: center; color: var(--muted); font-size: .9rem; padding: .6rem 0; }

.opp-submitted {
  margin: -.3rem auto .4rem; display: table;
  padding: .35rem .8rem; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent); font-weight: 700; font-size: .92rem;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  animation: oppPulse 1.6s ease-in-out infinite;
}
@keyframes oppPulse { 0%, 100% { opacity: .75; } 50% { opacity: 1; } }

.over-boards { margin-top: 1.2rem; text-align: right; max-height: 50vh; overflow-y: auto; }
.over-boards .history:first-child { margin-top: 0; }
#over-boards-toggle { margin-top: 1.2rem; }

/* Reveal */
.reveal { display: flex; gap: 1rem; justify-content: center; margin: 1.4rem 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; direction: ltr; }
.result-emoji { font-size: 4rem; animation: pop .6s ease; }
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }
.rematch-note { color: var(--accent); font-weight: 600; margin-bottom: .6rem; }

/* Countdown */
.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 */
.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; }

/* Modal */
.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; }
.modal-card .btn { margin-top: .8rem; }

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

.hidden { display: none !important; }

@media (max-width: 480px) {
    .digit { width: 48px; height: 58px; font-size: 1.6rem; }
    .game-logo { font-size: 2.1rem; }
    .room-code { font-size: 2.2rem; }
}
