:root {
    /* Theme Colors */
    /* Education-friendly light theme (readable + calm) */
    --bg-color: #f6f8fc;
    --card-bg: #ffffff;
    --card-hover: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --accent-blue: #2563eb;
    --border-color: #e2e8f0;
    --search-bg: #ffffff;

    /* Surfaces / effects */
    --surface-overlay: #ffffff;
    --panel-bg: rgba(15, 23, 42, 0.03);
    --divider-color: rgba(15, 23, 42, 0.10);
    --shadow-elevated: 0 10px 30px rgba(15, 23, 42, 0.12);

    /* Status */
    --danger: #dc2626;
    --chat-user-bg: #eef2ff;
    --chat-bot-bg: #1d4ed8;

    /* Scrollbar */
    --scrollbar-track: #eef2f7;
    --scrollbar-thumb: #cbd5e1;
    --scrollbar-thumb-hover: #94a3b8;
}

/* Dark theme (previous/original) */
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg-color: #0f1115;
    --card-bg: #15191e;
    --card-hover: #1c2128;
    --text-primary: #ffffff;
    --text-secondary: #8b949e;
    --accent-blue: #539bf5;
    --border-color: #30363d;
    --search-bg: #1c2128;

    --surface-overlay: #1a1f26;
    --panel-bg: rgba(21, 25, 30, 0.35);
    --divider-color: rgba(255,255,255,0.08);
    --shadow-elevated: 0 10px 30px rgba(0,0,0,0.55);

    --danger: #ff5252;
    --chat-user-bg: #2d333b;
    --chat-bot-bg: #1f6feb;

    --scrollbar-track: var(--bg-color);
    --scrollbar-thumb: #2d333b;
    --scrollbar-thumb-hover: #3d444d;
}

/* Default scheme */
:root:not([data-theme="dark"]) { color-scheme: light; }

/* Font size preference */
:root { --base-font-size: 16px; }
:root[data-font="sm"] { --base-font-size: 14px; }
:root[data-font="md"] { --base-font-size: 16px; }
:root[data-font="lg"] { --base-font-size: 18px; }
html { font-size: var(--base-font-size); }

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Global scrollbar (page) */
html {
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track); /* Firefox */
}

/* Chromium/WebKit */
html::-webkit-scrollbar,
body::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
html::-webkit-scrollbar-track,
body::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}
html::-webkit-scrollbar-thumb,
body::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 999px;
    border: 2px solid var(--scrollbar-track);
}
html::-webkit-scrollbar-thumb:hover,
body::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Header --- */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    font-size: 0.875rem;
    position: sticky;
    top: 0;
    z-index: 200;
    background: var(--bg-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 4px;
    text-decoration: none;
}

.brand {
    gap: 10px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(37, 99, 235, 0.12);
    color: var(--accent-blue);
    font-size: 22px;
}

:root[data-theme="dark"] .brand-icon {
    background: rgba(83, 155, 245, 0.15);
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.05;
}

.brand-name {
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.brand-sub {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 3px;
}

/* --- Top Right Area (New Style) --- */
.topRight ul {
    display: flex;
    align-items: center;
    list-style: none;
    gap: 16px; /* Space between buttons */
    padding: 0;
    margin: 0;
}

.topRight li {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* --- Alarm Button (Notification) --- */
.alarmBtn {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.alarmBtn .icon {
    width: 24px;
    height: 24px;
    display: none;
}

.alarmBtn .bell-icon {
    font-size: 22px;
    line-height: 1;
    color: var(--text-secondary);
    transition: color 0.2s, opacity 0.2s;
    opacity: 0.9;
}

.alarmBtn:hover .bell-icon {
    color: var(--text-primary);
    opacity: 1;
}

.alarmBtn .count {
    position: absolute;
    top: 6px;
    right: 6px;
    background-color: var(--danger);
    color: white;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    min-width: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5625rem;
    font-weight: 700;
    line-height: 1;
    border: 2px solid var(--bg-color);
    box-sizing: content-box;
}

/* --- GNB Button (Apps Grid) --- */
.gnbBtn {
    position: relative; /* For popup positioning */
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Apps Popup --- */
.apps-popup {
    display: none; /* Hidden by default */
    position: fixed;
    top: 60px;
    right: 24px;
    width: 500px;
    max-height: 580px;
    overflow: hidden;
    background-color: var(--surface-overlay);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 0;
    box-shadow: var(--shadow-elevated);
    z-index: 1000;
}

.apps-popup.show {
    display: flex;
    flex-direction: column;
}

/* Search row */
.apps-search-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px 8px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.apps-search-row .material-symbols-rounded { font-size: 18px; color: var(--text-secondary); flex-shrink: 0; }
.apps-search-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 0.85rem;
    color: var(--text-primary);
    font-family: inherit;
}
.apps-search-input::placeholder { color: var(--text-secondary); }

/* Category bar */
.app-category-bar {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    overflow-x: auto;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
    scrollbar-width: none;
}
.app-category-bar::-webkit-scrollbar { display: none; }
.app-category-btn {
    flex-shrink: 0;
    border: 1px solid var(--border-color);
    background: transparent;
    cursor: pointer;
    border-radius: 20px;
    padding: 3px 12px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}
.app-category-btn:hover { background: var(--card-hover); color: var(--text-primary); }
.app-category-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #fff;
}

/* Apps menu — Home row (shared header #apps-popup) */
.apps-popup-home-row {
    flex-shrink: 0;
    padding: 0 12px 8px;
    border-bottom: 1px solid var(--border-color);
}
#apps-popup-home-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--card-hover);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    transition: background 0.15s, border-color 0.15s;
}
#apps-popup-home-btn:hover {
    background: var(--panel-bg);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}
#apps-popup-home-btn .material-symbols-rounded {
    font-size: 18px;
    line-height: 1;
}

/* Scrollable body */
.apps-popup-body {
    overflow-y: auto;
    flex: 1;
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Section labels */
.apps-section-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* Inner tool grid */
.apps-popup-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

/* Pin button */
.app-pin-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
    color: var(--text-secondary);
}
.app-item:hover .app-pin-btn,
.app-pin-btn.pinned { opacity: 1; }
.app-pin-btn:hover { background: var(--card-hover); color: var(--text-primary); }
.app-pin-btn.pinned { color: #f59e0b; }

/* Empty state */
.apps-empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.app-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-decoration: none;
    color: var(--text-primary);
    gap: 10px;
    padding: 12px 8px;
    border-radius: 8px;
    transition: background-color 0.2s;
    min-height: 100px;
}

.app-item:hover {
    background-color: var(--card-hover);
}

/* Coming-Soon badge in the apps popup grid — centered overlay */
.app-coming-soon-badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    background: rgba(0, 0, 0, 0.52);
    color: #fff;
    border-radius: 12px;
    padding: 4px 10px;
    pointer-events: none;
    line-height: 1.4;
    white-space: nowrap;
    z-index: 2;
}

.app-icon {
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

:root[data-theme="dark"] .app-icon {
    background: rgba(83, 155, 245, 0.12);
    border-color: rgba(255,255,255,0.08);
}

.app-icon img {
    width: 40px;
    height: 40px;
    display: block;
    /* Light theme: white PNG icons become visible */
    filter: invert(1) brightness(0.35);
    opacity: 0.95;
}

:root[data-theme="dark"] .app-icon img {
    filter: none;
    opacity: 1;
}

.app-icon .material-symbols-rounded {
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.3;
    width: 100%;
    word-break: break-word;
    min-height: 2.6em;
}


.gnbBtn .icon {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px;
    transition: opacity 0.2s;
}

.gnbBtn:hover .icon {
     opacity: 1;
}

.gnbBtn .detail {
    display: flex;
    gap: 2px;
}

.gnbBtn .detail span {
    display: block;
    width: 4px;
    height: 4px;
    background-color: #94a3b8;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.gnbBtn:hover .detail span {
    background-color: var(--accent-blue);
}

/* --- Profile Button --- */
.profileBtn {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.profileBtn:hover {
    border-color: var(--accent-blue);
}

.profileBtn .name {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.10);
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}
/* --- Main Content --- */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 0 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Keep chat area centered (same feel in teacher + student modes) */
.chat-shell {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /*
      Keep chat area visually centered like before, but don't push tools too far down.
      Reserve a smaller "center area" than full viewport.
    */
    min-height: clamp(420px, 62vh, 640px);
    padding-top: 12px;
    margin-bottom: 8px;
}

/* --- Hero Section --- */
.hero-text {
    text-align: center;
    margin-bottom: 40px;
}

h1 {
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.4;
    max-width: 700px;
    margin: 0 auto;
}

.highlight-blue {
    color: var(--accent-blue);
}

/* --- Search Bar --- */
.search-container {
    width: 100%;
    max-width: 680px;
    background-color: var(--search-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 12px 16px;
    margin-bottom: 24px;
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    min-width: 0;
}

.search-input::placeholder {
    color: var(--text-secondary);
}

.search-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.action-icon {
    cursor: pointer;
    transition: opacity 0.2s;
}

.action-icon:hover {
    opacity: 0.8;
}

/* Mic button — voice input */
.mic-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    padding: 0;
    transition: color 0.2s, opacity 0.2s;
    font-size: 20px;
    flex-shrink: 0;
}

.mic-btn:hover {
    opacity: 0.75;
}

/* A switch that is off: still there, plainly not active. */
.mic-btn.off {
    color: var(--text-secondary);
    opacity: 0.6;
}

.mic-btn.recording {
    color: #ef4444;
    animation: mic-pulse 1.1s ease-in-out infinite;
}

@keyframes mic-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* --- Tools Grid Section --- */
.tools-section {
    width: 100%;
    margin-bottom: 40px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-title {
    font-size: 18px;
    font-weight: 600;
}

/* --- The Grid --- */
.grid {
    display: grid;
    /* Responsive by default */
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}

.grid.grid-center { justify-content: center; }
.grid.grid-left { justify-content: start; }

/* Force 4-in-a-row on desktop widths */
@media (min-width: 1100px) {
    .grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* Kids illustration banner is CSS-only via ::before — no HTML element needed */

/* --- Tool Card --- */
.tool-card {
    background-color: var(--card-bg);
    border-radius: 24px;
    padding: 0;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 0;
    box-sizing: border-box;
    overflow: visible;
    box-shadow: 0 4px 6px rgba(0,0,0,0.04), 0 10px 30px rgba(0,0,0,0.08);
    border: none;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    z-index: 1;
}

.tool-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 8px 12px rgba(0,0,0,0.06), 0 20px 40px rgba(0,0,0,0.13);
}

/* Coming Soon overlay — sits on top of the grayed-out card */
.tool-card--coming-soon {
    overflow: hidden;
}

.coming-soon-overlay {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.42);
    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);
    z-index: 2;
    pointer-events: none;
}

:root[data-theme="dark"] .coming-soon-overlay {
    background: rgba(15, 20, 30, 0.45);
}

.coming-soon-text {
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    background: rgba(0, 0, 0, 0.48);
    border-radius: 20px;
    padding: 5px 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

:root[data-theme="dark"] .coming-soon-text {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
}

.tool-card.show-full-desc {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
    z-index: 10;
}

/* Dark theme: brighter card surface + visible shadow */
:root[data-theme="dark"] .tool-card {
    background-color: #1e2430;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.06), 0 8px 24px rgba(0,0,0,0.4);
}

:root[data-theme="dark"] .tool-card:hover {
    background-color: #232b3a;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.09), 0 16px 40px rgba(0,0,0,0.55);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px 6px 20px;
    min-height: 56px;
}

.tool-icon {
    width: 40px;
    height: 40px;
    background-color: rgba(59, 130, 246, 0.1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-blue);
}

/* Icon colors are applied per-tool via inline styles in tool-cards.js */

.card-title-area {
    flex: 1;
}

.card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tag {
    font-size: 0.625rem;
    padding: 2px 6px;
    background-color: rgba(37, 99, 235, 0.10);
    border-radius: 4px;
    color: var(--accent-blue);
}

.card-desc {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    padding: 0 20px;
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.tool-card.show-full-desc .card-desc {
    -webkit-line-clamp: unset;
    line-clamp: unset;
    -webkit-box-orient: unset;
    overflow: visible;
    display: block;
}


/* --- User Menu (Profile Dropdown) --- */
.user-menu {
    position: absolute;
    right: 0;
    top: 52px;
    width: 260px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: var(--surface-overlay);
    box-shadow: var(--shadow-elevated);
    display: none;
    overflow: hidden;
    z-index: 60;
}

.user-menu.show { display: block; }

.user-menu-header {
    padding: 12px 12px 10px;
    border-bottom: 1px solid var(--divider-color);
}

.user-menu-name {
    font-weight: 700;
    font-size: 0.95rem;
}

/* Student info block in the user menu header */
#student-info-row {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.student-info-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.student-info-ico {
    font-size: 0.95rem;
    color: var(--accent-blue);
    flex-shrink: 0;
}

.student-info-label {
    flex: 1;
    color: var(--text-secondary);
}

.student-info-val {
    font-weight: 700;
    color: var(--text-primary);
    background: var(--card-hover);
    border-radius: 6px;
    padding: 1px 7px;
    font-size: 0.75rem;
    letter-spacing: 0.01em;
}

.menu-list {
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.menu-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.menu-ico {
    font-size: 18px;
    color: var(--text-secondary);
}

.menu-label {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.menu-select {
    width: 120px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-primary);
    padding: 6px 8px;
    font-size: 0.85rem;
}

.menu-select:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.menu-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 2px;
}

.menu-action-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.85rem;
}

.menu-action-btn:hover {
    background: var(--card-hover);
    border-color: var(--accent-blue);
}

.menu-action-btn.menu-danger {
    color: var(--danger);
}

.menu-action-btn.menu-danger:hover {
    background: rgba(220, 38, 38, 0.08);
    border-color: var(--danger);
}

.menu-right-spacer {
    flex: 1;
    min-width: 0;
}

/* Empty right column to keep Settings/Logout aligned with select rows */
.menu-right-spacer {
    width: 170px;
    height: 1px;
    justify-self: end;
}

.menu-danger {
    color: var(--danger);
}

/* --- Settings Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

:root[data-theme="dark"] .modal-overlay {
    background: rgba(0,0,0,0.55);
}

.modal-overlay.show { display: flex; }

.modal {
    width: 100%;
    max-width: 420px;
    background: var(--surface-overlay);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-elevated);
    padding: 16px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.modal-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 10px;
}

.icon-btn:hover { background: var(--card-hover); }

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

/* Settings modal buttons should not reserve the right "select column" */
.modal-actions .menu-action-btn {
    grid-template-columns: 32px 1fr;
}

.modal-actions .menu-action-btn span:not(.menu-ico) {
    justify-self: center;
}

/* ── Admin Portal Modal ─────────────────────────────────────────────────── */
.admin-portal-modal {
    max-width: 600px;
    width: 95vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.admin-tabs {
    display: flex;
    gap: 2px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0;
}

.admin-tab {
    background: none;
    border: none;
    padding: 10px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
}

.admin-tab.active, .admin-tab:hover {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
}

.admin-tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.admin-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0 0 12px;
}

.admin-tool-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.admin-tool-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: grab;
    transition: background 0.15s, opacity 0.15s, box-shadow 0.15s;
    user-select: none;
}

.admin-tool-row:active { cursor: grabbing; }
.admin-tool-row.dragging { opacity: 0.4; }
.admin-tool-row.drag-over { box-shadow: 0 0 0 2px var(--accent-blue); background: var(--card-hover); }
.admin-tool-row.disabled { opacity: 0.45; }

.admin-drag-handle {
    font-size: 1.2rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    cursor: grab;
}

.admin-tool-info {
    flex: 1;
    min-width: 0;
}

.admin-tool-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.admin-role-checks {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.admin-role-check {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.admin-role-check input { cursor: pointer; accent-color: var(--accent-blue); }
.admin-role-check input:disabled { cursor: default; opacity: 0.5; }

/* Toggle switch */
.admin-toggle {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.admin-toggle-input { display: none; }

.admin-toggle-track {
    width: 38px;
    height: 22px;
    background: var(--border-color);
    border-radius: 11px;
    position: relative;
    transition: background 0.2s;
}

.admin-toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform 0.2s;
}

.admin-toggle-input:checked + .admin-toggle-track {
    background: var(--accent-blue);
}

.admin-toggle-input:checked + .admin-toggle-track::after {
    transform: translateX(16px);
}

/* Footer buttons */
.admin-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
    margin-top: 14px;
}

.admin-btn {
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s, opacity 0.15s;
}

.admin-btn-primary {
    background: var(--accent-blue);
    color: #fff;
}

.admin-btn-primary:hover { opacity: 0.88; }

.admin-btn-ghost {
    background: var(--card-hover);
    color: var(--text-primary);
}

.admin-btn-ghost:hover { background: var(--border-color); }

/* Users tab */
.admin-role-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.admin-role-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
}

.admin-role-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.admin-role-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.admin-role-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.admin-role-desc {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.admin-role-select-btn {
    padding: 6px 14px;
    border-radius: 7px;
    border: 1px solid var(--accent-blue);
    background: transparent;
    color: var(--accent-blue);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.admin-role-select-btn:hover {
    background: var(--accent-blue);
    color: #fff;
}

/* Users tab */
.admin-users-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.admin-user-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
}

.admin-user-info {
    flex: 1;
    min-width: 0;
}

.admin-user-email {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-user-you {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.admin-user-role-select {
    flex-shrink: 0;
    padding: 4px 8px;
    border-radius: 7px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    accent-color: var(--accent-blue);
}

.admin-user-role-select:disabled {
    opacity: 0.5;
    cursor: default;
}

.admin-real-role-notice {
    font-size: 0.82rem;
    color: var(--text-secondary);
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 14px;
}

.admin-preview-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    padding: 8px 12px;
    margin-top: 14px;
    flex-wrap: wrap;
}

:root[data-theme="dark"] .admin-preview-status {
    background: #1c1a0a;
    border-color: #78350f;
}

/* Role badge in header menu */
.menu-role-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    background: #dbeafe;
    color: #2563eb;
    margin-left: auto;
}

:root[data-theme="dark"] .menu-role-badge {
    background: #1e3a5f;
    color: #93c5fd;
}

.star-icon.is-favorite {
    color: #fbbf24;
}

.favorite-label {
    pointer-events: none;
    margin-left: auto;
    text-align: right;
}

/* --- Chat UI --- */
#chat-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto 16px auto; /* reduce gap between messages and input/tools */
    display: none; /* Hidden until first message */
    flex-direction: column;
    gap: 16px;
    /* Scrollable area */
    max-height: 500px;
    overflow-y: auto;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background-color: var(--panel-bg);
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

#chat-container::-webkit-scrollbar {
    width: 6px;
}
#chat-container::-webkit-scrollbar-track {
    background: transparent;
}
#chat-container::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 3px;
}
#chat-container::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
}

.chat-message {
    padding: 16px;
    border-radius: 12px;
    line-height: 1.5;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
}

.chat-message.user {
    background-color: var(--chat-user-bg);
    align-self: flex-end;
    color: var(--text-primary);
    border-bottom-right-radius: 2px;
}

.chat-message.bot {
    background-color: var(--chat-bot-bg);
    align-self: flex-start;
    color: white;
    border-bottom-left-radius: 2px;
}

/* --- Chat history panel --- */

/* The history icon lives in the input bar's action row, so it inherits
   .action-icon sizing; this only marks the open state. */
#chat-history-btn.active {
    color: var(--accent-blue);
}

/* Popover anchored to the input bar. Absolutely positioned so opening it
   never reflows the hero or the tool grid below. */
.chat-history-panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 10px);
    z-index: 40;
    width: min(360px, calc(100vw - 32px));
    max-height: 340px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    /* Must be an opaque surface: --panel-bg is a translucent tint meant to
       layer over the page, and the hero text showed straight through it. */
    background: var(--card-bg);
    box-shadow: 0 12px 32px rgba(0, 0, 0, .16);
    animation: fadeIn .15s ease;
}

.chat-history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px 10px;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-secondary);
}

.chat-history-new {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: none;
    color: var(--text-primary);
    font-size: .72rem;
    text-transform: none;
    letter-spacing: normal;
    cursor: pointer;
    transition: background .15s ease;
}

.chat-history-new:hover {
    background: var(--bg-secondary);
}

.chat-history-new .material-symbols-rounded {
    font-size: 15px;
}

.chat-history-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 4px;
    border-radius: 8px;
}

.chat-history-item:hover {
    background: var(--bg-secondary);
}

.chat-history-item.active {
    background: var(--bg-secondary);
}

.chat-history-open {
    flex: 1;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    padding: 8px 10px;
    border: none;
    background: none;
    color: inherit;
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.chat-history-item-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
    font-size: .88rem;
}

.chat-history-item-meta {
    flex-shrink: 0;
    color: var(--text-secondary);
    font-size: .75rem;
}

.chat-history-delete {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 6px;
    margin-right: 4px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    opacity: 0;
    transition: opacity .15s ease, color .15s ease;
}

.chat-history-item:hover .chat-history-delete,
.chat-history-delete:focus-visible {
    opacity: 1;
}

/* Touch devices get no hover, so the control would be unreachable. */
@media (hover: none) {
    .chat-history-delete { opacity: 1; }
}

.chat-history-delete:hover {
    color: #b91c1c;
}

.chat-history-delete .material-symbols-rounded {
    font-size: 18px;
}

.chat-history-empty {
    padding: 12px 10px;
    color: var(--text-secondary);
    font-size: .85rem;
}

/* --- Drag and drop images onto the assistant --- */

/* The shell is the drop target, so the overlay is positioned against it. */
.chat-shell { position: relative; }

.chat-drop-overlay {
    position: absolute;
    inset: 8px;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--accent-blue);
    border-radius: 18px;
    background: color-mix(in srgb, var(--card-bg) 88%, transparent);
    /* The overlay sits over the input; without this the pointer would leave
       the shell the instant it entered the overlay and the drop would cancel. */
    pointer-events: none;
    animation: fadeIn .12s ease;
}

/* `display: flex` above outranks the browser's built-in `[hidden] {display:none}`,
   so without this the overlay was permanently visible over the homepage. */
.chat-drop-overlay[hidden] {
    display: none;
}

.chat-drop-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--accent-blue);
    font-size: .95rem;
    font-weight: 600;
}

.chat-drop-inner .material-symbols-rounded {
    font-size: 2.4rem;
}

/* --- Attachments on the homepage assistant --- */

/* Inside the input box, a row above the text: what goes with the next message. */
.chat-input-bar .chat-attachments {
    flex: 0 0 100%;
    flex-wrap: wrap;
    gap: 12px;
    padding: 6px 2px 12px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}

.chat-attachment {
    position: relative;
    flex-shrink: 0;
    height: 52px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
}

/* A picture: a square thumbnail. */
.chat-attachment:not(.doc) {
    width: 52px;
}

.chat-attachment img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 9px;
}

/* A document: a card with its type, name and size. */
.chat-attachment.doc {
    display: flex;
    align-items: center;
    width: 220px;
    max-width: 100%;
    padding: 0 12px 0 8px;
}

.chat-attachment.failed {
    border-color: #dc2626;
}

.chat-attachment.failed .chat-file-meta {
    color: #dc2626;
}

/* Remove: a small round button on the corner, always visible (touch screens
   have no hover). */
.chat-attachment-remove {
    position: absolute;
    top: -7px;
    right: -7px;
    width: 20px;
    height: 20px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--search-bg);
    border-radius: 50%;
    background: #475569;
    color: #fff;
    cursor: pointer;
}

.chat-attachment-remove .material-symbols-rounded {
    font-size: 13px;
}

.chat-attachment-remove:hover {
    background: #1e293b;
}

.chat-attachment-remove:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 1px;
}

/* A picture still uploading: dimmed, with a spinner over it. */
.chat-attachment.uploading img { opacity: .45; }

.chat-attachment-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border: 2px solid var(--accent-blue);
    border-top-color: transparent;
    border-radius: 50%;
    animation: chatAttachmentSpin .7s linear infinite;
}

@keyframes chatAttachmentSpin {
    to { transform: rotate(360deg); }
}

.chat-attachment.failed img { opacity: .35; }

.chat-attachment-failed {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #dc2626;
    font-size: 20px;
}

/* One file, wherever it is shown: a coloured tile for its type, its name, and
   a line under it (type and size, or what is happening to it). */
.chat-file-card {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.chat-file-tile {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: #fff;
}

.chat-file-tile .material-symbols-rounded {
    font-size: 20px;
}

.chat-file-tile.tone-pdf   { background: #dc2626; }
.chat-file-tile.tone-word  { background: #2563eb; }
.chat-file-tile.tone-sheet { background: #16a34a; }
.chat-file-tile.tone-text  { background: #64748b; }

.chat-file-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-top-color: transparent;
    border-radius: 50%;
    animation: chatAttachmentSpin .7s linear infinite;
}

.chat-file-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.3;
}

.chat-file-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-file-meta {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* The documents a sent message carried, above its text, as the same cards. */
.chat-message-files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-message-files .chat-file-card {
    flex: 0 1 auto;
    max-width: 260px;
    padding: 6px 12px 6px 6px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--card-bg);
}

/* Images shown inside a sent message. */
.chat-message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.chat-message-images img {
    max-width: 180px;
    max-height: 180px;
    border-radius: 8px;
    display: block;
}

/* Pictures the assistant drew: below its reply at a size worth looking at,
   each opening full size in a new tab. */
.chat-generated-images {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.chat-generated-image {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    width: min(100%, 420px);
}

.chat-generated-images .chat-image-open {
    display: block;
    width: 100%;
    border-radius: 12px;
    line-height: 0;
}

.chat-generated-images a:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

.chat-generated-images img {
    width: 100%;
    height: auto;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    display: block;
}

/* Specific enough to beat the bubble's own link style (.chat-message.bot a). */
.chat-message .chat-generated-images .chat-image-download {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    color: inherit;
    font-size: 13px;
    text-decoration: none;
}

.chat-message .chat-generated-images .chat-image-download:hover {
    background: rgba(255, 255, 255, 0.15);
}

.chat-image-download .material-symbols-rounded {
    font-size: 18px;
}

/* A teacher's own line breaks (Shift+Enter) are part of what they wrote. */
.chat-message .chat-message-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* The homepage chat box: several lines, growing as they are typed, with the
   buttons kept on the bottom line as in any chat app. Scoped to this bar —
   other pages reuse .search-container and .search-input. */
.chat-input-bar {
    align-items: flex-end;
    /* The attachment row takes a line of its own above the text. */
    flex-wrap: wrap;
}

.chat-input-bar #chat-input {
    flex: 1 1 0;         /* never pushes the buttons onto a line of their own */
    display: block;
    resize: none;
    line-height: 1.5;
    padding: 4px 0;
    max-height: 9.5em;   /* about six lines, then it scrolls */
    overflow-y: auto;
}

/* Send is a real button now; it keeps the round blue arrow it always had. */
.chat-input-bar .chat-send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--accent-blue);
    color: #fff;
    border-radius: 50%;
    padding: 4px;
    margin-left: 4px;
    cursor: pointer;
}

.chat-input-bar .chat-send-btn .material-symbols-rounded {
    font-size: 18px;
}

.chat-input-bar .chat-send-btn:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

/* --- Markdown styles inside bot messages --- */
.chat-message.bot :is(p, ul, ol, pre, table, blockquote, h1, h2, h3, h4, h5, h6) {
    margin: 0;
}
.chat-message.bot :is(p, ul, ol, pre, table, blockquote) + :is(p, ul, ol, pre, table, blockquote, h1, h2, h3, h4, h5, h6) {
    margin-top: 10px;
}
.chat-message.bot ul,
.chat-message.bot ol {
    padding-left: 18px;
}
.chat-message.bot a {
    color: rgba(255, 255, 255, 0.92);
    text-decoration: underline;
}
.chat-message.bot a.tool-cta-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 9px 16px;
    background: #ffffff;
    color: #1d4ed8;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: 999px;
    text-decoration: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.chat-message.bot a.tool-cta-btn:hover {
    background: #eff6ff;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.22);
}
.chat-message.bot a.tool-cta-btn .material-symbols-rounded {
    font-size: 18px;
}
.chat-message.bot code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.8125rem;
    background: rgba(255,255,255,0.12);
    padding: 2px 5px;
    border-radius: 6px;
}
.chat-message.bot pre {
    background: rgba(0,0,0,0.18);
    padding: 12px;
    border-radius: 10px;
    overflow: auto;
}
.chat-message.bot pre code {
    background: transparent;
    padding: 0;
}
.chat-message.bot table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.chat-message.bot th,
.chat-message.bot td {
    border: 1px solid rgba(255,255,255,0.22);
    padding: 8px 10px;
    vertical-align: top;
}
.chat-message.bot th {
    background: rgba(255,255,255,0.10);
    font-weight: 700;
}
.chat-message.bot blockquote {
    border-left: 3px solid rgba(255,255,255,0.35);
    padding-left: 10px;
    color: rgba(255,255,255,0.9);
}

.chat-message.error {
    background-color: var(--danger);
    color: white;
    align-self: center;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.loading-dots:after {
    content: '.';
    animation: dots 1.5s steps(5, end) infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60% { content: '...'; }
    80%, 100% { content: ''; }
}

/* Small clear chat button */
/* New chat / Clear chat: the first item of the scrolling message column,
   pinned to its top-right while the conversation scrolls. */
/* A strip across the top of the chat panel, in the panel's own colour, that the
   conversation scrolls under. It used to be two floating buttons with nothing
   behind them, which sat over (and hid) whatever message was at the top. */
.chat-toolbar {
    position: sticky;
    top: -16px;                     /* the panel's padding: stick to its very top */
    align-self: stretch;
    flex-shrink: 0;
    z-index: 10;
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin: -16px -16px 0;          /* full width: undo the panel's padding */
    padding: 10px 12px;
    /* The panel's tint is translucent; laid over the page colour it matches the
       panel and is opaque, so nothing scrolling under it shows through. */
    background: linear-gradient(var(--panel-bg), var(--panel-bg)), var(--bg-color);
    border-bottom: 1px solid var(--border-color);
}

.chat-toolbar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-toolbar-btn:hover {
    background-color: var(--card-hover);
    color: var(--text-primary);
    border-color: var(--accent-blue);
}

.chat-toolbar-btn .material-symbols-rounded {
    font-size: 16px;
}

/* Armed: the next click deletes this conversation. */
.chat-toolbar-btn.confirm,
.chat-toolbar-btn.confirm:hover {
    color: #dc2626;
    border-color: #dc2626;
    background-color: var(--card-bg);
}

#chat-container {
    position: relative;
}

/* ══════════════════════════════════════════════════════════
   KIDS THEME  (data-theme="kids")
   Full cartoon redesign. Scoped entirely to [data-theme="kids"].
   Zero impact on light or dark themes.
   ══════════════════════════════════════════════════════════ */

/* ─── CSS variables ─── */
:root[data-theme="kids"] {
    color-scheme: light;
    --bg-color:              #fef6ff;
    --card-bg:               #ffffff;
    --card-hover:            #fff8fd;
    --text-primary:          #2b1d6e;
    --text-secondary:        #7c5cbf;
    --accent-blue:           #f05fa3;
    --border-color:          #f9c0e0;
    --search-bg:             #ffffff;
    --surface-overlay:       #ffffff;
    --panel-bg:              rgba(240,95,163,0.06);
    --divider-color:         rgba(240,95,163,0.15);
    --shadow-elevated:       0 12px 40px rgba(240,95,163,0.20);
    --danger:                #ef4444;
    --chat-user-bg:          #fff0fa;
    --chat-bot-bg:           #f05fa3;
    --scrollbar-track:       #fce7f3;
    --scrollbar-thumb:       #f9a8d4;
    --scrollbar-thumb-hover: #f472b6;
}

/* ─── Bubbly font everywhere ─── */
:root[data-theme="kids"] body,
:root[data-theme="kids"] input,
:root[data-theme="kids"] select,
:root[data-theme="kids"] button,
:root[data-theme="kids"] textarea {
    font-family: 'Nunito', 'Inter', sans-serif !important;
}

/* ─── Page background: soft candy gradient + floating blobs ─── */
:root[data-theme="kids"] body {
    isolation: isolate;
    background: #fef6ff !important;
    background-image:
        radial-gradient(ellipse 55% 40% at 8%  15%,  rgba(255,182,255,0.45) 0%, transparent 100%),
        radial-gradient(ellipse 45% 35% at 92% 12%,  rgba(180,220,255,0.45) 0%, transparent 100%),
        radial-gradient(ellipse 50% 40% at 50% 92%,  rgba(180,255,220,0.40) 0%, transparent 100%),
        radial-gradient(ellipse 40% 30% at 88% 80%,  rgba(255,240,160,0.40) 0%, transparent 100%) !important;
    background-attachment: fixed !important;
    overflow-x: hidden !important;
}

/* ─── Floating cartoon clouds via body::before / ::after ─── */
:root[data-theme="kids"] body::before {
    content: '☁️';
    position: fixed;
    font-size: 5rem;
    top: 6%;
    left: 3%;
    opacity: 0.18;
    animation: kidsFloat 7s ease-in-out infinite;
    pointer-events: none;
    z-index: -1;
}

:root[data-theme="kids"] body::after {
    content: '☁️';
    position: fixed;
    font-size: 3.5rem;
    top: 12%;
    right: 5%;
    opacity: 0.14;
    animation: kidsFloat 9s ease-in-out infinite reverse;
    pointer-events: none;
    z-index: -1;
}

@keyframes kidsFloat {
    0%, 100% { transform: translateY(0px) translateX(0px); }
    33%       { transform: translateY(-12px) translateX(6px); }
    66%       { transform: translateY(-6px) translateX(-4px); }
}

:root[data-theme="kids"] .brand-name {
    font-weight: 900 !important;
    font-size: 1.15rem !important;
    background: linear-gradient(90deg, #e8006f, #7c3aed, #0ea5e9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none !important;
}

:root[data-theme="kids"] .brand-sub {
    font-weight: 800 !important;
    color: #7c3aed !important;
}

:root[data-theme="kids"] .brand-icon {
    background: rgba(255,255,255,0.6) !important;
    border-radius: 14px !important;
    box-shadow: 0 2px 8px rgba(240,95,163,0.25) !important;
}

/* ─── Hero section ─── */
:root[data-theme="kids"] .chat-shell {
    position: relative !important;
}

/* Big cartoon character left of hero text */
:root[data-theme="kids"] .hero-text {
    position: relative !important;
    background: rgba(255,255,255,0.55) !important;
    border-radius: 28px !important;
    padding: 32px 48px !important;
    border: 3px solid #f9c0e0 !important;
    box-shadow: 0 8px 32px rgba(240,95,163,0.15), 0 2px 0 rgba(255,255,255,0.8) inset !important;
    max-width: 780px !important;
    margin: 0 auto 32px !important;
}

/* Rocket on the left */
:root[data-theme="kids"] .hero-text::before {
    content: '🚀';
    position: absolute;
    font-size: 3.5rem;
    left: -28px;
    top: 50%;
    transform: translateY(-50%) rotate(-30deg);
    animation: kidsRocketWobble 3s ease-in-out infinite;
    pointer-events: none;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
}

/* Stars on the right */
:root[data-theme="kids"] .hero-text::after {
    content: '🌟';
    position: absolute;
    font-size: 2.8rem;
    right: -22px;
    top: 30%;
    animation: kidsSpin 5s linear infinite;
    pointer-events: none;
}

@keyframes kidsRocketWobble {
    0%, 100% { transform: translateY(-50%) rotate(-30deg) scale(1); }
    50%       { transform: translateY(calc(-50% - 10px)) rotate(-20deg) scale(1.05); }
}

@keyframes kidsSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

:root[data-theme="kids"] .hero-text h1 {
    font-family: 'Nunito', 'Inter', sans-serif !important;
    font-size: clamp(1.7rem, 4vw, 2.6rem) !important;
    font-weight: 900 !important;
    line-height: 1.35 !important;
    background: linear-gradient(135deg, #e8006f 0%, #7c3aed 50%, #0284c7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.01em !important;
}

/* ─── Search bar: wide bubbly pill ─── */
:root[data-theme="kids"] .search-container {
    border-radius: 999px !important;
    border: 3.5px solid #f9a8d4 !important;
    background: #ffffff !important;
    padding: 14px 22px 14px 28px !important;
    box-shadow:
        0 8px 28px rgba(240,95,163,0.18),
        0 2px 0 rgba(255,255,255,0.9) inset,
        0 -2px 0 rgba(240,95,163,0.08) inset !important;
    transition: border-color 0.2s, box-shadow 0.2s !important;
    max-width: 700px !important;
}

:root[data-theme="kids"] .search-container:focus-within {
    border-color: #e8006f !important;
    box-shadow:
        0 0 0 5px rgba(240,95,163,0.18),
        0 8px 28px rgba(240,95,163,0.18) !important;
}

:root[data-theme="kids"] .search-input {
    font-family: 'Nunito', 'Inter', sans-serif !important;
    font-size: 1.1rem !important;
    font-weight: 700 !important;
    color: #2b1d6e !important;
}

:root[data-theme="kids"] .search-input::placeholder {
    color: #d499e8 !important;
    font-weight: 700 !important;
}

/* ─── Send button: big gradient circle ─── */
:root[data-theme="kids"] #send-btn {
    background: linear-gradient(135deg, #f05fa3, #7c3aed) !important;
    color: #fff !important;
    border-radius: 50% !important;
    padding: 8px !important;
    font-size: 22px !important;
    box-shadow: 0 4px 16px rgba(240,95,163,0.45) !important;
    transition: transform 0.18s cubic-bezier(.34,1.56,.64,1), box-shadow 0.18s !important;
}

:root[data-theme="kids"] #send-btn:hover {
    transform: scale(1.2) rotate(-5deg) !important;
    box-shadow: 0 8px 24px rgba(240,95,163,0.55) !important;
}

/* ─── Section title ─── */
:root[data-theme="kids"] .section-title {
    font-family: 'Nunito', 'Inter', sans-serif !important;
    font-size: 1.5rem !important;
    font-weight: 900 !important;
    background: linear-gradient(90deg, #e8006f, #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.01em !important;
}

:root[data-theme="kids"] .section-title::before { content: '🎮 '; }

/* Card itself — kids theme */
:root[data-theme="kids"] .tool-card {
    border-radius: 24px !important;
    border: none !important;
    padding: 0 !important;
    gap: 0 !important;
    box-sizing: border-box !important;
    box-shadow:
        0 4px 6px rgba(0,0,0,0.04),
        0 10px 30px rgba(0,0,0,0.09) !important;
    transition: transform 0.22s cubic-bezier(.34,1.56,.64,1), box-shadow 0.22s !important;
    overflow: visible !important;
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    background: #fff !important;
}

/* ─── SVG banner: all themes ─── */
.tool-card-banner {
    display: block;
    width: 100%;
    margin: 0;
    height: 120px;
    flex-shrink: 0;
    line-height: 0;
    border-radius: 24px 24px 0 0;
    overflow: hidden;
}

.tool-card-banner svg {
    width: 100%;
    height: 100%;
    display: block;
    vertical-align: top;
}

/* Kids theme: wider padding */
:root[data-theme="kids"] .tool-card .card-header {
    padding: 18px 28px 6px 28px !important;
}

/* card-desc overflow:hidden swallows its own padding-bottom,
   so add a spacer after it via margin-bottom on the element,
   and put the actual bottom gap on the card itself */
:root[data-theme="kids"] .tool-card .card-desc {
    padding: 0 28px 0 28px !important;
    margin-bottom: 28px !important;
}

:root[data-theme="kids"] .tool-card:hover {
    transform: translateY(-8px) scale(1.02) !important;
    box-shadow:
        0 6px 8px rgba(0,0,0,0.04),
        0 20px 48px rgba(0,0,0,0.13) !important;
}

/* ─── Card header: stack icon above title in kids theme ─── */
:root[data-theme="kids"] .card-header {
    flex-direction: row !important;
    align-items: center !important;
    gap: 12px !important;
}

:root[data-theme="kids"] .card-title-area {
    flex: 1 !important;
    min-width: 0 !important;
}

:root[data-theme="kids"] .card-title {
    font-family: 'Nunito', 'Inter', sans-serif !important;
    font-size: 0.95rem !important;
    font-weight: 900 !important;
    color: #2b1d6e !important;
    line-height: 1.3 !important;
}

:root[data-theme="kids"] .card-header {
    min-height: 56px !important;
    align-items: center !important;
}

/* ─── Card icon bubble ─── */
:root[data-theme="kids"] .tool-icon {
    width: 44px !important;
    height: 44px !important;
    flex-shrink: 0 !important;
    border-radius: 16px !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.10) !important;
}

/* ─── Card description ─── */
:root[data-theme="kids"] .card-desc {
    font-size: 0.83rem !important;
    font-weight: 700 !important;
    line-height: 1.55 !important;
    -webkit-line-clamp: 2 !important;
    line-clamp: 2 !important;
    color: #5a4a8a !important;
}

/* ─── Tags: pill-shaped ─── */
:root[data-theme="kids"] .tag {
    border-radius: 999px !important;
    font-family: 'Nunito', 'Inter', sans-serif !important;
    font-weight: 800 !important;
    font-size: 0.68rem !important;
    padding: 2px 10px !important;
    background: rgba(240,95,163,0.12) !important;
    color: #c2185b !important;
}

/* ─── Chat bubbles ─── */
:root[data-theme="kids"] .chat-message.user {
    font-family: 'Nunito', 'Inter', sans-serif !important;
    font-weight: 700 !important;
    border-radius: 20px 20px 6px 20px !important;
}

:root[data-theme="kids"] .chat-message.bot {
    font-family: 'Nunito', 'Inter', sans-serif !important;
    border-radius: 6px 20px 20px 20px !important;
}

/* ─── User menu ─── */
:root[data-theme="kids"] .user-menu {
    border-radius: 22px !important;
    border: 2.5px solid #f9a8d4 !important;
    box-shadow: 0 12px 40px rgba(240,95,163,0.18) !important;
}

:root[data-theme="kids"] .menu-label,
:root[data-theme="kids"] .menu-select,
:root[data-theme="kids"] .user-menu-name {
    font-family: 'Nunito', 'Inter', sans-serif !important;
    font-weight: 800 !important;
}

/* ─── Clear chat button ─── */
:root[data-theme="kids"] .chat-toolbar-btn {
    border-radius: 999px !important;
    font-family: 'Nunito', 'Inter', sans-serif !important;
    font-weight: 800 !important;
    background: linear-gradient(135deg, #fce7f3, #ede9fe) !important;
    color: #7c3aed !important;
    border: 2px solid #f9a8d4 !important;
}

/* ─── Modal ─── */
:root[data-theme="kids"] .modal {
    border-radius: 26px !important;
    border: 3px solid #f9a8d4 !important;
}

/* ─── Scrollbar ─── */
:root[data-theme="kids"] ::-webkit-scrollbar-thumb {
    background: #f9a8d4 !important;
    border-radius: 999px !important;
}

:root[data-theme="kids"] ::-webkit-scrollbar-track {
    background: #fce7f3 !important;
}


/* ── Resource Library nav button (header) ────────────────────────────────── */

.resource-library-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 20px;
    border: 1.5px solid #7dd3fc;
    background: #f0f9ff;
    color: #0369a1;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
    cursor: pointer;
}
.resource-library-nav-btn:hover {
    background: #e0f2fe;
    border-color: #38bdf8;
    text-decoration: none;
}
:root[data-theme="dark"] .resource-library-nav-btn {
    background: #0c2232;
    border-color: #0369a1;
    color: #7dd3fc;
}
:root[data-theme="dark"] .resource-library-nav-btn:hover {
    background: #0f2d42;
}
.resource-library-nav-label {
    line-height: 1;
}
@media (max-width: 600px) {
    .resource-library-nav-label { display: none; }
    .resource-library-nav-btn { padding: 7px; border-radius: 50%; }
}

/* Platform attribution at the foot of the homepage. */
.site-attribution {
    margin: 36px 0 20px;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-secondary);
    opacity: 0.8;
}
