/**
 * xfCaptcha - 滑动验证码样式表
 *
 * @package     zxf/captcha
 * @license     MIT
 * @version     1.0.0
 */

/* ============================================
   CSS 变量定义 - 支持主题切换
   ============================================ */

:root {
    /* 浅色主题 (默认) */
    --xf-captcha-bg: #ffffff;
    --xf-captcha-text: #303133;
    --xf-captcha-border: #dcdfe6;
    --xf-captcha-shadow: rgba(0, 0, 0, 0.12);
    --xf-captcha-slide-bg: linear-gradient(135deg, #f5f7fa 0%, #e4e7ed 100%);
    --xf-captcha-slide-border: #c0c4cc;
    --xf-captcha-tools-border: #ebeef5;
    --xf-captcha-loading-bg: linear-gradient(135deg, #f5f7fa 0%, #e4e7ed 100%);
    --xf-captcha-msg-error-bg: #ff4d4f;
    --xf-captcha-msg-error-text: #ffffff;
    --xf-captcha-msg-error-border: #ff4d4f;
    --xf-captcha-msg-ok-bg: #52c41a;
    --xf-captcha-msg-ok-text: #ffffff;
    --xf-captcha-msg-ok-border: #52c41a;
    --xf-captcha-copyright: #909399;
    --xf-captcha-mask: rgba(0, 0, 0, 0.45);
}

/* 深色主题 */
[data-theme="dark"] {
    --xf-captcha-bg: #1f1f1f;
    --xf-captcha-text: #e0e0e0;
    --xf-captcha-border: #434343;
    --xf-captcha-shadow: rgba(0, 0, 0, 0.5);
    --xf-captcha-slide-bg: linear-gradient(135deg, #2d2d2d 0%, #262626 100%);
    --xf-captcha-slide-border: #555555;
    --xf-captcha-tools-border: #333333;
    --xf-captcha-loading-bg: linear-gradient(135deg, #2d2d2d 0%, #262626 100%);
    --xf-captcha-msg-error-bg: #ff4d4f;
    --xf-captcha-msg-error-text: #ffffff;
    --xf-captcha-msg-error-border: #ff4d4f;
    --xf-captcha-msg-ok-bg: #52c41a;
    --xf-captcha-msg-ok-text: #ffffff;
    --xf-captcha-msg-ok-border: #52c41a;
    --xf-captcha-copyright: #737373;
    --xf-captcha-mask: rgba(0, 0, 0, 0.65);
}

/* ============================================
   触发按钮样式
   ============================================ */

/* 基础按钮样式 */
.xf-captcha {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 260px;
    height: 42px;
    border: 1px solid var(--xf-captcha-border);
    border-radius: 8px;
    background: var(--xf-captcha-slide-bg);
    color: var(--xf-captcha-text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
    user-select: none;
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 4px var(--xf-captcha-shadow);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    letter-spacing: 0.3px;
}

.xf-captcha:hover {
    border-color: #409eff;
    color: #409eff;
    background: linear-gradient(135deg, #ecf5ff 0%, #d9ecff 100%);
    box-shadow: 0 2px 8px rgba(64, 158, 255, 0.25);
    transform: translateY(-1px);
}

.xf-captcha:active {
    transform: translateY(0);
}

.xf-captcha.verified {
    background: linear-gradient(135deg, #67c23a 0%, #85ce61 100%);
    border-color: #67c23a;
    color: #fff;
}

/* 深色主题下按钮样式调整 */
[data-theme="dark"] .xf-captcha:hover {
    background: linear-gradient(135deg, #1a3a5a 0%, #0a2a4a 100%);
}

/* ============================================
   水波纹动画效果
   ============================================ */

.captcha_ripple {
    position: relative;
    overflow: hidden;
}

.captcha_ripple::before,
.captcha_ripple::after {
    content: '';
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background-color: #1ab394;
    border-radius: 50%;
    pointer-events: none;
    box-shadow: 0 0 12px rgba(26, 179, 148, 0.5);
}

.captcha_ripple::before {
    animation: captcha-ripple 2s ease-out infinite;
}

.captcha_ripple::after {
    animation: captcha-ripple 2s ease-out infinite 0.5s;
}

@keyframes captcha-ripple {
    0% {
        transform: translateY(-50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(-50%) scale(5);
        opacity: 0;
    }
}

/* 验证通过后停止水波纹 */
.xf-captcha.verified::before,
.xf-captcha.verified::after {
    display: none;
}

/* ============================================
   遮罩层和弹窗
   ============================================ */

/* 背景遮罩 */
.captcha_div_bg {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--xf-captcha-mask);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 9998;
    animation: captcha-fade-in 0.25s ease;
    touch-action: none;
}

/* 验证码弹窗 */
.captcha_div {
    display: none;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 260px;
    padding: 8px;
    background: var(--xf-captcha-bg);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    animation: captcha-scale-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    border: 1px solid var(--xf-captcha-border);
}

/* 弹窗入场动画 */
@keyframes captcha-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes captcha-scale-in {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.85);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* 抖动动画 */
.captcha_shake {
    animation: captcha-shake 0.4s ease-in-out;
}

@keyframes captcha-shake {
    0%, 100% { transform: translate(-50%, -50%) translateX(0); }
    20%, 60% { transform: translate(-50%, -50%) translateX(-4px); }
    40%, 80% { transform: translate(-50%, -50%) translateX(4px); }
}

/* ============================================
   Canvas 画布
   ============================================ */

.captcha_div canvas {
    display: block;
    width: 244px;
    height: 152px;
    margin: 0 auto;
    border-radius: 6px;
    box-sizing: border-box;
    border: 2px solid transparent;
    transition: border-color 0.2s ease;
    touch-action: none;
}

.captcha_div:hover canvas {
    border-color: var(--xf-captcha-border);
}

.captcha_canvas_bg {
    position: relative;
    z-index: 1;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.captcha_canvas_mark {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    pointer-events: none;
    border-radius: 6px;
}

/* ============================================
   加载提示
   ============================================ */

.captcha_loading {
    position: relative;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 240px;
    height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--xf-captcha-bg);
    color: var(--xf-captcha-text);
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    z-index: 10;
    gap: 10px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.05);
}

.captcha_loading::before {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid var(--xf-captcha-border);
    border-top-color: #409eff;
    border-radius: 50%;
    animation: captcha-spin 0.8s linear infinite;
}

.captcha_loading::after {
    content: '加载中...';
    font-size: 13px;
    color: var(--xf-captcha-text);
    letter-spacing: 1px;
}

.captcha_loading_error::before,
.captcha_loading_error::after {
    display: none !important;
}

@keyframes captcha-spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   高亮光效 - 仅成功时显示
   ============================================ */

.captcha_hlight {
    display: none;
    position: absolute;
    top: 8px;
    left: 8px;
    width: 244px;
    height: 152px;
    overflow: hidden;
    pointer-events: none;
    z-index: 10;
    border-radius: 6px;
}

.captcha_hlight::before {
    content: '';
    position: absolute;
    top: 0;
    left: -50px;
    width: 30px;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.8),
        transparent
    );
    transform: skewX(-20deg);
}

/* 成功特效 */
.captcha_success_effect::before {
    animation: captcha-success-hlight 1s ease-out forwards;
}

@keyframes captcha-success-hlight {
    0% { left: -50px; opacity: 1; }
    100% { left: 270px; opacity: 0; }
}

/* ============================================
   消息提示 - 增强移动端可见性
   ============================================ */

.captcha_msg_error,
.captcha_msg_ok {
    position: absolute;
    top: 130px;
    left: 10px;
    right: 8px;
    height: 28px;
    line-height: 28px;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.25s ease;
    z-index: 10;
    box-sizing: border-box;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.captcha_msg_error {
    background-color: #ff4d4f;
    color: #ffffff;
    border: 1px solid #ff4d4f;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    font-weight: 600;
}

.captcha_msg_ok {
    background-color: #52c41a;
    color: #ffffff;
    border: 1px solid #52c41a;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    font-weight: 600;
}

/* 移动端增强 */
@media (pointer: coarse) {
    .captcha_msg_error,
    .captcha_msg_ok {
        font-size: 13px;
        font-weight: 700;
        height: 32px;
        line-height: 32px;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
    }
}

/* ============================================
   滑动条区域
   ============================================ */

.captcha_slide {
    position: relative;
    width: 244px;
    height: 38px;
    margin: 10px auto 6px;
    background: var(--xf-captcha-slide-bg);
    border-radius: 19px;
    border: 1px solid var(--xf-captcha-slide-border);
    overflow: visible;
    box-sizing: border-box;
    touch-action: none;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* 滑块 */
.captcha_slide_block {
    position: absolute;
    left: 0;
    top: 0;
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #1890ff 0%, #40a9ff 100%);
    border-radius: 19px;
    cursor: grab;
    box-shadow: 0 3px 8px rgba(24, 144, 255, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transition: box-shadow 0.2s ease, transform 0.08s linear;
    z-index: 2;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.captcha_slide_block::before {
    content: '››';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    letter-spacing: -1px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.captcha_slide_block:hover {
    box-shadow: 0 5px 15px rgba(24, 144, 255, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.captcha_slide_block:active,
.captcha_slide_block.dragging {
    cursor: grabbing;
    box-shadow: 0 8px 20px rgba(24, 144, 255, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

/* 滑块提示文字 */
.captcha_slide_text {
    position: absolute;
    left: 46px;
    right: 10px;
    top: 0;
    height: 38px;
    line-height: 38px;
    text-align: center;
    font-size: 12px;
    color: var(--xf-captcha-text);
    user-select: none;
    z-index: 1;
    opacity: 0.85;
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* ============================================
   工具栏
   ============================================ */

.captcha_tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-top: 1px solid var(--xf-captcha-tools-border);
    margin-top: 6px;
    min-height: 28px;
}

/* 版权链接 */
.captcha_copyright {
    font-size: 13px;
    color: var(--xf-captcha-copyright);
    user-select: none;
    cursor: pointer;
    text-decoration: none;
    padding: 2px 6px;
    border-radius: 3px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

/* 版权符号由 JS 控制，避免重复 */

.captcha_copyright:hover {
    color: #409eff;
    background: rgba(64, 158, 255, 0.1);
}

.captcha_copyright:active {
    transform: scale(0.95);
}

/* 工具按钮容器 */
.captcha_tools_actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.captcha_close,
.captcha_refresh {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 18px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

/* 关闭按钮 */
.captcha_close {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23909999'%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3C/svg%3E");
}

/* 刷新按钮 */
.captcha_refresh {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23909999'%3E%3Cpath d='M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z'/%3E%3C/svg%3E");
}

/* ============================================
   隐藏输入框
   ============================================ */

.captcha_hidden_input {
    display: none !important;
}

/* ============================================
   响应式设计
   ============================================ */

@media screen and (max-width: 360px) {
    .captcha_div {
        width: 240px;
        padding: 6px;
    }

    .captcha_div canvas {
        width: 228px;
        height: 142px;
    }

    .captcha_slide {
        width: 228px;
    }
}

/* ============================================
   深色模式媒体查询支持
   ============================================ */

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --xf-captcha-bg: #1a1a2e;
        --xf-captcha-text: #e0e0e0;
        --xf-captcha-border: #4a4a6a;
        --xf-captcha-shadow: rgba(0, 0, 0, 0.4);
        --xf-captcha-slide-bg: linear-gradient(135deg, #2d2d44 0%, #252538 100%);
        --xf-captcha-slide-border: #4a4a6a;
        --xf-captcha-tools-border: #3a3a5a;
        --xf-captcha-loading-bg: linear-gradient(135deg, #2d2d44 0%, #252538 100%);
        --xf-captcha-msg-error-bg: rgba(245, 108, 108, 0.25);
        --xf-captcha-msg-error-text: #ff8585;
        --xf-captcha-msg-error-border: rgba(245, 108, 108, 0.4);
        --xf-captcha-msg-ok-bg: rgba(103, 194, 58, 0.25);
        --xf-captcha-msg-ok-text: #95d475;
        --xf-captcha-msg-ok-border: rgba(103, 194, 58, 0.4);
        --xf-captcha-copyright: #6a6a8a;
        --xf-captcha-mask: rgba(0, 0, 0, 0.7);
    }
}
