/* Family Couch Co-op Platform - Zero-Framework CSS3 */
:root {
    --bg: #0f172a;
    --bg-elev: #1e293b;
    --bg-card: #162033;
    --border: #334155;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #38bdf8;
    --accent-hover: #0ea5e9;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --plus: #a855f7;
    --radius: 14px;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
select {
    font-family: inherit;
    font-size: 1rem;
}

.hidden {
    display: none !important;
}

/* Shared Buttons & Badges */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.12s ease, background-color 0.15s ease, opacity 0.15s ease;
    text-decoration: none;
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

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

.btn-primary {
    background: var(--accent);
    color: #082f49;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    text-decoration: none;
}

.btn-secondary {
    background: #334155;
    color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
    background: #475569;
    text-decoration: none;
}

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

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.badge-free {
    background: rgba(34, 197, 94, 0.18);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.4);
}

.badge-plus {
    background: rgba(168, 85, 247, 0.2);
    color: #d8b4fe;
    border: 1px solid rgba(168, 85, 247, 0.45);
}

.badge-locked {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.45);
}

.badge-admin {
    background: rgba(56, 189, 248, 0.2);
    color: #7dd3fc;
    border: 1px solid rgba(56, 189, 248, 0.45);
}

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 0.92rem;
    margin-bottom: 14px;
}

.alert-error {
    background: rgba(239, 68, 68, 0.16);
    border: 1px solid rgba(239, 68, 68, 0.45);
    color: #fecaca;
}

.alert-success {
    background: rgba(34, 197, 94, 0.16);
    border: 1px solid rgba(34, 197, 94, 0.45);
    color: #bbf7d0;
}

/* Header / Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    padding: 16px 28px;
    background: rgba(30, 41, 59, 0.92);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.brand-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--plus));
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.user-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.9rem;
}

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 28px 20px 60px;
}

/* Auth Landing Page (index.php) */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: radial-gradient(circle at top, #1e293b 0%, #0f172a 65%);
}

.auth-card {
    width: 100%;
    max-width: 440px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
}

.auth-header {
    text-align: center;
    margin-bottom: 22px;
}

.auth-header h1 {
    margin: 0 0 6px;
    font-size: 1.7rem;
}

.auth-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    background: var(--bg);
    padding: 5px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    padding: 9px 12px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
}

.tab-btn.active {
    background: var(--accent);
    color: #082f49;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.88rem;
    font-weight: 600;
    color: #cbd5e1;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    outline: none;
}

.form-control:focus {
    border-color: var(--accent);
}

.full-width {
    width: 100%;
}

/* Lobby (lobby.php) */
.section-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 22px;
}

.section-header h1,
.section-header h2 {
    margin: 0;
}

.section-sub {
    color: var(--text-muted);
    margin: 4px 0 0;
}

.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 20px;
}

.game-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 16px;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.game-card.playable:hover {
    transform: translateY(-3px);
    border-color: var(--accent);
}

.game-card.disabled {
    opacity: 0.72;
}

.game-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.game-card h3 {
    margin: 0;
    font-size: 1.25rem;
}

.game-desc {
    color: var(--text-muted);
    font-size: 0.94rem;
    margin: 8px 0 0;
}

.game-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.85rem;
    color: #cbd5e1;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 50;
}

.modal-card {
    width: 100%;
    max-width: 460px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px;
    box-shadow: var(--shadow);
}

.modal-card h2 {
    margin: 0 0 8px;
}

.player-count-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 18px 0 22px;
}

.count-btn {
    min-width: 58px;
    height: 52px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
}

.count-btn.selected {
    border-color: var(--accent);
    background: rgba(56, 189, 248, 0.2);
    color: #7dd3fc;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Admin Panel (admin.php) */
.admin-section {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 24px;
}

.admin-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.admin-section-head h2 {
    margin: 0;
    font-size: 1.25rem;
}

.table-wrap {
    overflow-x: auto;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.94rem;
}

table.data-table th,
table.data-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

table.data-table th {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.admin-game-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
}

.admin-game-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 14px;
}

.config-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.config-field label {
    font-size: 0.82rem;
    color: #cbd5e1;
    font-weight: 600;
}

.checkbox-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    min-height: 40px;
}

/* TV Viewport (tv.php) */
body.tv-body {
    background: #070b14;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

.tv-waiting-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: radial-gradient(circle at 50% 25%, #1e293b 0%, #090e1a 75%);
    text-align: center;
    z-index: 30;
}

.tv-waiting-card {
    background: rgba(22, 32, 51, 0.94);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 32px 42px;
    max-width: 780px;
    width: 100%;
    box-shadow: var(--shadow);
}

.tv-game-title {
    margin: 0 0 6px;
    font-size: 2rem;
    font-weight: 800;
}

.tv-join-row {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 32px;
    margin: 22px 0;
}

.qr-box {
    background: #ffffff;
    padding: 14px;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
}

.room-code-box {
    text-align: left;
}

.room-code-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.room-code-value {
    font-size: 3.6rem;
    font-weight: 900;
    letter-spacing: 0.16em;
    color: var(--accent);
    line-height: 1.1;
    margin: 6px 0 12px;
}

.room-url-hint {
    font-size: 0.9rem;
    color: #cbd5e1;
    word-break: break-all;
    max-width: 320px;
}

.waiting-counter {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 12px 0 14px;
}

.slot-pills {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
}

.slot-pill {
    padding: 8px 16px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.95rem;
    border: 2px solid #334155;
    background: #0f172a;
    color: #64748b;
}

.slot-pill.connected {
    color: #fff;
    border-color: transparent;
}

.tv-stage {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #070b14;
}

#game-canvas {
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100vh;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    display: block;
}

.game-result-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    padding: 20px;
}

.game-result-card {
    background: var(--bg-elev);
    border: 2px solid var(--border);
    border-radius: 20px;
    padding: 34px 42px;
    text-align: center;
    max-width: 460px;
    width: 100%;
    box-shadow: var(--shadow);
}

.game-result-card h2 {
    margin: 0 0 10px;
    font-size: 2.2rem;
}

.game-result-card p {
    margin: 0 0 22px;
    color: #cbd5e1;
}

.game-result-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* Phone Controller Viewport (play.php) */
body.play-body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

.play-status-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.play-status-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow);
}

#controller-root {
    width: 100%;
    height: 100%;
    position: relative;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}
