.auth-dialog {
    width: min(360px, calc(100vw - 28px));
    max-width: calc(100vw - 28px);
    max-height: calc(100svh - 28px);
    margin: auto;
    padding: 0;
    overflow: visible;
    border-radius: 14px;
}

.auth-dialog::backdrop {
    background: rgba(4, 6, 9, .68);
    backdrop-filter: blur(7px);
}

.auth-dialog-panel {
    position: relative;
    max-height: calc(100svh - 30px);
    padding: 16px;
    overflow-y: auto;
    border-radius: inherit;
    background: var(--surface);
}

.auth-dialog[open] .auth-dialog-panel {
    animation: auth-dialog-in .22s var(--ease) both;
}

.auth-dialog-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    padding: 0;
}

.auth-dialog-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-right: 34px;
}

.auth-dialog-mark {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border-radius: 10px;
    background: linear-gradient(145deg, #6f8cf2, #4561c5);
    color: #fff;
    box-shadow: 0 8px 20px rgba(74, 99, 202, .22);
    font-size: 18px;
    font-weight: 800;
    font-style: italic;
}

.auth-dialog-heading h2 {
    margin: 0;
    color: var(--text);
    font-family: var(--display-font);
    font-size: 18px;
    line-height: 1.3;
}

.auth-dialog-heading p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.auth-dialog-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    margin-top: 12px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--subtle);
}

.auth-dialog-tabs button {
    height: 30px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.auth-dialog-tabs button[aria-selected="true"] {
    background: var(--blue);
    color: #fff;
}

html[data-theme="dark"] .auth-dialog-tabs button[aria-selected="true"] {
    color: #19253e;
}

.auth-dialog-form {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.auth-dialog-field {
    display: grid;
    gap: 4px;
    line-height: 1.4;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.auth-dialog-field small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
}

.auth-dialog-input {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--subtle);
    color: var(--text);
    transition: border-color .15s ease, box-shadow .15s ease, background-color .18s ease;
}

.auth-dialog-input:focus-within {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-soft);
}

/* The outer field owns the focus ring. Reset the browser-wide input ring so
 * focusing a nested input does not draw a second, offset highlight. */
.auth-dialog-input input:focus,
.auth-dialog-input input:focus-visible {
    border-color: transparent !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

.auth-email-code-row input:focus {
    border-color: var(--blue);
    outline: none;
    box-shadow: 0 0 0 3px var(--blue-soft);
    background: var(--surface);
}

.auth-dialog-input .icon {
    width: 16px;
    height: 16px;
    flex: none;
    color: var(--muted);
}

.auth-dialog-input input,
.auth-email-code-row input {
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    caret-color: var(--blue);
}

.auth-dialog-input input::placeholder,
.auth-email-code-row input::placeholder {
    color: var(--muted);
}

.auth-password-toggle {
    width: 28px;
    height: 28px;
    flex: none;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
}

.auth-password-toggle span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.auth-password-toggle [data-password-icon-hide] {
    display: none;
}

.auth-password-toggle.is-visible [data-password-icon-show] {
    display: none;
}

.auth-password-toggle.is-visible [data-password-icon-hide] {
    display: inline-flex;
}

.auth-password-toggle .icon {
    width: 16px;
    height: 16px;
}

.auth-password-toggle:hover {
    background: var(--blue-soft);
    color: var(--blue);
}

.auth-dialog-options {
    display: grid;
    gap: 7px;
    margin-top: 3px;
}

.auth-dialog-remember {
    width: max-content;
    cursor: pointer;
    user-select: none;
}

.auth-dialog-remember,
.auth-dialog-agreement {
    display: grid;
    grid-template-columns: 16px minmax(0, 1fr);
    align-items: start;
    gap: 8px;
    margin: 0;
    line-height: 1.7;
    color: var(--muted);
    font-size: 12px;
}

/* 不继承普通输入框的内边距或全局 checkbox 的 flex 宽度。 */
.auth-dialog-remember input,
.auth-dialog-agreement > input {
    box-sizing: border-box;
    width: 16px;
    height: 16px;
    min-width: 0;
    min-height: 0;
    flex: 0 0 16px;
    margin: 2px 0 0;
    padding: 0;
    accent-color: var(--blue);
}

.auth-dialog-agreement p {
    display: flex;
    flex-wrap: wrap;
    gap: 0 4px;
    margin: 0;
    line-height: 1.7;
}

.auth-dialog-agreement a,
.auth-dialog-switch button {
    color: var(--blue);
    font-weight: 700;
}

.auth-dialog-agreement a:hover,
.auth-dialog-agreement a:focus-visible,
.auth-dialog-switch button:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.auth-email-code-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.auth-email-code-row input {
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--subtle);
}

.auth-dialog .auth-email-code-row .button {
    min-height: 34px;
    height: 34px;
    flex: 0 0 auto;
    padding: 0 10px;
    font-size: 12px;
}

.auth-dialog-error {
    margin: 0;
    line-height: 1.5;
    color: var(--red);
    font-size: 12px;
}

.auth-dialog-error:empty {
    display: none;
}

.auth-dialog-submit {
    height: 36px;
    border: 0;
    border-radius: 6px;
    background: var(--blue);
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    transition: background-color .15s ease, transform .15s ease;
}

html[data-theme="dark"] .auth-dialog-submit {
    color: #19253e;
}

.auth-dialog-submit:hover {
    filter: brightness(1.06);
}

.auth-dialog-submit:active {
    transform: translateY(1px);
}

.auth-dialog-submit:disabled {
    cursor: wait;
    opacity: .68;
}

.auth-dialog-switch {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.auth-dialog-switch button {
    padding: 1px 4px;
    border: 0;
    background: transparent;
}

@keyframes auth-dialog-in {
    from { opacity: 0; transform: translateY(10px) scale(.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 560px) {
    .auth-dialog {
        width: 100%;
        max-width: none;
        max-height: calc(100svh - 8px);
        margin: auto auto 0;
        border-radius: 20px 20px 0 0;
    }

    .auth-dialog-panel {
        max-height: calc(100svh - 12px);
        padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
        border-radius: inherit;
    }

    .auth-dialog-panel::before {
        content: "";
        display: block;
        width: 38px;
        height: 4px;
        margin: 0 auto 8px;
        border-radius: 2px;
        background: var(--line);
    }

    .auth-dialog-close {
        top: 14px;
        right: 10px;
    }

    .auth-dialog-input input,
    .auth-email-code-row input {
        font-size: 16px;
    }

    .auth-email-code-row {
        align-items: stretch;
    }

    .auth-email-code-row .button {
        padding-inline: 9px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .auth-dialog[open] .auth-dialog-panel,
    .auth-dialog-submit,
    .auth-dialog-input {
        animation: none;
        transition: none;
    }
}
