:root {
    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 20px;

    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', 'Kanit', system-ui, -apple-system, sans-serif;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ===== Shell ===== */
.lobby-body {
    min-height: 100vh;
    min-height: 100dvh;
    background:
        radial-gradient(circle at 100% 0%, rgba(30, 136, 229, 0.04), transparent 42%),
        radial-gradient(circle at 0% 100%, rgba(229, 57, 53, 0.04), transparent 38%),
        var(--bg);
    overscroll-behavior: none;
}

.lobby-shell {
    max-width: 440px;
    margin: 0 auto;
    padding: calc(1.25rem + env(safe-area-inset-top, 0px)) 1.25rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 100dvh;
}

/* ===== Header ===== */
.lobby-top {
    padding-top: 0.25rem;
}

.logo-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.logo-mark {
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 28px;
}

.logo-card {
    width: 14px;
    border-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.lc-red    { height: 28px; background: var(--uno-red); }
.lc-yellow { height: 22px; background: var(--uno-yellow); }
.lc-blue   { height: 18px; background: var(--uno-blue); }

.logo-title {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.logo-3d {
    font-weight: 600;
    color: var(--text-2);
}

.logo-sub {
    margin: 0.15rem 0 0;
    font-size: 0.8rem;
    color: var(--text-3);
    font-weight: 500;
}

/* ===== Main panel ===== */
.lobby-main {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-md);
}

.field {
    margin-bottom: 1rem;
}

.field:last-child {
    margin-bottom: 0;
}

.field-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-3);
    margin-bottom: 0.4rem;
}

.field-input {
    width: 100%;
    height: 48px;
    padding: 0 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--input-bg, var(--surface));
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.field-input::placeholder {
    color: var(--text-3);
}

.field-input:focus {
    outline: none;
    border-color: var(--border-strong);
    box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.06);
}

.field-inline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0;
    padding-top: 0.25rem;
}

.field-inline .field-label {
    margin-bottom: 0;
}

/* ===== Avatar ===== */
.avatar-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.avatar-opt {
    width: 38px;
    height: 38px;
    border-radius: var(--r-sm);
    border: 1.5px solid var(--border);
    background: var(--surface-2);
    font-size: 1.15rem;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.12s, background 0.15s;
}

.avatar-opt:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

.avatar-opt.is-active {
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

/* ===== Rejoin ===== */
.rejoin-banner {
    position: relative;
    margin-bottom: 1rem;
    padding: 0.85rem 2rem 0.85rem 0.9rem;
    border-radius: var(--r-md);
    border: 1px solid #bbf7d0;
    background: #f0fdf4;
}

.rejoin-banner-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.rejoin-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: #166534;
}

.rejoin-meta {
    font-size: 0.78rem;
    color: #15803d;
    margin-top: 0.1rem;
}

.rejoin-meta strong {
    letter-spacing: 0.06em;
    font-weight: 700;
}

.rejoin-dot {
    opacity: 0.45;
    margin: 0 0.2rem;
}

.rejoin-dismiss {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #86efac;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

.rejoin-dismiss:hover {
    background: rgba(22, 101, 52, 0.08);
    color: #166534;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.92rem;
    border-radius: var(--r-md);
    cursor: pointer;
    transition: background 0.15s var(--ease), border-color 0.15s, transform 0.12s, box-shadow 0.15s;
    border: none;
}

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

.action-stack {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    margin-bottom: 1rem;
}

.action-primary,
.action-secondary {
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    padding: 0.85rem 1rem;
    min-height: 58px;
}

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

.btn-primary:hover {
    background: #1f2937;
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: #ebeef2;
    border-color: var(--border-strong);
}

.btn-primary-soft {
    padding: 0.45rem 0.85rem;
    background: #166534;
    color: #fff;
    font-size: 0.82rem;
    white-space: nowrap;
}

.btn-primary-soft:hover {
    background: #14532d;
}

.btn-outline {
    height: 48px;
    padding: 0 1.1rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    white-space: nowrap;
}

.btn-outline:hover {
    background: var(--surface-2);
}

.btn-caption {
    display: block;
    font-size: 0.72rem;
    font-weight: 500;
    opacity: 0.65;
    margin-top: 0.1rem;
}

.btn-primary .btn-caption {
    opacity: 0.72;
}

/* ===== Max players ===== */
.mp-options {
    display: inline-flex;
    gap: 0.25rem;
    padding: 3px;
    background: var(--surface-2);
    border-radius: 999px;
    border: 1px solid var(--border);
}

.mp-opt {
    min-width: 36px;
    height: 30px;
    padding: 0 0.55rem;
    border: none;
    background: transparent;
    color: var(--text-2);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.82rem;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.mp-opt.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

/* ===== Divider & join ===== */
.divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0;
    color: var(--text-3);
    font-size: 0.75rem;
    font-weight: 500;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.join-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
    align-items: end;
}

.join-field {
    margin-bottom: 0;
}

.code-input {
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.35em;
    font-weight: 700;
    font-size: 1rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

.code-input::placeholder {
    letter-spacing: 0.05em;
    font-weight: 500;
    font-size: 0.85rem;
}

/* ===== Alerts & loading ===== */
.alert {
    margin-top: 0.85rem;
    padding: 0.65rem 0.85rem;
    border-radius: var(--r-sm);
    font-size: 0.85rem;
    border: 1px solid;
}

.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #b45309; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #dc2626; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }

.loading-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin-top: 0.85rem;
    color: var(--text-2);
    font-size: 0.85rem;
}

.loading-wrap.d-none { display: none !important; }

.loading-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Features ===== */
.feature-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem 0.75rem;
}

.feature-list li {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.8rem;
    color: var(--text-2);
    font-weight: 500;
}

.feature-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.fd-red    { background: var(--uno-red); }
.fd-green  { background: var(--uno-green); }
.fd-blue   { background: var(--uno-blue); }
.fd-yellow { background: var(--uno-yellow); }

/* ===== Rules ===== */
.rules-panel {
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    overflow: hidden;
}

.rules-panel summary {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-2);
    cursor: pointer;
    list-style: none;
}

.rules-panel summary::-webkit-details-marker {
    display: none;
}

.rules-list {
    margin: 0;
    padding: 0 1rem 0.85rem 1.85rem;
    color: var(--text-2);
    font-size: 0.82rem;
    line-height: 1.65;
}

.rules-list li {
    margin-bottom: 0.25rem;
}

/* ===== Footer ===== */
.lobby-footer {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-3);
    padding-top: 0.5rem;
}

.footer-dot {
    margin: 0 0.35rem;
    opacity: 0.5;
}

/* ===== Dark mode (lobby-specific) ===== */
[data-theme="dark"] .lobby-body {
    background:
        radial-gradient(circle at 100% 0%, rgba(99, 102, 241, 0.1), transparent 42%),
        radial-gradient(circle at 0% 100%, rgba(236, 72, 153, 0.08), transparent 38%),
        var(--bg);
}

[data-theme="dark"] .rejoin-banner {
    border-color: rgba(34, 197, 94, 0.35);
    background: rgba(22, 101, 52, 0.22);
}

[data-theme="dark"] .rejoin-title { color: #86efac; }
[data-theme="dark"] .rejoin-meta { color: #4ade80; }
[data-theme="dark"] .rejoin-dismiss { color: #86efac; }
[data-theme="dark"] .rejoin-dismiss:hover {
    background: rgba(34, 197, 94, 0.12);
    color: #bbf7d0;
}

[data-theme="dark"] .btn-primary:hover {
    background: #4338ca;
}

[data-theme="dark"] .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .field-input:focus {
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

[data-theme="dark"] .alert-info    { background: rgba(37, 99, 235, 0.15); border-color: rgba(96, 165, 250, 0.35); color: #93c5fd; }
[data-theme="dark"] .alert-warning { background: rgba(217, 119, 6, 0.15); border-color: rgba(251, 191, 36, 0.35); color: #fcd34d; }
[data-theme="dark"] .alert-danger  { background: rgba(220, 38, 38, 0.15); border-color: rgba(248, 113, 113, 0.35); color: #fca5a5; }
[data-theme="dark"] .alert-success { background: rgba(22, 163, 74, 0.15); border-color: rgba(74, 222, 128, 0.35); color: #86efac; }

.lobby-body:has(.lobby-top-actions .theme-toggle) .audio-cog.audio-pos-top-right {
    top: calc(1.25rem + env(safe-area-inset-top, 0px));
    right: calc(1.25rem + 40px + 0.5rem);
}

/* ===== Responsive ===== */
@media (max-width: 380px) {
    .lobby-shell { padding-inline: 1rem; }
    .panel { padding: 1rem; }
    .field-inline { flex-direction: column; align-items: stretch; }
    .mp-options { justify-content: space-between; }
    .mp-opt { flex: 1; }
    .rejoin-banner-body { flex-direction: column; align-items: stretch; }
}

@media (max-width: 480px) {
    .rejoin-banner-body {
        flex-wrap: wrap;
    }
    .btn-primary-soft {
        width: 100%;
    }
}

@media (max-height: 520px) and (orientation: landscape) {
    .lobby-shell {
        max-width: 720px;
        padding-top: 0.75rem;
        gap: 0.75rem;
    }
    .feature-list {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (prefers-reduced-motion: reduce) {
    .loading-spinner { animation: none; }
}
