:root {
    --font-body: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    --focus-ring: rgba(79, 70, 229, 0.26);
    --badge-bg: #eef2ff;
    --badge-text: #4338ca;
    --surface-hover: #f1f5f9;
}

body[data-theme="dark"] {
    color-scheme: dark;
    --focus-ring: rgba(129, 140, 248, 0.34);
    --badge-bg: #242d4a;
    --badge-text: #c7d2fe;
    --surface-hover: #202b3e;
}

html {
    color-scheme: light;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    line-height: 1.55;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    animation: page-enter 280ms ease-out both;
}

@keyframes page-enter {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes card-enter {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes menu-enter {
    from { opacity: 0; transform: translateY(-4px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

body,
button,
input,
select,
textarea {
    font-family: var(--font-body);
}

h1,
h2,
h3,
h4,
h5,
p {
    overflow-wrap: anywhere;
}

h1,
h2,
h3,
h4 {
    color: var(--text);
    letter-spacing: -0.025em;
    line-height: 1.25;
}

p {
    line-height: 1.65;
}

a {
    text-underline-offset: 3px;
}

.icon-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.nav-icon {
    display: block;
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    transition: transform 160ms ease;
}

.icon-link:hover .nav-icon {
    transform: scale(1.08);
}

a:hover {
    color: var(--primary-strong);
}

button,
.button,
.action,
.button-like,
.primary-btn,
.secondary-btn,
.learning-button,
.blocks-button,
.submit-btn {
    font-family: var(--font-body);
    transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

.page-shell {
    max-width: 1280px;
}

.topbar {
    background: var(--panel);
    border-color: var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    backdrop-filter: none;
}

.brand-mark {
    border-radius: 13px;
    background: var(--primary);
    box-shadow: none;
}

.topnav,
.muted,
.hero-copy p,
.feature-card p,
.stat-card small {
    color: var(--muted);
}

.badge {
    background: var(--badge-bg);
    border-color: transparent;
    color: var(--badge-text);
    margin-bottom: 12px;
}

.badge.secondary {
    background: color-mix(in srgb, var(--secondary) 12%, var(--panel));
    border-color: transparent;
    color: var(--secondary);
}

.button.primary,
.action,
.button-like.primary,
.primary-btn,
.learning-button,
.blocks-button.primary,
.submit-btn {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: none;
    color: #ffffff;
}

.button.primary:hover,
.action:hover,
.button-like.primary:hover,
.primary-btn:hover,
.learning-button:hover,
.blocks-button.primary:hover,
.submit-btn:hover {
    background: var(--primary-strong);
    border-color: var(--primary-strong);
    color: #ffffff;
    transform: translateY(-1px);
}

.button.secondary,
.button-like,
.secondary-btn,
.blocks-button {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
}

.action.secondary {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
}

.action.secondary:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.button.secondary:hover,
.button-like:hover,
.secondary-btn:hover,
.blocks-button:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.danger {
    background: color-mix(in srgb, #dc2626 12%, var(--panel));
    border-color: color-mix(in srgb, #dc2626 25%, var(--border));
    color: #b91c1c;
}

body[data-theme="dark"] .danger {
    color: #fca5a5;
}

.hero-panel,
.stat-card,
.feature-card,
.architecture-box,
.auth-shell,
.topbar-card,
.card,
.panel,
.learning-top,
.learning-card,
.class-card,
.assignment-card,
.blocks-header,
.blocks-panel {
    background: var(--panel);
    border-color: var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.hero-panel,
.stat-card,
.feature-card,
.card,
.panel,
.learning-top,
.learning-card,
.class-card,
.assignment-card,
.blocks-header,
.blocks-panel {
    animation: card-enter 360ms ease-out both;
}

.feature-card,
.stat-card {
    background: var(--panel);
}

.architecture-box {
    background: var(--panel-alt);
}

.code-preview {
    background: #101827;
}

.auth-shell {
    color: var(--text);
}

.auth-header {
    border-color: var(--border);
}

.field label,
.learning-form label,
.blocks-actions label {
    color: var(--text);
}

input:not([type="hidden"]),
select,
textarea,
.field input,
.field select,
.learning-form input,
.learning-form textarea,
.blocks-actions input {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--input-text);
    font-size: 0.95rem;
}

input::placeholder,
textarea::placeholder {
    color: var(--muted);
    opacity: 0.8;
}

.role-badge {
    background: var(--badge-bg);
    color: var(--badge-text);
}

.user-list li,
.students-list li,
.file-list li {
    border-color: var(--border);
    color: var(--text);
}

.list-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
}

.list-heading h2 {
    margin: 0;
}

.list-heading p {
    margin: 4px 0 0;
    font-size: 0.85rem;
}

.dashboard .user-list {
    max-height: 480px;
    overflow-y: auto;
    padding-right: 4px;
}

.user-list li {
    min-height: 52px;
    gap: 12px;
    border-color: var(--border);
    color: var(--text);
}

.user-identity {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 10px;
}

.user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-avatar {
    display: grid;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 50%;
    background: var(--badge-bg);
    color: var(--badge-text);
    font-size: 0.82rem;
    font-weight: 700;
}

.user-row-menu {
    position: relative;
    flex: 0 0 auto;
}

.user-row-menu summary {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border: 1px solid transparent;
    border-radius: 9px;
    color: var(--muted);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    list-style: none;
}

.user-row-menu summary span {
    transition: transform 140ms ease;
}

.user-row-menu[open] summary span {
    transform: rotate(90deg);
}

.user-row-menu summary::-webkit-details-marker {
    display: none;
}

.user-row-menu summary:hover,
.user-row-menu[open] summary {
    background: var(--surface-hover);
    border-color: var(--border);
    color: var(--text);
}

.user-row-popover {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    right: 0;
    display: grid;
    min-width: 170px;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
    box-shadow: var(--shadow);
    transform-origin: top right;
    animation: menu-enter 140ms ease-out both;
}

.user-row-popover a {
    padding: 9px 10px;
    border-radius: 7px;
    color: var(--text);
    font-size: 0.88rem;
}

.user-row-popover a:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.user-row-popover .nav-icon {
    width: 16px;
    height: 16px;
}

.sql-helper {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.84rem;
}

.sql-helper code {
    overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}

.learning-message.success,
.message {
    background: color-mix(in srgb, var(--success) 10%, var(--panel));
    border-color: color-mix(in srgb, var(--success) 25%, var(--border));
    color: var(--success);
}

.learning-message.error,
.error {
    background: color-mix(in srgb, #dc2626 9%, var(--panel));
    border-color: color-mix(in srgb, #dc2626 24%, var(--border));
    color: #b91c1c;
}

body[data-theme="dark"] .learning-message.error,
body[data-theme="dark"] .error {
    color: #fca5a5;
}

.theme-toggle {
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    border-radius: 999px;
    padding: 9px 14px;
    font-size: 0.85rem;
    font-weight: 650;
    cursor: pointer;
}

.theme-toggle:hover {
    background: var(--surface-hover);
}

.theme-toggle-floating {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.dashboard {
    max-width: 1180px;
}

.dashboard .grid {
    grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
    gap: 16px;
}

.dashboard .card {
    padding: 22px;
}

.workspace-shell {
    max-width: 1500px;
}

.workspace-layout {
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
}

.workspace-editor-layout {
    grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
}

.toolbar,
.preview-header,
.sql-toolbar,
.file-meta,
.status-bar,
.panel-title {
    border-color: var(--border);
    color: var(--text);
}

.tree {
    color: var(--text);
}

.tree button {
    color: var(--text);
}

.tree button:hover {
    background: var(--surface-hover);
}

.CodeMirror {
    border-radius: 8px;
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 0.9rem;
}

body[data-theme="dark"] .blocklyMainBackground {
    fill: #111827;
}

body:not([data-theme="dark"]) .blocklyMainBackground {
    fill: #f8fafc;
}

body[data-theme="dark"] .blocklyToolboxDiv,
body[data-theme="dark"] .blocklyFlyout {
    background-color: #182235;
}

body:not([data-theme="dark"]) .blocklyToolboxDiv,
body:not([data-theme="dark"]) .blocklyFlyout {
    background-color: #f1f5ff;
}

body[data-theme="dark"] .blocklyToolboxDiv .blocklyTreeLabel,
body[data-theme="dark"] .blocklyFlyout .blocklyText {
    fill: #e6edf7;
    color: #e6edf7;
}

body:not([data-theme="dark"]) .blocklyToolboxDiv .blocklyTreeLabel,
body:not([data-theme="dark"]) .blocklyFlyout .blocklyText {
    fill: #1e293b;
    color: #1e293b;
}

.sqlite-table-button,
summary {
    cursor: pointer;
}

dialog,
dialog form {
    background: var(--panel);
    color: var(--text);
}

dialog {
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

@media (max-width: 900px) {
    .workspace-layout {
        grid-template-columns: 1fr;
    }

    .workspace-editor-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .page-shell {
        padding: 12px 12px 36px;
    }

    .hero {
        padding-top: 32px;
    }

    .dashboard .grid {
        grid-template-columns: 1fr;
    }

    .theme-toggle-floating {
        right: 12px;
        bottom: 12px;
    }
}
