:root {
    --bg: #f6f9ff;
    --line: rgba(35, 62, 96, 0.12);
    --text: #163047;
    --primary: #2463f1;
    --primary-2: #5d8cff;
    --panel: rgba(255, 255, 255, 0.97);
    --shadow: 0 18px 38px rgba(18, 44, 70, 0.1);
    --app-dvh: 100dvh;
    --ui-zoom: 1;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

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

html,
body,
#app {
    width: 100%;
    height: var(--app-dvh);
    min-height: var(--app-dvh);
    overflow: hidden;
}

body {
    font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
    font-size: clamp(12px, calc(14px * var(--ui-zoom)), 14px);
    color: var(--text);
    background: radial-gradient(circle at 78% -8%, #dfebff 0%, transparent 34%),
        radial-gradient(circle at -16% 100%, #dff4ee 0%, transparent 34%),
        var(--bg);
}

.app-root {
    width: 100%;
    height: 100%;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    width: 100%;
    min-height: 64px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: calc(8px + var(--safe-top)) max(14px, var(--safe-right)) 8px max(14px, var(--safe-left));
    flex-shrink: 0;
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.brand {
    text-decoration: none;
    color: var(--text);
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    padding: 2px 4px;
}

.menu {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.menu-btn,
.auth-btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    padding: 9px 12px;
    cursor: pointer;
}

.auth-state {
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    color: rgba(23, 47, 68, 0.72);
    padding: 4px 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
}

.menu-btn:hover,
.auth-btn:hover {
    border-color: var(--line);
    background: rgba(255, 255, 255, 0.74);
}

.menu-btn.active {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

.user-menu {
    position: relative;
}

.user-trigger {
    appearance: none;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text);
    padding: 4px 6px 4px 10px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.user-name {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 700;
}

.user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), #22a18d);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 148px;
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: var(--shadow);
    z-index: 30;
}

.user-menu.open .user-dropdown {
    display: flex;
}

.dropdown-item {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    padding: 7px 8px;
    cursor: pointer;
}

.dropdown-item:hover {
    border-color: var(--line);
    background: rgba(255, 255, 255, 0.7);
}

.dropdown-item.danger {
    color: #b43a4a;
}

.main-region {
    width: 100%;
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    display: flex;
    padding: 12px max(12px, var(--safe-right)) max(12px, var(--safe-bottom)) max(12px, var(--safe-left));
    overflow: hidden;
}

.home-view {
    width: 100%;
    height: 100%;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow: auto;
}

.poster {
    width: 100%;
    min-height: 400px;
    border: 1px solid rgba(44, 89, 185, 0.16);
    border-radius: 22px;
    background:
        radial-gradient(circle at 82% 14%, rgba(255, 255, 255, 0.34), transparent 24%),
        radial-gradient(circle at 10% 72%, rgba(255, 255, 255, 0.24), transparent 24%),
        linear-gradient(165deg, #edf3ff, #e4efff 42%, #d9e7ff);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    text-align: center;
    padding: 24px 20px;
    box-shadow: 0 22px 46px rgba(31, 76, 138, 0.11);
}

.poster-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid rgba(36, 99, 241, 0.24);
    background: rgba(255, 255, 255, 0.72);
    color: rgba(31, 65, 105, 0.9);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
}

.poster h1 {
    font-size: clamp(38px, 5.2vw, 58px);
    line-height: 1.15;
}

.poster-powered {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid rgba(32, 79, 144, 0.24);
    background: rgba(255, 255, 255, 0.78);
    color: rgba(22, 54, 95, 0.94);
    font-size: clamp(14px, 1.8vw, 18px);
    font-weight: 700;
    letter-spacing: 0.2px;
}

.poster p {
    max-width: 860px;
    color: rgba(23, 47, 68, 0.8);
    font-size: clamp(16px, 2.3vw, 20px);
    line-height: 1.5;
}

.poster-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    width: min(900px, 100%);
}

.metric-chip {
    border: 1px solid rgba(38, 83, 150, 0.16);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.74);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
    text-align: center;
}

.metric-key {
    font-size: 13px;
    font-weight: 700;
    color: rgba(27, 63, 108, 0.88);
    letter-spacing: 0.3px;
}

.metric-val {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.poster-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.poster-btn {
    border: 1px solid transparent;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    padding: 12px 20px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(40, 87, 166, 0.22);
}

.poster-btn.ghost {
    background: rgba(255, 255, 255, 0.76);
    border-color: var(--line);
    color: var(--text);
}

.core-grid {
    width: 100%;
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.core-card {
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 15px;
    min-height: 188px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.core-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 22px 44px rgba(18, 44, 70, 0.13);
}

.core-card h2 {
    font-size: 20px;
}

.core-card p {
    color: rgba(23, 47, 68, 0.78);
    line-height: 1.45;
    font-size: 16px;
}

.core-tag {
    display: inline-flex;
    align-self: flex-start;
    border-radius: 999px;
    border: 1px solid rgba(36, 99, 241, 0.22);
    background: rgba(237, 245, 255, 0.9);
    color: rgba(32, 79, 144, 0.88);
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0.7px;
    padding: 5px 10px;
}

.card-btn {
    margin-top: auto;
    border: 1px solid transparent;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    padding: 11px 14px;
    cursor: pointer;
}

.window-view {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    overflow: auto;
}

.history-view {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    box-shadow: var(--shadow);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

.history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.history-head h2 {
    font-size: 22px;
}

.history-filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.history-filter-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 150px;
    flex: 0 1 auto;
}

.history-filter-field-keyword {
    min-width: 240px;
    flex: 1 1 320px;
}

.history-filter-field span {
    font-size: 12px;
    color: rgba(22, 48, 71, 0.72);
    font-weight: 700;
}

.history-filter-field input {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-size: 13px;
    padding: 8px 9px;
    min-height: 34px;
}

.history-refresh-btn,
.history-open-btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    padding: 7px 11px;
    cursor: pointer;
}

.history-filter-reset-btn {
    appearance: none;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    padding: 8px 12px;
    min-height: 34px;
    cursor: pointer;
}

.history-refresh-btn:disabled {
    opacity: 0.65;
    cursor: default;
}

.history-error {
    border: 1px solid rgba(180, 58, 74, 0.22);
    border-radius: 10px;
    background: rgba(255, 236, 239, 0.8);
    color: #b43a4a;
    padding: 10px 12px;
    font-size: 13px;
}

.history-grid {
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.history-section {
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(247, 250, 255, 0.85);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.history-section-head {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.history-section-head h3 {
    font-size: 16px;
}

.history-section-head span {
    font-size: 12px;
    color: rgba(22, 48, 71, 0.7);
}

.history-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
}

.history-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 9px 10px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.history-time {
    font-size: 12px;
    color: rgba(22, 48, 71, 0.66);
}

.history-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.history-summary {
    font-size: 13px;
    line-height: 1.45;
    color: rgba(22, 48, 71, 0.82);
    word-break: break-word;
}

.history-open-btn {
    align-self: flex-start;
}

.history-pagination {
    border-top: 1px solid var(--line);
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.history-page-btn {
    appearance: none;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    padding: 5px 10px;
    cursor: pointer;
}

.history-page-btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.history-page-text {
    font-size: 12px;
    color: rgba(22, 48, 71, 0.76);
    min-width: 58px;
    text-align: center;
}

.history-empty {
    font-size: 13px;
    color: rgba(22, 48, 71, 0.62);
    padding: 8px 4px;
}

.iframe-window {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
}

.play-window {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    margin: 0;
    flex: 1 1 auto;
}

.service-blocked {
    width: min(760px, 100%);
    margin: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
}

.service-blocked h3 {
    font-size: 20px;
}

.service-blocked p {
    font-size: 14px;
    color: rgba(23, 47, 68, 0.82);
    line-height: 1.5;
}

.main-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
    display: block;
}

.auth-mask {
    position: fixed;
    inset: 0;
    background: rgba(15, 26, 40, 0.46);
    display: grid;
    place-items: center;
    z-index: 120;
    padding: 8px;
}

.auth-modal {
    width: min(460px, 100%);
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 20px 40px rgba(14, 34, 56, 0.32);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.auth-modal-head h3 {
    font-size: 18px;
}

.close-btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    width: 28px;
    height: 28px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-form label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 13px;
    font-weight: 600;
}

.auth-form input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
    padding: 9px 10px;
    background: rgba(255, 255, 255, 0.94);
    color: var(--text);
}

.auth-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.confirm-btn,
.swap-btn {
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    padding: 8px 10px;
    cursor: pointer;
}

.confirm-btn {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

.swap-btn {
    color: var(--text);
    border-color: var(--line);
    background: rgba(255, 255, 255, 0.76);
}

.auth-error {
    font-size: 13px;
    color: #b43a4a;
}

@media (max-width: 980px) {
    .topbar {
        flex-wrap: wrap;
    }

    .menu {
        width: 100%;
    }

    .core-grid {
        grid-template-columns: 1fr;
    }

    .play-window {
        width: 100%;
    }

    .history-grid {
        grid-template-columns: 1fr;
    }

    .history-filter-field,
    .history-filter-field-keyword {
        min-width: 0;
        flex: 1 1 180px;
    }
}

@media (max-width: 640px) {
    .poster {
        min-height: 280px;
    }

    .poster h1 {
        font-size: 30px;
    }

    .poster p {
        font-size: 15px;
    }

    .poster-metrics {
        grid-template-columns: 1fr;
    }

    .brand {
        font-size: 20px;
    }

    .user-name {
        max-width: 96px;
    }

    .topbar {
        padding-top: calc(4px + var(--safe-top));
    }

    .main-region {
        padding-bottom: max(6px, var(--safe-bottom));
    }

    .window-view,
    .iframe-window {
        min-height: 0;
    }
}

body[data-static-layout="mobile-portrait"] .topbar {
    flex-wrap: wrap;
}

body[data-static-layout="mobile-portrait"] .menu {
    width: 100%;
}

body[data-static-layout="mobile-portrait"] .play-window {
    width: 100%;
}

body[data-static-layout="mobile-landscape"] .topbar {
    min-height: 44px;
    padding: calc(2px + var(--safe-top)) max(6px, var(--safe-right)) 2px max(6px, var(--safe-left));
    gap: 4px;
}

body[data-static-layout="mobile-landscape"] .brand {
    font-size: 20px;
}

body[data-static-layout="mobile-landscape"] .menu-btn,
body[data-static-layout="mobile-landscape"] .auth-btn,
body[data-static-layout="mobile-landscape"] .dropdown-item {
    font-size: 12px;
    padding: 6px 8px;
}

body[data-static-layout="mobile-landscape"] .main-region {
    padding: 4px max(4px, var(--safe-right)) max(4px, var(--safe-bottom)) max(4px, var(--safe-left));
}

body[data-static-layout="mobile-landscape"] .poster {
    min-height: 220px;
}

body[data-static-layout="mobile-landscape"] .poster h1 {
    font-size: clamp(22px, 4.2vw, 34px);
}

body[data-static-layout="mobile-landscape"] .poster p {
    font-size: 14px;
}

body[data-static-layout="mobile-landscape"] .home-view {
    gap: 6px;
}
