/**
 * 难度系统样式
 * 包含难度提升动画、难度进度卡片等
 * 特别优化了移动端适配
 */

/* ===== 难度提升模态框 ===== */
.difficulty-upgrade-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.difficulty-upgrade-modal.active {
    opacity: 1;
    visibility: visible;
    animation: screenFlash 0.5s ease;
}

/* 屏幕闪烁效果 */
@keyframes screenFlash {
    0%, 100% {
        background: rgba(0, 0, 0, 0.3);
    }
    25% {
        background: rgba(220, 38, 38, 0.3);
    }
    50% {
        background: rgba(220, 38, 38, 0.5);
    }
    75% {
        background: rgba(220, 38, 38, 0.3);
    }
}

/* 难度提升卡片 */
.difficulty-upgrade-card {
    background: rgba(220, 38, 38, 0.95);
    border: 3px solid #fbbf24;
    border-radius: 20px;
    padding: 40px;
    max-width: 500px;
    width: 85%;
    box-shadow: 0 0 60px rgba(220, 38, 38, 0.8),
                0 0 100px rgba(251, 191, 36, 0.5),
                inset 0 0 30px rgba(255, 255, 255, 0.1);
    text-align: center;
    animation: cardPopup 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    position: relative;
    overflow: hidden;
}

/* 卡片弹出动画 */
@keyframes cardPopup {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 卡片背景光效 */
.difficulty-upgrade-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg,
        transparent 30%,
        rgba(255, 255, 255, 0.1) 50%,
        transparent 70%);
    animation: shine 2s infinite;
}

@keyframes shine {
    0% {
        transform: rotate(0deg) translateX(-100%);
    }
    100% {
        transform: rotate(0deg) translateX(100%);
    }
}

/* 标题 */
.difficulty-upgrade-title {
    color: white;
    font-size: 32px;
    font-weight: bold;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5),
                 0 4px 8px rgba(0, 0, 0, 0.5);
    animation: titlePulse 1s ease-in-out infinite alternate;
}

@keyframes titlePulse {
    from {
        transform: scale(1);
    }
    to {
        transform: scale(1.05);
    }
}

/* 等级显示 */
.difficulty-upgrade-level {
    font-size: 48px;
    font-weight: bold;
    margin: 20px 0;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.8),
                 0 4px 12px rgba(0, 0, 0, 0.5);
    animation: levelBounce 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes levelBounce {
    0% {
        transform: scale(0) rotate(-180deg);
    }
    60% {
        transform: scale(1.2) rotate(10deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

/* 变化列表 */
.difficulty-upgrade-changes {
    margin: 25px 0;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.difficulty-change-item {
    color: white;
    font-size: 18px;
    margin: 12px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.difficulty-change-label {
    opacity: 0.9;
}

.difficulty-change-value {
    font-weight: bold;
    color: #fbbf24;
}

.difficulty-change-arrow {
    color: #fbbf24;
    font-size: 20px;
}

/* ===== 难度进度卡片（方案A） ===== */
/* 桌面端样式（默认） */
.difficulty-progress-card {
    position: fixed;
    top: 45px;  /* 增加top值，避免与header重叠 */
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;  /* 降低z-index，让header在上面 */
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 610px;
    max-width: calc(100% - 20px);
    background: var(--bg-card);
    padding: 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: all 0.3s ease;
}

.difficulty-progress-card:hover {
    transform: translateX(-50%) translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* 桌面端隐藏SVG环形进度条 */
.difficulty-progress-card svg {
    display: none;
}

/* 顶部信息栏 */
.difficulty-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0;
    gap: 12px;
    position: relative;  /* 确保不是绝对定位 */
}

.difficulty-card-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.difficulty-card-right {
    flex-shrink: 0;
}

.difficulty-indicator-icon {
    font-size: 24px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.difficulty-indicator-level {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.difficulty-indicator-bonus {
    font-size: 13px;
    color: var(--text-primary);
    background: var(--color-secondary-light);
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid var(--color-secondary);
    white-space: nowrap;
    font-weight: 500;
}

/* 进度条区域 */
.difficulty-card-progress {
    padding: 12px 0 0 0;
}

.difficulty-progress-bar-wrapper {
    width: 100%;
    height: 10px;
    background: var(--border-light);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 8px;
    position: relative;
    border: 1px solid var(--border-color);
}

.difficulty-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4ade80 0%, #22c55e 100%);
    border-radius: 8px;
    transition: width 1s linear, background 0.3s ease;
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.3);
    position: relative;
    overflow: hidden;
}

.difficulty-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: progressShine 2s infinite;
}

@keyframes progressShine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* 难度等级对应的进度条颜色 */
.difficulty-progress-bar.level-1 {
    background: linear-gradient(90deg, #4ade80 0%, #22c55e 100%);
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.5);
}

.difficulty-progress-bar.level-2 {
    background: linear-gradient(90deg, #fbbf24 0%, #f59e0b 100%);
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
}

.difficulty-progress-bar.level-3 {
    background: linear-gradient(90deg, #fb923c 0%, #f97316 100%);
    box-shadow: 0 0 10px rgba(251, 146, 60, 0.5);
}

.difficulty-progress-bar.level-4 {
    background: linear-gradient(90deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
}

.difficulty-progress-bar.level-5 {
    background: linear-gradient(90deg, #991b1b 0%, #7c2d12 100%);
    box-shadow: 0 0 10px rgba(153, 27, 27, 0.5);
}

.difficulty-progress-bar.level-6 {
    background: linear-gradient(90deg, #ffd700 0%, #ffa500 100%);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
}

.difficulty-countdown-text {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    transition: all 0.3s ease;
    font-weight: 500;
}

/* 警告状态（最后30秒） */
.difficulty-countdown-text.warning {
    color: #ff6b6b;
    font-weight: bold;
    animation: textPulse 1s ease-in-out infinite;
}

@keyframes textPulse {
    0%, 100% {
        transform: scale(1);
        text-shadow: 0 0 5px rgba(255, 107, 107, 0.3);
    }
    50% {
        transform: scale(1.05);
        text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    }
}

/* 最高难度状态 */
.difficulty-progress-card.max-level .difficulty-progress-bar-wrapper {
    background: rgba(255, 215, 0, 0.3);
}

.difficulty-progress-card.max-level .difficulty-countdown-text {
    color: #ffd700;
    font-weight: bold;
}

/* 弹跳动画（难度提升时） */
.difficulty-progress-card.bounce {
    animation: cardBounce 0.6s ease;
}

@keyframes cardBounce {
    0%, 100% {
        transform: translateX(-50%) scale(1);
    }
    25% {
        transform: translateX(-50%) scale(1.1);
    }
    50% {
        transform: translateX(-50%) scale(0.95);
    }
    75% {
        transform: translateX(-50%) scale(1.05);
    }
}

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
    /* 难度提升卡片 */
    .difficulty-upgrade-card {
        padding: 30px 20px;
        width: 90%;
        max-width: none;
        border-radius: 15px;
    }

    .difficulty-upgrade-title {
        font-size: 24px;
        margin-bottom: 15px;
    }

    .difficulty-upgrade-level {
        font-size: 36px;
        margin: 15px 0;
    }

    .difficulty-upgrade-changes {
        margin: 20px 0;
        padding: 15px;
    }

    .difficulty-change-item {
        font-size: 16px;
        margin: 10px 0;
        flex-wrap: wrap;
    }

    /* 【圆形UI方案】移动端难度卡片改为圆形悬浮按钮 */
    .difficulty-progress-card {
        position: fixed !important;
        top: 10px !important;  /* 顶部固定 */
        left: 50% !important;  /* 水平居中 */
        right: auto !important;
        transform: translateX(-50%) scale(0.7) !important;  /* 水平居中+缩放0.7 */
        width: 90px;
        height: 90px;
        padding: 0;
        margin: 0;
        background: rgba(255, 255, 255, 0.98);  /* 直接设置白色背景 */
        border: none;
        border-radius: 50%;  /* 圆形 */
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        z-index: 1000;
        cursor: pointer;
        transition: all 0.3s ease;
        overflow: visible;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);  /* 阴影移到这里 */
    }

    /* SVG环形进度条容器 */
    .difficulty-progress-card svg {
        display: block;  /* 移动端显示SVG */
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        transform: rotate(-90deg);  /* 从12点钟位置开始 */
        z-index: 1;  /* 在内容下方 */
        pointer-events: none;  /* 不阻挡点击 */
    }

    /* 环形进度条背景圆环（灰色） */
    .difficulty-progress-card .circle-bg {
        fill: none;
        stroke: #e5e7eb;
        stroke-width: 3;  /* 更细的环 */
    }

    /* 环形进度条前景圆环（彩色动态） */
    .difficulty-progress-card .circle-progress {
        fill: none;
        stroke: var(--progress-color, #4ade80);
        stroke-width: 3;  /* 与背景环同宽 */
        stroke-linecap: round;
        stroke-dasharray: 263.89;  /* 2 * PI * 42 = 263.89 */
        stroke-dashoffset: 0;
        transition: stroke-dashoffset 0.5s ease, stroke 0.3s ease;
    }

    .difficulty-progress-card:active {
        transform: translateX(-50%) scale(0.665) !important;  /* 0.7 * 0.95 = 0.665 */
    }

    /* 圆形内部布局 */
    .difficulty-card-header {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;  /* 两个文本之间的间距 */
        z-index: 2;  /* 确保内容在SVG上方 */
    }

    .difficulty-card-left {
        display: flex;
        flex-direction: column;
        gap: 0;
        align-items: center;
        justify-content: center;
    }

    .difficulty-card-right {
        display: flex;  /* 显示消除信息 */
        align-items: center;
        justify-content: center;
    }

    .difficulty-indicator-icon {
        display: none;  /* 隐藏代表难度等级的小圆形 */
    }

    .difficulty-indicator-level {
        font-size: 11px;  /* 放大字体 */
        font-weight: 700;
        text-align: center;
        line-height: 1.3;
        max-width: 70px;
        word-break: keep-all;
        color: var(--text-primary, #333);
    }

    .difficulty-indicator-bonus {
        display: block;  /* 显示消除奖励 */
        font-size: 10px;  /* 放大字体 */
        font-weight: 600;
        padding: 2px 6px;
        background: rgba(74, 222, 128, 0.2);
        border-radius: 6px;
        color: #16a34a;
        white-space: nowrap;
    }

    /* 隐藏原有的进度条区域 */
    .difficulty-card-progress {
        display: none;
    }
}

@media (max-width: 480px) {
    /* 小屏幕进一步优化 */
    .difficulty-upgrade-card {
        padding: 25px 15px;
        width: 95%;
        border-width: 2px;
    }

    .difficulty-upgrade-title {
        font-size: 20px;
        margin-bottom: 12px;
    }

    .difficulty-upgrade-level {
        font-size: 32px;
        margin: 12px 0;
    }

    .difficulty-upgrade-changes {
        margin: 15px 0;
        padding: 12px;
    }

    .difficulty-change-item {
        font-size: 14px;
        margin: 8px 0;
    }

    .difficulty-change-arrow {
        font-size: 16px;
    }

    /* 【圆形UI方案】小屏幕难度卡片 - 更小的圆形 */
    .difficulty-progress-card {
        position: fixed !important;
        top: -10px !important;  /* 顶部固定 */
        left: 50% !important;  /* 水平居中 */
        right: auto !important;
        transform: translateX(-50%) scale(0.7) !important;  /* 水平居中+缩放0.7 */
        width: 80px;
        height: 80px;
        padding: 0;
        margin: 0;
        background: rgba(255, 255, 255, 0.98);
        border: none;
        border-radius: 50%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        z-index: 1000;
        cursor: pointer;
        transition: all 0.3s ease;
        overflow: visible;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
    }

    /* SVG环形进度条 */
    .difficulty-progress-card svg {
        display: block;  /* 移动端显示SVG */
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        transform: rotate(-90deg);
        z-index: 1;
        pointer-events: none;
    }

    .difficulty-progress-card .circle-bg {
        fill: none;
        stroke: #e5e7eb;
        stroke-width: 3;  /* 更细的环 */
    }

    .difficulty-progress-card .circle-progress {
        fill: none;
        stroke: var(--progress-color, #4ade80);
        stroke-width: 3;  /* 与背景环同宽 */
        stroke-linecap: round;
        stroke-dasharray: 263.89;  /* 2 * PI * 42 */
        stroke-dashoffset: 0;
        transition: stroke-dashoffset 0.5s ease, stroke 0.3s ease;
    }

    .difficulty-progress-card:active {
        transform: translateX(-50%) scale(0.665) !important;  /* 0.7 * 0.95 = 0.665 */
    }

    .difficulty-card-header {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;  /* 两个文本之间的间距 */
        z-index: 2;
    }

    .difficulty-card-left {
        display: flex;
        flex-direction: column;
        gap: 0;
        align-items: center;
        justify-content: center;
    }

    .difficulty-card-right {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .difficulty-indicator-icon {
        display: none;  /* 隐藏代表难度等级的小圆形 */
    }

    .difficulty-indicator-level {
        font-size: 10px;  /* 放大字体 */
        font-weight: 700;
        text-align: center;
        line-height: 1.3;
        max-width: 60px;
        word-break: keep-all;
        color: var(--text-primary, #333);
    }

    .difficulty-indicator-bonus {
        display: block;
        font-size: 9px;  /* 放大字体 */
        font-weight: 600;
        padding: 2px 5px;
        background: rgba(74, 222, 128, 0.2);
        border-radius: 5px;
        color: #16a34a;
        white-space: nowrap;
    }

    .difficulty-card-progress {
        display: none;
    }
}

/* ===== 横屏模式适配 ===== */
@media (max-height: 500px) and (orientation: landscape) {
    .difficulty-upgrade-card {
        padding: 20px 25px;
        max-height: 85vh;
        overflow-y: auto;
    }

    .difficulty-upgrade-title {
        font-size: 20px;
        margin-bottom: 10px;
    }

    .difficulty-upgrade-level {
        font-size: 28px;
        margin: 10px 0;
    }

    .difficulty-upgrade-changes {
        margin: 15px 0;
        padding: 10px;
    }

    .difficulty-change-item {
        font-size: 14px;
        margin: 6px 0;
    }

    .difficulty-progress-card {
        top: 10px;
        width: auto;  /* 横屏自适应 */
        min-width: 400px;
        max-width: calc(100% - 20px);
        padding: 5px;
    }

    .difficulty-card-header {
        gap: 8px;
    }

    .difficulty-card-progress {
        padding: 4px 0 0 0;
    }
}

/* ===== 高清屏优化 ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .difficulty-upgrade-card {
        border-width: 2px;
    }
}

/* ===== 暗黑模式支持 ===== */
@media (prefers-color-scheme: dark) {
    /* 暗黑模式下保持和 header 一致的样式，不做额外修改 */
}

/* ===== 减少动画（用户偏好） ===== */
@media (prefers-reduced-motion: reduce) {
    .difficulty-upgrade-modal,
    .difficulty-upgrade-card,
    .difficulty-upgrade-title,
    .difficulty-upgrade-level,
    .difficulty-progress-card {
        animation: none;
        transition: none;
    }

    .difficulty-upgrade-card::before {
        display: none;
    }
}

/* ===== 触摸优化 ===== */
@media (hover: none) and (pointer: coarse) {
    .difficulty-progress-card:hover {
        transform: translateX(-50%);
    }

    .difficulty-progress-card:active {
        transform: translateX(-50%) scale(0.98);
    }
}
