:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef1f8;
    --text: #141a2b;
    --muted: #5d6680;
    --border: #dde2ee;
    --accent: #6d5dfc;
    --accent-2: #22c5c5;
    --danger: #e5484d;
    --shadow: 0 6px 24px rgba(20, 26, 43, .08);
    --radius: 16px;

    --happy: #f5b400;
    --sad: #3b82f6;
    --angry: #ef4444;
    --surprise: #ec4899;
    --neutral: #10b981;
    --disgust: #84cc16;
    --fear: #8b5cf6;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0b0f1a;
        --surface: #131a2a;
        --surface-2: #1b2438;
        --text: #e8ecf6;
        --muted: #94a0bb;
        --border: #26314a;
        --shadow: 0 6px 24px rgba(0, 0, 0, .35);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0b0f1a;
    --surface: #131a2a;
    --surface-2: #1b2438;
    --text: #e8ecf6;
    --muted: #94a0bb;
    --border: #26314a;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
}

h1, h2 { margin: 0; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1rem; font-weight: 600; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: .8rem; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 24px;
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand .muted { font-size: .8rem; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.pill {
    font-size: .78rem;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    white-space: nowrap;
}
.pill-ok { color: var(--neutral); }
.pill-wait { color: var(--happy); }
.pill-err { color: var(--danger); }

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: 20px;
    padding: 20px 24px 40px;
    max-width: 1400px;
    margin: 0 auto;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    min-width: 0;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.history-card { grid-column: 1 / -1; }

/* ---------- Kamera ---------- */
.stage {
    position: relative;
    aspect-ratio: 4 / 3;
    background: #05070d;
    border-radius: 12px;
    overflow: hidden;
}
.stage video, .stage img, .stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}
/* Mode cermin hanya untuk kamera, bukan video dari URL. */
.stage.mirror[data-mode="camera"] video { transform: scaleX(-1); }
.stage[data-mode="tab"] { aspect-ratio: 16 / 9; }
/* isolation: syarat Element Capture (RestrictionTarget) agar overlay tidak ikut terekam. */
.stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; isolation: isolate; }
/* Overlay tidak boleh menghalangi kontrol video/YouTube di bawahnya. */
.stage canvas { pointer-events: none; }
.stage.dragging { outline: 3px dashed var(--accent); outline-offset: -6px; }

.placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    text-align: center;
    color: #aab3c9;
    padding: 16px;
}
.big-emoji { font-size: 4rem; animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px); } }

.drop-hint {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    background: color-mix(in srgb, var(--accent) 35%, transparent);
    color: #fff;
    font-weight: 600;
}

.stats-inline { display: flex; gap: 10px; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.controls.compact { margin-top: 0; }
.url-form { display: flex; gap: 8px; margin-top: 8px; }
.url-form .select { flex: 1; min-width: 0; max-width: none; cursor: text; }
.url-hint { margin: 6px 0 0; }

.btn, .select {
    font: inherit;
    font-size: .88rem;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 14px;
    cursor: pointer;
    text-decoration: none;
    transition: transform .1s, background .2s;
}
.btn:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 12%, var(--surface-2)); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, #000); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.select { max-width: 220px; }
.icon-btn { font-size: 1.1rem; background: none; border: none; cursor: pointer; padding: 6px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Mood ---------- */
.mood-hero { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.mood-emoji {
    font-size: 4.2rem;
    line-height: 1;
    transition: transform .3s;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .2));
}
.mood-emoji.pop { animation: pop .4s; }
@keyframes pop { 40% { transform: scale(1.25) rotate(-6deg); } }
.mood-label { font-size: 1.6rem; font-weight: 700; text-transform: capitalize; }
.mood-extra { font-size: .85rem; margin-top: 4px; }

.bars { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.bars li { display: grid; grid-template-columns: 96px 1fr 52px; align-items: center; gap: 8px; font-size: .85rem; }
.bars .track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bars .fill { height: 100%; width: 0; border-radius: inherit; transition: width .35s ease; }
.bars .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.bars li.active { font-weight: 600; }

.vibe { margin-top: 18px; }
.vibe-track {
    position: relative;
    height: 10px;
    margin: 6px 0 4px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--angry), var(--sad), var(--neutral), var(--happy));
}
.vibe-marker {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--surface);
    border: 3px solid var(--text);
    transform: translate(-50%, -50%);
    transition: left .4s ease;
}
.vibe-scale { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); }

/* ---------- Grafik & tabel ---------- */
.chart-wrap { position: relative; height: 260px; }
.summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { font-size: .8rem; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); }
.table-wrap { max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; }
.tag { display: inline-flex; align-items: center; gap: 6px; text-transform: capitalize; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ---------- Dialog & toast ---------- */
.dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    width: min(440px, calc(100vw - 32px));
    padding: 20px;
}
.dialog::backdrop { background: rgba(5, 8, 16, .55); backdrop-filter: blur(3px); }
.dialog form { display: grid; gap: 14px; }
.dialog label { display: grid; gap: 6px; font-size: .9rem; }
.dialog label.check { display: flex; align-items: center; gap: 8px; }
.dialog output { color: var(--accent); font-weight: 600; margin-left: 6px; }
.dialog input[type="range"] { accent-color: var(--accent); }
.dialog .select { max-width: none; }
.dialog-actions { display: flex; justify-content: flex-end; }
kbd { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font-size: .75rem; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, calc(100% + 32px));
    opacity: 0;
    background: var(--text);
    color: var(--bg);
    padding: 10px 18px;
    border-radius: 12px;
    font-size: .88rem;
    transition: transform .3s ease, opacity .3s;
    z-index: 50;
    max-width: calc(100vw - 32px);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 960px) {
    .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
    .topbar { padding: 10px 16px; }
    .brand .muted { display: none; }
    h1 { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
