:root {
    --app-max-width: 560px;
    --good: #3b82f6;
    --good-bg: #dbeafe;
    --evil: #ef4444;
    --evil-bg: #fee2e2;
    --bg: #000000;
    --surface: #0d0d0d;
    --surface2: #1a1a1a;
    --text: #f1f5f9;
    --text-dim: #a3a3a3;
    --border: #2a2a2a;
    --success: #22c55e;
    --danger: #ef4444;
    --warn: #f59e0b;
}

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

html {
    font-size: 20px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 300;
    font-size: 1rem;
    line-height: 1.5;
    letter-spacing: 0.012em;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

#app {
    width: 100%;
    max-width: var(--app-max-width);
    padding: 0 20px 164px;
    position: relative;
}

/* Connection bar */
#connection-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 100;
    transition: background 0.3s;
}
#connection-bar.connected { background: var(--success); }
#connection-bar.disconnected { background: var(--danger); }
#connection-bar .reconnecting { background: var(--warn); }
#connection-text { display: none; }

/* Screens */
.screen { padding-top: 52px; }
.hidden { display: none !important; }

/* Fixed footer actions */
.screen-footer {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    width: min(100%, var(--app-max-width));
    padding: 18px 20px calc(18px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(
        180deg,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0.85) 20%,
        rgba(0, 0, 0, 0.95) 50%,
        rgba(0, 0, 0, 1) 100%
    );
    z-index: 90;
}
.screen-footer .action-area {
    width: 100%;
    align-items: stretch;
}
.screen-footer .btn {
    width: 100%;
    min-height: 56px;
    font-size: 1.08rem;
    border-radius: 8px;
}
#lobby-footer .btn + .btn {
    margin-top: 8px;
}
.screen-footer .vote-buttons,
.screen-footer .quest-buttons {
    width: 100%;
}
.screen-footer .btn-success-card,
.screen-footer .btn-fail-card {
    padding: 16px;
    font-size: 1.05rem;
}

/* Home Screen */
#screen-home { text-align: center; padding-top: 80px; }
#screen-home h1 {
    font-size: 3rem;
    letter-spacing: 0.1em;
    margin-bottom: 8px;
}
.subtitle {
    color: var(--text-dim);
    margin-bottom: 40px;
}
.home-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 300px;
    margin: 0 auto;
}
.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-dim);
    margin: 8px 0;
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Inputs */
input[type="text"] {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    color: var(--text);
    font-size: 1rem;
    outline: none;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
}
input[type="text"]:focus {
    border-color: var(--good);
}
input[type="text"]::placeholder {
    color: var(--text-dim);
}
#room-code-input {
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 0.2em;
    font-size: 1.3rem;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
@media (hover: none) {
    .btn:active:not(:disabled) {
        transform: scale(0.96);
        opacity: 0.85;
    }
}
.btn-primary {
    background: var(--good);
    color: white;
}
.btn-secondary {
    background: var(--surface2);
    color: var(--text);
}
.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-leave-room {
    position: fixed;
    top: 10px;
    right: max(12px, env(safe-area-inset-right, 12px));
    z-index: 120;
    padding: 10px 14px;
    font-size: 0.85rem;
    min-height: 40px;
    min-width: 40px;
}
.btn-change-name {
    position: fixed;
    top: 10px;
    left: max(12px, env(safe-area-inset-left, 12px));
    z-index: 120;
    padding: 10px 14px;
    font-size: 0.85rem;
    min-height: 40px;
    min-width: 40px;
}
.change-name-inline {
    position: fixed;
    top: 10px;
    left: max(12px, env(safe-area-inset-left, 12px));
    right: max(110px, calc(env(safe-area-inset-right, 0px) + 110px));
    z-index: 120;
    display: flex;
    gap: 6px;
    align-items: center;
}
.change-name-inline.hidden { display: none !important; }
.change-name-inline input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font-size: 1rem;
}
.btn-sm {
    padding: 8px 12px;
    font-size: 0.85rem;
}
.btn-approve {
    background: var(--success);
    color: white;
    flex: 1;
}
.btn-reject {
    background: var(--danger);
    color: white;
    flex: 1;
}
.vote-choice-dimmed {
    background: #888 !important;
    opacity: 0.5;
}
.btn-success-card {
    background: var(--success);
    color: white;
    flex: 1;
    padding: 20px;
    font-size: 1.1rem;
    transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.btn-fail-card {
    background: var(--danger);
    color: white;
    flex: 1;
    padding: 20px;
    font-size: 1.1rem;
    transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
}

/* Room header */
.room-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.room-code-display, .room-code-small {
    color: var(--text-dim);
    font-size: 1rem;
}
.room-code {
    font-weight: 700;
    color: var(--warn);
    letter-spacing: 0.15em;
    font-size: 1.1em;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.15s;
}
.room-code:active {
    background: rgba(245, 158, 11, 0.15);
}
.room-code-small {
    text-align: right;
    margin-bottom: 8px;
}

/* Player list */
.lobby-team-split {
    text-align: center;
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    margin-bottom: 12px;
}
.lobby-good-count {
    color: var(--success);
}
.lobby-evil-count {
    color: var(--evil);
}
.lobby-vs {
    color: var(--text-dim);
}
.player-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}
.player-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--surface);
    border-radius: 6px;
    border: 1px solid var(--border);
    min-height: 48px;
}
.player-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.player-dot.connected { background: var(--success); }
.player-dot.disconnected { background: var(--danger); }
.player-name {
    flex: 1;
    font-weight: 400;
}
.player-badge {
    font-size: 0.82rem;
    padding: 3px 9px;
    border-radius: 3px;
    font-weight: 600;
}
.badge-host { background: var(--warn); color: #000; }
.badge-you { background: var(--good); color: white; }
.badge-ai { background: #6b7280; color: white; }
.badge-leader { background: #a855f7; color: white; }

.btn-kick {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: auto;
    transition: background 0.15s, color 0.15s;
}
.btn-kick:hover,
.btn-kick:active {
    background: var(--danger);
    color: white;
}

/* Spectator list */
.spectator-list {
    margin-bottom: 16px;
}
.spectator-list h4 {
    color: var(--text-dim);
    font-size: 0.95rem;
    margin-bottom: 6px;
}

/* Role config */
.role-toggles {
    width: 100%;
    margin-bottom: 12px;
}
.role-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.role-cell {
    min-height: 84px;
    padding: 14px 12px;
    border-radius: 8px;
    border: 2px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 1.02rem;
    font-weight: 600;
    text-align: center;
    transition: all 0.15s;
    touch-action: manipulation;
}
.role-cell-good {
    background: rgba(16, 185, 129, 0.05);
}
.role-cell-evil {
    background: rgba(239, 68, 68, 0.05);
}
.role-cell.active-good {
    border-color: var(--good);
    background: var(--good);
    color: white;
}
.role-cell.active-evil {
    border-color: var(--evil);
    background: var(--evil);
    color: white;
}
.role-cell.inactive:hover:not(:disabled),
.role-cell.inactive:active:not(:disabled) {
    transform: translateY(-1px);
    border-color: #6b7280;
}
.role-cell:active:not(:disabled) {
    transform: scale(0.97);
}
.role-cell:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
@media (max-width: 560px) {
    .role-grid {
        grid-template-columns: 1fr;
    }
}
.role-summary {
    color: var(--text-dim);
    font-size: 0.95rem;
    margin-bottom: 8px;
}
.waiting-text { color: var(--text-dim); text-align: center; margin-top: 12px; }

/* Role card */
.role-card {
    text-align: center;
    padding: 40px 24px;
    border-radius: 10px;
    margin: 24px 0;
    border: 3px solid;
}
.role-card.good {
    background: linear-gradient(135deg, #1c1c1c, #111111);
    border-color: var(--good);
}
.role-card.evil {
    background: linear-gradient(135deg, #5f1e1e, #111111);
    border-color: var(--evil);
}
.role-name {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
}
.role-team {
    font-size: 1.1rem;
    font-weight: 500;
}
.known-info {
    margin-bottom: 24px;
}
.known-info h3 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: var(--text-dim);
}
.known-player {
    padding: 8px 14px;
    background: var(--surface);
    border-radius: 6px;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.known-tag {
    font-size: 0.82rem;
    padding: 3px 9px;
    border-radius: 3px;
    font-weight: 600;
}
.tag-evil { background: var(--evil); color: white; }
.tag-unknown { background: #a855f7; color: white; }

/* Quest board */
.quest-board {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}
.quest-circle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    border: 3px solid var(--border);
    background: var(--surface);
    position: relative;
}
.quest-size {
    display: inline-flex;
    align-items: flex-start;
    line-height: 1;
}
.quest-circle.current {
    border-color: var(--warn);
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
}
.quest-circle.passed {
    background: var(--success);
    border-color: var(--success);
    color: white;
}
.quest-circle.failed {
    background: var(--evil);
    border-color: var(--evil);
    color: white;
}
.quest-fails-plus {
    font-size: 0.6em;
    margin-left: 2px;
    transform: translateY(-0.28em);
    color: currentColor;
}

/* Vote track */
.vote-track {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 16px;
}
.vote-track-label {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-right: 8px;
    align-self: center;
}
.vote-marker {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 2px solid var(--border);
    background: var(--surface);
}
.vote-marker.filled {
    background: var(--danger);
    border-color: var(--danger);
}

/* Phase banner */
.phase-banner {
    text-align: center;
    padding: 10px;
    margin-bottom: 12px;
    border-radius: 6px;
    background: var(--surface);
    font-weight: 600;
}

.banner-leader-name {
    display: block;
    font-size: 1.4em;
    font-weight: 700;
}

/* Your role badge */
.your-role-badge {
    text-align: center;
    font-size: 0.9rem;
    margin-bottom: 12px;
    padding: 8px 12px;
    border-radius: 6px;
    display: block;
}
.your-role-badge.good { background: rgba(255,255,255,0.12); color: var(--good); }
.your-role-badge.evil { background: rgba(239,68,68,0.2); color: var(--evil); }

/* Game player list */
.game-player-list {
    margin-bottom: 16px;
    overflow-x: auto;
}
.game-player-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 6px;
    min-width: 280px;
}
.game-player-table th {
    text-align: left;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-dim);
    padding: 0 12px 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.game-player-table th:last-child {
    text-align: right;
}
.game-player-row td {
    background: var(--surface);
    border-top: 2px solid var(--border);
    border-bottom: 2px solid var(--border);
    padding: 12px 12px;
    transition: border-color 0.15s, background 0.15s;
}
.game-player-row td:first-child {
    border-left: 2px solid var(--border);
    border-radius: 6px 0 0 6px;
    font-weight: 600;
    font-size: 0.9rem;
}
.game-player-row td:last-child {
    border-right: 2px solid var(--border);
    border-radius: 0 6px 6px 0;
    text-align: right;
}
.game-player-row.selectable {
    cursor: pointer;
    touch-action: manipulation;
}
.game-player-row.selectable:hover td,
.game-player-row.selectable:active td {
    border-color: var(--good);
    background: rgba(59, 130, 246, 0.08);
}
.game-player-row.on-team td {
    border-color: var(--warn);
    background: rgba(245, 158, 11, 0.15);
}
.game-player-row.disconnected-player {
    opacity: 0.5;
}
.player-you {
    color: var(--good);
    font-size: 0.9rem;
}
.player-status-cell {
    white-space: nowrap;
}
.player-status-chip {
    display: inline-block;
    font-size: 0.78rem;
    padding: 4px 10px;
    border-radius: 10px;
    font-weight: 600;
    margin-left: 4px;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-dim);
}
.player-status-chip:first-child {
    margin-left: 0;
}
.player-status-chip.voted {
    background: rgba(34, 197, 94, 0.18);
    color: var(--success);
}
.player-status-chip.leader {
    background: rgba(59, 130, 246, 0.18);
    color: var(--good);
}
.player-status-chip.hammer {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}
.player-status-chip.disconnected {
    background: rgba(239, 68, 68, 0.18);
    color: var(--evil);
}
.player-status-empty {
    color: var(--text-dim);
}
.inline-quest-result {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    text-align: center;
}
.inline-quest-result-dismiss {
    margin-top: 12px;
}
.known-marker {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-left: 4px;
}
.known-marker.evil-known { background: var(--evil); }
.known-marker.merlin-morgana-known { background: #a855f7; }
.known-marker.evil-teammate-known { background: var(--evil); }

/* Action area */
.action-area {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    min-height: 30px;
}
.vote-buttons {
    display: flex;
    gap: 12px;
    width: 100%;
}
.quest-buttons {
    display: flex;
    gap: 12px;
    width: 100%;
}
.quest-choice-selected {
    transform: scale(1.05);
    box-shadow: 0 0 12px rgba(255,255,255,0.4);
    opacity: 1;
}
.quest-choice-dimmed {
    opacity: 0.3;
    transform: scale(0.95);
}

/* Assassination */
#screen-assassinate h2 {
    text-align: center;
}
.assassination-targets {
    width: 100%;
    margin-bottom: 16px;
}
.assassination-target-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.assassination-target-table th {
    text-align: center;
    padding: 10px 12px;
    color: var(--text-dim);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}
.assassination-target-table td {
    padding: 0;
}
.assassination-target-table tbody tr + tr td {
    border-top: 1px solid var(--border);
}
.assassination-target {
    width: 100%;
    padding: 16px 12px;
    background: transparent;
    border: none;
    text-align: center;
    color: var(--text);
    font: inherit;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.15s;
    min-height: 48px;
}
.assassination-target:hover,
.assassination-target:active {
    background: rgba(239, 68, 68, 0.1);
}
.assassination-target.selected {
    background: rgba(239, 68, 68, 0.2);
}

/* Game Over */
#screen-gameover { text-align: center; }
#gameover-title {
    font-size: 2rem;
    margin-bottom: 8px;
}
#gameover-title.good-win { color: var(--good); }
#gameover-title.evil-win { color: var(--evil); }
#gameover-reason {
    color: var(--text-dim);
    margin-bottom: 24px;
}
.gameover-roles {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 24px;
}
.gameover-role-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--surface);
    border-radius: 6px;
    border-left: 4px solid;
}
.gameover-role-item.good-role { border-left-color: var(--good); }
.gameover-role-item.evil-role { border-left-color: var(--evil); }
.gameover-role-name { font-weight: 500; }
.gameover-role-role { font-weight: 600; }
.gameover-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.gameover-actions .btn {
    min-width: 140px;
}

/* Spectator banner */
.spectator-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface2);
    color: var(--text-dim);
    text-align: center;
    padding: 10px;
    font-size: 0.95rem;
    z-index: 50;
}


/* Vote result list */
.vote-result-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 8px;
    font-weight: 500;
}
.vote-result-table th {
    font-weight: 600;
    font-size: 0.85rem;
    padding: 6px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    text-align: center;
    color: var(--text);
}
.vote-result-table td {
    padding: 4px 12px;
    text-align: center;
}
.vote-result-table td.vote-col-approve { color: var(--success); text-align: center; }
.vote-result-table td.vote-col-reject { color: var(--danger); text-align: center; }
.vote-result-verdict {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 12px;
}
.vote-result-verdict.approved { color: var(--success); }
.vote-result-verdict.rejected { color: var(--danger); }

/* Inline vote result (replaces modal) */
.inline-vote-result {
    background: var(--surface);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    text-align: center;
}
.inline-vote-result .vote-result-table {
    margin: 0 auto;
}
.inline-vote-result-dismiss {
    margin-top: 12px;
}

/* Quest result display */
.quest-result-cards {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin: 0;
}
.quest-result-card {
    padding: 12px 20px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 1.2rem;
}
.qrc-success { background: var(--success); color: white; }
.qrc-fail { background: var(--evil); color: white; }

/* Quest card reveal */
.quest-reveal {
    text-align: center;
    padding: 1rem 0;
}
.quest-reveal-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1.2rem;
    color: var(--text);
}
.quest-reveal-cards {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}
.reveal-card {
    width: 80px;
    height: 110px;
    perspective: 600px;
}
.reveal-card .card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s ease;
    transform-style: preserve-3d;
}
.reveal-card.revealed .card-inner {
    transform: rotateY(180deg);
}
.reveal-card .card-face {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.9rem;
}
.reveal-card .card-back {
    background: #334155;
    color: #94a3b8;
    border: 2px solid #475569;
    font-size: 1.5rem;
}
.reveal-card .card-front {
    transform: rotateY(180deg);
}
.reveal-card.card-success .card-front {
    background: #166534;
    color: #4ade80;
    border: 2px solid #22c55e;
}
.reveal-card.card-fail .card-front {
    background: #7f1d1d;
    color: #f87171;
    border: 2px solid #ef4444;
}
.waiting-text {
    color: #94a3b8;
    font-style: italic;
    margin-top: 0.5rem;
}

/* Responsive - general mobile */
@media (max-width: 480px) {
    html { font-size: 18px; }
    #screen-home h1 { font-size: 2.6rem; }
    .room-header h2 { font-size: 1.1rem; }
    .phase-banner { font-size: 0.95rem; padding: 8px; }
    .btn-change-name,
    .btn-leave-room {
        padding: 8px 10px;
        font-size: 0.8rem;
    }
    .change-name-inline input {
        font-size: 0.9rem;
    }
    .game-player-row td:first-child {
        font-size: 0.85rem;
    }
    .player-status-chip {
        font-size: 0.74rem;
        padding: 3px 8px;
    }
}

/* Responsive - very small screens */
@media (max-width: 360px) {
    html { font-size: 16px; }
    .quest-circle { width: 44px; height: 44px; font-size: 0.95rem; }
    .quest-board { gap: 8px; }
    .game-player-table th {
        font-size: 0.74rem;
        padding: 0 10px 3px;
    }
    .game-player-row td {
        padding: 10px 10px;
    }
    .player-status-chip {
        font-size: 0.72rem;
        padding: 3px 7px;
    }
    .screen-footer .btn {
        min-height: 52px;
        font-size: 1rem;
    }
    .role-card { padding: 28px 16px; }
    .role-name { font-size: 1.6rem; }
    .btn-change-name,
    .btn-leave-room {
        padding: 6px 8px;
        font-size: 0.75rem;
    }
    #app { padding: 0 14px 164px; }
}
