:root {
    --ink: #171815;
    --muted: #73746d;
    --paper: #f2efe8;
    --shell: #e7e3da;
    --card: #fbfaf6;
    --line: #dedbd2;
    --sidebar-bg: #ebe7df;
    --acid: #d9ff66;
    --acid-ink: #171815;
    --orange: #ff7043;
    --blue: #6578ff;
    --danger: #c0392b;
    --shadow: 0 18px 50px rgba(36, 34, 26, 0.10);
    --radius: 20px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --ink: #f0ece2;
        --muted: #a39c8c;
        --paper: #1c1a16;
        --shell: #141210;
        --card: #24211c;
        --line: #3a362e;
        --sidebar-bg: #1f1c17;
        --acid: #d9ff66;
        --acid-ink: #171815;
        --orange: #ff8a63;
        --blue: #8695ff;
        --danger: #e6685a;
        --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    }
}

:root[data-theme="dark"] {
    --ink: #ece9e2;
    --muted: #9a9a92;
    --paper: #1a1b1a;
    --shell: #131413;
    --card: #212220;
    --line: #33342f;
    --sidebar-bg: #1c1d1b;
    --acid: #d9ff66;
    --acid-ink: #171815;
    --orange: #ff8a63;
    --blue: #8695ff;
    --danger: #e6685a;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    background: var(--shell);
    color: var(--ink);
    font: 15px/1.45 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

h1, h2, h3 { font-family: Georgia, serif; }

a { color: var(--ink); }
a:hover { color: var(--orange); }

button, input, select, textarea { font: inherit; color: inherit; }

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* --- Plain (non-app-shell) pages: login, record, edit --- */

.plain-header {
    border-bottom: 1px solid var(--line);
    background: var(--paper);
}

.plain-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font: bold 19px Georgia, serif;
    letter-spacing: -0.2px;
    color: var(--ink);
}

.site-nav a {
    color: var(--muted);
    margin-left: 1rem;
}

.login-form, .edit-form {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    max-width: 420px;
}

.login-form input, .edit-form input, .edit-form select, .edit-form textarea {
    padding: 0.6rem 0.7rem;
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--ink);
    border-radius: 12px;
}

button {
    cursor: pointer;
}

.btn {
    display: inline-block;
    padding: 0.6rem 1rem;
    background: var(--ink);
    color: var(--paper);
    border: none;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { color: var(--paper); opacity: 0.9; text-decoration: none; }

.btn-secondary {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink);
}

.danger {
    background: none;
    border: 1px solid var(--danger);
    color: var(--danger);
    border-radius: 12px;
    padding: 0.6rem 1rem;
}

.flash {
    background: var(--card);
    border: 1px solid var(--orange);
    padding: 0.6rem 1rem;
    border-radius: 12px;
    margin: 0.5rem 0;
}

.muted { color: var(--muted); }

.tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.tag {
    font-size: 0.78rem;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.5rem;
}

.badge-reminder { background: var(--orange); color: #fff; }
.badge-idea { background: var(--blue); color: #fff; }
.badge-shopping_item { background: var(--acid); color: var(--acid-ink); }
.badge-note { background: var(--line); color: var(--ink); }

#mic-select {
    padding: 0.5rem;
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--ink);
    border-radius: 12px;
}

.record-page {
    min-height: 100vh;
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 2rem;
    padding: 2rem 1.25rem;
}

/* --- Recorder button, inside the overlay --- */

.big-record-btn {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: var(--orange);
    color: #fff;
    border: none;
    font-size: 1rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    box-shadow: 0 20px 50px rgba(255, 112, 67, 0.35);
}

.live-wave {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 60px;
    min-height: 60px;
}

.live-wave i {
    display: block;
    width: 4px;
    height: 4px;
    min-height: 4px;
    border-radius: 4px;
    background: var(--orange);
    transition: height 0.05s linear;
}

.rec-time {
    font: 500 2.2rem/1 Georgia, serif;
    font-variant-numeric: tabular-nums;
}

.rec-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
}

.rec-ctrl-btn {
    border: none;
    cursor: pointer;
    display: grid;
    place-items: center;
    border-radius: 50%;
}

.rec-discard {
    width: 48px;
    height: 48px;
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 1.1rem;
}

.rec-stop {
    width: 76px;
    height: 76px;
    background: var(--danger);
    color: #fff;
    font-size: 1.5rem;
}

.rec-pause {
    width: 48px;
    height: 48px;
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--ink);
    font-size: 1.1rem;
}

/* --- Record overlay: pops over whatever page you're on, blurs it behind --- */

.record-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 8, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: none;
    place-items: center;
    z-index: 30;
    padding: 20px;
}

.record-overlay.open { display: grid; }

.recorder {
    position: relative;
    width: min(480px, 100%);
    background: #171815;
    color: #f0ece2;
    border-radius: 28px;
    padding: 2.5rem 2rem 2rem;
    text-align: center;
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.recorder .muted { color: #9a958c; }

.recorder #mic-select {
    background: #24211c;
    border: 1px solid #3a362e;
    color: #f0ece2;
}

.recorder-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    border: none;
    background: transparent;
    color: #9a958c;
    font-size: 1.1rem;
    cursor: pointer;
}

/* --- App shell: sidebar + list + detail --- */

.app {
    min-height: 100vh;
    max-width: 1440px;
    margin: auto;
    display: grid;
    grid-template-columns: 220px minmax(320px, 420px) minmax(380px, 680px);
    justify-content: center;
}

.sidebar {
    min-width: 0;
    height: 100vh;
    position: sticky;
    top: 0;
    padding: 1.75rem 1.25rem;
    border-right: 1px solid var(--line);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0 0.5rem 2rem;
}

.brandmark {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: var(--ink);
    color: var(--acid);
    display: grid;
    place-items: center;
    font: 700 20px Georgia, serif;
    flex-shrink: 0;
}

.brandname { font: bold 18px Georgia, serif; }
.brand small { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; }

.sidebar-nav { display: grid; gap: 0.35rem; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.7rem;
    border-radius: 12px;
    color: var(--muted);
    font-size: 0.9rem;
}

.sidebar-nav a:hover, .sidebar-nav a.active {
    background: var(--card);
    color: var(--ink);
}

.sidebar-nav .count {
    margin-left: auto;
    background: var(--line);
    border-radius: 999px;
    font-size: 0.7rem;
    padding: 0.1rem 0.45rem;
}

.sidebar-profile {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border-top: 1px solid var(--line);
    padding-top: 1rem;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--paper);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.sidebar-profile small { display: block; color: var(--muted); font-size: 0.75rem; }

.logout-form { display: inline; }

.link-button {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    color: var(--ink);
    text-decoration: underline;
    cursor: pointer;
}

.feed {
    min-width: 0;
    min-height: 100vh;
    border-right: 1px solid var(--line);
    padding: 1.75rem 1.5rem 6rem;
    background: var(--paper);
}

.feed-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 1rem; }
.feed-top h1 { font-size: 1.7rem; margin: 0; letter-spacing: -0.5px; }

.view-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.view-tabs a {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.35rem 0.8rem;
    font-size: 0.78rem;
    color: var(--muted);
}
.view-tabs a.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.memo-cards { display: grid; gap: 0.6rem; list-style: none; margin: 0; padding: 0; min-width: 0; }
.memo-cards li { min-width: 0; }

.memo-card {
    position: relative;
    display: block;
    min-width: 0;
    border: 1px solid var(--line);
    background: var(--card);
    border-radius: var(--radius);
    padding: 0.9rem 1rem;
    overflow: hidden;
}

.memo-card:hover { color: var(--ink); box-shadow: 0 9px 25px rgba(25, 25, 20, 0.08); }

.memo-card.active {
    border-color: var(--orange);
    box-shadow: var(--shadow);
}

.memo-card-time {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.68rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.memo-card h3 { font: 600 1.05rem/1.2 Georgia, serif; margin: 0.3rem 0 0.35rem; }
.memo-card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.8rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.memo-card-meta { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.5rem; flex-wrap: wrap; }
.memo-card-status {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.memo-card-status.open { color: var(--orange); }
.memo-card-duration { font-size: 0.7rem; color: var(--muted); }

.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }

.detail-empty {
    min-width: 0;
    display: grid;
    place-items: center;
    min-height: 100vh;
    color: var(--muted);
    background: var(--card);
}
@media (max-width: 1000px) {
    .detail-empty { display: none; }
}

.detail-pane {
    min-width: 0;
    min-height: 100vh;
    padding: 1.75rem 2rem 6rem;
    background: var(--card);
}

.detail-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.detail-toolbar .back-link { display: none; }

.detail-date { color: var(--muted); text-transform: uppercase; font-size: 0.68rem; letter-spacing: 0.08em; margin-bottom: 0.4rem; }
.detail-pane h1 { font: 500 clamp(24px, 3vw, 36px)/1.1 Georgia, serif; letter-spacing: -0.5px; margin: 0 0 1rem; }

audio { width: 100%; margin: 1rem 0; }

.action-item-list { display: grid; gap: 0.5rem; list-style: none; margin: 0; padding: 0; }
.action-item-list li {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0.7rem 0.9rem;
    background: var(--paper);
}

.transcript-text { line-height: 1.8; color: var(--ink); }

/* --- Shopping list --- */

.shopping-section h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }
.shopping-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.shopping-list li {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0.6rem 0.8rem;
    background: var(--card);
}
.shopping-check {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--paper);
    flex-shrink: 0;
}

.record-fab {
    position: fixed;
    right: 30px;
    bottom: 26px;
    z-index: 8;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--orange);
    color: #fff;
    border-radius: 999px;
    padding: 0.9rem 1.4rem;
    font-weight: 700;
    font-size: 0.85rem;
    box-shadow: 0 12px 35px rgba(255, 112, 67, 0.35);
}
.record-fab:hover { color: #fff; text-decoration: none; }

/* --- Mobile: collapse to single column + bottom nav with centered record --- */

.mobile-nav, .mobile-header { display: none; }

@media (max-width: 1000px) {
    .app { grid-template-columns: 1fr; display: block; min-height: auto; }
    .sidebar { display: none; }
    .record-fab { display: none; }
    .mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1rem 1.25rem;
        background: var(--paper);
        border-bottom: 1px solid var(--line);
    }
    .feed { border: 0; min-height: auto; padding: 1.25rem 1.25rem 6rem; }
    .detail-pane { min-height: auto; padding: 1.25rem 1.25rem 6rem; }
    .detail-toolbar .back-link { display: inline-block; }

    .mobile-nav {
        display: grid;
        grid-template-columns: 1fr 96px 1fr;
        align-items: center;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--paper);
        border-top: 1px solid var(--line);
        padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-bottom));
        z-index: 9;
    }
    .mobile-nav a {
        display: grid;
        justify-items: center;
        gap: 0.15rem;
        font-size: 0.68rem;
        color: var(--muted);
    }
    .mobile-nav a.active { color: var(--ink); }
    .mobile-record-btn {
        justify-self: center;
        width: 64px;
        height: 64px;
        margin-top: -20px;
        border-radius: 50%;
        background: var(--orange);
        color: #fff;
        border: 4px solid var(--paper);
        box-shadow: 0 10px 25px rgba(255, 112, 67, 0.4);
        font-size: 1.5rem;
        display: grid;
        place-items: center;
    }
}
