.avatar-preview-button {
    display: inline-flex;
    width: 72px;
    height: 72px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--surface-muted);
    cursor: zoom-in;
}

.avatar-preview-button:hover {
    border-color: var(--accent);
    background: var(--surface-muted);
}

.avatar-preview-button:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

.avatar-preview-button .avatar {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    object-fit: cover;
}

.avatar-file-control {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 10px;
}

.avatar-file-control .avatar-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    min-height: 0;
    overflow: hidden;
    margin: -1px;
    padding: 0;
    border: 0;
    clip-path: inset(50%);
    white-space: nowrap;
}

.avatar-file-button {
    display: inline-flex;
    height: 36px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
}

.avatar-file-button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.avatar-file-input:focus-visible + .avatar-file-button {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.avatar-file-input:disabled + .avatar-file-button {
    cursor: not-allowed;
    opacity: 0.7;
}

.avatar-file-status {
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    font-weight: 400;
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.avatar-file-status.is-pending {
    color: var(--accent);
}

.avatar-file-status.is-selected {
    color: var(--success);
}

.avatar-crop-dialog {
    width: min(680px, calc(100% - 32px));
    max-height: calc(100dvh - 32px);
    overflow: auto;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
}

.avatar-crop-dialog::backdrop {
    background: rgba(23, 33, 43, 0.48);
}

.avatar-crop-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}

.avatar-crop-header h2 {
    margin: 0;
    font-size: 17px;
    font-weight: 650;
    letter-spacing: 0;
}

.avatar-crop-header p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.avatar-crop-close {
    width: 32px;
    min-height: 32px;
    flex: 0 0 auto;
    padding: 0;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
}

.avatar-crop-close:hover {
    border-color: var(--line);
    background: var(--bg);
    color: var(--text);
}

.avatar-crop-stage {
    position: relative;
    width: min(560px, calc(100% - 36px), calc(100dvh - 220px));
    aspect-ratio: 1;
    overflow: hidden;
    margin: 18px auto;
    border: 1px solid var(--line-strong);
    background: #27313c;
    touch-action: none;
}

.avatar-crop-stage canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.avatar-crop-selection {
    position: absolute;
    aspect-ratio: 1;
    border: 2px dashed var(--accent);
    box-shadow: 0 0 0 9999px rgba(20, 27, 34, 0.54);
    cursor: move;
    touch-action: none;
}

.avatar-crop-selection.is-dragging {
    cursor: grabbing;
}

.avatar-crop-grid-line {
    position: absolute;
    background: rgba(255, 255, 255, 0.5);
    pointer-events: none;
}

.avatar-crop-grid-line-v {
    top: 0;
    bottom: 0;
    width: 1px;
}

.avatar-crop-grid-line-h {
    right: 0;
    left: 0;
    height: 1px;
}

.avatar-crop-grid-line-v1 {
    left: 33.333%;
}

.avatar-crop-grid-line-v2 {
    left: 66.666%;
}

.avatar-crop-grid-line-h1 {
    top: 33.333%;
}

.avatar-crop-grid-line-h2 {
    top: 66.666%;
}

.avatar-crop-handle {
    position: absolute;
    z-index: 1;
    width: 20px;
    height: 20px;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    touch-action: none;
}

.avatar-crop-handle::after {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 7px;
    height: 7px;
    border: 1px solid var(--accent);
    background: var(--panel);
    content: "";
    transform: translate(-50%, -50%);
}

.avatar-crop-handle:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

.avatar-crop-handle-nw {
    top: 0;
    left: 0;
    cursor: nwse-resize;
    transform: translate(-50%, -50%);
}

.avatar-crop-handle-n {
    top: 0;
    left: 50%;
    cursor: ns-resize;
    transform: translate(-50%, -50%);
}

.avatar-crop-handle-ne {
    top: 0;
    right: 0;
    cursor: nesw-resize;
    transform: translate(50%, -50%);
}

.avatar-crop-handle-e {
    top: 50%;
    right: 0;
    cursor: ew-resize;
    transform: translate(50%, -50%);
}

.avatar-crop-handle-se {
    right: 0;
    bottom: 0;
    cursor: nwse-resize;
    transform: translate(50%, 50%);
}

.avatar-crop-handle-s {
    bottom: 0;
    left: 50%;
    cursor: ns-resize;
    transform: translate(-50%, 50%);
}

.avatar-crop-handle-sw {
    bottom: 0;
    left: 0;
    cursor: nesw-resize;
    transform: translate(-50%, 50%);
}

.avatar-crop-handle-w {
    top: 50%;
    left: 0;
    cursor: ew-resize;
    transform: translate(-50%, -50%);
}

.avatar-crop-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid var(--line);
    background: var(--bg);
}

.avatar-crop-actions .secondary-button {
    border-color: var(--line);
    background: var(--panel);
    color: var(--text);
}

.avatar-crop-actions .secondary-button:hover {
    border-color: var(--accent);
    background: var(--panel);
    color: var(--accent);
}

[hidden] {
    display: none !important;
}

@media (max-width: 680px) {
    .avatar-file-control {
        align-items: flex-start;
        flex-direction: column;
    }

    .avatar-file-status {
        max-width: 100%;
    }

    .avatar-crop-dialog {
        width: calc(100% - 20px);
        max-height: calc(100dvh - 20px);
    }

    .avatar-crop-stage {
        width: min(calc(100% - 24px), calc(100dvh - 210px));
        margin: 12px auto;
    }

    .avatar-crop-handle {
        width: 24px;
        height: 24px;
    }
}
