/* Shared visual system for application pages. Game canvases and article content
   retain their own internal layout. Keep theme tokens here, not in templates. */
html { color-scheme: dark; }
html.light-mode { color-scheme: light; }
html body {
    --bg: #142033 !important;
    --bg-secondary: #22324a !important;
    --bg-card: #1c2b41 !important;
    --bg-glass: #ffffff08 !important;
    --text: #f1f5fb !important;
    --text-primary: #f1f5fb !important;
    --text-secondary: #d0dae8 !important;
    --text-muted: #adbbcf !important;
    --border: #42536c !important;
    --border-hover: #b7a4ff !important;
    --primary: #8b5cf6;
    --primary-light: #c4b5fd;
    --primary-dark: #6d28d9;
    --action: #6d28d9;
    --action-hover: #5b21b6;
    --selection: #38345a;
    --card-bg: var(--bg-card) !important;
    --bg-color: var(--bg) !important;
    --surface: var(--bg-card);
    --surface2: var(--bg-secondary);
    --card: var(--bg-card);
    --muted: var(--text-muted);
    --border-color: var(--border);
    --bg-deep: var(--bg);
    --bg-surface: var(--bg-secondary);
    --border-glass: var(--border);
    --study-nav: var(--bg-card);
    --study-selection: var(--selection);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 20px;
    --shadow: 0 8px 28px #00000018;
    background: var(--bg) !important;
    color: var(--text) !important;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 1.65;
}
html.light-mode body {
    --bg: #f2f5fa !important;
    --bg-secondary: #e9eef7 !important;
    --bg-card: #ffffff !important;
    --bg-glass: #17243b06 !important;
    --text: #17243b !important;
    --text-primary: #17243b !important;
    --text-secondary: #34445c !important;
    --text-muted: #52627a !important;
    --border: #c9d4e4 !important;
    --border-hover: #7c3aed !important;
    --primary: #6d28d9;
    --primary-light: #6d28d9;
    --primary-dark: #5b21b6;
    --selection: #ede7ff;
    --shadow: 0 8px 28px #17243b0a;
}
/* Shared page widths. Reading and form pages are intentionally narrower. */
html body :is(.page-container, .admin-container, .school-page, .evaluations-page,
    .profile-page, .traffic, .ll-page, .listing-container, .gallery-main, .catalog-main,
    .study-container, .les-page, .ca-page, .explorer, .lesson-container, .exe-container) {
    box-sizing: border-box;
    width: 100%;
    max-width: 1280px;
    margin-inline: auto;
    padding-inline: clamp(16px, 3vw, 40px);
    padding-bottom: 48px;
    min-width: 0;
}
html body :is(.page, .chat-page, .legal-page, .article-detail-container) {
    box-sizing: border-box;
    width: 100%;
    max-width: 960px;
    margin-inline: auto;
    padding-inline: clamp(16px, 3vw, 40px);
}
html body :is(.les-page, .ca-page, .ll-page, .profile-page, .traffic) { padding-top: 100px; }
html body :is(.page-container, .school-page, .evaluations-page, .study-container, .page) { padding-top: 40px; }
html body :is(.page-title, .listing-title, .les-hero h1, .ll-hero-title, .ca-hero h1,
    .gallery-hero h1, .catalog-hero h1, .study-title, .profile-page h1,
    .school-page h1, .evaluations-page h1, .traffic h1, .auth-page h2) {
    font-size: clamp(1.75rem, 3vw, 2.5rem);
    line-height: 1.2;
    letter-spacing: -.035em;
    color: var(--text) !important;
    background: none !important;
    -webkit-text-fill-color: var(--text) !important;
}
html body :is(.subtitle, .study-subtitle, .gallery-hero-sub, .back, .back-link, .sub-help) { color: var(--text-muted); }
/* Surfaces share borders, radius and elevation, including legacy forms. */
html body :is(.form-card, .form-section, .list-panel, .school-card, .profile-panel,
    .traffic-panel, .traffic-metrics article, .study-card, .les-panel, .ca-panel,
    .tree-group, .detail-panel, .auth-card, .modal-box, .confirm-dialog, .legal-card,
    .chat-box, .chat-header-bar, .lesson-material, .lesson-text-card, .exercise-preview,
    .exe-card, .exe-editor-panel, .exe-chat-panel, .agent-card, .lesson-card, .listing-card,
    .ll-drawer, .ll-confirm-box, .ca-modal-box, .import-page .panel, .auth-page .card) {
    background: var(--bg-card) !important;
    color: var(--text);
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    min-width: 0;
}
html body :is(.form-card, .form-section, .school-card, .profile-panel, .study-card,
    .les-panel, .ca-panel, .auth-card, .auth-page .card) { padding: clamp(20px, 3vw, 32px); }
html body :is(.header-actions, .school-toolbar, .evaluations-toolbar, .study-toolbar,
    .catalog-toolbar, .traffic-header, .ll-topbar, .chat-header-bar, .top-buttons,
    .actions-row, .btn-row) { gap: 12px; flex-wrap: wrap; }
html body :is(.form-grid, .les-form-grid, .profile-grid, .school-form, .details-grid) { gap: 20px; }
html body :is(.form-grid, .les-form-grid, .profile-grid, .school-form, .details-grid) > * { min-width: 0; }
html body :is(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]):not([type=hidden]), select, textarea) {
    box-sizing: border-box;
    background: var(--bg-card) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px;
    font-family: inherit;
    font-size: 1rem;
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    accent-color: var(--action);
}
html body :is(input, textarea)::placeholder { color: var(--text-muted); opacity: 1; }
html body textarea { line-height: 1.65; }
html body select option { background: var(--bg-card); color: var(--text); }
html body button { font-family: inherit; }
html body :is(.btn, .btn-save, .btn-submit, .btn-ca-submit, .btn-custom, .btn-primary,
    .btn-sm, .btn-action, .btn-create, .les-btn, .ll-new-btn, .exercise-start) {
    border-radius: 10px;
    min-height: 44px;
    font-weight: 650;
    text-decoration: none;
    transition: background-color .15s, border-color .15s, box-shadow .15s;
}
html body :is(.btn-primary, .btn-primary-sm, .btn-save, .btn-submit, .btn-ca-submit,
    .btn-custom, .btn-create, .ll-new-btn, .exercise-start) {
    background: var(--action) !important;
    color: #fff !important;
    -webkit-text-fill-color: #fff;
    border-color: transparent;
}
html body :is(.btn-primary, .btn-save, .btn-submit, .btn-ca-submit, .btn-custom, .exercise-start):hover:not(:disabled) {
    background: var(--action-hover) !important;
    transform: none;
    box-shadow: 0 4px 12px #6d28d926;
}
html body .btn-ghost { background: var(--bg-secondary); color: var(--text) !important; border: 1px solid var(--border); }
html body :is(button, input, select, textarea, a, [tabindex]):focus-visible { outline: 3px solid var(--primary-light) !important; outline-offset: 3px; }
html body :is(button, input):disabled { cursor: not-allowed; opacity: .55; }
html body :is(.school-table, .traffic-table, .table-wrapper, .table-container, .list-panel) { overflow-x: auto; }
html body :is(.school-table, .traffic-table, .exercise-table) :is(th, td) { padding: 14px 16px; border-color: var(--border); color: var(--text) !important; }
html body :is(.school-table, .traffic-table, .exercise-table) th { background: var(--bg-secondary); text-align: left; }
html body :is(.school-table, .traffic-table, .exercise-table) tbody tr:hover { background: var(--bg-glass); }
html body :is(.navbar, .eliseo-header, .book-header, .game-topbar) { background: var(--bg-card) !important; border-color: var(--border); color: var(--text); }
html body :is(.socratico-sidebar, .socratico-bottom) { background: var(--bg-card) !important; color: var(--text-secondary); border-color: var(--border) !important; }
html body .socratico-sidebar a:hover { background: var(--bg-secondary) !important; color: var(--text) !important; }
html body :is(.socratico-sidebar, .socratico-bottom) a[aria-current] { background: var(--selection) !important; color: var(--primary-light) !important; }
html body .theme-toggle-icon {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 44px; min-height: 44px; padding: 8px;
    border: 1px solid var(--border) !important; border-radius: 12px;
    background: var(--bg-card) !important; color: var(--text) !important;
    cursor: pointer; font-size: 1.15rem;
}
html body .app-theme-control { position: fixed; right: 16px; bottom: 20px; z-index: 1150; box-shadow: var(--shadow); }
html body.auth-page { min-height: 100dvh; padding: 32px 16px; }
html body.auth-page :is(.auth-card, .card) { width: 100%; max-width: 460px; }
html body.auth-page :is(.footer-text, .divider, .subtitle, .back-link) { color: var(--text-muted); }
html body.auth-page :is(.footer-text a, .forgot-link) { color: var(--primary-light); }
html body.auth-page :is(h1, h2, .logo, .subtitle strong) { color: var(--text) !important; -webkit-text-fill-color: var(--text); }
html body :is(.ql-toolbar, .ql-container) { border-color: var(--border) !important; background: var(--bg-card) !important; }
html body .ql-editor { color: var(--text) !important; }
html body .ql-editor.ql-blank::before { color: var(--text-muted); }
html body .ql-snow .ql-stroke { stroke: var(--text-secondary); }
html body .ql-snow .ql-fill { fill: var(--text-secondary); }
html body .ql-snow .ql-picker { color: var(--text-secondary); }
html body :is(.chat-input-row, .exe-chat-input, .exe-chat-header, .import-page .header) { background: var(--bg-secondary) !important; color: var(--text); }
html body :is(.chat-input-row, .exe-chat-input) input { flex: 1; min-width: 0; }
html.light-mode body :is(.msg pre, .msg code) { background: var(--bg-secondary); }
html.light-mode body :is(.text-error, .msg.error) { color: #b91c1c; }
html.light-mode body :is(.text-success-msg, .msg.success) { color: #166534; }
html.light-mode body.eliseo-page { --gold-1: #8a580b; --gold-2: #91610c; --text-secondary: #52627a !important; }
@media (max-width: 800px) {
    html body .app-theme-control { bottom: calc(92px + env(safe-area-inset-bottom)); }
    html body.auth-page .app-theme-control { bottom: 16px; }
    html body :is(.form-grid, .les-form-grid, .details-grid) { grid-template-columns: minmax(0, 1fr); }
    html body :is(.page-container, .school-page, .evaluations-page, .study-container, .page) { padding-top: 24px; }
    html body .chat-input-row { gap: 8px; padding: 12px; }
    html body .chat-input-row button { padding-inline: 14px; }
    html body .node-details { padding-left: 16px; }
    html body .node-summary { flex-wrap: wrap; }
    html body .status-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
/* Reading, information pages and specialist tools use the same outer shell. */
html body {
    --card-glass: var(--bg-card);
    --landing-bg-color: var(--bg);
    --landing-card-bg: var(--bg-card);
    --landing-card-border: var(--border);
    --landing-text-main: var(--text);
    --landing-text-muted: var(--text-muted);
}
html body :is(.landing-wrapper, .editor-wrapper, .games-body, .game-play-body) { background: var(--bg); color: var(--text); }
html body :is(.glass-card, .info-hero-card, .info-panel, .price-card, .contact-card,
    .game-card, .editor-wrapper .app-container) {
    background: var(--bg-card); color: var(--text); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
html body :is(.lesson-title, .games-hero h1, .landing-wrapper .hero-title,
    .landing-wrapper .section-title, .editor-wrapper h1) {
    color: var(--text) !important; background: none !important; -webkit-text-fill-color: var(--text) !important;
}
html body :is(.legal-card h2, .legal-card h3, .legal-badge, .lesson-material-header,
    .lesson-badge-section, .ca-hero-badge, .img-picker-btn, .game-topbar-back,
    .game-card-title, .game-topbar-title h1) { color: var(--primary-light); }
html body :is(.games-hero .subtitle, .game-card-desc, .landing-wrapper .section-subtitle) { color: var(--text-muted); }
html body .games-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
html body :is(.editor-wrapper .toolbar, .editor-wrapper .file-zone, .ql-snow .ql-picker-options) {
    background: var(--bg-secondary); color: var(--text); border-color: var(--border);
}
html body .editor-wrapper :is(.tool-btn, .file-label) { background: var(--bg-secondary); color: var(--text); border-color: var(--border); }
html body .editor-wrapper .tool-btn.active { background: var(--action); color: #fff; }
html body :is(.form-control, .search-input)::placeholder { color: var(--text-muted); opacity: 1; }
html.light-mode body :is(.legal-card a, .legal-card strong, .info-panel-body strong) { color: var(--primary-dark); }
html body :is(.lesson-container, .exe-container, .editor-wrapper) { padding-top: 96px; }
html body :is(.lesson-layout, .ca-layout, .explorer-layout) > * { min-width: 0; }
html body input[type=file] { box-sizing: border-box; min-width: 0; max-width: 100%; color: var(--text); }
html body.agent-settings-page :is(.toggle-row, .images-container, .field > a, input[type=file]) {
    background: var(--bg-secondary) !important; color: var(--text); border-color: var(--border);
}
html body.agent-settings-page .switch { flex: 0 0 44px; margin-left: 12px; }
html body .agent-upload-row { flex-wrap: wrap; }
html body .agent-upload-row input { flex-basis: 180px !important; }
html body :is(.header-panel h1, .explorer h1) { color: var(--text); background: none; -webkit-text-fill-color: var(--text); font-size: clamp(1.75rem, 3vw, 2.5rem); }
html body .explorer-nav { top: 88px; }
html body.agent-settings-page { --accent: var(--primary-light); }
html.light-mode body.eliseo-page { --gold-gradient: linear-gradient(135deg, #8a580b, #996614); --purple-accent: #6d28d9; }
html.light-mode body.eliseo-page .msg-bubble pre { background: var(--bg-secondary); }
html body.import-page .header h1 { background: none; color: var(--text); -webkit-text-fill-color: var(--text); }
/* Keep the decorative hero glow inside narrow viewports even while scaling. */
html body .hero::before { width: min(76vw, 600px); }
