/* ========================================
   INSIDER GAME - Purple/Violet Dark Theme
   ======================================== */

:root {
    --bg-primary: #0f0a1e;
    --bg-secondary: #1a1230;
    --bg-card: #241b3d;
    --bg-hover: #2d2249;
    --accent: #9b59f0;
    --accent-glow: rgba(155, 89, 240, 0.3);
    --accent-light: #c084fc;
    --accent-dark: #7c3aed;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --text-primary: #f0e6ff;
    --text-secondary: #a78bbd;
    --text-muted: #6b5587;
    --border: rgba(155, 89, 240, 0.2);
    --shadow: rgba(0, 0, 0, 0.4);
    --glass: rgba(36, 27, 61, 0.8);
    --insider-color: #f59e0b;
    --moderator-color: #3b82f6;
    --villager-color: #10b981;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Prompt', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(155, 89, 240, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(124, 58, 237, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(192, 132, 252, 0.04) 0%, transparent 50%);
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

.hidden { display: none !important; }

/* Sections */
.section {
    display: none;
    flex-direction: column;
    align-items: center;
    animation: fadeIn 0.4s ease;
}
.section.active { display: flex; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Back Link */
.back-home {
    align-self: flex-start;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 20px;
    transition: color 0.2s;
}
.back-home:hover { color: var(--accent); }

/* Logo */
.logo {
    text-align: center;
    margin-bottom: 30px;
}
.logo-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 10px;
    filter: drop-shadow(0 0 20px var(--accent-glow));
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
.logo h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.15em;
}
.tagline {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-top: 5px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 25px;
    width: 100%;
    max-width: 500px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px var(--shadow);
}

/* Input Groups */
.input-group {
    margin-bottom: 20px;
}
.input-group label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 8px;
    font-weight: 500;
}
.input-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'Prompt', sans-serif;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-family: 'Prompt', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
    box-shadow: 0 4px 15px var(--accent-glow);
}
.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(155, 89, 240, 0.5);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-accent {
    background: linear-gradient(135deg, var(--insider-color), #d97706);
    color: white;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}
.btn-accent:hover {
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.5);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { filter: brightness(1.1); }

.btn-small { padding: 8px 16px; font-size: 0.85rem; }
.btn-large { padding: 16px 32px; font-size: 1.1rem; }

.button-group {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}
.button-group .btn { flex: 1; }

/* Join Room */
.join-room { margin-top: 10px; }
.join-room .btn { width: 100%; }

/* Room List */
.room-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.room-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.2s;
}
.room-item:hover { border-color: var(--accent); }
.room-info { display: flex; flex-direction: column; gap: 4px; }
.room-name { font-weight: 600; }
.room-host { font-size: 0.8rem; color: var(--text-secondary); }
.room-meta { display: flex; align-items: center; gap: 12px; }
.no-rooms {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
}

/* Rules */
.rules-preview {
    margin-top: 30px;
    width: 100%;
    max-width: 500px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
}
.rules-preview h3 {
    text-align: center;
    margin-bottom: 15px;
    color: var(--accent-light);
}
.rules-list { display: flex; flex-direction: column; gap: 8px; }
.rule-item {
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding: 6px 0;
    border-bottom: 1px solid rgba(155, 89, 240, 0.1);
}
.rule-item:last-child { border-bottom: none; }

/* Lobby */
.room-header { text-align: center; margin-bottom: 20px; }
.room-code-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.room-code-display .label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.room-code-display .code {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-light);
    letter-spacing: 0.3em;
}
.btn-copy {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    transition: transform 0.2s;
}
.btn-copy:hover { transform: scale(1.2); }

.player-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}
.player-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    background: var(--bg-secondary);
    border-radius: 10px;
    border: 1px solid transparent;
    transition: all 0.2s;
}
.player-item.me {
    border-color: var(--accent);
    background: rgba(155, 89, 240, 0.1);
}
.player-name { font-weight: 500; }
.player-badges { display: flex; gap: 6px; align-items: center; }
.badge {
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge.you {
    background: var(--accent);
    color: white;
}
.badge.host {
    background: var(--warning);
    color: #1a1a2e;
}
.badge.moderator {
    background: var(--moderator-color);
    color: white;
}
.btn-toggle-mod {
    padding: 4px 10px;
    border: 1px solid var(--moderator-color);
    border-radius: 6px;
    background: transparent;
    color: var(--moderator-color);
    font-family: 'Prompt', sans-serif;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-toggle-mod:hover {
    background: var(--moderator-color);
    color: white;
}
.btn-toggle-mod.active {
    background: var(--moderator-color);
    color: white;
}

.timer-setting {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
    color: var(--text-secondary);
}
.timer-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-light);
}

.lobby-actions { text-align: center; }
.waiting-text { color: var(--text-secondary); font-style: italic; }
.min-players-text {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 8px;
}

/* Game Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.phase-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
}
.phase-icon { font-size: 1.5rem; }

.game-timer {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-light);
    font-variant-numeric: tabular-nums;
}
.game-timer.urgent { color: var(--danger); animation: blink 0.5s infinite; }
@keyframes blink {
    50% { opacity: 0.5; }
}

/* Player Status Bar */
.player-status-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    margin-bottom: 20px;
}
.status-chip {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 6px;
}
.status-chip.me { border-color: var(--accent); }
.status-chip.flipped { opacity: 0.6; }
.status-chip .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}
.status-chip.flipped .status-dot { background: var(--success); }
.status-chip.mod-chip { border-color: var(--moderator-color); }
.status-chip.mod-chip .status-dot { background: var(--moderator-color); }

/* Flip Card */
.flip-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}
.flip-instruction {
    text-align: center;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.flip-card {
    width: 260px;
    height: 380px;
    perspective: 1000px;
    cursor: pointer;
}
.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}
.flip-card-inner.flipped { transform: rotateY(180deg); }

.flip-card-front, .flip-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
}
.flip-card-front {
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    border: 2px solid var(--accent-light);
    box-shadow: 0 10px 40px var(--accent-glow), inset 0 0 60px rgba(255,255,255,0.05);
}
.flip-card-front .card-icon { font-size: 5rem; }
.flip-card-front .card-text {
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
}

.flip-card-back {
    background: var(--bg-card);
    border: 2px solid var(--border);
    transform: rotateY(180deg);
    padding: 30px;
    box-shadow: 0 10px 40px var(--shadow);
}

/* Countdown */
.flip-countdown {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.countdown-ring {
    width: 120px;
    height: 120px;
    position: relative;
}
.countdown-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.countdown-bg {
    fill: none;
    stroke: var(--bg-secondary);
    stroke-width: 4;
}
.countdown-progress {
    fill: none;
    stroke: var(--accent);
    stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s linear;
}
.countdown-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent-light);
}

/* Role Reveal */
.flip-role-reveal {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}
.role-icon { font-size: 4rem; }
.role-text {
    font-size: 1.3rem;
    font-weight: 600;
}
.secret-word {
    margin-top: 15px;
    padding: 15px 25px;
    background: rgba(155, 89, 240, 0.15);
    border: 1px solid var(--accent);
    border-radius: 12px;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent-light);
    text-align: center;
}

.flip-waiting {
    text-align: center;
    color: var(--text-secondary);
}
.flip-progress {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 10px;
    flex-wrap: wrap;
}

/* Question Phase */
.question-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}
.question-info { text-align: center; }
.question-role {
    font-size: 1.1rem;
    margin-bottom: 10px;
}
.secret-word-display {
    padding: 15px 25px;
    background: rgba(155, 89, 240, 0.15);
    border: 1px solid var(--accent);
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.word-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.the-word {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent-light);
}
.question-hint {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 15px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 100%;
}
.guess-panel {
    width: 100%;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
.guess-panel .input-group { flex: 1; margin-bottom: 0; }
.guess-panel .btn { white-space: nowrap; }

/* Vote Phase */
.vote-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}
.vote-header { text-align: center; }
.vote-header h2 { margin-bottom: 10px; }
.vote-hint {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 5px;
}
.vote-targets {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.vote-target-btn {
    width: 100%;
    padding: 15px 20px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: 'Prompt', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.vote-target-btn:hover {
    border-color: var(--accent);
    background: rgba(155, 89, 240, 0.1);
    transform: translateY(-2px);
}
.vote-target-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}
.vote-waiting {
    text-align: center;
    color: var(--text-secondary);
}

/* Results */
.result-content {
    width: 100%;
    text-align: center;
}
.winner-announcement {
    margin-bottom: 30px;
    padding: 30px;
    background: var(--bg-card);
    border: 2px solid var(--accent);
    border-radius: 20px;
    box-shadow: 0 0 40px var(--accent-glow);
}
.winner-icon { font-size: 4rem; margin-bottom: 10px; }
.winner-announcement h2 {
    font-size: 1.5rem;
    color: var(--accent-light);
    margin-bottom: 8px;
}
.winner-reason {
    color: var(--text-secondary);
    font-size: 0.95rem;
}
.result-secret-word {
    margin: 20px 0;
    padding: 15px;
    background: rgba(155, 89, 240, 0.1);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.result-secret-word .word-label { color: var(--text-secondary); }
.result-secret-word .the-word {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-light);
    display: block;
    margin-top: 5px;
}
.role-reveal-list {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.role-reveal-item {
    padding: 10px 15px;
    background: var(--bg-secondary);
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.role-badge {
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
}
.role-badge.insider { background: var(--insider-color); color: #1a1a2e; }
.role-badge.moderator { background: var(--moderator-color); color: white; }
.role-badge.villager { background: var(--villager-color); color: white; }

.vote-detail-list {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.vote-detail-item {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 5px 10px;
    background: var(--bg-secondary);
    border-radius: 8px;
}

/* Guess Overlay */
.guess-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(15, 10, 30, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s;
}
.guess-content {
    text-align: center;
    padding: 40px;
}
.guess-icon { font-size: 5rem; margin-bottom: 15px; }
.guess-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 10px;
}
.guess-message { color: var(--text-secondary); }

/* Chat Widget */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
}
.chat-toggle-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    position: relative;
    box-shadow: 0 4px 15px var(--accent-glow);
    transition: transform 0.2s;
}
.chat-toggle-btn:hover { transform: scale(1.1); }
.unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger);
    color: white;
    font-size: 0.7rem;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}
.chat-container {
    position: absolute;
    bottom: 65px;
    right: 0;
    width: 320px;
    height: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px var(--shadow);
    overflow: hidden;
}
.chat-header {
    padding: 12px 15px;
    background: var(--bg-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}
.chat-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.3rem;
    cursor: pointer;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.chat-msg {
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    background: var(--bg-secondary);
    max-width: 85%;
}
.chat-msg.mine {
    align-self: flex-end;
    background: rgba(155, 89, 240, 0.2);
    border: 1px solid var(--border);
}
.chat-msg.system {
    align-self: center;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: var(--warning);
    text-align: center;
}
.chat-name {
    font-weight: 600;
    margin-right: 6px;
    color: var(--accent-light);
    font-size: 0.8rem;
}
.chat-text { color: var(--text-primary); }
.chat-input-area {
    padding: 10px;
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--border);
}
.chat-input-area input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'Prompt', sans-serif;
    font-size: 0.85rem;
}
.chat-input-area input:focus {
    outline: none;
    border-color: var(--accent);
}
.chat-input-area button {
    padding: 8px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-family: 'Prompt', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.chat-input-area button:hover { background: var(--accent-dark); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

/* Loading Spinner */
.loading-spinner {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
}

/* Responsive */
@media (max-width: 480px) {
    .container { padding: 15px; }
    .logo h1 { font-size: 2rem; }
    .flip-card { width: 220px; height: 320px; }
    .chat-container { width: 280px; height: 350px; }
    .room-code-display .code { font-size: 1.5rem; }
}
