:root {
    --bg: #0b1220;
    --bg-2: #121c2f;
    --panel: #17233a;
    --line: #2b3c5c;
    --text: #e8eefc;
    --muted: #9db0d0;
    --accent: #ffcc33;
    --accent-2: #38d39f;
    --danger: #ff5d6c;
    --case: #243552;
    --case-open: #0f1728;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
    --radius: 16px;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at top right, rgba(255, 204, 51, 0.12), transparent 35%),
        radial-gradient(circle at bottom left, rgba(56, 211, 159, 0.1), transparent 30%),
        linear-gradient(160deg, var(--bg), #081018 60%, #101828);
}

.app {
    width: min(1200px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 1.5rem 0 3rem;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.eyebrow {
    margin: 0;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.75rem;
    font-weight: 700;
}

h1, h2, h3 { margin: 0.2rem 0; }

.admin-link, .btn, button {
    appearance: none;
    border: 0;
    cursor: pointer;
    text-decoration: none;
}

.admin-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    border: 1px solid var(--line);
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    background: rgba(255,255,255,0.03);
    font-family: inherit;
    font-size: 0.95rem;
}

.admin-link:hover {
    color: var(--text);
    border-color: var(--accent);
}

.topbar-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

#how-to-play-btn {
    color: var(--accent);
    border-color: rgba(255, 204, 51, 0.4);
}

.howto-card {
    width: min(560px, 100%);
    text-align: left;
    max-height: 85vh;
    overflow-y: auto;
}

.howto-body ol {
    margin: 0.75rem 0;
    padding-left: 1.25rem;
    display: grid;
    gap: 0.5rem;
}

.howto-body li {
    color: var(--muted);
    line-height: 1.5;
}

.howto-body li strong {
    color: var(--text);
}

.howto-tip {
    color: var(--accent-2) !important;
    font-weight: 700;
}

.panel, .game-screen, .modal-card, .admin-card {
    background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent), var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.start-panel {
    max-width: 640px;
    margin: 1.5rem auto 3rem;
    padding: 1.25rem 1.5rem 2rem;
}

.start-banner-wrap {
    margin: -0.25rem -0.5rem 1.25rem;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(160, 100, 255, 0.35);
    background: #0a0614;
    line-height: 0;
}

.start-banner {
    display: block;
    width: 100%;
    height: auto;
    max-width: 100%;
    object-fit: contain;
}

.lede, .phase-message, label, .muted {
    color: var(--muted);
}

.start-form {
    display: grid;
    gap: 0.7rem;
    margin-top: 1.25rem;
}

input[type="text"], input[type="password"], input:not([type]) {
    width: 100%;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--bg-2);
    color: var(--text);
    font-size: 1rem;
}

.btn, .modal-actions button, .admin-actions button, .admin-actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    font-weight: 700;
    color: #111;
    background: var(--accent);
}

.btn.primary:hover, .modal-actions button:hover {
    filter: brightness(1.05);
}

.btn.secondary, .modal-actions .secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
}

.btn.danger, .modal-actions .danger {
    background: var(--danger);
    color: white;
}

.btn.success, .modal-actions .success {
    background: var(--accent-2);
    color: #062318;
}

.error {
    color: #ffb4bb;
    margin-top: 0.8rem;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(0,0,0,0.18);
}

.status-meta {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    color: var(--muted);
}

.offer-chip {
    background: rgba(255, 204, 51, 0.15);
    color: var(--accent);
    border: 1px solid rgba(255, 204, 51, 0.35);
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-weight: 700;
}

.board-layout {
    display: grid;
    grid-template-columns: 160px 1fr 160px;
    gap: 1rem;
}

.ladder {
    display: grid;
    gap: 0.35rem;
    align-content: start;
}

.ladder-item {
    padding: 0.45rem 0.55rem;
    border-radius: 8px;
    background: #102038;
    border: 1px solid #22365a;
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
}

.ladder-item.eliminated {
    opacity: 0.28;
    text-decoration: line-through;
}

.ladder-item.high {
    color: var(--accent);
}

.stage {
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(0,0,0,0.16);
}

.your-case-wrap {
    display: grid;
    justify-items: center;
    margin-bottom: 1rem;
}

.your-case-wrap p {
    margin: 0.35rem 0 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.case-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.55rem;
}

.case {
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    border: 1px solid #35507a;
    background: linear-gradient(180deg, #314d74, var(--case));
    color: var(--text);
    font-weight: 800;
    font-size: 1rem;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: transform 0.12s ease, filter 0.12s ease, opacity 0.2s ease;
    user-select: none;
}

.case:hover:not(:disabled):not(.opened):not(.selected) {
    transform: translateY(-2px);
    filter: brightness(1.08);
}

.case.selected, .case.your-case:not(.empty) {
    outline: 2px solid var(--accent);
    box-shadow: 0 0 0 3px rgba(255, 204, 51, 0.2);
}

.case.opened {
    background: var(--case-open);
    border-color: #1c2940;
    color: var(--muted);
    cursor: default;
    font-size: 0.72rem;
    line-height: 1.1;
    padding: 0.25rem;
    text-align: center;
}

.case:disabled {
    cursor: default;
}

.flash {
    margin: 1rem 0 0;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    background: rgba(56, 211, 159, 0.12);
    border: 1px solid rgba(56, 211, 159, 0.35);
    color: #b7ffe4;
    text-align: center;
    font-weight: 700;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(4, 8, 16, 0.72);
    display: grid;
    place-items: center;
    padding: 1rem;
    z-index: 50;
}

.modal[hidden], [hidden] { display: none !important; }

.modal-card {
    width: min(440px, 100%);
    padding: 1.5rem;
}

.modal-card p {
    color: var(--muted);
    line-height: 1.5;
}

.modal-amount {
    font-size: 2rem;
    font-weight: 800;
    color: var(--accent);
    margin: 0.6rem 0 1rem;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.modal-actions button {
    flex: 1 1 140px;
}

/* Admin */
.admin-wrap {
    width: min(1100px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2rem 0 3rem;
}

.admin-card {
    padding: 1.5rem;
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.8rem;
    margin: 1rem 0 1.5rem;
}

.stat {
    background: rgba(0,0,0,0.18);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 1rem;
}

.stat strong {
    display: block;
    font-size: 1.3rem;
    margin-top: 0.3rem;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.admin-actions a {
    background: var(--accent-2);
    color: #062318;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

th, td {
    text-align: left;
    padding: 0.7rem 0.55rem;
    border-bottom: 1px solid var(--line);
}

th a {
    color: var(--accent);
    text-decoration: none;
}

@media (max-width: 960px) {
    .board-layout {
        grid-template-columns: 1fr;
    }
    .ladder {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .case-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
    .admin-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .app {
        width: calc(100% - 1rem);
        padding: 0.85rem 0 2rem;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .topbar-actions {
        width: 100%;
    }

    .topbar-actions .admin-link,
    #how-to-play-btn {
        flex: 1 1 auto;
        text-align: center;
        justify-content: center;
        min-height: 44px;
    }

    .start-panel {
        margin: 0.75rem auto 2rem;
        padding: 0.85rem 0.85rem 1.35rem;
        max-width: none;
    }

    .start-banner-wrap {
        margin: 0 0 1rem;
        border-radius: 10px;
    }

    .start-form .btn.primary {
        min-height: 48px;
        width: 100%;
    }

    input[type="text"], input[type="password"], input:not([type]) {
        font-size: 16px; /* prevents iOS zoom on focus */
        min-height: 48px;
    }

    .case-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.4rem;
    }

    .case {
        font-size: 0.9rem;
        min-height: 44px;
    }

    .howto-card {
        max-height: 90vh;
        padding: 1.15rem;
    }

    .admin-grid {
        grid-template-columns: 1fr;
    }

    .status-bar {
        flex-direction: column;
        align-items: flex-start;
    }
}
