/* ===== SOCRATIC TUTOR — Theme-Adaptive Styles ===== */

#socratic-tutor-app {
    --st-primary: #2ea3f2;
    --st-primary-dark: #1a8cd8;
    --st-primary-light: #0f2135;
    --st-bg: #0a0a0a;
    --st-card: #151515;
    --st-text: #f0f0f0;
    --st-text2: #b0b0b0;
    --st-text3: #6b6b6b;
    --st-border: #2a2a2a;
    --st-radius: 14px;
    /* Z-index scale — kept here so layering is consistent across components.
       Fullscreen chat must sit above page chrome; modal/toast sit above that. */
    --st-z-chat-fullscreen: 100001;
    --st-z-toast: 100002;
    --st-z-modal: 100010;
    font-family: inherit;
    color: var(--st-text);
    line-height: 1.7;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
    font-size: 16px;
}

/* Color variants computed in CSS — overrides PHP fallbacks when supported */
@supports (color: color-mix(in oklch, red, blue)) {
    #socratic-tutor-app {
        --st-primary-dark: color-mix(in oklch, var(--st-primary), black 20%);
        --st-primary-light: color-mix(in oklch, var(--st-primary), var(--st-bg) 85%);
    }
}

/* Zero-specificity resets — theme CSS can override these without !important */
:where(#socratic-tutor-app) *, :where(#socratic-tutor-app) *::before, :where(#socratic-tutor-app) *::after { box-sizing: border-box; }
:where(#socratic-tutor-app) a { color: var(--st-primary); text-decoration: none; }
:where(#socratic-tutor-app) button { cursor: pointer; font-family: inherit; border: none; background: none; }
:where(#socratic-tutor-app) input, :where(#socratic-tutor-app) textarea { font-family: inherit; }

/* ===== HERO ===== */
.st-hero { text-align: center; padding: 48px 20px 28px; }
.st-hero-logo { max-height: 70px; margin-bottom: 18px; }
.st-hero-title { font-size: 2.2rem; font-weight: 700; margin: 0 0 10px; color: var(--st-primary); }
.st-hero-text { font-size: 1.1rem; color: var(--st-text2); max-width: 620px; margin: 0 auto; opacity: 0.85; }

/* ===== CATEGORY FILTER ===== */
.st-category-filter { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 32px; }
.st-pill {
    padding: 8px 20px; border-radius: 24px; font-size: 0.9rem; font-weight: 500;
    background: var(--st-card); color: var(--st-text2); border: 1.5px solid var(--st-border);
    transition: all 0.25s; cursor: pointer;
}
.st-pill:hover { border-color: var(--st-primary); color: var(--st-primary); }
.st-pill.active { background: var(--st-primary); color: #fff; border-color: var(--st-primary); }

/* ===== SUBJECT CARDS ===== */
.st-subjects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 24px; padding-bottom: 48px; container-type: inline-size; }
.st-card {
    background: var(--st-card); border-radius: var(--st-radius); overflow: hidden;
    border: 1.5px solid var(--st-border); transition: transform 0.25s, box-shadow 0.25s;
    display: flex; flex-direction: column;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.st-card:hover { transform: translateY(-4px); box-shadow: 0 12px 32px rgba(0,0,0,0.12); }
.st-card-cover {
    height: 180px; background: var(--st-primary-light);
    display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative;
}
.st-card-cover img { width: 100%; height: 100%; object-fit: cover; }
.st-card-cover .st-cover-icon { font-size: 3.5rem; opacity: 0.5; }
.st-card-cover .st-cover-icon-img { width: 80px; height: 80px; object-fit: contain; }
.st-card-badge {
    position: absolute; top: 12px; left: 12px; padding: 4px 12px; border-radius: 12px;
    font-size: 0.75rem; font-weight: 600; color: #fff; background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
}
.st-card-body { padding: 20px; display: flex; flex-direction: column; flex-grow: 1; }
.st-card-body h3 { font-size: 1.2rem; font-weight: 700; margin: 0 0 6px; }
.st-card-body p {
    font-size: 0.95rem; color: var(--st-text2); flex-grow: 1; margin: 0 0 16px;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.st-card-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding-top: 16px; border-top: 1px solid var(--st-border);
}
.st-card-footer .st-mat-count { font-size: 0.8rem; color: var(--st-text3); }
.st-btn-study {
    background: var(--st-primary); color: #fff; padding: 10px 24px; border-radius: 24px;
    font-size: 0.9rem; font-weight: 600; transition: background 0.25s, transform 0.15s;
}
.st-btn-study:hover { background: var(--st-primary-dark); transform: scale(1.03); }

/* ===== EMPTY STATE ===== */
.st-empty { text-align: center; padding: 60px 20px; color: var(--st-text2); }
.st-empty-icon { font-size: 3rem; margin-bottom: 14px; opacity: 0.4; }
.st-empty h3 { font-size: 1.2rem; margin: 0 0 8px; }
.st-empty p { margin: 0; }

/* ===== CHAT VIEW ===== */
/* When portaled to <body>, chat needs its own font/color context */
body > #st-chat-view {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--st-text);
    line-height: 1.7;
    font-size: 16px;
}
body > #st-chat-view *, body > #st-chat-view *::before, body > #st-chat-view *::after { box-sizing: border-box; }
body > #st-chat-view button { cursor: pointer; font-family: inherit; border: none; background: none; }
body > #st-chat-view a { color: var(--st-primary); text-decoration: none; }

#st-chat-view {
    display: flex; flex-direction: column;
    min-height: 75vh; max-height: 88vh;
    background: var(--st-bg); border-radius: var(--st-radius);
    overflow: hidden; border: 1.5px solid var(--st-border);
}

.st-chat-header {
    padding: 14px 24px; background: var(--st-card); border-bottom: 1.5px solid var(--st-border);
    display: flex; align-items: center; gap: 14px;
}
.st-chat-back { color: var(--st-text2); font-size: 0.95rem; font-weight: 500; padding: 8px 0; transition: color 0.2s; }
.st-chat-back:hover { color: var(--st-primary); }
.st-chat-header-info { flex: 1; min-width: 0; }
.st-chat-header-info h2 { font-size: 1.1rem; font-weight: 700; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-chat-subtitle { font-size: 0.8rem; color: var(--st-text3); }
.st-btn-icon {
    width: 36px; height: 36px; border-radius: 8px; background: var(--st-bg);
    display: flex; align-items: center; justify-content: center; font-size: 1rem;
    color: var(--st-text); transition: background 0.2s;
}
.st-btn-icon svg { fill: currentColor; }
.st-btn-icon:hover { background: var(--st-primary-light); }

/* ===== MESSAGES ===== */
.st-chat-messages { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 24px; display: flex; flex-direction: column; gap: 16px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.st-msg { display: flex; gap: 12px; max-width: 78%; animation: stMsgIn 0.3s ease; content-visibility: auto; contain-intrinsic-size: auto 80px; }
@keyframes stMsgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.st-msg-user { align-self: flex-end; flex-direction: row-reverse; }
.st-msg-avatar {
    width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-size: 0.9rem; flex-shrink: 0;
}
.st-msg-user .st-msg-avatar { background: var(--st-primary); color: #fff; }
.st-msg-tutor .st-msg-avatar { background: var(--st-primary-light); color: var(--st-primary); }
.st-msg-bubble { padding: 12px 18px; border-radius: var(--st-radius); font-size: clamp(0.9rem, 2.2vw, 1rem); word-wrap: break-word; overflow-wrap: break-word; hyphens: auto; line-height: 1.5; color: var(--st-text); overflow-x: auto; }
.st-msg-user .st-msg-bubble { background: var(--st-primary); color: #fff; border-bottom-right-radius: 4px; }
.st-msg-tutor .st-msg-bubble { background: var(--st-card); border: 1.5px solid var(--st-border); border-bottom-left-radius: 4px; color: var(--st-text); }

/* Markdown in messages */
.st-msg-bubble strong { font-weight: 700; }
.st-msg-bubble em { font-style: italic; }
.st-msg-bubble code { background: rgba(0,0,0,0.06); padding: 2px 6px; border-radius: 4px; font-size: 0.88em; }
.st-msg-user .st-msg-bubble code { background: rgba(255,255,255,0.2); }
.st-msg-bubble hr { border: none; border-top: 1.5px solid var(--st-border); margin: 8px 0; }
.st-msg-user .st-msg-bubble hr { border-top-color: rgba(255,255,255,0.3); }
.st-msg-bubble p { margin: 0 0 4px; }
.st-msg-bubble p:last-child { margin-bottom: 0; }
.st-msg-bubble ul, .st-msg-bubble ol { margin: 4px 0; padding-left: 20px; }
.st-msg-bubble li { margin-bottom: 2px; }
.st-msg-bubble hr { margin: 8px 0; }
.st-msg-bubble .st-md-oli { margin: 2px 0; padding-left: 4px; }
.st-msg-bubble .st-md-num { font-weight: 700; color: var(--st-primary); }
.st-msg-bubble .st-md-table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 0.9em; }
.st-msg-bubble .st-md-table th,
.st-msg-bubble .st-md-table td { padding: 6px 10px; border: 1px solid var(--st-border); text-align: left; }
.st-msg-bubble .st-md-table th { background: rgba(255,255,255,0.05); font-weight: 700; }
.st-msg-user .st-msg-bubble .st-md-table th,
.st-msg-user .st-msg-bubble .st-md-table td { border-color: rgba(255,255,255,0.2); }
.st-msg-user .st-msg-bubble .st-md-table th { background: rgba(255,255,255,0.1); }

/* ===== COPY BUTTON ===== */
.st-btn-copy {
    position: absolute; top: 6px; right: 6px;
    width: 28px; height: 28px; border-radius: 6px;
    background: rgba(0,0,0,0.15); color: var(--st-text);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; cursor: pointer; opacity: 0;
    transition: opacity 0.2s, background 0.2s; border: none; padding: 0;
}
.st-msg-tutor:hover .st-btn-copy { opacity: 1; }
.st-btn-copy:hover { background: rgba(0,0,0,0.3); }
.st-msg-tutor { position: relative; }

/* ===== OPTION BUTTONS ===== */
.st-option-buttons {
    display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px;
    padding-top: 14px; border-top: 1px solid var(--st-border);
}
.st-option-btn {
    background: var(--st-primary-light); color: var(--st-primary); border: 1.5px solid var(--st-primary);
    padding: 8px 18px; border-radius: 20px; font-size: 0.88rem; font-weight: 600;
    cursor: pointer; transition: all 0.2s;
}
.st-option-btn:hover {
    background: var(--st-primary); color: #fff; transform: scale(1.03);
}

/* ===== WELCOME ===== */
.st-welcome { text-align: center; padding: 36px 20px; color: var(--st-text2); }
.st-welcome-icon { font-size: 3rem; margin-bottom: 14px; }
.st-welcome h2 { font-size: 1.3rem; font-weight: 700; margin: 0 0 8px; }
.st-welcome p { font-size: 1rem; max-width: 400px; margin: 0 auto; }

/* ===== START SCREEN ===== */
.st-start-screen {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 60px 20px; flex: 1; min-height: 50vh;
}
.st-start-icon { font-size: 4rem; margin-bottom: 20px; }
.st-start-subject-icon { width: 80px; height: 80px; object-fit: contain; border-radius: 12px; margin-bottom: 20px; }
.st-start-screen h2 { font-size: 1.5rem; font-weight: 700; margin: 0 0 12px; color: var(--st-text); }
.st-start-screen p { font-size: 1rem; color: var(--st-text2); max-width: 420px; margin: 0 0 32px; opacity: 0.85; line-height: 1.6; }
.st-btn-start {
    background: var(--st-primary); color: #fff; padding: 14px 44px; border-radius: 28px;
    font-size: 1.1rem; font-weight: 700; cursor: pointer; border: none;
    transition: background 0.25s, transform 0.15s; font-family: inherit;
}
.st-btn-start:hover { background: var(--st-primary-dark); transform: scale(1.04); }
.st-btn-resume {
    background: transparent; color: var(--st-primary); padding: 10px 28px; border-radius: 24px;
    font-size: 0.9rem; font-weight: 600; cursor: pointer; margin-top: 16px;
    border: 1.5px solid var(--st-primary); transition: all 0.25s; font-family: inherit;
}
.st-btn-resume:hover { background: var(--st-primary); color: #fff; }

/* ===== FULLSCREEN ===== */
#st-chat-view.st-fullscreen {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important; height: 100dvh !important;
    max-height: 100vh !important; max-height: 100dvh !important;
    min-height: 100vh !important; min-height: 100dvh !important;
    border-radius: 0 !important; border: none !important;
    z-index: var(--st-z-chat-fullscreen, 100001);
    margin: 0 !important;
    background: var(--st-bg) !important;
}

/* Admin bar compensation — fullscreen desktop (32px) */
body.admin-bar #st-chat-view.st-fullscreen {
    top: 32px;
    height: calc(100vh - 32px) !important; height: calc(100dvh - 32px) !important;
    min-height: calc(100vh - 32px) !important; min-height: calc(100dvh - 32px) !important;
    max-height: calc(100vh - 32px) !important; max-height: calc(100dvh - 32px) !important;
}
@media screen and (max-width: 782px) {
    body.admin-bar #st-chat-view.st-fullscreen {
        top: 46px;
        height: calc(100vh - 46px) !important; height: calc(100dvh - 46px) !important;
        min-height: calc(100vh - 46px) !important; min-height: calc(100dvh - 46px) !important;
        max-height: calc(100vh - 46px) !important; max-height: calc(100dvh - 46px) !important;
    }
}
@media screen and (max-width: 600px) {
    body.admin-bar #st-chat-view.st-fullscreen {
        top: 0;
        height: 100vh !important; height: 100dvh !important;
        min-height: 100vh !important; min-height: 100dvh !important;
        max-height: 100vh !important; max-height: 100dvh !important;
    }
}

/* Safe area insets for fullscreen (notch / island devices) */
#st-chat-view.st-fullscreen .st-chat-header {
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    padding-left: calc(24px + env(safe-area-inset-left, 0px));
    padding-right: calc(24px + env(safe-area-inset-right, 0px));
}
#st-chat-view.st-fullscreen .st-chat-input-area {
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(24px + env(safe-area-inset-left, 0px));
    padding-right: calc(24px + env(safe-area-inset-right, 0px));
}

/* Body scroll lock (fullscreen & mobile) */
body.st-no-scroll {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
    top: calc(-1 * var(--st-scroll-position, 0px));
}

/* ===== COVERAGE INDICATOR (in-action transparency) ===== */
.st-coverage-indicator {
    display: flex; align-items: center; gap: 8px;
    margin-top: 2px;
}
.st-coverage-bar {
    width: 60px; height: 4px; background: var(--st-border);
    border-radius: 2px; overflow: hidden; flex-shrink: 0;
}
.st-coverage-fill {
    height: 100%; background: var(--st-primary);
    border-radius: 2px; transition: width 0.5s ease;
}
.st-coverage-text {
    font-size: 0.7rem; color: var(--st-text3); white-space: nowrap;
}

/* ===== REGENERATE BUTTON ===== */
#st-btn-regenerate {
    font-size: 0.85rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}
#st-btn-regenerate:hover { opacity: 1; }

/* ===== TYPING ===== */
.st-typing { display: none; padding: 12px 16px; background: var(--st-card); border: 1.5px solid var(--st-border); border-radius: var(--st-radius); border-bottom-left-radius: 4px; margin: 0 24px; align-self: flex-start; }
.st-typing.active { display: flex; gap: 5px; align-items: center; }
.st-typing-dot { width: 8px; height: 8px; background: var(--st-text3); border-radius: 50%; animation: stBounce 1.4s infinite; }
.st-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.st-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes stBounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* ===== INPUT ===== */
.st-chat-input-area { padding: 16px 24px; background: var(--st-card); border-top: 1.5px solid var(--st-border); }
.st-chat-input-wrapper { display: flex; align-items: flex-end; gap: 12px; max-width: 780px; margin: 0 auto; }
.st-chat-input {
    flex: 1; border: 1.5px solid var(--st-border); border-radius: var(--st-radius);
    padding: 12px 16px; font-size: 1rem; resize: none; min-height: 44px; max-height: 120px;
    outline: none; color: #fff !important; background: transparent; transition: border-color 0.2s;
}
.st-chat-input:focus { border-color: var(--st-primary); box-shadow: 0 0 0 3px rgba(46,163,242,0.12); }
.st-chat-input::placeholder { color: var(--st-text3); }
.st-chat-input:disabled { opacity: 0.5; cursor: not-allowed; }
.st-btn-send {
    width: 44px; height: 44px; background: var(--st-primary); color: #fff; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
    flex-shrink: 0; transition: background 0.2s;
}
.st-btn-send:hover { background: var(--st-primary-dark); }
.st-btn-send:disabled { background: var(--st-border); cursor: not-allowed; }
.st-btn-voice {
    width: 44px; height: 44px; background: var(--st-bg); color: var(--st-text);
    border: 1.5px solid var(--st-border); border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
    flex-shrink: 0; transition: all 0.2s; cursor: pointer;
}
.st-btn-voice:hover { border-color: var(--st-primary); background: var(--st-primary-light); }
.st-btn-voice.st-voice-active { background: #e53e3e; border-color: #e53e3e; color: #fff; animation: stPulse 1.5s ease-in-out infinite; }
.st-input-hint { text-align: center; font-size: 0.75rem; color: var(--st-text3); margin-top: 8px; }

/* ===== TIME LIMIT ===== */
.st-time-limit-msg {
    text-align: center; padding: 40px 20px; margin: 20px 0;
    background: var(--st-card); border-radius: var(--st-radius);
    border: 2px dashed var(--st-border);
}
.st-time-limit-icon { font-size: 3rem; margin-bottom: 12px; }
.st-time-limit-msg h3 { font-size: 1.2rem; margin: 0 0 8px; color: var(--st-primary); }
.st-time-limit-msg p { font-size: 0.95rem; color: var(--st-text2); margin: 0; }

/* ===== TOAST ===== */
.st-toast {
    position: fixed; bottom: 24px; right: 24px; padding: 12px 22px; color: #fff;
    border-radius: 10px; font-size: 0.9rem; z-index: var(--st-z-toast, 100002);
    animation: stToastIn 0.3s ease, stToastOut 0.3s ease 2.7s forwards;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
@keyframes stToastIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes stToastOut { to { opacity: 0; transform: translateY(10px); } }
.st-toast-error { background: #e53e3e; }
.st-toast-success { background: #38a169; }
.st-toast-info { background: #3182ce; }

/* ===== RESPONSIVE ===== */

/* -- TABLET (max 768px) -- */
@media (max-width: 768px) {
    #socratic-tutor-app { padding: 0 12px; font-size: 15px; }
    .st-hero-title { font-size: 1.5rem; }
    .st-hero { padding: 20px 12px 16px; }
    .st-hero-text { font-size: 0.95rem; }
    .st-hero-logo { max-height: 50px; margin-bottom: 12px; }

    /* Category pills: horizontal scroll instead of wrapping */
    .st-category-filter {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0 12px 12px;
        gap: 8px;
        scroll-snap-type: x mandatory;
    }
    .st-category-filter::-webkit-scrollbar { display: none; }
    .st-pill { white-space: nowrap; flex-shrink: 0; scroll-snap-align: start; padding: 10px 20px; min-height: 44px; display: flex; align-items: center; }

    /* Cards: single column, compact */
    .st-subjects-grid { grid-template-columns: 1fr; gap: 14px; padding-bottom: 32px; }
    .st-card-cover { height: 150px; }
    .st-card-body { padding: 16px; }
    .st-card-body h3 { font-size: 1.1rem; }
    .st-card-body p { font-size: 0.9rem; margin-bottom: 12px; -webkit-line-clamp: 2; }
    .st-btn-study { padding: 12px 24px; min-height: 44px; font-size: 0.95rem; }
    .st-card-footer .st-mat-count { font-size: 0.78rem; }

    .st-msg { max-width: 90%; }

    /* Chat fullscreen on mobile (WhatsApp-style) */
    #st-chat-view {
        position: fixed !important;
        inset: 0 !important;
        height: 100vh !important; height: 100dvh !important;
        min-height: 100vh !important; min-height: 100dvh !important;
        max-height: 100vh !important; max-height: 100dvh !important;
        width: 100vw !important;
        border-radius: 0 !important; border: none !important;
        z-index: var(--st-z-chat-fullscreen, 100001);
        margin: 0 !important;
        background: var(--st-bg) !important;
    }
    /* Admin bar compensation — mobile/tablet (46px) */
    body.admin-bar #st-chat-view {
        top: 46px;
        height: calc(100vh - 46px) !important; height: calc(100dvh - 46px) !important;
        min-height: calc(100vh - 46px) !important; min-height: calc(100dvh - 46px) !important;
        max-height: calc(100vh - 46px) !important; max-height: calc(100dvh - 46px) !important;
    }
    .st-chat-messages { padding: 16px; gap: 12px; }
    .st-chat-input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
    .st-chat-header {
        padding: 12px 16px;
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
        min-height: 52px;
    }

    /* Touch-friendly: all interactive elements min 44px */
    .st-btn-send { width: 48px; height: 48px; }
    .st-btn-attach { width: 44px; height: 44px; }
    .st-btn-icon { width: 44px; height: 44px; }
    .st-chat-back { padding: 12px 0; min-height: 44px; display: flex; align-items: center; font-size: 1rem; }
    .st-option-btn { padding: 12px 20px; font-size: 0.95rem; min-height: 44px; }
    .st-chat-input { font-size: 16px; min-height: 48px; }

    /* Toast repositioned for mobile */
    .st-toast { bottom: auto; top: 12px; right: 12px; left: 12px; text-align: center; }

    /* Copy button always visible on touch */
    .st-btn-copy { opacity: 0.7; }

    /* Suggested questions: inside messages area on mobile (scrollable, not fixed) */
    .st-suggested-questions {
        flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
        padding: 8px 0; gap: 6px; border-top: none; background: transparent;
    }
    .st-suggested-label { display: none; }
    .st-suggested-btn { white-space: nowrap; flex-shrink: 0; min-height: 36px; padding: 6px 14px; font-size: 0.8rem; }

    /* Scrollbar hidden on mobile */
    .st-chat-messages::-webkit-scrollbar { display: none; }
    .st-chat-messages { -ms-overflow-style: none; scrollbar-width: none; }

    /* Start screen compact */
    .st-start-screen { padding: 40px 16px; min-height: 40vh; }
    .st-start-icon { font-size: 3rem; }
    .st-start-subject-icon { width: 60px; height: 60px; }
    .st-start-screen h2 { font-size: 1.3rem; }
    .st-start-screen p { font-size: 0.92rem; margin-bottom: 24px; }
    .st-btn-start { padding: 14px 40px; font-size: 1rem; min-height: 48px; }
    .st-btn-resume { min-height: 44px; padding: 10px 24px; }

    /* Empty state compact */
    .st-empty { padding: 40px 16px; }
}

/* -- Admin bar resets at ≤600px (WP admin bar becomes position:absolute) -- */
@media (max-width: 600px) {
    body.admin-bar #st-chat-view {
        top: 0;
        height: 100vh !important; height: 100dvh !important;
        min-height: 100vh !important; min-height: 100dvh !important;
        max-height: 100vh !important; max-height: 100dvh !important;
    }
}

/* -- MOBILE SMALL (max 480px) -- */
@media (max-width: 480px) {
    .st-hero-title { font-size: 1.3rem; }
    .st-hero-text { font-size: 0.9rem; }
    .st-hero { padding: 16px 8px 12px; }
    .st-card-cover { height: 120px; }
    .st-msg-bubble { font-size: 0.92rem; padding: 10px 14px; }
    .st-msg-avatar { width: 28px; height: 28px; font-size: 0.75rem; }
    .st-msg { gap: 8px; }
    .st-chat-header-info h2 { font-size: 1rem; }
    .st-welcome h2 { font-size: 1.1rem; }
    .st-welcome-icon { font-size: 2.5rem; }
    .st-image-preview img { max-height: 60px; max-width: 80px; }
    /* Cards: horizontal layout on small phones */
    .st-card { flex-direction: row; }
    .st-card:hover { transform: none; }
    .st-card-cover { height: auto; width: 100px; min-height: 100px; flex-shrink: 0; border-radius: var(--st-radius) 0 0 var(--st-radius); }
    .st-card-body { padding: 12px; }
    .st-card-body h3 { font-size: 1rem; }
    .st-card-body p { -webkit-line-clamp: 2; font-size: 0.85rem; margin-bottom: 8px; }
    .st-card-footer { padding-top: 8px; }
    .st-btn-study { padding: 8px 16px; font-size: 0.85rem; }
    .st-card-badge { top: 6px; left: 6px; font-size: 0.65rem; padding: 2px 8px; }
}

/* -- MOBILE TINY (max 360px) — very small phones -- */
@media (max-width: 360px) {
    .st-hero-title { font-size: 1.15rem; }
    .st-hero-text { font-size: 0.85rem; }
    .st-card-cover { width: 80px; min-height: 80px; }
    .st-card-body h3 { font-size: 0.95rem; }
    .st-card-body { padding: 10px; }
    .st-card-body p { display: none; }
    .st-card-footer { border-top: none; padding-top: 4px; }
    .st-card-footer .st-mat-count { display: none; }
    .st-btn-study { width: 100%; }
    .st-chat-input { font-size: 16px; padding: 10px 12px; }
    .st-msg-bubble { font-size: 0.88rem; padding: 8px 12px; }
    .st-option-btn { padding: 10px 14px; font-size: 0.85rem; }
    .st-pill { font-size: 0.8rem; padding: 8px 14px; }
}

/* -- LANDSCAPE MOBILE -- */
@media (max-height: 500px) and (orientation: landscape) {
    #st-chat-view {
        min-height: 100vh !important; min-height: 100dvh !important;
        max-height: 100vh !important; max-height: 100dvh !important;
        z-index: var(--st-z-chat-fullscreen, 100001);
    }
    .st-chat-header { padding: 8px 16px; min-height: 44px; }
    .st-chat-header-info h2 { font-size: 0.95rem; }
    .st-chat-subtitle { display: none; }
    .st-chat-messages { padding: 8px 16px; gap: 8px; }
    .st-chat-input-area { padding: 8px 16px; }
    .st-start-screen { padding: 20px; min-height: auto; }
    .st-start-icon, .st-start-subject-icon { display: none; }
    .st-start-screen h2 { font-size: 1.1rem; margin-bottom: 8px; }
    .st-start-screen p { margin-bottom: 16px; }
}

/* ===== IMAGE ATTACH BUTTON ===== */
.st-btn-attach {
    width: 40px; height: 40px; border-radius: 50%; background: var(--st-bg);
    border: 1.5px solid var(--st-border); display: flex; align-items: center;
    justify-content: center; font-size: 1.1rem; flex-shrink: 0;
    transition: border-color 0.2s, background 0.2s; cursor: pointer;
}
.st-btn-attach:hover { border-color: var(--st-primary); background: var(--st-primary-light); }

/* ===== IMAGE PREVIEW ===== */
.st-image-preview {
    display: flex; align-items: center; gap: 10px; margin-top: 10px;
    padding: 8px 12px; background: var(--st-bg); border: 1.5px solid var(--st-border);
    border-radius: var(--st-radius); max-width: 780px; margin-left: auto; margin-right: auto;
}
.st-image-preview img { max-height: 80px; max-width: 120px; border-radius: 8px; object-fit: cover; }
.st-btn-remove-img {
    width: 28px; height: 28px; border-radius: 50%; background: rgba(229,62,62,0.15);
    color: #e53e3e; display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; cursor: pointer; border: none; transition: background 0.2s;
    margin-left: auto; flex-shrink: 0;
}
.st-btn-remove-img:hover { background: rgba(229,62,62,0.3); }

/* ===== SUGGESTED QUESTIONS ===== */
.st-suggested-questions {
    display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
    padding: 10px 24px; background: var(--st-card); border-top: 1px solid var(--st-border);
}
.st-suggested-label { font-size: 0.78rem; color: var(--st-text3); margin-right: 4px; }
.st-suggested-btn {
    background: var(--st-bg); color: var(--st-text2); border: 1.5px solid var(--st-border);
    padding: 6px 16px; border-radius: 18px; font-size: 0.82rem; cursor: pointer;
    transition: all 0.2s; font-family: inherit;
}
.st-suggested-btn:hover {
    border-color: var(--st-primary); color: var(--st-primary); background: var(--st-primary-light);
}

/* ===== KATEX OVERRIDES ===== */
.st-msg-bubble .katex { font-size: 1em; }
.st-msg-bubble .katex-display { margin: 12px 0; overflow-x: auto; overflow-y: hidden; }

/* ===== ACCESSIBILITY ===== */

/* Screen reader only */
.st-sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Focus visible for keyboard navigation */
#socratic-tutor-app :focus-visible {
    outline: 2px solid var(--st-primary);
    outline-offset: 2px;
}
#socratic-tutor-app button:focus:not(:focus-visible),
#socratic-tutor-app textarea:focus:not(:focus-visible) {
    outline: none;
}

/* Reduced motion: disable all animations */
@media (prefers-reduced-motion: reduce) {
    #socratic-tutor-app *, #socratic-tutor-app *::before, #socratic-tutor-app *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .st-card:hover { transform: none; }
    .st-btn-study:hover { transform: none; }
    .st-btn-start:hover { transform: none; }
    .st-option-btn:hover { transform: none; }
}

/* High contrast adjustments */
@media (prefers-contrast: high) {
    .st-msg-tutor .st-msg-bubble { border-width: 2px; }
    .st-pill { border-width: 2px; }
    .st-chat-input { border-width: 2px; }
    .st-btn-study { border: 2px solid #fff; }
    .st-card { border-width: 2px; }
}

/* ===== REMAINING TIME INDICATOR ===== */
.st-remaining-time {
    font-size: 0.7rem; color: var(--st-text3); white-space: nowrap;
    padding: 2px 8px; background: var(--st-border); border-radius: 10px;
    display: inline-block; margin-top: 2px;
}
.st-remaining-caution { color: #f6ad55; background: rgba(246,173,85,0.15); }
.st-remaining-warning { color: #fc8181; background: rgba(252,129,129,0.15); animation: stPulse 2s ease-in-out infinite; }
@keyframes stPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ===== SCROLLBAR ===== */
.st-chat-messages::-webkit-scrollbar { width: 6px; }
.st-chat-messages::-webkit-scrollbar-track { background: transparent; }
.st-chat-messages::-webkit-scrollbar-thumb { background: var(--st-border); border-radius: 3px; }

/* ===== DASHBOARD ===== */
#socratic-dashboard-app {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--st-text, #f0f0f0); max-width: 900px; margin: 0 auto; padding: 0 20px;
    --st-bg: #0a0a0a; --st-card: #151515; --st-text: #f0f0f0; --st-text2: #b0b0b0;
    --st-text3: #6b6b6b; --st-border: #2a2a2a; --st-radius: 14px;
}
.st-dashboard-loading { text-align: center; padding: 60px; color: var(--st-text3); }
.st-dashboard-summary {
    display: flex; gap: 16px; margin-bottom: 32px; flex-wrap: wrap;
}
.st-dash-stat {
    flex: 1; min-width: 120px; background: var(--st-card); border: 1.5px solid var(--st-border);
    border-radius: var(--st-radius); padding: 20px; text-align: center;
}
.st-dash-stat-num { display: block; font-size: 1.5rem; font-weight: 700; color: var(--st-primary, #2ea3f2); }
.st-dash-stat-label { font-size: 0.8rem; color: var(--st-text3); }
.st-dashboard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.st-dash-card {
    background: var(--st-card); border: 1.5px solid var(--st-border); border-radius: var(--st-radius);
    padding: 20px; transition: transform 0.2s;
}
.st-dash-card:hover { transform: translateY(-2px); }
.st-dash-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.st-dash-card-header h3 { margin: 0; font-size: 1.1rem; font-weight: 700; color: var(--st-text); }
.st-dash-card-header small { color: var(--st-text3); font-size: 0.8rem; }
.st-dash-icon { width: 40px; height: 40px; border-radius: 8px; object-fit: contain; }
.st-dash-emoji { font-size: 2rem; }
.st-dash-progress {
    height: 6px; background: var(--st-border); border-radius: 3px; overflow: hidden; margin-bottom: 10px;
}
.st-dash-progress-fill { height: 100%; background: var(--st-primary, #2ea3f2); border-radius: 3px; transition: width 0.5s; }
.st-dash-card-info { display: flex; justify-content: space-between; align-items: center; }
.st-dash-badge { font-size: 0.75rem; color: var(--st-text2); padding: 2px 8px; background: var(--st-border); border-radius: 8px; }
.st-dash-completed { color: #38a169; background: rgba(56,161,105,0.15); }
.st-dash-time { font-size: 0.75rem; color: var(--st-text3); }

@media (prefers-color-scheme: light) {
    #socratic-dashboard-app {
        --st-bg: #fff; --st-card: #f5f6f8; --st-text: #1a1a2e;
        --st-text2: #555566; --st-text3: #8888a0; --st-border: #e2e4e8;
    }
}

/* ===== CONCEPT MAP MODAL ===== */
.st-concepts-modal {
    position: fixed; inset: 0; z-index: var(--st-z-modal, 100010); background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.st-concepts-content {
    background: var(--st-card, #151515); border-radius: var(--st-radius, 14px);
    max-width: 420px; width: 100%; max-height: 70vh; overflow-y: auto;
    border: 1.5px solid var(--st-border, #2a2a2a); padding: 20px;
}
.st-concepts-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.st-concepts-header h3 { margin: 0; font-size: 1.1rem; color: var(--st-text, #f0f0f0); }
.st-concept-item {
    padding: 8px 12px; margin-bottom: 4px; border-radius: 8px;
    background: var(--st-bg, #0a0a0a); color: var(--st-text, #f0f0f0); font-size: 0.9rem;
}
.st-concept-num { color: var(--st-primary, #2ea3f2); font-weight: 700; margin-right: 4px; }

/* ===== CONTAINER QUERIES — card adaptation ===== */
@container (max-width: 350px) {
    .st-card-cover { height: 120px; }
    .st-card-body h3 { font-size: 1rem; }
    .st-card-body { padding: 14px; }
    .st-card-body p { -webkit-line-clamp: 2; }
}

/* ===== LIGHT MODE (opt-in via data attribute) ===== */
#socratic-tutor-app[data-st-theme="auto"] {
    /* Light mode inherits from user's system preference */
}
@media (prefers-color-scheme: light) {
    #socratic-tutor-app[data-st-theme="auto"] {
        --st-bg: #ffffff;
        --st-card: #f5f6f8;
        --st-text: #1a1a2e;
        --st-text2: #555566;
        --st-text3: #8888a0;
        --st-border: #e2e4e8;
    }
    #socratic-tutor-app[data-st-theme="auto"] .st-chat-input { color: var(--st-text) !important; }
    #socratic-tutor-app[data-st-theme="auto"] .st-msg-tutor .st-msg-bubble code { background: rgba(0,0,0,0.06); }
}
