*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #1a1a2e;
    color: #eee;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
    height: 100dvh;
}

/* ========== 登录页（无地图） ========== */
#auth-screen {
    position: absolute;
    inset: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    background: linear-gradient(160deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    overflow-y: auto;
}

.auth-brand {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo {
    font-size: 3rem;
    color: #3388ff;
    line-height: 1;
    margin-bottom: 12px;
}

.auth-brand h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.auth-brand p {
    font-size: 0.95rem;
    opacity: 0.65;
}

.auth-card {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    width: min(92vw, 380px);
    padding: 24px;
    background: rgba(22, 33, 62, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* ========== 游戏页（含地图） ========== */
#game-screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
}

#game-screen.hidden {
    display: none !important;
}

#map {
    flex: 1;
    width: 100%;
    min-height: 0;
    z-index: 1;
}

.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    background: linear-gradient(to bottom, rgba(26, 26, 46, 0.95), rgba(26, 26, 46, 0.6));
    pointer-events: none;
}

.top-bar h1 {
    font-size: 1.1rem;
    font-weight: 700;
    pointer-events: auto;
}

.user-info {
    font-size: 0.85rem;
    opacity: 0.9;
    pointer-events: auto;
}

.panel {
    position: absolute;
    z-index: 1000;
    pointer-events: auto;
    width: min(92vw, 360px);
    padding: 20px;
    background: rgba(22, 33, 62, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
}

#guild-panel {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.panel h2 {
    font-size: 1rem;
    margin-bottom: 12px;
}

.panel-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

#auth-screen .panel-tabs {
    position: relative;
    z-index: 2;
}

#auth-screen .tab {
    position: relative;
    z-index: 2;
}

.tab {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #ccc;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.tab.active {
    background: #3388ff;
    color: #fff;
}

.tab:not(.active):hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.panel-form input,
.panel-form button,
#create-guild-form input,
#create-guild-form button {
    width: 100%;
    margin-bottom: 10px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
    color: #fff;
    font-size: 1rem;
}

.panel-form button,
#create-guild-form button {
    background: #3388ff;
    border: none;
    cursor: pointer;
    font-weight: 600;
    pointer-events: auto;
    touch-action: manipulation;
}

.panel-form button:active,
#create-guild-form button:active {
    opacity: 0.85;
}

.message {
    font-size: 0.85rem;
    color: #ff6b6b;
    min-height: 1.2em;
    margin-top: 4px;
}

.message.success {
    color: #51cf66;
}

.guild-current {
    padding: 12px;
    margin-bottom: 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    border-left: 4px solid #3388ff;
}

details {
    margin-bottom: 10px;
}

details summary {
    cursor: pointer;
    padding: 8px 0;
    font-weight: 600;
}

.guild-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    margin-bottom: 6px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
}

.guild-color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-right: 8px;
    flex-shrink: 0;
}

.guild-item-info {
    display: flex;
    align-items: center;
    flex: 1;
}

.guild-item button {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background: #3388ff;
    color: #fff;
    cursor: pointer;
    font-size: 0.85rem;
}

.bottom-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: linear-gradient(to top, rgba(26, 26, 46, 0.95), rgba(26, 26, 46, 0.5));
    overflow-x: auto;
}

.btn {
    flex-shrink: 0;
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-size: 0.9rem;
    cursor: pointer;
    backdrop-filter: blur(8px);
}

.btn.primary {
    background: #3388ff;
    border-color: #3388ff;
    font-weight: 600;
}

.btn.active {
    background: rgba(81, 207, 102, 0.35);
    border-color: #51cf66;
}

.btn.hidden,
.hidden {
    display: none !important;
}

.toast {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    max-width: 90%;
    padding: 12px 20px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    font-size: 0.9rem;
    text-align: center;
    pointer-events: none;
    animation: fadeIn 0.2s ease;
}

.toast.success {
    background: rgba(40, 120, 60, 0.95);
}

.loading {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(26, 26, 46, 0.85);
    font-size: 1.1rem;
    pointer-events: none;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(8px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.9rem;
}

input[type="color"] {
    width: 48px;
    height: 36px;
    padding: 2px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.locate-prompt {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 88px;
    z-index: 200;
    padding: 16px;
    border-radius: 14px;
    background: rgba(22, 33, 62, 0.96);
    border: 1px solid rgba(81, 207, 102, 0.5);
    text-align: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.locate-prompt p {
    margin-bottom: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.locate-prompt .btn {
    width: 100%;
}

.settings-panel {
    top: auto;
    bottom: 76px;
    left: 50%;
    transform: translateX(-50%);
    max-height: 50vh;
    width: min(94vw, 380px);
}

.settings-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.9rem;
}

.settings-field input {
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.25);
    color: #fff;
    font-size: 0.95rem;
}

.settings-save {
    width: 100%;
}

.settings-divider {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 4px 0;
}

.onboarding-panel {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(10, 10, 24, 0.88);
    backdrop-filter: blur(10px);
}

.onboarding-card {
    width: min(100%, 380px);
    padding: 24px 20px;
    border-radius: 16px;
    background: rgba(26, 26, 46, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.onboarding-card h2 {
    margin: 0 0 6px;
    font-size: 1.25rem;
}

.onboarding-desc {
    margin: 0 0 16px;
    font-size: 0.88rem;
    opacity: 0.75;
}

.onboarding-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.onboarding-tab {
    flex: 1;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: 0.9rem;
}

.onboarding-tab.active {
    background: #3388ff;
    border-color: #3388ff;
}

.onboarding-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.onboarding-form input[type="text"] {
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
    color: #fff;
    font-size: 1rem;
}

.onboarding-form input[name="invite_code"] {
    font-size: 1.4rem;
    letter-spacing: 0.3em;
    text-align: center;
}

.guild-invite {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 10px;
    border-radius: 8px;
    background: rgba(51, 136, 255, 0.15);
}

.invite-code {
    font-size: 1.3rem;
    letter-spacing: 0.2em;
    color: #74c0fc;
}

.btn-copy {
    margin-left: auto;
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    background: #3388ff;
    color: #fff;
    font-size: 0.8rem;
    cursor: pointer;
}

.guild-hint,
.guild-meta {
    margin-top: 6px;
    font-size: 0.8rem;
    opacity: 0.7;
}

.guild-slogan-edit {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.guild-slogan-edit input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.25);
    color: #fff;
}

.guild-slogan-view {
    margin-top: 8px;
    font-size: 0.85rem;
    opacity: 0.85;
}

.guild-members {
    margin-top: 12px;
    max-height: 180px;
    overflow-y: auto;
}

.guild-member-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.85rem;
}

.member-role {
    margin-left: auto;
    font-size: 0.75rem;
    opacity: 0.65;
}

.member-action {
    padding: 4px 8px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 0.72rem;
    cursor: pointer;
}

.btn-leave-guild {
    margin-top: 12px;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 107, 107, 0.25);
    color: #ff6b6b;
    cursor: pointer;
    font-size: 0.85rem;
}

.hex-slogan {
    display: block;
    margin-top: 6px;
    font-size: 0.9rem;
    opacity: 0.9;
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.settings-row output {
    font-weight: 700;
    color: #3388ff;
}

#cell-opacity {
    width: 100%;
    accent-color: #3388ff;
}

.settings-hint {
    font-size: 0.78rem;
    opacity: 0.6;
    line-height: 1.4;
    margin: 0;
}

.settings-logout {
    width: 100%;
    margin-top: 8px;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 107, 107, 0.25);
    color: #ff6b6b;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}

.settings-logout:active {
    opacity: 0.85;
}

@media (min-width: 768px) {
    #guild-panel,
    .rank-panel,
    .settings-panel {
        top: auto;
        bottom: 80px;
        left: auto;
        right: 16px;
        transform: none;
        max-height: 60vh;
        overflow-y: auto;
    }
}

/* ========== 排行榜 ========== */
.rank-panel {
    top: auto;
    bottom: 76px;
    left: 50%;
    transform: translateX(-50%);
    max-height: 55vh;
    width: min(94vw, 400px);
    display: flex;
    flex-direction: column;
}

.rank-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.rank-header h2 {
    margin: 0;
    font-size: 1rem;
}

.panel-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
}

.rank-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.rank-tab {
    flex: 1;
    padding: 8px 4px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #ccc;
    font-size: 0.8rem;
    cursor: pointer;
}

.rank-tab.active {
    background: #3388ff;
    color: #fff;
}

.rank-sort-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.rank-sort-btn {
    padding: 5px 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    background: transparent;
    color: #aaa;
    font-size: 0.75rem;
    cursor: pointer;
}

.rank-sort-btn.active {
    background: rgba(51, 136, 255, 0.3);
    border-color: #3388ff;
    color: #fff;
}

.rank-body {
    overflow-y: auto;
    flex: 1;
    min-height: 120px;
}

.rank-date {
    font-size: 0.8rem;
    opacity: 0.6;
    margin-bottom: 10px;
}

.rank-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rank-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
}

.rank-no {
    font-weight: 700;
    color: #3388ff;
    min-width: 22px;
}

.rank-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-top: 4px;
    flex-shrink: 0;
}

.rank-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.85rem;
}

.rank-info strong {
    font-size: 0.95rem;
}

.rank-info span {
    opacity: 0.75;
    font-size: 0.78rem;
}

.rank-empty, .rank-loading {
    text-align: center;
    opacity: 0.6;
    padding: 20px;
    font-size: 0.9rem;
}

.my-stats-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 14px;
}

.stat-box {
    padding: 12px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
    text-align: center;
}

.stat-box b {
    display: block;
    font-size: 1.4rem;
    color: #3388ff;
}

.stat-box span {
    font-size: 0.75rem;
    opacity: 0.7;
}

.rank-subtitle {
    font-size: 0.85rem;
    margin: 12px 0 8px;
    opacity: 0.85;
}

.hex-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.hex-list-item {
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
    cursor: pointer;
    font-size: 0.8rem;
}

.hex-list-item:active {
    background: rgba(51, 136, 255, 0.2);
}

.hex-id {
    display: block;
    font-weight: 600;
    margin-bottom: 2px;
}

.hex-meta, .hex-time {
    display: block;
    opacity: 0.75;
    font-size: 0.75rem;
}

.hex-detail-panel {
    position: absolute;
    top: 60px;
    left: 12px;
    right: 12px;
    z-index: 1500;
    max-height: 40vh;
    overflow-y: auto;
    padding: 14px;
    border-radius: 14px;
    background: rgba(22, 33, 62, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.hex-detail-close {
    position: absolute;
    top: 8px;
    right: 10px;
    border: none;
    background: none;
    color: #fff;
    font-size: 1.3rem;
    cursor: pointer;
}

.hex-winner {
    padding: 10px;
    margin: 8px 0;
    border-left: 4px solid #3388ff;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.2);
    font-size: 0.85rem;
}

.hex-winner span {
    display: block;
    opacity: 0.75;
    font-size: 0.78rem;
    margin-top: 4px;
}

.hex-guild-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 8px;
}

.hex-member-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-left: 12px;
    margin-bottom: 6px;
    font-size: 0.78rem;
    opacity: 0.85;
}

.hex-member-list small {
    opacity: 0.6;
}
