/*
 * 颜色保持原来的球场深绿和荧光黄绿。
 * 桌面导航把消息、档案、设置、更多功能和退出固定在右侧，
 * 避免被横向滚动挤出可视区域。其余规则补手机访问体验。
 */

:root {
    --green-950: #071a14;
    --green-900: #0c2b20;
    --green-800: #124936;
    --green-700: #176a4b;
    --green-600: #1d8a5e;
    --green-500: #28a873;
    --lime: #d9f740;
    --lime-strong: #c9eb24;
    --lime-soft: #f2facd;
    --orange: #ef6b42;
    --blue: #316bc4;
    --red: #ce4150;
    --purple: #7853b6;
    --gold: #d2a514;
    --text: #14231e;
    --muted: #66746e;
    --line: #d9e1dd;
    --line-strong: #c4d0ca;
    --surface: #ffffff;
    --surface-soft: #f5f7f6;
    --background: #eef2f0;
    --shadow: 0 24px 64px rgba(7, 26, 20, .13);
    --shadow-small: 0 8px 28px rgba(7, 26, 20, .07);
    --radius: 8px;
    --radius-small: 6px;
}

.brand {
    flex: 0 0 auto;
    align-items: center;
    gap: 12px;
}

.brand-ball {
    flex: 0 0 42px;
    margin: 0;
}

.brand-copy {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: max-content;
    gap: 2px;
}

.brand strong,
.brand small {
    display: block;
    margin: 0;
    white-space: nowrap;
    line-height: 1.15;
    text-align: left;
}

.main-nav {
    min-width: 0;
}

.main-nav a,
.main-nav .nav-logout {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.main-nav a svg,
.main-nav .nav-logout svg {
    width: 16px;
    height: 16px;
    flex: none;
}

.main-nav .nav-logout-form {
    display: flex;
    margin: 0;
}

.main-nav .nav-logout {
    margin: 0;
    border: 0;
    background: transparent;
    padding: 8px 11px;
    border-radius: var(--radius-small);
    color: #ff9ba4;
    font: inherit;
    font-size: 14px;
    font-weight: 650;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
}

.main-nav .nav-logout:hover {
    color: var(--green-950);
    background: var(--lime);
}

.nav-scroll,
.nav-pin {
    display: flex;
    align-items: center;
    gap: 5px;
}

.nav-scroll {
    min-width: 0;
    flex: 0 1 auto;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
}

.nav-scroll::-webkit-scrollbar {
    display: none;
}

.nav-pin {
    flex: 0 0 auto;
}

@media not all and (max-width: 1080px) {
    .site-header .main-nav {
        flex: 1 1 auto;
        justify-content: flex-end;
        overflow: visible;
    }

    .site-header .main-nav a,
    .site-header .main-nav .nav-logout {
        padding: 8px;
    }

    .nav-scroll + .nav-pin {
        margin-left: 4px;
    }

    .site-header.is-admin {
        align-items: center;
        row-gap: 8px;
    }

    .site-header.is-admin .brand {
        margin-right: auto;
    }

    .site-header.is-admin .main-nav {
        display: contents;
    }

    .site-header.is-admin .nav-pin {
        order: 2;
        margin-left: 0;
    }

    .site-header.is-admin .nav-scroll {
        order: 3;
        flex: 1 1 100%;
        overflow: visible;
        flex-wrap: wrap;
        align-items: center;
        gap: 4px 6px;
        padding-top: 8px;
        border-top: 1px solid rgba(255, 255, 255, .12);
    }

    .site-header.is-admin .main-nav a,
    .site-header.is-admin .main-nav .nav-logout {
        height: 34px;
        padding: 0 10px;
        line-height: 1;
    }

    .site-header.is-admin .message-count {
        position: static;
        top: auto;
        right: auto;
        margin-left: 4px;
    }

    .admin-module-tabs {
        top: 128px;
        display: grid;
        grid-template-columns: repeat(6, minmax(0, 1fr));
        overflow: visible;
    }

    .admin-module-tabs .tab {
        min-width: 0;
        width: auto;
        flex: none;
    }
}

.tab:has(svg),
.region-chip:has(svg) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.tab svg,
.region-chip svg {
    width: 16px;
    height: 16px;
    flex: none;
}

.mobile-tabbar {
    display: none;
}

/*
 * 安卓应用内嵌页面。
 * 顶栏贴边，菜单盖住内容，底栏不再压住正文。
 */
body.is-android-app {
    --app-header: calc(56px + env(safe-area-inset-top, 0px));
    --app-tab: 57px;
    background: linear-gradient(
        to bottom,
        #071a14 0,
        #071a14 env(safe-area-inset-top, 0px),
        #edf2ef env(safe-area-inset-top, 0px)
    );
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: calc(var(--app-tab) + env(safe-area-inset-bottom, 0px));
}

body.is-android-app.page-tennis_passport {
    padding-top: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background:
        radial-gradient(ellipse at 12% 8%, rgba(217, 247, 64, .12), transparent 34%),
        radial-gradient(ellipse at 90% 92%, rgba(40, 168, 115, .24), transparent 38%),
        #071a14;
}

body.is-android-app .site-shell {
    width: 100%;
}

body.is-android-app .site-header {
    top: env(safe-area-inset-top, 0px);
    z-index: 150;
    height: 56px;
    min-height: 56px;
    margin: 0;
    padding: 0 8px 0 14px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

body.is-android-app .brand-ball {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
}

body.is-android-app .brand-copy small {
    display: none;
}

body.is-android-app .nav-toggle {
    width: 40px;
    height: 40px;
    border: 0;
}

body.is-android-app .main-nav.is-open {
    position: fixed;
    z-index: 140;
    top: var(--app-header);
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    width: auto;
    max-height: none;
    margin: 0;
    padding: 8px 12px calc(var(--app-tab) + 16px);
    overflow: auto;
    border: 0;
    border-radius: 0;
    background: #071a14;
}

body.is-android-app .main-nav.is-open .nav-scroll,
body.is-android-app .main-nav.is-open .nav-pin {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 4px;
}

body.is-android-app .mobile-tabbar {
    z-index: 145;
    padding-top: 4px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
    background: #071a14;
}

body.is-android-app .site-footer {
    display: none;
}

body.is-android-app .main-content {
    padding: 0 0 12px;
}

body.is-android-app .page-index .hero {
    min-height: 0;
    margin: 0 0 12px;
    border-radius: 0;
    padding: 22px 16px 16px;
}

body.is-android-app .hero-label {
    display: none;
}

body.is-android-app .page-index .hero h1,
body.is-android-app .hero-title {
    margin-top: 0;
    font-size: 28px;
    line-height: 1.2;
}

body.is-android-app .hero-stats,
body.is-android-app .page-index .hero-stats {
    grid-template-columns: 1fr 1fr;
}

body.is-android-app .hero-stat {
    min-height: 64px;
}

body.is-android-app .panel,
body.is-android-app .auth-card,
body.is-android-app .filter-form {
    margin-right: 12px;
    margin-left: 12px;
}

body.is-android-app .auth-card {
    width: auto;
    margin-top: 16px;
    padding: 22px 16px;
}

body.is-android-app .page-back-actions {
    margin: 12px 12px 0;
}

body.is-android-app .profile-hero {
    margin: 12px;
    padding: 18px 16px;
}

body.is-android-app .score-grid {
    grid-template-columns: 1fr 1fr;
}

body.is-android-app .stat-row {
    margin: 0 12px 12px;
}

@media (max-width: 760px) {
    body.is-android-app .ranking-panel > .panel-title > div {
        flex: 0 1 auto;
    }

    body.is-android-app .ranking-panel > .filter-form {
        margin-right: 0;
        margin-left: 0;
    }

    body.is-android-app .ranking-panel .region-tabs {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    body.is-android-app .ranking-panel .region-chip {
        display: flex;
        min-width: 0;
        justify-content: center;
        padding-right: 4px;
        padding-left: 4px;
        text-align: center;
        white-space: nowrap;
    }
}

.android-update-overlay {
    position: fixed;
    z-index: 1000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
    background: rgba(7, 26, 20, .72);
}

.android-update-dialog {
    width: min(100%, 440px);
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px);
    overflow: auto;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.android-update-dialog h2 {
    margin: 0 0 10px;
    color: var(--green-950);
    font-size: 22px;
    line-height: 1.35;
}

.android-update-description,
.android-update-notes {
    margin: 0 0 12px;
    overflow-wrap: anywhere;
}

.android-update-notes {
    padding: 12px;
    border-radius: 8px;
    white-space: pre-wrap;
    background: var(--surface-soft);
}

.android-update-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.android-update-actions .btn {
    flex: 1 1 130px;
    text-align: center;
}

.mobile-access-note {
    display: none;
}

@media (max-width: 1080px) {
    .main-nav {
        border-top-color: rgba(255, 255, 255, .12);
    }

    .main-nav.is-open {
        grid-template-columns: 1fr;
    }

    .main-nav.is-open .nav-scroll,
    .main-nav.is-open .nav-pin {
        display: grid;
        grid-template-columns: 1fr;
        gap: 4px;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        margin: 0;
        padding: 0;
        overflow: visible;
        border: 0;
    }

    .main-nav a,
    .main-nav .nav-logout-form,
    .main-nav .nav-logout {
        display: flex;
        width: 100%;
        min-height: 48px;
        align-items: center;
        box-sizing: border-box;
    }
}

@media (max-width: 760px) {
    html {
        scroll-padding-top: 76px;
    }

    body {
        padding-bottom: calc(64px + env(safe-area-inset-bottom));
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    .site-header {
        top: 0;
        padding-top: calc(8px + env(safe-area-inset-top));
    }

    .brand-copy small {
        display: block;
    }

    input,
    select,
    textarea {
        font-size: 16px;
    }

    .btn,
    .region-chip,
    .tab {
        min-height: 44px;
    }

    .table-wrap,
    .community-filters,
    .filter-form,
    .inline-fields,
    .member-actions,
    .post-actions {
        max-width: 100%;
    }

    .table-wrap {
        overflow-x: auto;
    }

    .hero,
    .page-index .hero {
        min-height: 0;
        aspect-ratio: auto;
        grid-template-columns: 1fr;
        padding: 28px 18px 20px;
    }

    .page-index .hero h1,
    .page-index .hero-title,
    .hero h1 {
        font-size: 32px;
        line-height: 1.25;
        white-space: normal;
    }

    .hero-stats,
    .page-index .hero-stats {
        width: 100%;
        grid-template-columns: 1fr 1fr;
    }

    .more-function-grid,
    .admin-grid,
    .admin-stats,
    .community-list {
        grid-template-columns: 1fr;
    }

    .mobile-tabbar {
        position: fixed;
        z-index: 120;
        right: 0;
        bottom: 0;
        left: 0;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 2px;
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
        border-top: 1px solid rgba(255, 255, 255, .08);
        background: rgba(7, 26, 21, .97);
        box-shadow: 0 -8px 24px rgba(7, 26, 21, .18);
    }

    .mobile-tabbar a {
        display: flex;
        min-height: 48px;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        color: rgba(255, 255, 255, .72);
        font-size: 11px;
        font-weight: 700;
        text-decoration: none;
    }

    .mobile-tabbar a svg {
        width: 18px;
        height: 18px;
    }

    .mobile-tabbar a[aria-current="page"] {
        color: var(--lime);
    }

    .mobile-access-note {
        display: block;
        margin-top: 10px;
        color: var(--muted);
        font-size: 12px;
        line-height: 1.6;
    }
}

/*
 * 全站布局对齐。
 * 只处理面板、表单、表格和卡片的排列，不改配色和品牌锁。
 */
.site-shell,
.main-content,
.panel,
.box,
.auth-card,
.hero,
.profile-hero {
    min-width: 0;
    max-width: 100%;
}

.panel h1,
.panel-title h1,
.box h1,
.message-card h2,
.message-card h3,
.message-card p {
    margin-top: 0;
}

.panel-title {
    align-items: center;
    flex-wrap: wrap;
}

.panel-title > div,
.panel-title > h1,
.panel-title > h2,
.panel-title > h3 {
    min-width: 0;
    flex: 1 1 220px;
}

.panel-title h1,
.panel-title h2,
.panel-title h3,
.panel-title h4 {
    margin: 0;
    line-height: 1.3;
}

.panel-title .muted,
.panel-title p {
    margin: 4px 0 0;
}

.panel-title > .btn,
.panel-title > a.btn,
.panel-title > form,
.panel-title > .tag {
    flex: 0 0 auto;
}

.message-card h3,
.match-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.message-card p {
    margin-bottom: 0;
    overflow-wrap: anywhere;
}

body:not(.page-index) .hero {
    min-height: 0;
    align-items: center;
    padding: 32px 36px;
}

body:not(.page-index) .hero:not(:has(.hero-stats)) {
    grid-template-columns: minmax(0, 1fr);
}

.hero-content,
.profile-identity,
.profile-identity > div,
.player-name,
.player-meta,
.community-card,
.post-card,
.operation-row,
.list-row {
    min-width: 0;
}

.profile-hero p,
.hero p,
.community-card p {
    overflow-wrap: anywhere;
}

.post-card img,
.message-card img,
.community-card img,
.panel img {
    max-width: 100%;
    height: auto;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.filter-form > input:not([type="hidden"]),
.filter-form > select,
.filter-form > textarea {
    width: auto;
    min-width: 0;
    max-width: 100%;
    flex: 1 1 180px;
}

.filter-form > input[type="search"],
.filter-form > input[name="search"],
.filter-form > input[name="q"] {
    flex: 2 1 240px;
}

.filter-form > .btn,
.filter-form > button {
    width: auto;
    flex: 0 0 auto;
}

.form-grid > .btn,
.form-grid > button {
    grid-column: 1 / -1;
    justify-self: start;
    width: auto;
}

.tabs,
.region-tabs {
    flex-wrap: wrap;
    overflow: visible;
}

.tabs .tab,
.ranking-panel .tab,
.court-operation-tabs .tab {
    min-width: 0;
    flex: 1 1 148px;
}

.ranking-panel .tabs {
    width: 100%;
}

a.admin-stat {
    display: block;
    color: inherit;
    text-decoration: none;
}

a.admin-stat:hover {
    border-color: var(--green-700);
}

.admin-stats,
.court-metric-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.player-card,
.ranking-panel .player-card {
    min-width: 0;
}

.ranking-panel .player-score,
.player-score {
    min-width: 0;
}

.table-wrap table {
    min-width: 0;
}

.table-wrap:has(th:nth-child(6)):not(.admin-card-table) table {
    min-width: 720px;
}

.table-wrap th,
.table-wrap td {
    vertical-align: middle;
}

.admin-card-table th,
.admin-card-table td,
.table-wrap td:has(form),
.table-wrap td:has(.inline-form) {
    vertical-align: top;
}

@media (max-width: 1080px) {
    .admin-module-tabs {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .court-benefit-grid,
    .court-public-facts {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .court-metric-grid,
    .admin-stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .review-decision-form {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px) {
    .operation-row,
    .list-row,
    .message-card-header,
    .h2h-panel {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .operation-row > div:last-child,
    .list-row form,
    .h2h-score {
        flex: 1 1 100%;
        min-width: 0;
        text-align: left;
    }

    .player-card,
    .ranking-panel .player-card {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .player-score,
    .ranking-panel .player-score {
        grid-column: 1 / -1;
        justify-content: space-between;
        padding-top: 8px;
        padding-left: 58px;
        border-top: 1px solid var(--line);
    }
}

@media (max-width: 760px) {
    .auth-card {
        margin: 12px auto 20px;
    }

    .panel-title > .btn,
    .panel-title > a.btn,
    .panel-title > form {
        flex: 1 1 100%;
    }

    .panel-title > form .btn,
    .filter-form > .btn,
    .filter-form > button {
        flex: 1 1 auto;
    }

    .admin-grid,
    .admin-stats,
    .court-metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .community-filters input[type="search"],
    .community-filters input[type="text"],
    .community-filters select,
    .inline-fields input[type="text"],
    .inline-fields select,
    .member-actions input[type="text"],
    .post-actions input[type="text"],
    .reply-actions input[type="text"] {
        width: 100%;
        min-width: 0;
        flex-basis: 100%;
    }

    .player-score,
    .ranking-panel .player-score {
        padding-left: 0;
    }

    body:not(.page-index) .hero {
        padding: 28px 18px 20px;
    }
}

@media (max-width: 420px) {
    .admin-module-tabs {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .admin-grid,
    .admin-stats,
    .court-metric-grid,
    .hero-stats,
    .page-index .hero-stats {
        grid-template-columns: 1fr;
    }
}
