.rice-page {
    --rice-column: min(752px, calc(100% - 32px));
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    color: var(--rice-ink);
    background: var(--rice-bg);
    line-height: 1.5;
}

.rice-main {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: 0;
}

.rice-log {
    position: relative;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scroll-padding-block: 16px;
}

.rice-thread,
.rice-controls {
    width: var(--rice-column);
    margin-inline: auto;
}

.rice-thread {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    gap: 14px;
    padding-block: clamp(16px, 3dvh, 28px) 18px;
}

.rice-welcome {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
    align-items: center;
    gap: clamp(16px, 3vw, 28px);
    margin-block: auto;
    padding: clamp(20px, 4vw, 32px);
    background: var(--rice-welcome-bg);
    border: 1px solid var(--rice-border);
    border-radius: 24px;
    box-shadow: var(--rice-welcome-shadow);
}

.rice-welcome[hidden] {
    display: none;
}

.rice-school {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--rice-ink);
    font-size: 0.86rem;
    line-height: 1.25;
}

.rice-school::before {
    content: "";
    flex: 0 0 44px;
    height: 44px;
    /* Centra el sello circular dentro del margen transparente del PNG. */
    background: url("../assets/img/chat-rice/logo-mds-152.png") 40% 49% / 184% no-repeat;
}

.rice-school span {
    display: block;
    margin-top: 2px;
    color: var(--rice-muted);
    font-size: 0.78rem;
}

.rice-welcome h1 {
    margin-top: 20px;
    font-size: clamp(1.8rem, 3.6vw, 2.55rem);
    line-height: 1.08;
    letter-spacing: -0.035em;
    text-wrap: balance;
}

.rice-intro {
    max-width: 36ch;
    margin-top: 14px;
    color: var(--rice-muted);
}

.rice-portrait {
    position: relative;
    isolation: isolate;
    display: grid;
    place-items: center;
    min-width: 0;
}

.rice-portrait::before {
    position: absolute;
    inset: 9% 4% 3%;
    z-index: -1;
    border-radius: 48% 48% 22% 22%;
    background: var(--rice-portrait-bg);
    content: "";
}

.rice-portrait::after {
    position: absolute;
    inset: auto 17% 2% 14%;
    z-index: -1;
    height: 10%;
    background: var(--rice-portrait-ground);
    content: "";
}

.rice-portrait img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(var(--rice-portrait-shadow));
}

.rice-powered {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: 22px;
    color: var(--rice-muted);
    font-size: 0.8rem;
    font-weight: bold;
}

.rice-powered svg {
    flex: none;
    color: var(--rice-accent);
}

.rice-message {
    align-self: flex-start;
    max-width: min(100%, 680px);
    padding: 12px 14px;
    overflow-wrap: anywhere;
    background: var(--surface);
    border: 1px solid var(--rice-border);
    border-radius: 14px;
}

.rice-welcome[hidden] + .rice-message {
    margin-top: auto;
}

.rice-message-text {
    white-space: pre-wrap;
}

.rice-with-mascot {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: clamp(8px, 2vw, 14px);
}

.rice-with-mascot[hidden] {
    display: none;
}

.rice-mascot {
    display: block;
    width: clamp(44px, 12vw, 64px);
    height: auto;
    object-fit: contain;
}

.rice-message.rice-visitor {
    align-self: flex-end;
    background: var(--rice-visitor-bg);
    border-color: var(--rice-visitor-border);
}

.rice-sender {
    margin-bottom: 3px;
    color: var(--rice-sender);
    font-size: 0.8rem;
    font-weight: bold;
}

.rice-message.rice-error {
    border-color: var(--error-border);
    color: var(--error-text);
    background: var(--error-bg);
}

.rice-error .rice-sender {
    color: inherit;
}

.rice-loading {
    width: min(100%, 450px);
    color: var(--rice-muted);
    font-size: 0.9rem;
}

.rice-loading .rice-mascot {
    width: clamp(70px, 20vw, 108px);
}

.rice-loading .rice-mascot img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
}

.rice-skeleton {
    display: grid;
    gap: 8px;
    margin-block: 12px 4px;
}

.rice-skeleton span {
    height: 8px;
    border-radius: 999px;
    background: var(--rice-skeleton);
    background-size: 240% 100%;
    animation: rice-skeleton-shimmer 1.6s ease-in-out infinite;
}

.rice-skeleton span:nth-child(2) {
    width: 82%;
}

.rice-skeleton span:nth-child(3) {
    width: 56%;
}

@keyframes rice-skeleton-shimmer {
    from { background-position: 100% 0; }
    to { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
    .rice-skeleton span {
        animation: none;
    }
}

.rice-sources {
    display: grid;
    gap: 9px;
    margin-top: 10px;
    list-style: none;
}

.rice-sources li {
    padding: 9px 11px;
    background: var(--rice-source-bg);
    border-left: 3px solid var(--rice-source-border);
    border-radius: 5px;
}

.rice-sources a {
    color: var(--rice-source-link);
    font-weight: bold;
}

.rice-sources a:hover {
    color: var(--link-hover);
}

.rice-sources blockquote {
    margin-top: 3px;
    color: var(--rice-source-copy);
    font-size: 0.9rem;
}

.rice-dock {
    display: block;
    z-index: 1;
    padding-block: 10px max(12px, env(safe-area-inset-bottom));
    padding-inline: 0;
    background: var(--rice-dock-bg);
    border-top: 1px solid var(--border);
}

.rice-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.rice-tools .rice-privacy {
    flex: 1;
    margin: 0;
}

.rice-menu {
    position: relative;
}

.rice-icon-button {
    display: grid;
    flex: none;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid transparent;
    color: var(--rice-accent);
    background: var(--rice-tool-bg);
    border-radius: 50%;
    cursor: pointer;
}

.rice-icon-button:hover,
.rice-menu[open] > summary {
    background: var(--rice-tool-hover);
}

.rice-menu summary {
    list-style: none;
}

.rice-menu summary::-webkit-details-marker {
    display: none;
}

.rice-menu-panel {
    position: absolute;
    z-index: 2;
    inset-inline-start: 0;
    bottom: calc(100% + 10px);
    width: min(272px, calc(100vw - 32px));
    max-height: 60dvh;
    overflow-y: auto;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--rice-border);
    border-radius: 12px;
    box-shadow: var(--rice-menu-shadow);
}

.rice-suggestions button {
    display: block;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 6px;
    color: var(--rice-ink);
    background: transparent;
    font: inherit;
    font-size: 0.88rem;
    text-align: start;
}

.rice-suggestions button:hover {
    background: var(--rice-option-hover);
}

.rice-suggestions p {
    padding: 5px 10px 2px;
    color: var(--rice-muted);
    font-size: 0.76rem;
    font-weight: bold;
}

.rice-suggestions button {
    cursor: pointer;
}

.rice-controls button:disabled {
    cursor: wait;
    opacity: 0.55;
}

.rice-home {
    display: grid;
    flex: none;
    place-items: center;
    width: 48px;
    height: 46px;
    margin-inline-start: auto;
    color: var(--heading);
    background: var(--surface);
    border: 2px solid currentColor;
    border-radius: 6px;
}

.rice-home:hover {
    background: var(--rice-option-hover);
}

.rice-compose {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 10px;
}

.rice-compose textarea {
    display: block;
    width: 100%;
    max-height: min(140px, 24dvh);
    padding: 10px 12px;
    color: var(--rice-ink);
    background: var(--surface);
    border: 1px solid var(--field-border);
    border-radius: 12px;
    font: inherit;
    resize: vertical;
}

.rice-compose textarea::placeholder {
    color: var(--rice-placeholder);
}

.rice-compose textarea:user-invalid {
    border-color: var(--error-border);
}

.rice-send {
    width: 44px;
    height: 44px;
    color: var(--rice-send-text);
    background: var(--rice-send-bg);
    border-radius: 12px;
}

.rice-send:hover {
    background: var(--rice-send-hover);
}

.rice-privacy {
    margin-top: 6px;
    color: var(--rice-muted);
    font-size: 0.76rem;
    line-height: 1.4;
}

.rice-announcement {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

@media (min-width: 980px) {
    .rice-log {
        scrollbar-gutter: stable both-edges;
    }

    .rice-menu,
    .rice-home {
        position: fixed;
        bottom: max(16px, env(safe-area-inset-bottom));
    }

    .rice-menu {
        inset-inline-start: 16px;
    }

    .rice-home {
        inset-inline-end: 16px;
    }
}

@media (max-width: 640px) {
    .rice-welcome {
        grid-template-columns: minmax(0, 1fr);
        gap: 18px;
        text-align: center;
    }

    .rice-portrait {
        grid-row: 1;
        width: min(100%, 300px);
        margin-inline: auto;
    }

    .rice-school,
    .rice-powered {
        justify-content: center;
    }

    .rice-school p {
        text-align: start;
    }

    .rice-intro {
        margin-inline: auto;
    }
}

@media (max-width: 640px) and (max-height: 700px) {
    .rice-portrait {
        max-width: 245px;
    }

    .rice-welcome h1 {
        margin-top: 14px;
    }
}

@media (max-width: 540px) {
    .rice-tools {
        gap: 6px;
    }

    .rice-home,
    .rice-menu > summary {
        width: 44px;
        height: 44px;
    }

    .rice-compose {
        gap: 8px;
    }
}
