:root {
    --bg: #0a051c;
    --surface: #160f30;
    --surface-2: #120b28;
    --text: #f2f3f5;
    --muted: #9d94c2;
    --primary: #7c3ce0;
    --primary-hover: #6b2fc7;
    --danger: #e74c3c;
    --border: #2a2050;
    --radius: 12px;

    --tier-s: #fd3e5a;
    --tier-a: #fe7a25;
    --tier-b: #fdc92e;
    --tier-c: #5acb56;
    --tier-d: #2c7bf4;
    --tier-e: #7e3cdd;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.4;
}

.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.brand-logo {
    display: block;
    max-width: 260px;
    width: 100%;
    margin: 1rem auto 0;
}

.room-logo {
    display: block;
    width: 40px;
    height: 40px;
    margin-bottom: 0.5rem;
}

.tagline {
    text-align: center;
    color: var(--muted);
    margin-top: 0;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.card h1 {
    margin-top: 0;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.checkbox-label {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    flex: 0 0 auto;
}

input, button {
    font-size: 1rem;
    padding: 0.65rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
}

button {
    cursor: pointer;
    border: 1px solid var(--border);
    background: #241a48;
}

button.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    font-weight: 600;
}

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

button:hover {
    filter: brightness(1.1);
}

details summary {
    cursor: pointer;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.room-share {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
}

.cast-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.cast-separator {
    color: var(--muted);
    font-style: italic;
}

.cast-controls google-cast-launcher {
    width: 28px;
    height: 28px;
    --disconnected-color: var(--text);
    --connected-color: var(--primary);
}

.cast-tv-hint {
    font-size: 1.3rem;
    color: var(--muted);
    text-align: center;
    padding: 1.5rem 0;
}

.room-code {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.15em;
}

.qr-code {
    width: 160px;
    height: 160px;
    border-radius: 8px;
    background: white;
    padding: 8px;
}

.player-list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.player-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
}

.badge {
    font-size: 0.75rem;
    background: var(--primary);
    color: white;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
}

.kick-btn {
    color: var(--danger);
    border-color: var(--danger);
    background: transparent;
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
}

.breakdown-list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.breakdown-list li {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.25rem 0.75rem;
    font-size: 0.85rem;
}

.breakdown-list .count {
    font-weight: 700;
    color: var(--primary);
}

.proposal-list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.proposal-list li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
}

.proposal-list img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
}

.proposal-list span {
    flex: 1;
}

.delete-proposal-btn {
    color: var(--danger);
    border-color: var(--danger);
    background: transparent;
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
}

.proposal-preview {
    width: 100%;
    max-height: 220px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.hint {
    color: #6ce7a0;
    font-size: 0.9rem;
}

#close-proposals-btn {
    margin-top: 0.75rem;
    color: var(--danger);
    border-color: var(--danger);
    background: transparent;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 100;
}

.modal[hidden] {
    display: none;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 360px;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.tier-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem;
}

.tier-grid[hidden] {
    display: none;
}

.tier-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.tier-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.tier-label {
    flex: 0 0 2.5rem;
    font-weight: 700;
    font-size: 1.1rem;
    text-align: center;
    padding: 0.4rem 0;
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
}

.tier-row[data-tier-index="0"] .tier-label { background: var(--tier-s); color: #2b0410; }
.tier-row[data-tier-index="1"] .tier-label { background: var(--tier-a); color: #3a1a00; }
.tier-row[data-tier-index="2"] .tier-label { background: var(--tier-b); color: #3a2c00; }
.tier-row[data-tier-index="3"] .tier-label { background: var(--tier-c); color: #0a2b0a; }
.tier-row[data-tier-index="4"] .tier-label { background: var(--tier-d); color: #ffffff; }
.tier-row[data-tier-index="5"] .tier-label { background: var(--tier-e); color: #ffffff; }

.tier-items {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 3rem;
}

.tier-item {
    margin: 0;
    width: 64px;
}

.tier-item img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

.tier-item figcaption {
    font-size: 0.65rem;
    text-align: center;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tier-item.just-revealed img {
    box-shadow: 0 0 0 3px var(--primary), 0 0 18px 5px rgba(124, 60, 224, 0.7);
    animation: pulse-highlight 1.4s ease-in-out 2;
}

@keyframes pulse-highlight {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.12);
    }
}

#toggle-tier-grid-btn {
    margin-bottom: 0.75rem;
}

#force-resolve-btn {
    margin-top: 1rem;
    color: var(--danger);
    border-color: var(--danger);
    background: transparent;
}

#advance-btn {
    margin-top: 0.5rem;
}

#joker-used-msg {
    background: var(--surface-2);
    border: 1px solid var(--primary);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}

.vote-panel {
    text-align: center;
}

.vote-panel .proposal-preview {
    max-height: 260px;
    width: auto;
    max-width: 100%;
}

.proposal-title {
    font-size: 1.2rem;
    font-weight: 700;
}

.tier-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 1rem;
}

.tier-vote-btn {
    font-weight: 700;
    font-size: 1.1rem;
    padding: 0.9rem 0.5rem;
    border: none;
}

.tier-vote-btn[data-tier-index="0"] { background: var(--tier-s); color: #2b0410; }
.tier-vote-btn[data-tier-index="1"] { background: var(--tier-a); color: #3a1a00; }
.tier-vote-btn[data-tier-index="2"] { background: var(--tier-b); color: #3a2c00; }
.tier-vote-btn[data-tier-index="3"] { background: var(--tier-c); color: #0a2b0a; }
.tier-vote-btn[data-tier-index="4"] { background: var(--tier-d); color: #ffffff; }
.tier-vote-btn[data-tier-index="5"] { background: var(--tier-e); color: #ffffff; }

@media (min-width: 640px) {
    .container {
        padding: 2rem 1rem;
    }

    .room-share {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .room-share > div {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        flex: 1;
    }
}

.cast-main {
    max-width: 100%;
    padding: 1.5rem 3rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.cast-main h1 {
    font-size: 3rem;
    margin: 0 0 0.25rem;
    flex-shrink: 0;
}

.cast-main #cast-subtitle {
    color: var(--muted);
    font-size: 1.5rem;
    margin: 0 0 0.5rem;
    flex-shrink: 0;
}

.cast-main .vote-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.cast-main .vote-panel[hidden] {
    display: none;
}

.cast-main .vote-panel .proposal-preview {
    max-height: 65vh;
    max-width: 70vw;
    object-fit: contain;
}

.cast-main .proposal-title {
    font-size: 2.2rem;
}

.cast-main .tier-grid {
    flex: 1;
    min-height: 0;
    gap: 0.25rem;
    padding: 0.5rem;
    margin-bottom: 0;
}

.cast-main .tier-row {
    flex: 1;
    min-height: 0;
    align-items: stretch;
    padding-bottom: 0.25rem;
    overflow: hidden;
}

.cast-main .tier-label {
    flex: 0 0 5rem;
    font-size: 1.6rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cast-main .tier-items {
    min-height: 0;
    align-items: stretch;
    flex-wrap: nowrap;
    overflow: hidden;
}

.cast-main .tier-item {
    width: auto;
    height: 100%;
    flex-shrink: 0;
    overflow: hidden;
}

.cast-main .tier-item img {
    width: auto;
    height: 100%;
    max-height: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.cast-main .tier-item figcaption {
    display: none;
}

.cast-main .proposals-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    overflow: hidden;
}

.cast-main .proposals-panel[hidden] {
    display: none;
}

.cast-main .proposal-card {
    text-align: center;
}

.cast-main .proposal-card img {
    width: 16vh;
    height: 16vh;
    object-fit: cover;
    border-radius: 10px;
    border: 2px solid var(--border);
}

.cast-main .proposal-card p {
    margin: 0.4rem 0 0;
    font-size: 1rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
