/* ========================================
   新音抽奖兑换系统 - 全局样式
   深紫渐变主题，移动端优先
   ======================================== */

:root {
    --bg-dark: #1a0d2e;
    --bg-card: rgba(255, 255, 255, 0.06);
    --bg-card-hover: rgba(255, 255, 255, 0.1);
    --purple-primary: #7b4cff;
    --purple-light: #c46fff;
    --gold: #ffd700;
    --gold-dark: #e6a800;
    --text-white: #ffffff;
    --text-gray: rgba(255, 255, 255, 0.6);
    --text-muted: rgba(255, 255, 255, 0.4);
    --border-radius: 14px;
    --gradient-purple: linear-gradient(135deg, #7b4cff, #c46fff);
    --gradient-gold: linear-gradient(135deg, #ffd700, #ffaa00);
    --gradient-bg: linear-gradient(180deg, #1a0d2e 0%, #2d1b4e 50%, #1a0d2e 100%);
    --shadow-glow: 0 0 20px rgba(123, 76, 255, 0.3);
    --shadow-gold: 0 0 30px rgba(255, 215, 0, 0.4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg-dark);
    color: var(--text-white);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    user-select: none;
}

input, button, textarea {
    font-family: inherit;
    -webkit-appearance: none;
    outline: none;
}

a { text-decoration: none; color: inherit; }
img { display: block; max-width: 100%; }

/* ============ 通用组件 ============ */
.page-bg {
    min-height: 100vh;
    background: var(--gradient-bg);
    position: relative;
}

.page-bg::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background:
        radial-gradient(circle at 20% 10%, rgba(123, 76, 255, 0.15), transparent 40%),
        radial-gradient(circle at 80% 60%, rgba(196, 111, 255, 0.1), transparent 40%);
    pointer-events: none;
    z-index: 0;
}

/* 顶部导航 */
.nav-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(26, 13, 46, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.nav-bar .nav-left,
.nav-bar .nav-right {
    width: 32px;
    display: flex;
    align-items: center;
}

.nav-bar .nav-title {
    text-align: center;
    flex: 1;
    font-size: 18px;
    font-weight: 600;
}

.nav-bar .nav-title .subtitle {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.back-btn, .nav-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: background 0.2s;
}

.back-btn:active, .nav-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.back-btn svg, .nav-btn svg {
    width: 18px;
    height: 18px;
    fill: var(--text-white);
}

/* 卡片 */
.card {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--border-radius);
    padding: 16px;
}

/* 按钮 */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    background: var(--gradient-purple);
    color: var(--text-white);
    border: none;
    border-radius: 22px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:active {
    transform: scale(0.97);
    opacity: 0.85;
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-gold {
    background: var(--gradient-gold);
    color: #4a3000;
}

.btn-outline {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-white);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
    border-radius: 16px;
}

/* ============ 抽奖弹窗 ============ */
.lottery-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(10, 5, 20, 0.92);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.lottery-popup {
    width: 100%;
    max-width: 360px;
    background: linear-gradient(180deg, #2d1b4e, #1a0d2e);
    border-radius: 24px;
    padding: 24px 20px 20px;
    position: relative;
    box-shadow: 0 0 60px rgba(123, 76, 255, 0.3);
    animation: popIn 0.3s ease;
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* 抽奖弹窗顶部 */
.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.popup-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-gray);
    font-size: 22px;
    line-height: 1;
}

.popup-more {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-gray);
    font-size: 20px;
    letter-spacing: 1px;
}

.popup-title {
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

/* 中奖播报条 */
.broadcast-bar {
    text-align: center;
    padding: 6px 0;
    font-size: 13px;
    color: var(--gold);
    min-height: 24px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* 抽奖核心区 */
.lottery-core {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
}

.cube-container {
    width: 200px;
    height: 200px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.cube-glow {
    position: absolute;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.3) 0%, transparent 70%);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.15); opacity: 1; }
}

.cube-body {
    width: 160px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.15s;
}

.cube-body:active {
    transform: scale(0.95);
}

/* 2D等距视角魔方 - 用伪元素模拟三个面 */
.cube-magic {
    width: 130px;
    height: 130px;
    position: relative;
}

/* 正面：3x3格子 */
.cube-magic .face-front {
    position: absolute;
    width: 120px;
    height: 120px;
    left: 5px;
    top: 10px;
    background: linear-gradient(135deg, #ffd700, #ff9500);
    border-radius: 8px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 3px;
    padding: 5px;
    box-shadow:
        inset 0 0 12px rgba(180, 90, 0, 0.25),
        0 4px 8px rgba(0, 0, 0, 0.3);
    z-index: 2;
}

.cube-magic .face-top {
    position: absolute;
    width: 120px;
    height: 16px;
    left: 5px;
    top: -6px;
    background: linear-gradient(180deg, #fff0a0, #ffd700);
    border-radius: 8px 8px 0 0;
    transform: skewX(-50deg);
    transform-origin: bottom left;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
    padding: 2px 5px;
    z-index: 1;
}

.cube-magic .face-right {
    position: absolute;
    width: 16px;
    height: 120px;
    right: -11px;
    top: 10px;
    background: linear-gradient(90deg, #cc7a00, #995500);
    border-radius: 0 8px 8px 0;
    transform: skewY(-50deg);
    transform-origin: top left;
    display: grid;
    grid-template-rows: repeat(3, 1fr);
    gap: 3px;
    padding: 5px 2px;
    z-index: 1;
}

/* 魔方格子 */
.cube-magic .cell {
    background: linear-gradient(135deg, #ffe680, #ffa500);
    border-radius: 4px;
    box-shadow:
        inset 0 1px 2px rgba(255, 255, 255, 0.4),
        inset 0 -1px 2px rgba(0, 0, 0, 0.12);
}

.cube-magic .face-top .cell {
    background: linear-gradient(135deg, #fff5b0, #ffc233);
}

.cube-magic .face-right .cell {
    background: linear-gradient(135deg, #e6a010, #b07800);
}

/* 抽奖旋转动画 */
.cube-body.spinning .cube-magic {
    animation: spinCube 0.8s linear infinite;
}

@keyframes spinCube {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.cube-text {
    position: absolute;
    z-index: 10;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

.lottery-cost {
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-gray);
}

.lottery-cost .highlight {
    color: var(--gold);
    font-weight: 600;
}

/* 抽奖底部操作区 */
.lottery-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.item-count {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-gray);
}

.item-icon {
    width: 28px;
    height: 28px;
    background: var(--gradient-purple);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.item-add {
    width: 22px;
    height: 22px;
    background: var(--gradient-gold);
    color: #4a3000;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
}

.btn-auto {
    padding: 8px 18px;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-white);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 18px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-auto:active {
    background: rgba(255, 255, 255, 0.2);
}

/* 碎片兑换入口浮动 */
.fragment-entry {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 8px;
    background: rgba(123, 76, 255, 0.15);
    border: 1px solid rgba(123, 76, 255, 0.3);
    border-radius: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.fragment-entry:active {
    background: rgba(123, 76, 255, 0.3);
}

.fragment-icon {
    width: 36px;
    height: 36px;
    background: var(--gradient-purple);
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.fragment-count {
    font-size: 11px;
    color: var(--gold);
    white-space: nowrap;
}

.fragment-label {
    font-size: 10px;
    color: var(--text-gray);
}

/* ============ 抽奖结果弹窗 ============ */
.result-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.result-popup {
    text-align: center;
    animation: bounceIn 0.5s ease;
}

@keyframes bounceIn {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.result-prize-icon {
    width: 120px;
    height: 120px;
    margin: 0 auto 16px;
    border-radius: 20px;
    background: var(--gradient-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    box-shadow: var(--shadow-gold);
}

.result-prize-name {
    font-size: 24px;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: 8px;
}

.result-prize-desc {
    font-size: 14px;
    color: var(--text-gray);
    margin-bottom: 24px;
}

.result-close {
    margin-top: 8px;
    padding: 10px 40px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-gray);
    border: none;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
}

/* ============ 碎片兑换页面 ============ */
.balance-card {
    margin: 16px;
    padding: 24px 20px;
    text-align: center;
    background: linear-gradient(135deg, rgba(123, 76, 255, 0.15), rgba(196, 111, 255, 0.08));
    border: 1px solid rgba(123, 76, 255, 0.2);
    border-radius: var(--border-radius);
}

.balance-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 10px;
    background: var(--gradient-purple);
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-glow);
}

.balance-number {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-white);
}

.balance-label {
    font-size: 13px;
    color: var(--text-gray);
    margin-top: 4px;
}

/* 兑换商品网格 */
.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    margin: 20px 0 12px;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
}

.section-help {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
}

.exchange-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 0 16px 24px;
}

.exchange-card {
    background: linear-gradient(180deg, rgba(45, 27, 78, 0.8), rgba(26, 13, 46, 0.8));
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    padding: 14px 8px 12px;
    text-align: center;
    transition: transform 0.2s;
}

.exchange-card:active {
    transform: scale(0.96);
}

.gift-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 8px;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(123, 76, 255, 0.2), rgba(196, 111, 255, 0.1));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.gift-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.gift-value {
    font-size: 11px;
    color: var(--gold);
    margin-bottom: 8px;
}

.gift-badge {
    display: inline-block;
    padding: 1px 6px;
    font-size: 9px;
    background: rgba(255, 215, 0, 0.15);
    color: var(--gold);
    border-radius: 4px;
    margin-bottom: 6px;
}

.btn-exchange {
    width: 100%;
    padding: 6px 0;
    background: var(--gradient-purple);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.btn-exchange.pool {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-gray);
}

.btn-exchange:active {
    transform: scale(0.95);
}

.btn-exchange:disabled {
    opacity: 0.4;
}

/* ============ 记录页面 ============ */
.tabs {
    display: flex;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(26, 13, 46, 0.6);
    position: sticky;
    top: 0;
    z-index: 50;
}

.tab {
    flex: 1;
    text-align: center;
    padding: 14px 0;
    font-size: 14px;
    color: var(--text-gray);
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
}

.tab.active {
    color: var(--text-white);
    font-weight: 600;
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 2px;
    background: var(--purple-light);
    border-radius: 1px;
}

.record-list {
    padding: 12px 16px;
}

.record-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    margin-bottom: 8px;
    background: var(--bg-card);
    border-radius: 12px;
}

.record-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--gradient-purple);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.record-info {
    flex: 1;
    min-width: 0;
}

.record-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.record-time {
    font-size: 12px;
    color: var(--text-muted);
}

.record-value {
    text-align: right;
    flex-shrink: 0;
}

.record-value.plus { color: #4ade80; }
.record-value.minus { color: #f87171; }

.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

/* ============ 底部导航 ============ */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    display: flex;
    background: rgba(26, 13, 46, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 0;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    transition: color 0.2s;
}

.bottom-nav-item.active {
    color: var(--purple-light);
}

.bottom-nav-item svg {
    width: 22px;
    height: 22px;
}

/* ============ 登录注册 ============ */
.auth-page {
    min-height: 100vh;
    background: var(--gradient-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
    background: var(--gradient-purple);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    box-shadow: var(--shadow-glow);
}

.auth-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
    background: var(--gradient-purple);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-subtitle {
    font-size: 14px;
    color: var(--text-gray);
    margin-bottom: 30px;
}

.auth-form {
    width: 100%;
    max-width: 340px;
}

.input-group {
    margin-bottom: 14px;
}

.input-group label {
    display: block;
    font-size: 13px;
    color: var(--text-gray);
    margin-bottom: 6px;
}

.input-group input {
    width: 100%;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--text-white);
    font-size: 15px;
    transition: border-color 0.2s;
}

.input-group input:focus {
    border-color: var(--purple-primary);
}

.auth-btn {
    width: 100%;
    padding: 14px;
    background: var(--gradient-purple);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 6px;
    transition: opacity 0.2s;
}

.auth-btn:active { opacity: 0.85; }
.auth-btn:disabled { opacity: 0.4; }

.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-gray);
}

.auth-switch a {
    color: var(--purple-light);
    font-weight: 600;
}

/* ============ Toast ============ */
.toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 16px 24px;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 12px;
    color: #fff;
    font-size: 14px;
    z-index: 9999;
    max-width: 80%;
    text-align: center;
    animation: toastShow 0.2s;
}

@keyframes toastShow {
    from { opacity: 0; transform: translate(-50%, -40%); }
    to { opacity: 1; transform: translate(-50%, -50%); }
}

/* ============ 加载 ============ */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(123, 76, 255, 0.2);
    border-top-color: var(--purple-light);
    border-radius: 50%;
    animation: spin360 0.8s linear infinite;
}

@keyframes spin360 {
    to { transform: rotate(360deg); }
}

/* ============ 奖池预览 ============ */
.pool-preview {
    padding: 16px;
}

.pool-prize-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    margin-bottom: 8px;
    background: var(--bg-card);
    border-radius: 12px;
}

.pool-prize-rank {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.pool-prize-rank.r1 { background: linear-gradient(135deg, #ffd700, #ff9500); color: #4a3000; }
.pool-prize-rank.r2 { background: linear-gradient(135deg, #c0c0c0, #808080); color: #333; }
.pool-prize-rank.r3 { background: linear-gradient(135deg, #cd7f32, #8b4513); color: #fff; }
.pool-prize-rank.r4 { background: rgba(255, 255, 255, 0.1); color: var(--text-gray); }

.pool-prize-prob {
    text-align: right;
    flex-shrink: 0;
    font-size: 12px;
    color: var(--gold);
}

/* 响应式微调 */
@media (max-width: 360px) {
    .exchange-grid { grid-template-columns: repeat(2, 1fr); }
    .cube-container { width: 180px; height: 180px; }
    .cube-body { width: 140px; height: 140px; }
}
