:root {
    --bg-page: #f8fafc;
    --bg-card: #ffffff;
    --border-color: #e2e8f0;
    --border-focus: #0284c7;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --primary: #0284c7;
    --primary-hover: #0369a1;
    --secondary: #64748b;

    --color-left: #f97316;
    --color-right: #0d9488;
    --color-success: #10b981;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);

    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* HEADER */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1.2rem;
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 50;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.room-badge {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background: #e0f2fe;
    color: #0369a1;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 700;
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.2rem;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
    text-decoration: none;
    min-height: 42px;
}

.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-outline {
    background-color: #ffffff;
    border: 1.5px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover {
    background-color: #f1f5f9;
    border-color: #cbd5e1;
}

.btn-success {
    background-color: var(--color-success);
    color: #ffffff;
}

.btn-success:hover {
    background-color: #059669;
}

.btn-subtle {
    background-color: #fee2e2;
    color: #b91c1c;
}

.btn-subtle:hover {
    background-color: #fca5a5;
}

.btn-large {
    padding: 0.85rem 1.8rem;
    font-size: 1.05rem;
    border-radius: var(--radius-lg);
}

.btn-full {
    width: 100%;
}

.btn-icon {
    background-color: #f1f5f9;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
}

.btn-icon:hover {
    background-color: #e2e8f0;
    color: var(--text-primary);
}

/* CARDS & MAIN CONTAINER */
.main-content {
    flex: 1;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding: 1.2rem 1rem;
}

.view-panel {
    display: none;
}

.view-panel.active {
    display: block;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.2rem;
}

/* LOBBY LANDING VIEW */
.lobby-card {
    max-width: 440px;
    margin: 2rem auto;
    text-align: center;
}

.title {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 0.4rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
    line-height: 1.4;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    text-align: left;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.field label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.field input {
    padding: 0.75rem 0.9rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.15s;
}

.field input:focus {
    border-color: var(--border-focus);
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 0.5rem;
}

/* GAME OVER CARD */
.game-over-card {
    max-width: 540px;
    margin: 1.5rem auto;
    text-align: center;
}

.final-leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 1.2rem;
}

.final-rank-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1.2rem;
    background-color: #f8fafc;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
}

.final-rank-item.rank-1 {
    border-color: #f59e0b;
    background-color: #fffbeb;
    font-weight: 800;
}

.final-rank-item.rank-2 {
    border-color: #94a3b8;
    background-color: #f8fafc;
    font-weight: 700;
}

.final-rank-item.rank-3 {
    border-color: #d97706;
    background-color: #fff7ed;
    font-weight: 700;
}

.final-rank-left {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.rank-badge {
    font-weight: 800;
    font-size: 0.9rem;
    min-width: 24px;
    color: var(--text-secondary);
}

.final-score {
    font-weight: 800;
    color: var(--primary);
    font-size: 1.1rem;
}

/* GAME VIEW GRID */
.game-grid {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 1.2rem;
}

.board-card {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    align-items: center;
}

.status-header {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
    justify-content: space-between;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.status-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.round-pill {
    background-color: #fef3c7;
    color: #b45309;
    font-weight: 800;
    font-size: 0.85rem;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-full);
}

.timer-pill {
    background-color: #fee2e2;
    color: #b91c1c;
    font-weight: 800;
    font-size: 0.85rem;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-full);
}

.status-text {
    font-weight: 700;
    font-size: 1rem;
    color: var(--primary);
}

/* ROOM SETTINGS & SHARE PANEL */
.settings-panel {
    width: 100%;
    background-color: #f8fafc;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.2rem;
}

.share-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #ffffff;
    border: 1.5px solid var(--border-color);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.2rem;
    gap: 0.5rem;
}

.share-label {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.settings-panel h3 {
    font-size: 1rem;
    font-weight: 800;
    margin-bottom: 0.8rem;
    color: var(--text-primary);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.8rem;
}

.settings-grid select {
    padding: 0.65rem 0.8rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-family: var(--font-sans);
    background-color: #ffffff;
    outline: none;
    width: 100%;
}

/* SPECTRUM CARD */
.spectrum-card {
    display: flex;
    align-items: center;
    width: 100%;
    background-color: #f8fafc;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.8rem 1rem;
    justify-content: space-between;
    gap: 0.5rem;
}

.spectrum-side {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.val-badge {
    font-size: 0.75rem;
    font-weight: 800;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    color: #ffffff;
    flex-shrink: 0;
}

.left-side .val-badge { background-color: var(--color-left); }
.right-side .val-badge { background-color: var(--color-right); }

.side-text {
    font-size: 1.1rem;
    font-weight: 800;
    word-break: break-word;
}

.left-side .side-text { color: var(--color-left); }
.right-side .side-text { color: var(--color-right); }

.spectrum-line {
    flex: 1;
    height: 4px;
    background: linear-gradient(90deg, var(--color-left), var(--color-right));
    margin: 0 0.5rem;
    border-radius: var(--radius-full);
    min-width: 20px;
}

/* CLUE & TARGET SECTION */
.clue-section {
    width: 100%;
}

.target-callout {
    background-color: #fef2f2;
    border: 2px solid #ef4444;
    color: #991b1b;
    padding: 0.8rem 1.2rem;
    border-radius: var(--radius-md);
    text-align: center;
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 0.8rem;
}

.target-callout strong {
    font-size: 1.5rem;
    color: #dc2626;
    margin: 0 0.3rem;
}

.clue-form {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.input-row {
    display: flex;
    gap: 0.6rem;
}

.input-row input {
    flex: 1;
    padding: 0.75rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    outline: none;
}

.input-row input:focus {
    border-color: var(--border-focus);
}

.clue-box {
    background-color: #f0f9ff;
    border: 1.5px dashed #0284c7;
    border-radius: var(--radius-md);
    padding: 0.9rem;
    text-align: center;
}

.clue-tag {
    font-size: 0.75rem;
    font-weight: 700;
    color: #0369a1;
    text-transform: uppercase;
}

.clue-val {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-top: 0.2rem;
    word-break: break-word;
}

/* DIAL CANVAS & HINTS */
.dial-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
}

.dial-hint {
    background-color: #f1f5f9;
    border: 1.5px solid #cbd5e1;
    color: #475569;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius-full);
    text-align: center;
}

.dial-holder {
    width: 100%;
    max-width: 650px;
}

#dial-canvas {
    width: 100%;
    height: auto;
    max-height: 380px;
    touch-action: none;
    transition: opacity 0.2s ease;
}

.controls-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
}

.guess-display {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.guess-display strong {
    font-size: 1.5rem;
    color: var(--primary);
}

/* REVEAL SUMMARY */
.reveal-box {
    width: 100%;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    text-align: center;
}

.target-info {
    margin: 0.4rem 0 0.8rem 0;
    font-size: 1rem;
}

.target-info strong {
    color: var(--color-danger);
    font-size: 1.2rem;
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.8rem;
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.player-tag {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 700;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.pts {
    font-weight: 800;
    color: var(--color-success);
}

/* SIDEBAR PLAYERS */
.players-card {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.players-header h3 {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.players-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 450px;
    overflow-y: auto;
}

.player-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.8rem;
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.player-item.is-me {
    border-color: var(--primary);
    background-color: #f0f9ff;
}

.p-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-weight: 800;
    font-size: 0.8rem;
}

.p-name {
    font-weight: 700;
    font-size: 0.9rem;
}

.p-badges {
    display: flex;
    gap: 0.2rem;
}

.badge {
    font-size: 0.65rem;
    font-weight: 800;
    padding: 0.1rem 0.35rem;
    border-radius: var(--radius-full);
}

.badge-host { background-color: #fef3c7; color: #b45309; }
.badge-cg { background-color: #fce7f3; color: #be185d; }

.p-score {
    font-weight: 800;
    color: var(--primary);
}

.host-box {
    margin-top: 0.4rem;
}

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.5);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal {
    background-color: #ffffff;
    border-radius: var(--radius-lg);
    max-width: 500px;
    width: 100%;
    padding: 1.2rem;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.modal-head h2 {
    font-size: 1.2rem;
    font-weight: 800;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--text-muted);
}

.rules-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    padding-left: 1.2rem;
    font-size: 0.9rem;
    line-height: 1.4;
}

.modal-foot {
    margin-top: 1.2rem;
    text-align: right;
}

/* TOASTS */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 200;
}

.toast {
    background-color: #0f172a;
    color: #ffffff;
    padding: 0.7rem 1.1rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
}

.toast-error {
    background-color: var(--color-danger);
}

.hidden {
    display: none !important;
}

/* MEDIA QUERIES FOR MOBILE & TABLETS */
@media (max-width: 820px) {
    .game-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .app-header {
        padding: 0.6rem 0.8rem;
    }

    .logo-title {
        font-size: 1.1rem;
    }

    .room-badge {
        font-size: 0.75rem;
        padding: 0.2rem 0.5rem;
    }

    .btn-icon {
        padding: 0.3rem 0.5rem;
        font-size: 0.8rem;
    }

    .main-content {
        padding: 0.8rem 0.5rem;
    }

    .card {
        padding: 0.9rem;
    }

    .side-text {
        font-size: 0.95rem;
    }

    .spectrum-card {
        padding: 0.6rem 0.7rem;
    }

    .status-text {
        font-size: 0.9rem;
    }

    .share-box {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .controls-box .btn-large {
        width: 100%;
    }
}

@media (max-width: 440px) {
    .input-row {
        flex-direction: column;
    }

    .input-row button {
        width: 100%;
    }
}
