/* ============================================================
   OSKI — Soft-Dark Gold UI
   Tokens derived from design.json
   ============================================================ */
:root {
    --canvas: #DCD6C7;
    --canvas-alt: #D4CEBE;

    --surface: #171A21;
    --surface-2: #1C2028;
    --surface-base: #121419;
    --surface-sunken: #0E1014;
    --overlay: rgba(18,20,25,.72);

    --stroke-hairline: rgba(255,255,255,.06);
    --stroke-soft: rgba(255,255,255,.09);

    --text: rgba(255,255,255,.92);
    --text-secondary: rgba(255,255,255,.70);
    --muted: rgba(255,255,255,.52);
    --faint: rgba(255,255,255,.38);
    --on-canvas: rgba(14,16,20,.86);

    --gold: #D6B15C;
    --gold-soft: #C8A65A;
    --gold-dim: rgba(214,177,92,.55);
    --gold-glow: rgba(214,177,92,.22);

    --danger: #FF5A6A;
    --success: #58D49E;

    --r-sm: 14px;
    --r-md: 18px;
    --r-lg: 24px;
    --r-xl: 32px;
    --r-pill: 9999px;

    --pad: 20px;
    --gap: 16px;

    --shadow-card:
        0 18px 40px -18px rgba(0,0,0,.55),
        0 6px 16px -10px rgba(0,0,0,.45);
    --shadow-pill:
        0 10px 22px -14px rgba(0,0,0,.45),
        0 2px 8px -6px rgba(0,0,0,.35);
    --sheen-inset:
        inset 0 1px 0 rgba(255,255,255,.06),
        inset 0 -1px 0 rgba(0,0,0,.35);
    --focus-gold:
        0 0 0 2px rgba(214,177,92,.35),
        0 0 18px 0 rgba(214,177,92,.20);

    --ease: cubic-bezier(.2,.8,.2,1);
    --ease-in: cubic-bezier(.16,1,.3,1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body.canvas {
    background: var(--canvas);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: 0;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
    overflow-x: hidden;
}
html { overflow-x: hidden; }
img, video, iframe { max-width: 100%; display: block; }
.card, .item, .topic-card { min-width: 0; }
.item-body { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Type scale */
.display { font-size: 44px; line-height: 52px; font-weight: 500; letter-spacing: -.01em; margin: 0 0 6px; color: var(--text); }
.h1 { font-size: 28px; line-height: 34px; font-weight: 600; letter-spacing: -.01em; margin: 24px 0 8px; color: var(--on-canvas); }
.h2 { font-size: 22px; line-height: 28px; font-weight: 600; margin: 0; color: var(--text); }
.h3 { font-size: 18px; line-height: 24px; font-weight: 600; margin: 0 0 8px; color: var(--text); }
.body { font-size: 14px; line-height: 20px; }
.micro { font-size: 11px; line-height: 14px; font-weight: 500; letter-spacing: .01em; }
.muted { color: var(--muted); }

/* Container */
.container {
    max-width: 920px;
    margin: 0 auto;
    padding: 16px 20px 80px;
}
@media (min-width: 768px) {
    .container { padding: 24px 32px 100px; }
}

/* ===== Top bar ===== */
.topbar {
    position: sticky; top: 0; z-index: 50;
    padding: 12px 12px 0;
    backdrop-filter: blur(8px);
}
.topbar-pill {
    max-width: 920px; margin: 0 auto;
    display: flex; align-items: center; gap: 10px;
    background: var(--surface);
    border-radius: var(--r-pill);
    padding: 8px 12px;
    box-shadow: var(--shadow-pill), var(--sheen-inset);
    min-height: 56px;
}
.topbar-title {
    font-size: 16px; font-weight: 600; color: var(--text);
    margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.brand {
    font-weight: 700; font-size: 18px; letter-spacing: -.01em;
    color: var(--gold); text-decoration: none; padding: 4px 8px;
}
.spacer { flex: 1; }
.user-pill {
    display: flex; align-items: center; gap: 8px;
    background: var(--surface-2);
    padding: 4px 10px 4px 4px;
    border-radius: var(--r-pill);
    box-shadow: var(--sheen-inset);
}
.user-pill.compact { padding: 4px; }
.user-pill .user-name { color: var(--text-secondary); font-size: 13px; }
.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, var(--gold), var(--gold-soft));
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--surface-base); font-weight: 700; font-size: 13px;
    box-shadow: 0 0 0 2px rgba(255,255,255,.08);
    flex-shrink: 0;
}
.avatar.small { width: 26px; height: 26px; font-size: 11px; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    background: rgba(255,255,255,.05);
    color: var(--text-secondary);
    border: none; border-radius: var(--r-pill);
    cursor: pointer; text-decoration: none;
    font-size: 16px;
    transition: background .18s var(--ease), transform .18s var(--ease);
}
.icon-btn:hover { background: rgba(255,255,255,.08); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0); }

/* ===== Login ===== */
.login {
    min-height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}
.login-card {
    width: 100%; max-width: 380px;
    padding: 32px;
    text-align: center;
}
.login-card .display { color: var(--gold); margin-bottom: 4px; }
.login-card .form { margin-top: 24px; text-align: left; }

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-card), var(--sheen-inset);
    padding: var(--pad);
    color: var(--text);
}

/* ===== Topic grid (home) ===== */
.topic-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 20px;
}
@media (min-width: 600px) { .topic-grid { grid-template-columns: 1fr 1fr; gap: 16px; } }
@media (min-width: 960px) { .topic-grid { grid-template-columns: 1fr 1fr 1fr; } }

.topic-card {
    background: var(--surface);
    border-radius: var(--r-lg);
    padding: 20px;
    text-decoration: none;
    color: var(--text);
    display: flex; flex-direction: column; gap: 8px;
    box-shadow: var(--shadow-card), var(--sheen-inset);
    transition: transform .18s var(--ease), box-shadow .18s var(--ease);
    position: relative; overflow: hidden;
    min-height: 130px;
}
.topic-card::before {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,.04) 0%, transparent 35%, rgba(0,0,0,.18) 100%);
    pointer-events: none;
}
.topic-card:hover { transform: translateY(-2px); }
.topic-card:active { transform: translateY(0); }
.topic-num {
    font-size: 11px; font-weight: 600; letter-spacing: .08em;
    color: var(--gold);
}
.topic-title { font-size: 18px; font-weight: 600; flex: 1; }
.topic-meta { display: flex; gap: 6px; }

.pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    border-radius: var(--r-pill);
    background: rgba(18,20,25,.62);
    color: var(--text-secondary);
    font-size: 11px; font-weight: 500;
    border: none; text-decoration: none;
    cursor: pointer;
}
.pill.muted { color: var(--muted); }
.pill-action {
    background: rgba(255,255,255,.05);
    color: var(--text-secondary);
    height: 36px; padding: 0 14px;
    font-size: 13px;
}
.pill-action.active {
    background: rgba(214,177,92,.16);
    color: var(--gold);
    box-shadow: var(--focus-gold);
}
.pill-action .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--muted);
}
.pill-action.active .dot { background: var(--gold); box-shadow: 0 0 8px var(--gold-glow); }

/* ===== Buttons ===== */
.btn-primary, .btn-secondary {
    display: inline-flex; align-items: center; justify-content: center;
    height: 44px; padding: 0 20px;
    border-radius: var(--r-pill);
    font-weight: 600; font-size: 14px;
    border: none; cursor: pointer;
    transition: transform .18s var(--ease), box-shadow .18s var(--ease);
}
.btn-primary {
    background: var(--gold); color: var(--surface-base);
    box-shadow: 0 0 0 0 var(--gold-glow), 0 4px 12px -4px rgba(214,177,92,.5);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 0 18px var(--gold-glow), 0 6px 16px -4px rgba(214,177,92,.55); }
.btn-secondary {
    background: rgba(255,255,255,.06);
    color: var(--text);
    box-shadow: var(--sheen-inset);
}
.btn-secondary:hover { background: rgba(255,255,255,.09); transform: translateY(-1px); }

/* ===== Forms ===== */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; color: var(--muted); padding-left: 4px; }
.input, select.input, textarea.input {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    background: var(--surface-base);
    color: var(--text);
    border: 1px solid var(--stroke-hairline);
    border-radius: var(--r-md);
    font: inherit;
    outline: none;
    transition: box-shadow .18s var(--ease), border-color .18s var(--ease);
}
textarea.input { height: auto; padding: 12px 14px; resize: vertical; min-height: 80px; }
.input:focus { border-color: var(--gold-dim); box-shadow: var(--focus-gold); }
select.input { appearance: none; padding-right: 32px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' stroke='%23999' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat; background-position: right 12px center;
}

.alert {
    padding: 10px 14px;
    background: rgba(255,90,106,.12);
    color: var(--danger);
    border-radius: var(--r-md);
    font-size: 13px;
}

/* ===== Items list ===== */
.items-list {
    display: flex; flex-direction: column; gap: 16px;
    margin-top: 16px;
}
.item {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 16px;
    align-items: start;
}
.item-handle {
    display: none;
    color: var(--muted);
    font-size: 18px;
    cursor: grab;
    user-select: none;
    padding: 8px 4px;
    line-height: 1;
}
body.editing .item-handle { display: block; }
body.editing .container { padding-bottom: 120px; }
.item-handle:active { cursor: grabbing; }
.item-body {
    grid-column: 2;
    display: flex; flex-direction: column; gap: 10px;
}
body:not(.editing) .item-body { grid-column: 1 / -1; }

.prose { white-space: pre-wrap; word-wrap: break-word; color: var(--text-secondary); }

.media-img {
    width: 100%; max-height: 70vh; object-fit: contain;
    border-radius: var(--r-md);
    background: var(--surface-base);
    display: block;
}
.media-video {
    width: 100%;
    aspect-ratio: 16/9;
    height: auto;
    border-radius: var(--r-md);
    background: var(--surface-base);
    object-fit: contain;
}
.media-audio {
    width: 100%; border-radius: var(--r-md);
    background: var(--surface-base);
}
.pdf-frame {
    width: 100%;
    aspect-ratio: 4/5;
    max-height: 80vh;
    border: none;
    border-radius: var(--r-md);
    background: var(--surface-base);
}
.video-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: var(--r-md);
    overflow: hidden;
    background: var(--surface-base);
}
.video-frame iframe { width: 100%; height: 100%; border: none; }

.link-card {
    display: block;
    padding: 14px 16px;
    background: var(--surface-base);
    border-radius: var(--r-md);
    text-decoration: none;
    color: var(--text);
    border: 1px solid var(--stroke-hairline);
    transition: border-color .18s var(--ease);
}
.link-card:hover { border-color: var(--gold-dim); }
.link-domain { font-size: 11px; color: var(--gold); text-transform: lowercase; letter-spacing: .04em; }
.link-title { font-weight: 600; margin-top: 4px; word-break: break-word; }

.file-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.file-meta .pill { max-width: 100%; }

.item-foot {
    grid-column: 1 / -1;
    display: flex; justify-content: space-between; align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--stroke-hairline);
    margin-top: 4px;
}
.edit-only { display: none; }
body.editing .edit-only { display: inline-flex; gap: 4px; }

.sortable-ghost { opacity: .4; background: var(--surface-2); }

/* ===== Edit bar (sticky bottom) ===== */
.edit-bar {
    position: fixed;
    left: 12px; right: 12px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    display: flex; gap: 8px; justify-content: center;
    background: var(--surface);
    padding: 8px;
    border-radius: var(--r-pill);
    box-shadow: var(--shadow-card), var(--sheen-inset);
    z-index: 40;
    margin: 0 auto;
    max-width: max-content;
}
@media (max-width: 480px) {
    .edit-bar {
        max-width: none;
        flex-wrap: wrap;
        border-radius: var(--r-lg);
    }
    .edit-bar button { flex: 1 1 auto; padding: 0 10px; font-size: 12px; }
}
.edit-bar button {
    height: 40px; padding: 0 14px; font-size: 13px;
    flex: 0 1 auto; min-width: 0;
    white-space: nowrap;
}

/* ===== History sidebar ===== */
.sidebar {
    position: fixed; top: 0; right: 0;
    width: 100%; max-width: 380px; height: 100dvh;
    background: var(--surface);
    box-shadow: -20px 0 40px -20px rgba(0,0,0,.6);
    z-index: 60;
    display: flex; flex-direction: column;
    transform: translateX(0);
    transition: transform .22s var(--ease);
    padding-top: env(safe-area-inset-top);
}
.sidebar.hidden { transform: translateX(100%); }
.sidebar-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--stroke-hairline);
}
.history-list { flex: 1; overflow-y: auto; padding: 8px 12px 20px; }
.history-item { padding: 10px 8px; border-bottom: 1px solid var(--stroke-hairline); }
.history-item:last-child { border-bottom: none; }
.history-row { display: flex; align-items: center; gap: 10px; }
.history-text { flex: 1; font-size: 13px; color: var(--text-secondary); }
.history-text b { color: var(--text); font-weight: 600; }

/* ===== Modal ===== */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.55);
    backdrop-filter: blur(8px);
    z-index: 80;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    overflow-y: auto;
}
.modal-card {
    width: 100%; max-width: 480px;
    max-height: 90vh; overflow-y: auto;
    padding: 24px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.hidden { display: none !important; }

/* ===== Upload progress ===== */
.upload-state { display: flex; flex-direction: column; gap: 10px; }
.upload-name { font-weight: 600; word-break: break-all; }
.progress {
    height: 8px;
    background: var(--surface-base);
    border-radius: var(--r-pill);
    overflow: hidden;
    box-shadow: var(--sheen-inset);
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--gold), var(--gold-soft));
    width: 0;
    transition: width .25s var(--ease);
    border-radius: var(--r-pill);
}

/* ===== Empty state ===== */
.empty { margin-top: 32px; }
.empty .card { text-align: center; padding: 40px 20px; }

/* ===== Responsive tweaks ===== */
@media (max-width: 480px) {
    :root { --pad: 16px; }
    .topbar { padding: 8px 8px 0; }
    .topbar-pill { padding: 6px 10px; min-height: 52px; }
    .topbar-title { font-size: 15px; }
    .h1 { font-size: 24px; line-height: 30px; }
    .display { font-size: 36px; line-height: 42px; }
    .user-pill .user-name { display: none; }
    .topic-card { min-height: 110px; padding: 16px; }
    .modal-card { padding: 18px; }
}
