:root {
    --blue: #003399;
    --gold: #FFD700;
    --bg: #f0f4ff;
    --white: #ffffff;
    --text: #1a1a2e;
    --subtext: #888;
    --border: #e0e7f0;
    --danger: #c0392b;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Views ─────────────────────────────────────────────────── */

.view {
    display: none;
    min-height: 100vh;
    flex-direction: column;
}

.view.active {
    display: flex;
}

/* ── Landing ────────────────────────────────────────────────── */

#view-landing,
#view-setname {
    background: var(--blue);
}

.landing-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 40px 24px;
    text-align: center;
    color: white;
}

.landing-logo {
    font-size: 4rem;
    margin-bottom: 20px;
}

.landing-inner h1 {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1.25;
    margin-bottom: 10px;
}

.landing-inner > p {
    opacity: 0.75;
    margin-bottom: 32px;
    font-size: 0.95rem;
    max-width: 260px;
}

/* ── Buttons ────────────────────────────────────────────────── */

.btn {
    display: block;
    width: 100%;
    max-width: 300px;
    padding: 15px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    margin-bottom: 12px;
    letter-spacing: 0.3px;
    transition: opacity 0.15s;
}

.btn:hover { opacity: 0.9; }
.btn:active { opacity: 0.75; }

.btn-gold {
    background: var(--gold);
    color: var(--blue);
}

.btn-outline {
    background: transparent;
    color: white;
    border: 2px solid rgba(255,255,255,0.45);
}

.btn-primary {
    background: var(--blue);
    color: white;
    margin-top: 16px;
    max-width: none;
}

/* ── Secondary views (bg) ───────────────────────────────────── */

#view-create,
#view-join,
#view-results {
    background: var(--bg);
}

/* ── Shared view header (create/join/results) ───────────────── */

.view-header {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: var(--blue);
    color: white;
    gap: 12px;
    flex-shrink: 0;
}

.view-header h2 {
    font-size: 1rem;
    font-weight: 700;
}

.back-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 2px 8px 2px 0;
    line-height: 1;
    flex-shrink: 0;
}

/* ── Set name view ──────────────────────────────────────────── */

.setname-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 300px;
}

.setname-form input {
    width: 100%;
    padding: 14px 16px;
    border-radius: 10px;
    border: none;
    font-size: 1.05rem;
    outline: none;
    text-align: center;
    background: white;
    color: var(--text);
}

.setname-form input:focus {
    box-shadow: 0 0 0 3px rgba(255,215,0,0.4);
}

.error-msg-light {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.75);
    min-height: 18px;
}

/* ── Landing identity bar ───────────────────────────────────── */

.identity-bar {
    margin-top: 32px;
    font-size: 0.82rem;
    color: rgba(255,255,255,0.6);
}

.change-name-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.85);
    font-size: 0.82rem;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}

/* ── Form name display ──────────────────────────────────────── */

.form-name-display {
    font-size: 0.9rem;
    color: var(--subtext);
    margin-top: 8px;
}

/* ── Form (create/join) ─────────────────────────────────────── */

.form-body {
    padding: 28px 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 420px;
    width: calc(100% - 32px);
    margin: 20px auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 2px 16px rgba(0,0,0,0.07);
}

.form-body label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--subtext);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 6px;
}

.form-body input {
    padding: 13px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    outline: none;
    background: var(--white);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-body input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(0,51,153,0.1);
}

/* Join room code — prominent code-entry field */
#join-code {
    text-align: center;
    font-size: 1.5rem;
    letter-spacing: 6px;
    font-weight: 700;
    font-family: monospace;
    text-transform: uppercase;
    border-width: 2px;
    border-color: var(--blue);
    padding: 16px;
}

#join-code::placeholder {
    letter-spacing: 2px;
    font-size: 0.95rem;
    font-weight: 400;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: #bbb;
}

.error-msg {
    font-size: 0.85rem;
    color: var(--danger);
    min-height: 18px;
    margin-top: 4px;
}

/* ── Voting header ──────────────────────────────────────────── */

.voting-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--blue);
    color: white;
    flex-shrink: 0;
}

.room-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-label {
    font-size: 0.72rem;
    opacity: 0.65;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.room-code-btn {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.3);
    color: var(--gold);
    font-weight: 700;
    font-size: 0.95rem;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    letter-spacing: 3px;
    font-family: monospace;
    transition: background 0.15s;
}

.room-code-btn:active {
    background: rgba(255,255,255,0.2);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 1rem;
    cursor: pointer;
    color: white;
    transition: background 0.15s;
}

.icon-btn:hover {
    background: rgba(255,255,255,0.2);
}

.icon-btn:active {
    background: rgba(255,255,255,0.25);
}

/* ── Tabs ───────────────────────────────────────────────────── */

.tabs {
    display: flex;
    background: var(--blue);
    border-top: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.tab {
    flex: 1;
    padding: 11px 6px;
    text-align: center;
    color: rgba(255,255,255,0.5);
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: none;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

.tab.active {
    color: var(--gold);
    border-bottom-color: var(--gold);
}

/* ── Voting sections & cards ────────────────────────────────── */

main {
    flex: 1;
    padding-bottom: 76px;
    overflow-y: auto;
    position: relative;
}

.section {
    display: none;
    padding: 12px 14px;
}

.section.active {
    display: block;
}

.country-card {
    background: var(--white);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.07);
    display: flex;
    align-items: center;
    gap: 12px;
}

.country-flag {
    width: 44px;
    height: 30px;
    object-fit: cover;
    border-radius: 3px;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.country-info {
    flex: 1;
    min-width: 0;
}

.country-name {
    font-weight: 600;
    font-size: 0.92rem;
    margin-bottom: 7px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.score-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.score-slider {
    flex: 1;
    accent-color: var(--blue);
    cursor: pointer;
}

.score-badge {
    background: var(--blue);
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.88rem;
    flex-shrink: 0;
    transition: background 0.15s;
}

.score-badge.has-score {
    background: #1a7a3c;
}

.live-score {
    font-size: 0.72rem;
    color: var(--subtext);
    margin-top: 4px;
}

/* ── Save bar ───────────────────────────────────────────────── */

.save-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    background: var(--white);
    box-shadow: 0 -2px 12px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 14px;
}

.save-btn {
    flex: 1;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 13px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s;
}

.save-btn:active { opacity: 0.75; }

.status {
    font-size: 0.85rem;
    color: var(--subtext);
    min-width: 90px;
    text-align: right;
}

/* ── Admin modal ────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    align-items: flex-end;
}

.modal-sheet {
    background: var(--white);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-height: 70vh;
    overflow-y: auto;
    padding: 20px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    color: var(--subtext);
    padding: 4px;
}

.participant-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.participant-row:last-child {
    border-bottom: none;
}

.participant-name {
    font-size: 0.95rem;
    font-weight: 500;
}

.participant-tag {
    font-size: 0.75rem;
    color: var(--subtext);
    margin-left: 6px;
    font-weight: 400;
}

.remove-btn {
    background: #fdecea;
    color: var(--danger);
    border: none;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

/* ── Results ────────────────────────────────────────────────── */

.results-content {
    flex: 1;
    overflow-x: auto;
    padding: 16px;
    padding-bottom: 40px;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 320px;
}

.results-table th {
    background: var(--blue);
    color: white;
    padding: 9px 10px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
    user-select: none;
}

.results-table th.num {
    text-align: center;
}

.results-table th.sortable {
    cursor: pointer;
}

.results-table th.sortable:hover {
    background: #002288;
}

.results-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.results-table td.num {
    text-align: center;
}

.results-table tbody tr:nth-child(1) td { background: #fffbe6; }
.results-table tbody tr:nth-child(2) td { background: #f5f5f5; }
.results-table tbody tr:nth-child(3) td { background: #fdf3e3; }

/* Qualified row overrides the rank highlighting */
.results-table tbody tr.row-qualified td {
    background: #e6f5ec;
}

.avg {
    font-weight: 700;
    color: var(--blue);
}

.country-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.country-cell img {
    width: 28px;
    height: 19px;
    object-fit: cover;
    border-radius: 2px;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.qualified-badge {
    background: #1a7a3c;
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 3px;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}

.no-results {
    text-align: center;
    color: var(--subtext);
    padding: 48px 20px;
    font-size: 0.95rem;
}

.prediction-footer {
    margin-top: 16px;
    padding: 14px 18px;
    background: white;
    border-radius: 10px;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.prediction-footer strong {
    color: #1a7a3c;
    font-size: 1.05rem;
}

/* ── Room switcher ──────────────────────────────────────────── */

.switcher-empty {
    font-size: 0.88rem;
    color: var(--subtext);
    padding: 12px 0;
}

.room-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.room-row:last-child {
    border-bottom: none;
}

.room-row-active {
    opacity: 0.6;
}

.room-row-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.room-row-code {
    font-family: monospace;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 2px;
    color: var(--blue);
}

.room-row-name {
    font-size: 0.78rem;
    color: var(--subtext);
}

.room-row-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.switch-btn {
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.current-badge {
    font-size: 0.78rem;
    color: #1a7a3c;
    font-weight: 600;
}

.forget-btn {
    background: none;
    border: none;
    color: var(--subtext);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 6px;
}

.switcher-actions {
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
    display: flex;
    flex-direction: column;
}

/* ── View mode toggle ───────────────────────────────────────── */

.view-toggle {
    display: flex;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 8px 14px;
    gap: 8px;
    flex-shrink: 0;
}

.toggle-btn {
    flex: 1;
    padding: 7px 10px;
    border-radius: 8px;
    border: 1.5px solid var(--border);
    background: transparent;
    color: var(--subtext);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.toggle-btn.active {
    background: var(--blue);
    border-color: var(--blue);
    color: white;
}

/* ── Single country view ────────────────────────────────────── */

.single-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 20px 12px;
    gap: 12px;
}

.single-progress {
    font-size: 0.78rem;
    color: var(--subtext);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.single-flag {
    width: 180px;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.single-name {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
}

.single-live {
    font-size: 0.8rem;
    color: var(--subtext);
    min-height: 18px;
}

.single-score-control {
    display: flex;
    align-items: center;
    gap: 20px;
    margin: 8px 0;
}

.score-step {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 2px solid var(--blue);
    background: transparent;
    color: var(--blue);
    font-size: 1.6rem;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    line-height: 1;
}

.score-step:hover {
    background: rgba(0,51,153,0.08);
}

.score-step:active {
    background: var(--blue);
    color: white;
}

.single-score-number {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--border);
    color: var(--subtext);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    transition: all 0.15s;
}

.single-score-number.has-score {
    background: var(--blue);
    color: white;
}

.single-nav {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 320px;
    margin-top: 8px;
}

.nav-btn {
    flex: 1;
    padding: 13px;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: var(--white);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text);
    transition: all 0.15s;
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-btn.nav-next {
    background: var(--blue);
    border-color: var(--blue);
    color: white;
}

.nav-btn.nav-next:disabled {
    opacity: 0.3;
}

/* ── Coming soon ────────────────────────────────────────────── */

.coming-soon {
    text-align: center;
    padding: 52px 24px;
    color: var(--subtext);
}

.coming-soon-icon {
    font-size: 2.4rem;
    margin-bottom: 14px;
}

.coming-soon h3 {
    font-size: 1.05rem;
    color: var(--text);
    margin-bottom: 6px;
}

.coming-soon p {
    font-size: 0.88rem;
    line-height: 1.5;
}

.all-closed {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.all-closed-inner {
    text-align: center;
    padding: 40px 24px;
}

.all-closed-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.all-closed h2 {
    font-size: 1.2rem;
    color: var(--text);
    margin-bottom: 8px;
}

.all-closed p {
    font-size: 0.9rem;
    color: var(--subtext);
    line-height: 1.5;
    max-width: 260px;
    margin: 0 auto;
}
