/**
 * UserAvatar 前台样式
 * 包含: 顶栏用户区、下拉、头像弹窗、裁剪画布
 */

/* ---------- 顶栏用户区 ---------- */
.user-menu {
    position: relative;
    display: flex;
    align-items: center;
}

.user-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px 4px 6px;
    background: transparent;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: background .2s ease;
}

.user-trigger:hover {
    background: var(--btn-secondary-bg, #f3f3f3);
}

.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    background: #1A1A1A;
    flex: none;
}

.user-name {
    font-size: 14px;
    color: var(--color-text, #222);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 70;
    min-width: 150px;
    padding: 6px 0;
    /* 与导航二级菜单同一套黑色半透明 */
    background: rgba(17, 17, 17, .92);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .08);
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
}

.user-menu:hover .user-dropdown,
.user-menu:focus-within .user-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown a {
    display: block;
    padding: 8px 16px;
    font-size: 14px;
    color: rgba(255, 255, 255, .78);
    white-space: nowrap;
}

.user-dropdown a:hover {
    background: #2E2E2E;
    color: #fff;
}

.ua-login-error {
    margin-top: 8px;
    font-size: 13px;
    color: #d33;
}

/* ---------- 头像弹窗 ---------- */
.ua-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
}

.ua-modal.is-open {
    display: block;
}

.ua-mask {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .45);
}

.ua-panel {
    position: relative;
    width: min(420px, 92vw);
    margin: 8vh auto 0;
    padding: 22px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .2);
    box-sizing: border-box;
}

.ua-title {
    margin: 0 0 14px;
    font-size: 17px;
    font-weight: 600;
}

.ua-stage {
    position: relative;
    width: 100%;
    max-width: 300px;
    margin: 0 auto 14px;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    overflow: hidden;
    background: #141414;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.ua-stage.is-dragging {
    cursor: grabbing;
}

.ua-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: inherit;
}

/* 裁剪框：白色实线 + 三分构图线，框外压暗；位置尺寸由 JS 按拖动结果写入 */
.ua-crop {
    position: absolute;
    left: 0;
    top: 0;
    border: 1px solid rgba(255, 255, 255, .95);
    /* 主题的「全站直角/无投影」用 *{box-shadow:none!important} 收口，这里必须 !important 才能压住 */
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .35), 0 0 0 9999px rgba(0, 0, 0, .55) !important;
    background-image:
        linear-gradient(to right, rgba(255, 255, 255, .24) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, .24) 1px, transparent 1px);
    background-size: 33.3334% 33.3334%;
    background-position: -1px -1px;
    pointer-events: none;
}

.ua-crop[hidden] {
    display: none;
}

/* 四角拖拽手柄：拖动改变取景框大小 */
.ua-crop-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #fff;
    border: 1px solid #111;
    pointer-events: auto;
    touch-action: none;
    cursor: nwse-resize;
}

.ua-crop-handle[data-corner="nw"] {
    left: -7px;
    top: -7px;
}

.ua-crop-handle[data-corner="ne"] {
    right: -7px;
    top: -7px;
    cursor: nesw-resize;
}

.ua-crop-handle[data-corner="sw"] {
    left: -7px;
    bottom: -7px;
    cursor: nesw-resize;
}

.ua-crop-handle[data-corner="se"] {
    right: -7px;
    bottom: -7px;
}

/* 拖框时整块舞台都换成缩放光标，避免鼠标穿过手柄后光标跳变 */
.ua-stage.is-resizing,
.ua-stage.is-resizing .ua-canvas {
    cursor: nwse-resize;
}

.ua-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #999;
    pointer-events: none;
}

.ua-tools {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 6px;
}

.ua-file {
    display: block;
    flex: none;
    text-align: center;
}

.ua-file span {
    display: inline-block;
    padding: 7px 16px;
    font-size: 13px;
    color: #333;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
}

.ua-file span:hover {
    background: #f7f7f7;
}

.ua-zoom {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 10px;
    min-width: 0;
    margin: 0;
    font-size: 12px;
    color: #888;
}

.ua-zoom input {
    flex: 1;
    min-width: 0;
}

.ua-tip {
    min-height: 18px;
    font-size: 12px;
    color: #666;
    text-align: center;
}

.ua-tip.is-error {
    color: #d33;
}

.ua-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.ua-spacer {
    flex: 1;
}

.ua-btn {
    padding: 7px 14px;
    font-size: 13px;
    color: #333;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
}

.ua-btn:hover {
    background: #f7f7f7;
}

.ua-btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.ua-primary {
    color: #fff;
    background: #111;
    border-color: #111;
}

.ua-primary:hover {
    background: #333;
}

/* ---------- 预设头像网格（注册页 / 个人中心共用） ---------- */
.ua-presets {
    margin: 0 0 18px;
}

.ua-presets.is-empty {
    display: none;
}

.ua-presets-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.ua-presets-title {
    font-size: 12px;
    color: var(--color-text-secondary, #888);
}

.ua-presets-random {
    padding: 0;
    font-size: 12px;
    color: var(--color-text, #1a1a1a);
    background: none;
    border: 0;
    border-bottom: 1px solid currentColor;
    cursor: pointer;
    transition: opacity var(--transition, .2s ease);
}

.ua-presets-random:hover {
    opacity: .6;
}

.ua-presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 6px;
    max-height: 168px;
    padding: 2px;
    overflow-y: auto;
    border: 1px solid var(--color-border, #e5e5e5);
    border-radius: var(--radius, 0);
    overscroll-behavior: contain;
}

.ua-preset {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    padding: 0;
    overflow: hidden;
    background: #f4f4f4;
    border: 2px solid transparent;
    border-radius: 0;
    cursor: pointer;
    transition: border-color var(--transition, .2s ease);
}

.ua-preset img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ua-preset:hover {
    border-color: #999;
}

.ua-preset.is-active {
    border-color: #111;
}

@media (max-width: 768px) {
    .user-name { display: none; }
    .ua-panel { margin-top: 12vh; padding: 16px; }
}
