/* 资源留言：卡片右下角按钮 + 原生 dialog 弹窗 */

.resource {
    position: relative;
}

/* 有留言按钮时才给脚印留位置、隐藏原来的箭头 */
.resource:has(.card-message) .card__foot {
    padding-right: 96px;
}

.resource:has(.card-message) .card__arrow {
    display: none;
}

.card-message {
    position: absolute;
    right: 14px;
    bottom: 10px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.88);
    color: var(--ink-dim);
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    animation: rise 0.7s var(--ease) backwards;
    animation-delay: calc(var(--i, 0) * 0.04s);
    transition: color 0.22s var(--ease), border-color 0.22s var(--ease),
    background-color 0.22s var(--ease);
}

.card-message:hover {
    border-color: var(--line-strong);
    background: #fff;
    color: var(--accent-deep);
}

.card-message:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}

.card-message svg {
    width: 14px;
    height: 14px;
    flex: none;
}

.card-message__count {
    min-width: 1.3rem;
    padding: 0 5px;
    border-radius: var(--radius-pill);
    background: var(--accent-soft);
    color: var(--accent-deep);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 500;
    line-height: 1.55;
    text-align: center;
}

/* ---- 留言弹窗 ---- */

.message-dialog {
    width: min(580px, calc(100vw - 32px));
    max-height: min(82vh, 760px);
    margin: auto;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: 22px;
    background: #fff;
    color: var(--ink);
    font-family: var(--font-sans);
    box-shadow: 0 30px 80px -30px rgba(11, 28, 57, 0.55);
}

.message-dialog[open] {
    display: flex;
    flex-direction: column;
}

.message-dialog::backdrop {
    background: rgba(11, 28, 57, 0.42);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.message-dialog__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex: none;
    padding: 20px 22px 16px;
    border-bottom: 1px solid var(--line);
}

.message-dialog__heading {
    min-width: 0;
}

.message-dialog__title {
    font-size: 1.0625rem;
    font-weight: 700;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.message-dialog__subtitle {
    margin-top: 4px;
    color: var(--ink-faint);
    font-size: 0.75rem;
    line-height: 1.4;
}

.message-dialog__close {
    display: grid;
    place-items: center;
    flex: none;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    color: var(--ink-dim);
    font-family: inherit;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background-color 0.2s var(--ease);
}

.message-dialog__close:hover {
    border-color: var(--line-strong);
    background: #fff;
    color: var(--accent-deep);
}

.message-dialog__body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-height: 120px;
    padding: 16px 22px 4px;
    overflow-y: auto;
}

.message-dialog__hint {
    flex: none;
    min-height: 1.2em;
    color: var(--ink-faint);
    font-size: 0.75rem;
    line-height: 1.5;
}

.message-empty {
    margin: 8px 0 18px;
    padding: 26px 16px;
    border: 1px dashed var(--line-strong);
    border-radius: 14px;
    background: rgba(246, 250, 255, 0.8);
    color: var(--ink-faint);
    font-size: 0.8125rem;
    line-height: 1.6;
    text-align: center;
}

.message-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    list-style: none;
}

.message-item {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(246, 250, 255, 0.8);
}

.message-item__content {
    color: var(--ink);
    font-size: 0.875rem;
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message-item__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
}

.message-delete {
    padding: 2px 6px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--danger);
    font-family: var(--font-sans);
    font-size: 0.6875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s var(--ease);
}

.message-delete:hover {
    background: rgba(163, 35, 24, 0.08);
}

/* ---- 发布留言 ---- */

.message-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: none;
    padding: 12px 22px 20px;
    border-top: 1px solid var(--line);
}

.message-form textarea {
    width: 100%;
    min-height: 82px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #f8fbff;
    color: var(--ink);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.6;
    resize: vertical;
    transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.message-form textarea::placeholder {
    color: #8aa0c0;
}

.message-form textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.message-form__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.message-form__count {
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
}

.message-submit {
    height: 36px;
    padding: 0 18px;
    border: 0;
    border-radius: var(--radius-pill);
    background: linear-gradient(140deg, var(--accent-deep), var(--accent));
    color: #fff;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 10px 20px -12px rgba(29, 78, 216, 0.9);
    transition: transform 0.2s var(--ease), opacity 0.2s var(--ease);
}

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

.message-submit:disabled {
    cursor: default;
    opacity: 0.6;
}

.message-submit:focus-visible,
.message-delete:focus-visible,
.message-dialog__close:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}

@media (max-width: 560px) {
    .message-dialog {
        width: calc(100vw - 20px);
        max-height: calc(100vh - 24px);
        border-radius: 18px;
    }

    .message-dialog__head {
        padding: 16px 16px 12px;
    }

    .message-dialog__body {
        padding: 12px 16px 4px;
    }

    .message-form {
        padding: 10px 16px 16px;
    }
}
