/* 专用样式覆盖和增强 */

/* Fallbacks for palette names referenced by inline styles / older rules that the
   root stylesheet does not define. Keeps everything resolving to real colors. */
:root {
    --primary: var(--teal);
    --danger: #ef4444;
    --warn: #f59e0b;
    --surface: rgba(255, 255, 255, 0.4);
    --bg: transparent;
}
@media (prefers-color-scheme: dark) {
    :root { --surface: rgba(30, 41, 59, 0.4); }
}

.app-container {
    width: min(900px, calc(100% - 30px));
    margin: 80px auto 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.glass-panel {
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 30px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
}

.view {
    display: none;
    animation: fadeIn 0.3s ease;
}
.view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.title { color: var(--teal); font-size: 2.5rem; text-align: center; margin-bottom: 10px; }
.subtitle { color: var(--dim); text-align: center; margin-bottom: 40px; }
.text-center { text-align: center; }

/* ---- Cloud-server status widget (home) ---- */
.server-status {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    margin: -22px auto 28px;
    padding: 7px 14px;
    max-width: 320px;
    background: var(--soft);
    border: 1px solid var(--line);
    border-radius: 30px;
    font-size: 0.85rem; color: var(--dim);
}
.server-status .ss-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--dim); flex: 0 0 auto;
    transition: background 0.2s, box-shadow 0.2s;
}
.server-status.ok   .ss-dot { background: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,0.18); }
.server-status.slow .ss-dot { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245,158,11,0.18); }
.server-status.bad  .ss-dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(239,68,68,0.18); }
.server-status.ok   .ss-text { color: #0f766e; }
.server-status.slow .ss-text { color: #b45309; }
.server-status.bad  .ss-text { color: var(--danger); }
.server-status .ss-text { font-weight: 600; }
.server-status .ss-latency { font-weight: 500; opacity: 0.85; }
.server-status .ss-refresh {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; padding: 0;
    border: 1px solid transparent; border-radius: 50%;
    background: transparent; color: var(--dim); cursor: pointer;
    transition: all 0.2s;
}
.server-status .ss-refresh:hover { color: var(--teal); border-color: var(--line); background: var(--card-bg); }
.server-status .ss-refresh.spinning svg { animation: ss-spin 0.8s linear infinite; }
@keyframes ss-spin { to { transform: rotate(360deg); } }

/* ---- Inline SVG icon helpers ---- */
.icon-teal { color: var(--teal); }
[data-icon] { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
[data-icon] svg { display: block; }

/* 卡片网格 (首页) */
.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
@media (min-width: 600px) {
    .card-grid { grid-template-columns: 1fr 1fr; }
}
.action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px;
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}
.action-card:hover {
    background: var(--card-hover-bg);
    border-color: var(--teal);
    transform: translateY(-4px);
}
.action-card h3 { margin: 0 0 6px; }
.action-card p { margin: 0; color: var(--dim); font-size: 0.9rem; }
.card-icon { margin-bottom: 15px; }
.card-icon svg { width: 48px; height: 48px; stroke-width: 1.75; }

/* 表单与按钮 */
.form-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px dashed var(--line);
    width: 100%;
}
.hidden { display: none !important; }

/* Full-width wrapper so a nested .big-input matches the standalone inputs'
   width (a shrink-to-fit flex child would otherwise collapse to ~170px). */
.field-block { width: 100%; max-width: 300px; display: flex; }
.field-block .big-input { width: 100%; }

.big-input {
    width: 100%;
    max-width: 300px;
    padding: 15px;
    font-size: 1.2rem;
    text-align: center;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: var(--soft);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}
.big-input:focus { border-color: var(--teal); }
.uppercase { text-transform: uppercase; }

.btn {
    padding: 12px 24px;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-block { width: 100%; padding: 15px; font-size: 1.1rem; }
.primary-btn {
    background: var(--teal);
    color: white;
}
.primary-btn:hover { filter: brightness(1.1); transform: translateY(-2px); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.danger-btn {
    background: var(--danger);
    color: white;
}
.danger-btn:hover { background: #dc2626; }
.text-btn {
    background: transparent;
    color: var(--dim);
    border: 1px solid var(--line);
}
.text-btn:hover { color: var(--text); border-color: var(--teal); background: rgba(0,0,0,0.05); }

/* 大厅布局 */
.lobby-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    padding: 20px;
    margin-bottom: 20px;
}
.room-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.room-code-label { color: var(--dim); }
.room-actions { display: flex; align-items: center; gap: 6px; margin-left: 4px; }
.highlight { font-size: 1.5rem; color: var(--teal); letter-spacing: 2px; }

/* Small square icon buttons (history / leave / password) */
.icon-btn {
    width: 34px; height: 34px;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--soft);
    color: var(--dim);
    cursor: pointer;
    transition: all 0.2s;
}
.icon-btn:hover { color: var(--text); border-color: var(--teal); }
.icon-btn.danger:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
.icon-btn svg { width: 18px; height: 18px; }

.host-controls { text-align: center; }
#qrcode { background: white; padding: 10px; border-radius: 8px; display: inline-block; line-height: 0; }
#qrcode img, #qrcode canvas { display: block; }
.host-controls p { margin: 8px 0 0; font-size: 0.85rem; color: var(--dim); }

.main-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}
@media (min-width: 768px) {
    .main-layout { grid-template-columns: 250px 1fr; }
}

.player-list { list-style: none; padding: 0; margin: 0; }
.player-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-bottom: 1px solid var(--line);
}
.player-item:last-child { border-bottom: none; }
.player-avatar {
    width: 32px; height: 32px; flex: 0 0 32px;
    background: var(--teal); color: white;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; text-transform: uppercase;
}
.player-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; }
.player-name .name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-edit-btn {
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: none; cursor: pointer;
    color: var(--dim); padding: 2px; margin-left: 6px; border-radius: 4px;
}
.player-edit-btn:hover { color: var(--teal); }
.player-edit-btn svg { width: 15px; height: 15px; }
.player-remove-btn {
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: none; cursor: pointer;
    color: var(--danger); padding: 2px; border-radius: 4px;
}
.player-remove-btn svg { width: 16px; height: 16px; }
.player-transfer-btn {
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: none; cursor: pointer;
    color: var(--warn); padding: 2px; margin-left: 4px; border-radius: 4px;
}
.player-transfer-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.player-transfer-btn svg { width: 15px; height: 15px; }
.player-kick-btn {
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: none; cursor: pointer;
    color: var(--danger); padding: 2px; margin-left: 4px; border-radius: 4px;
}
.player-kick-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.player-kick-btn svg { width: 16px; height: 16px; }
.host-badge { font-size: 0.8rem; background: var(--warn); color: white; padding: 2px 6px; border-radius: 4px; }
.offline { opacity: 0.5; }

.add-player-row { margin-top: 15px; display: flex; gap: 8px; }
.add-player-row .big-input { flex: 1; max-width: none; padding: 10px; font-size: 1rem; text-align: left; }
.add-player-row .btn { padding: 10px 16px; }

/* 模板选择 */
.template-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    margin-top: 15px;
}
.template-card {
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    background: rgba(255,255,255,0.2);
    transition: all 0.2s;
}
.template-card:hover { border-color: var(--teal); background: rgba(8, 127, 140, 0.1); }
.template-card.selected { border-color: var(--teal); background: var(--teal); color: white; }

.template-config { margin-top: 20px; padding-top: 20px; border-top: 1px dashed var(--line); }
.config-options { margin-bottom: 20px; display: flex; flex-wrap: wrap; gap: 8px; }
.config-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    row-gap: 12px;
    margin-top: 22px;
}
.config-actions .btn { flex: 1 1 auto; min-width: 120px; }
.config-block { margin-top: 15px; text-align: left; }
.config-subhead { margin: 0 0 8px; color: var(--text); font-size: 0.95rem; }
.voter-selection-list {
    display: flex; flex-wrap: wrap; gap: 8px;
    max-height: 140px; overflow-y: auto;
    background: var(--soft); padding: 10px;
    border-radius: 6px; border: 1px solid var(--line);
}
.voter-chip {
    display: flex; align-items: center; gap: 6px;
    background: var(--card-bg); padding: 6px 10px;
    border-radius: 6px; font-size: 0.9rem; cursor: pointer;
    border: 1px solid var(--line);
}
.voter-chip.offline { opacity: 0.55; }
.voter-chip.offline:hover { border-color: var(--warn); opacity: 0.85; }
.voter-offline-hint {
    flex-basis: 100%; font-size: 0.85rem; color: #f59e0b; margin-top: 6px;
}
.duration-select { max-width: 260px; padding: 10px; font-size: 1rem; text-align: left; }

/* 投票界面 */
.vote-title { text-align: center; margin-bottom: 24px; font-size: 1.8rem; }
.options-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
    max-width: 500px;
    margin: 0 auto;
}
.vote-btn {
    padding: 20px;
    font-size: 1.2rem;
    background: var(--card-bg);
    border: 2px solid var(--line);
    border-radius: 12px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}
.vote-btn:hover { border-color: var(--teal); transform: scale(1.02); }
.vote-btn.selected { background: var(--teal); color: white; border-color: var(--teal); }

.progress-circle {
    width: 120px; height: 120px;
    border-radius: 50%;
    border: 4px solid var(--line);
    border-top-color: var(--teal);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 20px;
    font-size: 1.5rem; font-weight: bold;
    animation: spin 2s linear infinite;
}
.progress-circle span {
    animation: spin-reverse 2s linear infinite;
}
.deal-progress-circle { margin: 20px auto; }
@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes spin-reverse { 100% { transform: rotate(-360deg); } }

.success-msg { text-align: center; color: #10b981; font-weight: bold; margin-top: 20px; font-size: 1.2rem; }
.host-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.host-actions .btn { flex: 0 1 auto; }

/* 结果界面 */
.chart-container {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}
.chart-container canvas { width: 100%; height: auto; }
.result-details { margin-top: 30px; }
.result-item {
    display: flex; justify-content: space-between;
    padding: 10px; border-bottom: 1px solid var(--line);
}
.result-actions { text-align: center; margin-top: 30px; }

/* Toast */
.toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.8); color: white;
    padding: 10px 20px; border-radius: 30px;
    opacity: 0; visibility: hidden; transition: all 0.3s;
    z-index: 9999; max-width: calc(100% - 40px); text-align: center;
}
.toast.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(-10px); }

/* 等待区动画 */
.spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--line); border-top-color: var(--teal);
    border-radius: 50%; margin: 0 auto 15px;
    animation: spin 1s linear infinite;
}
.waiting-area { text-align: center; padding: 40px 20px; }
#btn-lobby-view-card { margin-top: 18px; }

/* Mode Selector Cards */
.network-mode-selector { text-align: center; margin-top: 20px; }
.mode-label { color: var(--dim); font-size: 0.9rem; display: block; margin-bottom: 10px; }
.mode-cards {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 10px;
}
.mode-card {
    cursor: pointer;
    flex: 1;
    max-width: 120px;
}
.mode-card input[type="radio"] {
    display: none;
}
.mode-card-content {
    background: var(--soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 10px;
    text-align: center;
    transition: all 0.2s ease;
    color: var(--dim);
}
.mode-card-content .icon { margin-bottom: 6px; color: var(--dim); }
.mode-card-content .icon svg { width: 24px; height: 24px; }
.mode-card-content .name {
    font-size: 0.85rem;
    color: var(--text);
    font-weight: 500;
}
.mode-card input[type="radio"]:checked + .mode-card-content {
    border-color: var(--teal);
    background: rgba(8, 127, 140, 0.1);
    box-shadow: 0 2px 8px rgba(8, 127, 140, 0.18);
}
.mode-card input[type="radio"]:checked + .mode-card-content .icon { color: var(--teal); }

/* Secondary button (deal / peek role) */
.secondary-btn {
    background: var(--soft);
    color: var(--text);
    border: 1px solid var(--line);
}
.secondary-btn:hover { border-color: var(--teal); }

/* Vote countdown */
.vote-countdown {
    display: flex; align-items: center; gap: 6px;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--teal);
    margin: -8px auto 20px;
    padding: 4px 14px;
    width: fit-content;
    border: 1px solid var(--line);
    border-radius: 30px;
    background: var(--soft);
}
.vote-countdown .cd-icon { display: inline-flex; }
.vote-countdown .cd-icon svg { width: 18px; height: 18px; }

/* Pass & play */
.passplay-panel { max-width: 420px; margin: 0 auto; }
.passplay-icon { margin: 20px 0; }
.passplay-icon svg { width: 64px; height: 64px; stroke-width: 1.5; }
.passplay-desc { font-size: 1.2rem; margin-bottom: 30px; }
.passplay-name { color: var(--teal); font-size: 1.5rem; display: block; margin-top: 10px; }

/* My card */
.my-card-icon { margin: 20px 0; color: var(--teal); }
.my-card-icon svg { width: 88px; height: 88px; stroke-width: 1.5; }
.my-card-icon.evil { color: var(--danger); }
.my-card-name { font-size: 2rem; color: var(--teal); margin: 0; }
.my-card-desc { margin: 20px 0; font-size: 1.1rem; color: var(--dim); }

/* Dealing config */
.dealing-roles-container { text-align: left; margin: 15px 0; }
.deal-role-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--line);
}
.deal-role-row:last-child { border-bottom: none; }
.deal-role-name { font-weight: 500; display: flex; align-items: center; gap: 8px; }
.deal-role-name .role-icon { display: inline-flex; color: var(--teal); }
.deal-role-name .role-icon svg { width: 22px; height: 22px; }
.deal-role-name.evil .role-icon { color: var(--danger); }
.deal-role-auto, .deal-role-fixed { color: var(--dim); font-size: 0.9rem; }
.deal-role-auto em { font-style: normal; font-weight: 700; color: var(--teal); }
.deal-stepper { display: flex; align-items: center; gap: 10px; }
.step-btn {
    width: 32px; height: 32px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--soft);
    color: var(--text);
    font-size: 1.2rem; line-height: 1;
    cursor: pointer;
}
.step-btn:hover { border-color: var(--teal); }
.step-val { min-width: 20px; text-align: center; font-weight: 700; }
.dealing-summary { text-align: center; margin: 10px 0; font-size: 0.95rem; color: var(--dim); }
.deal-offline-hint { margin-top: 6px; font-size: 0.85rem; color: #f59e0b; }
.word-field { display: block; margin-bottom: 12px; }
.word-field span { display: block; margin-bottom: 4px; font-size: 0.9rem; color: var(--dim); }
.word-field .big-input { max-width: 100%; text-align: left; padding: 10px; font-size: 1rem; }

/* History */
.history-list { text-align: left; margin: 15px 0; max-height: 50vh; overflow-y: auto; }
.history-item {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 10px;
    background: var(--soft);
}
.history-head { display: flex; justify-content: space-between; gap: 10px; }
.history-head .muted { color: var(--dim); font-size: 0.85rem; }
.history-results { margin-top: 6px; font-size: 0.9rem; color: var(--text); }
.history-empty { color: var(--dim); text-align: center; padding: 20px 0; }

/* Tie highlight */
.vote-title.tie { color: var(--warn); }

/* ---- Scan-to-join confirmation ---- */
.join-confirm-panel { max-width: 460px; margin: 0 auto; text-align: center; }
.join-confirm-icon { margin-bottom: 12px; }
.join-confirm-icon svg { width: 56px; height: 56px; stroke-width: 1.6; }
.join-confirm-panel h2 { margin: 0 0 16px; }
.join-confirm-code { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin-bottom: 8px; color: var(--dim); }

/* ---- Connection status banner ---- */
.conn-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1200;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 8px 16px;
    font-size: 0.9rem; font-weight: 600;
    color: #fff;
    background: var(--warn);
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
.conn-banner.error { background: var(--danger); }
.conn-banner.ok { background: #10b981; }
.conn-banner svg { width: 16px; height: 16px; }

/* Persistent identity badge (top-center chrome, whole round) */
.identity-badge {
    position: fixed;
    top: 18px; left: 50%; transform: translateX(-50%);
    z-index: 1100;
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--line);
    border-radius: 30px;
    background: var(--soft);
    color: var(--teal);
    font-size: 0.85rem; font-weight: 600;
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(0,0,0,0.1);
    transition: all 0.2s;
}
.identity-badge:hover { border-color: var(--teal); transform: translateX(-50%) translateY(-1px); }
.identity-badge.hidden { display: none; }
.identity-badge svg { width: 16px; height: 16px; }
.identity-badge.evil { color: var(--danger); }

/* ---- Generic modal ---- */
.modal-overlay {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}
.modal-card {
    width: min(420px, 100%);
    max-height: 85vh; overflow-y: auto;
    background: var(--card-hover-bg);
    padding: 24px;
}
.modal-title { margin: 0 0 12px; font-size: 1.3rem; color: var(--text); }
.modal-body { color: var(--dim); font-size: 0.98rem; line-height: 1.5; }
.modal-body .big-input { max-width: 100%; text-align: left; margin-top: 12px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.modal-actions .btn { padding: 10px 18px; font-size: 1rem; }

/* Loading state for async buttons */
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after {
    content: ""; position: absolute; top: 50%; left: 50%;
    width: 18px; height: 18px; margin: -9px 0 0 -9px;
    border: 2px solid rgba(255,255,255,0.5); border-top-color: #fff;
    border-radius: 50%; animation: spin 0.8s linear infinite;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
    .app-container { width: calc(100% - 20px); margin: 68px auto 24px; gap: 14px; }
    .glass-panel { padding: 20px 16px; border-radius: 14px; }
    .title { font-size: 1.9rem; }
    .subtitle { margin-bottom: 24px; }
    .action-card { padding: 22px 16px; }
    .card-icon svg { width: 40px; height: 40px; }
    .lobby-header { flex-direction: column; align-items: stretch; text-align: center; }
    .room-info { justify-content: center; }
    .host-controls { margin-top: 6px; }
    .main-layout { gap: 14px; }
    .vote-title { font-size: 1.5rem; }
    .vote-btn { padding: 16px; font-size: 1.1rem; }
    .my-card-icon svg { width: 72px; height: 72px; }
    .modal-actions { justify-content: stretch; }
    .modal-actions .btn { flex: 1; }
    .home-btn span { display: none; }
    .home-btn { padding: 10px; }
}
@media (max-width: 380px) {
    .mode-cards { gap: 6px; }
    .mode-card-content { padding: 10px 6px; }
}
