/* ============================================
   Werewolf Game - Mobile-First CSS
   Dark theme for atmosphere
   ============================================ */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --bg-input: #1a1a3e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #606078;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --accent-secondary: #533483;
    --success: #2ecc71;
    --warning: #f39c12;
    --danger: #e74c3c;
    --border: rgba(255, 255, 255, 0.08);
    --shadow: rgba(0, 0, 0, 0.3);

    --wolf-color: #e74c3c;
    --villager-color: #2ecc71;
    --god-color: #9b59b6;
    --special-color: #3498db;

    --night-bg: #0a0a2e;
    --day-bg: #1a2a3e;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    font-size: 14px;
    line-height: 1.5;
}

/* ---- Screens ---- */
.screen {
    display: none;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px;
    padding-bottom: 80px;
}
.screen.active {
    display: flex;
    flex-direction: column;
}

/* ---- Home ---- */
.home-header {
    text-align: center;
    padding: 40px 0 20px;
}
.home-header h1 {
    font-size: 2em;
    margin-bottom: 4px;
}
.home-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.9em;
}

.form-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}
.form-card h2, .form-card h3 {
    margin-bottom: 16px;
    font-size: 1.1em;
}

input[type="text"], input[type="tel"] {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 16px; /* Prevents zoom on iOS */
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.2s;
}
input:focus {
    border-color: var(--accent);
}

button {
    cursor: pointer;
    font-size: 15px;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    transition: all 0.2s;
    font-weight: 600;
}
button:active {
    transform: scale(0.97);
}

.btn.primary {
    background: var(--accent);
    color: white;
    width: 100%;
}
.btn.primary:hover { background: var(--accent-hover); }

.btn.secondary {
    background: var(--accent-secondary);
    color: white;
    width: 100%;
}

.btn-full { width: 100%; }

.btn-large {
    padding: 16px 24px;
    font-size: 1.1em;
}

.btn-icon {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
    font-size: 1.2em;
}
.btn-icon:hover { color: var(--text-primary); }

.divider {
    text-align: center;
    margin: 20px 0;
    color: var(--text-muted);
    font-size: 0.85em;
    position: relative;
}
.divider::before, .divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--border);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

/* ---- Result display (QR code etc) ---- */
.result {
    text-align: center;
    padding: 16px;
    background: var(--bg-card);
    border-radius: 12px;
    margin-top: 12px;
}
.result.hidden { display: none; }
.result h3 {
    font-size: 2em;
    letter-spacing: 8px;
    color: var(--accent);
    margin: 8px 0;
}
#qr-code {
    width: 200px;
    height: 200px;
    margin: 12px auto;
    border-radius: 8px;
}

/* ---- Lobby ---- */
.lobby-header {
    text-align: center;
    padding: 12px 0;
}
.room-code-badge {
    display: inline-block;
    background: var(--bg-card);
    padding: 4px 16px;
    border-radius: 20px;
    font-size: 1.2em;
    font-weight: bold;
    letter-spacing: 4px;
    margin: 8px 0;
    color: var(--accent);
}
.player-count {
    color: var(--text-secondary);
    font-size: 0.85em;
}

.player-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 16px 0;
}
@media (min-width: 400px) {
    .player-grid { grid-template-columns: repeat(4, 1fr); }
}

.status-text {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9em;
    padding: 8px;
}

.lobby-config {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
}
.lobby-config h3 {
    font-size: 0.95em;
    margin-bottom: 10px;
    color: var(--text-secondary);
}
.char-config-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.9em;
    color: var(--text-secondary);
}
.char-config-item span:last-child {
    font-weight: bold;
    color: var(--text-primary);
}

/* ---- Game Screen ---- */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0 12px;
    gap: 8px;
}
.phase-indicator {
    text-align: center;
    flex: 1;
}
.badge {
    display: inline-block;
    padding: 2px 12px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
}
.badge.night { background: var(--accent-secondary); }
.badge.day { background: var(--warning); color: #000; }
#phase-number {
    display: block;
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-top: 2px;
}

.timer-display {
    font-size: 1.5em;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
    min-width: 50px;
    text-align: center;
}
.timer-display.warning { color: var(--warning); }
.timer-display.danger { color: var(--danger); animation: pulse 1s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.players-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 6px;
    margin: 8px 0;
}

/* ---- Player Card ---- */
.player-card {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 8px 4px;
    text-align: center;
    border: 2px solid transparent;
    transition: all 0.2s;
    cursor: pointer;
    position: relative;
}
.player-card.dead { opacity: 0.4; filter: grayscale(1); }
.player-card.selected { border-color: var(--accent); }
.player-card.self { border-color: var(--accent-secondary); }
.player-card:not(.dead):hover { transform: scale(1.03); }
.player-card:not(.dead):active { transform: scale(0.95); }

.player-avatar {
    font-size: 1.8em;
    margin-bottom: 2px;
}
.player-name {
    font-size: 0.75em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.player-status {
    font-size: 0.65em;
    color: var(--text-muted);
    margin-top: 2px;
}
.player-role-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: 0.7em;
}

/* ---- Action Panel ---- */
.action-panel {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    margin: 12px 0;
    border: 1px solid var(--border);
}
.action-panel.hidden { display: none; }
.action-panel h3 { margin-bottom: 6px; }
.action-panel p { font-size: 0.85em; color: var(--text-secondary); margin-bottom: 10px; }

.action-targets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ---- Vote Panel ---- */
.vote-panel {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    margin: 12px 0;
    border: 1px solid var(--border);
}
.vote-panel.hidden { display: none; }
.vote-targets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* ---- Chat ---- */
.chat-section {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding-top: 8px;
}
.chat-messages {
    max-height: 120px;
    overflow-y: auto;
    margin-bottom: 8px;
    padding: 4px 0;
}
.chat-msg {
    font-size: 0.8em;
    padding: 2px 0;
}
.chat-msg.system { color: var(--text-muted); font-style: italic; }
.chat-msg.announcement { color: var(--warning); font-weight: 600; }
.chat-msg .sender { color: var(--accent-secondary); font-weight: 600; }
.chat-msg .text { color: var(--text-secondary); }

.chat-form {
    display: flex;
    gap: 6px;
}
.chat-form input {
    margin-bottom: 0;
    flex: 1;
}
.chat-form button {
    white-space: nowrap;
    padding: 0 16px;
}

/* ---- Result Screen ---- */
.result-header { text-align: center; padding: 20px 0; }
.result-content {
    text-align: center;
    padding: 20px 0;
}
.result-icon {
    font-size: 4em;
    margin-bottom: 12px;
}
.result-content h3 {
    font-size: 1.5em;
    margin-bottom: 8px;
}
.result-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* ---- Overlay ---- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.overlay.hidden { display: none; }
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Utility ---- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
