/* TV Class — Modern edu SaaS design system */

:root {
    --bg: #F6F8FC;
    --bg-elev: #FFFFFF;
    --surface-2: #F1F4FA;
    --border: #E4E8F0;
    --border-strong: #CBD3E1;

    --ink-900: #0B1220;
    --ink-700: #1F2A44;
    --ink-500: #475569;
    --ink-400: #64748B;
    --ink-300: #94A3B8;

    --brand: #4F46E5;
    --brand-600: #4338CA;
    --brand-50: #EEF0FF;
    --accent: #14B8A6;
    --accent-50: #E6FAF6;

    --success: #10B981;
    --success-50: #ECFDF5;
    --warn: #F59E0B;
    --warn-50: #FFF7E6;
    --danger: #EF4444;
    --danger-50: #FEF2F2;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --radius-pill: 999px;

    --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.04);
    --shadow-2: 0 8px 24px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.04);
    --shadow-brand: 0 10px 30px rgba(79, 70, 229, 0.18);

    --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink-700);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-600); }

/* Layout shell */
.shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.shell-header {
    padding: 18px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elev);
}
.shell-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
}
.shell-body.start-top { align-items: flex-start; padding-top: 56px; }
.shell-footer {
    padding: 14px 28px;
    text-align: center;
    color: var(--ink-300);
    font-size: 12.5px;
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--ink-900);
    letter-spacing: -0.01em;
}
.brand-mark {
    width: 30px; height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--accent) 100%);
    box-shadow: var(--shadow-brand);
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 14px;
}
.brand-title { font-size: 15px; }
.brand-sub { color: var(--ink-300); font-weight: 500; font-size: 12.5px; margin-left: 4px; }

/* Card */
.card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
    padding: 32px;
    width: 100%;
    max-width: 560px;
}
.card.wide { max-width: 880px; }
.card.tv  { max-width: 1100px; padding: 40px; }

.kicker {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 4px 10px;
    background: var(--brand-50);
    color: var(--brand);
    border-radius: var(--radius-pill);
    font-size: 12px; font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.kicker.accent { background: var(--accent-50); color: #0F766E; }

h1.title {
    font-size: 28px; line-height: 1.2;
    color: var(--ink-900);
    margin: 14px 0 8px;
    letter-spacing: -0.02em;
    font-weight: 700;
}
h2.subtitle {
    font-size: 18px;
    color: var(--ink-700);
    margin: 0 0 6px;
    font-weight: 600;
}
p.lede { color: var(--ink-500); margin: 0 0 22px; }
p.muted { color: var(--ink-400); }

/* Buttons */
.btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 11px 18px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    transition: transform .08s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease;
    text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--brand);
    color: #fff;
    box-shadow: var(--shadow-brand);
}
.btn-primary:hover { background: var(--brand-600); color: #fff; }
.btn-secondary {
    background: var(--bg-elev);
    color: var(--ink-700);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost {
    background: transparent;
    color: var(--ink-500);
}
.btn-ghost:hover { color: var(--ink-900); background: var(--surface-2); }
.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: #DC2626; color: #fff; }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 22px; font-size: 16px; border-radius: var(--radius); }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* Role picker (start screen) */
.role-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 8px;
}
@media (max-width: 620px) {
    .role-grid { grid-template-columns: 1fr; }
}
.role-card {
    appearance: none;
    text-align: left;
    background: var(--bg-elev);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    cursor: pointer;
    transition: border-color .15s ease, transform .08s ease, box-shadow .15s ease;
    font: inherit;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 180px;
}
.role-card:hover {
    border-color: var(--brand);
    box-shadow: var(--shadow-2);
    transform: translateY(-1px);
}
.role-card .role-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--brand-50); color: var(--brand);
}
.role-card .role-icon.accent { background: var(--accent-50); color: #0F766E; }
.role-card h3 { margin: 0; font-size: 17px; color: var(--ink-900); }
.role-card p { margin: 0; color: var(--ink-500); font-size: 13.5px; }

/* Status pills */
.pill {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 5px 11px;
    border-radius: var(--radius-pill);
    font-size: 12.5px; font-weight: 600;
    background: var(--surface-2);
    color: var(--ink-500);
}
.pill .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: currentColor; opacity: .85;
}
.pill.waiting { background: var(--warn-50); color: #92400E; }
.pill.paired  { background: var(--success-50); color: #065F46; }
.pill.error   { background: var(--danger-50); color: #991B1B; }
.pill.live {
    background: var(--success-50); color: #065F46;
}
.pill.live .dot {
    animation: pulseDot 1.4s ease-in-out infinite;
}
@keyframes pulseDot {
    0%,100% { transform: scale(1); opacity: .85; }
    50%     { transform: scale(1.4); opacity: 1; }
}

/* Status text */
.status {
    margin-top: 18px;
    padding: 12px 14px;
    background: var(--surface-2);
    color: var(--ink-500);
    border-radius: var(--radius);
    font-size: 13.5px;
}
.status.error { background: var(--danger-50); color: #991B1B; }
.status.success { background: var(--success-50); color: #065F46; }

/* Meta */
.meta {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px dashed var(--border);
    color: var(--ink-400);
    font-size: 12.5px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 16px;
}
.meta dt { color: var(--ink-300); }
.meta dd { margin: 0; color: var(--ink-500); }

/* QR */
.qr-stage {
    display: grid;
    grid-template-columns: minmax(280px, 360px) 1fr;
    gap: 32px;
    align-items: center;
    margin-top: 14px;
}
@media (max-width: 820px) {
    .qr-stage { grid-template-columns: 1fr; }
}
.qr-frame {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-2);
    display: flex; align-items: center; justify-content: center;
    aspect-ratio: 1 / 1;
    position: relative;
    overflow: hidden;
}
.qr-frame img { width: 100%; height: 100%; object-fit: contain; display: block; }
.qr-frame.loading::after {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(110deg, transparent 30%, rgba(79,70,229,0.08) 50%, transparent 70%);
    animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { 0% { transform: translateX(-100%);} 100% { transform: translateX(100%);} }

.code-display {
    font-family: var(--font-mono);
    font-size: 38px;
    letter-spacing: 0.3em;
    color: var(--ink-900);
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 14px 18px;
    text-align: center;
    margin-top: 14px;
}

.steps { list-style: none; padding: 0; margin: 18px 0 0; }
.steps li {
    display: flex; gap: 12px; padding: 10px 0;
    color: var(--ink-500);
}
.steps li .num {
    flex: 0 0 26px; height: 26px;
    border-radius: 50%;
    background: var(--brand-50); color: var(--brand);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
}

/* TV (room) full-bleed layout */
.tv-stage {
    min-height: 100vh;
    background:
        radial-gradient(1200px 600px at 80% -10%, rgba(79,70,229,0.10), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, rgba(20,184,166,0.10), transparent 60%),
        var(--bg);
    display: flex; align-items: center; justify-content: center;
    padding: 40px;
}
.tv-room {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    gap: 56px;
    max-width: 1200px;
    width: 100%;
    align-items: center;
}
.tv-room .qr-frame { max-width: 420px; }
.tv-room h1 { font-size: 38px; line-height: 1.1; margin: 18px 0 10px; color: var(--ink-900); letter-spacing: -0.02em; }
.tv-room .lede { font-size: 16px; }
.tv-room .code-display { font-size: 48px; }

/* Lesson list */
.lesson-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
    margin-top: 18px;
}
.lesson-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    cursor: pointer;
    transition: border-color .15s ease, transform .08s ease, box-shadow .15s ease;
    text-align: left;
    text-decoration: none;
    color: inherit;
    display: flex; flex-direction: column; gap: 8px;
    min-height: 140px;
}
.lesson-card:hover {
    border-color: var(--brand);
    box-shadow: var(--shadow-2);
    transform: translateY(-1px);
}
.lesson-card .lesson-title {
    font-size: 15.5px; font-weight: 600; color: var(--ink-900); margin: 0;
}
.lesson-card .lesson-desc {
    font-size: 13px; color: var(--ink-500); margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.lesson-card .lesson-tag {
    margin-top: auto;
    font-size: 11.5px; font-weight: 600;
    color: var(--brand);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Toolbar */
.toolbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}
.toolbar .left { display: flex; align-items: center; gap: 10px; }

/* Lesson viewer */
.viewer-frame {
    width: 100%;
    height: calc(100vh - 110px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-elev);
    box-shadow: var(--shadow-1);
    overflow: hidden;
}
.viewer-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

/* Toast */
.toast {
    position: fixed; bottom: 24px; left: 50%;
    transform: translateX(-50%);
    background: var(--ink-900);
    color: #fff;
    padding: 10px 16px;
    border-radius: var(--radius-pill);
    font-size: 13.5px;
    box-shadow: var(--shadow-2);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* Hide chrome when running in webview-only fullscreen lesson */
body.embedded .shell-header,
body.embedded .shell-footer { display: none; }
body.embedded .shell-body { padding: 0; align-items: stretch; }
body.embedded .viewer-frame { height: 100vh; border-radius: 0; border: 0; }
