:root {
    /* Light, cheerful cyan palette — bright but soft. */
    --bg:           #f0fdff;          /* very light cyan paper */
    --bg-soft:      #cffafe;          /* light cyan wash */
    --surface:      #ffffff;
    --fg:           #134e4a;          /* deep teal text — readable, on-brand */
    --muted:        #5b7b80;
    --accent:       #06b6d4;          /* vivid cyan — buttons + brand */
    --accent-hover: #0891b2;          /* deeper cyan on hover */
    --accent-soft:  #67e8f9;          /* lighter cyan for soft fills */
    --sky:          #0284c7;          /* sky blue — links */
    --warm:         #fbbf24;          /* sunshine amber — complementary accent */
    --sage:         #10b981;          /* fresh mint — success */
    --user-bg:      #e0f7fa;          /* soft cyan for the user bubble */
    --assistant-bg: #fef9c3;          /* light sunshine for Angel replies */
    --border:       #a5f3fc;          /* light cyan border */
    --ok:           #047857;
    --error:        #dc2626;
    --shadow:       0 1px 2px rgba(6, 182, 212, 0.10), 0 6px 16px rgba(6, 182, 212, 0.08);
    --radius:       12px;
    --radius-sm:    8px;
}

* { box-sizing: border-box; }

/* Root font-size drives every rem-based size in the app. The text-size toggle
   in the top nav adds .font-md / .font-lg to <html>, scaling everything
   proportionally — headings, body text, buttons, inputs, chat bubbles. */
html { font-size: 16px; }
html.font-md { font-size: 19px; }
html.font-lg { font-size: 22px; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background:
        radial-gradient(circle at 12% 0%, #cffafe 0%, transparent 45%),
        radial-gradient(circle at 88% 5%, #fef9c3 0%, transparent 40%),
        var(--bg);
    color: var(--fg);
    line-height: 1.55;
    min-height: 100vh;
}

a { color: var(--sky); text-decoration: none; }
a:hover { color: var(--accent); text-decoration: underline; }

.page { min-height: 100vh; display: flex; flex-direction: column; }
.content { max-width: 880px; margin: 0 auto; padding: 1.5rem; width: 100%; flex: 1; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    flex-wrap: wrap;
}
@media (max-width: 640px) {
    .topbar { padding: 0.7rem 1rem; gap: 0.6rem; }
    .nav-links { gap: 0.7rem; flex-wrap: wrap; }
    .font-controls { margin-right: 0; }
}
.brand {
    display: inline-flex; align-items: center; gap: 0.5rem;
    font-weight: 700; font-size: 1.15rem; text-decoration: none;
    color: var(--accent); letter-spacing: 0.02em;
}
.brand-mark { height: 1.7em; width: auto; display: block; }
.brand-text { color: var(--accent); }
.brand-sub  { color: var(--muted); font-weight: 400; font-size: 0.9rem; letter-spacing: 0; }
@media (max-width: 520px) {
    .brand-sub { display: none; }
}
.nav-links { margin-left: auto; display: flex; gap: 1.1rem; align-items: center; }
.nav-links a { text-decoration: none; color: var(--fg); transition: color 0.15s ease; }
.nav-links a:hover { color: var(--accent); }
.nav-links .who { color: var(--muted); font-size: 0.9rem; }
.inline-form { display: inline; margin: 0; }
.link-button {
    background: none; border: none; cursor: pointer;
    color: var(--sky); padding: 0; font: inherit;
}
.link-button:hover { color: var(--accent); }

/* Text-size toggle in the topbar */
.font-controls {
    display: inline-flex; align-items: center; gap: 0.15rem;
    background: var(--bg-soft); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 0.2rem;
    margin-right: 0.8rem;
}
.font-btn {
    border: none; background: transparent; cursor: pointer;
    color: var(--fg); padding: 0.25rem 0.55rem; border-radius: 6px;
    line-height: 1; min-width: 36px; min-height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}
.font-btn:hover { background: var(--surface); }
.font-btn.active { background: var(--accent); color: white; }
.font-btn-sm { font-size: 0.85rem; }
.font-btn-md { font-size: 1rem;    font-weight: 600; }
.font-btn-lg { font-size: 1.25rem; font-weight: 700; }

.hero { padding: 0.5rem 0 1.5rem 0; }
.hero-logo {
    display: block;
    height: 4.5rem; width: auto;
    margin: 0 0 1.2rem 0;
}
.hero h1 {
    font-size: 2.25rem; line-height: 1.2; margin: 0 0 1rem 0;
    color: var(--fg); font-weight: 700; letter-spacing: -0.01em;
}
.lede { font-size: 1.1rem; color: var(--muted); }
.cta {
    display: inline-block; padding: 0.8rem 1.4rem; background: var(--accent);
    color: white !important; text-decoration: none !important; border-radius: var(--radius-sm);
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(6, 182, 212, 0.35);
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
}
.cta:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.40);
    transform: translateY(-1px);
}

.visually-hidden { position: absolute; clip: rect(0 0 0 0); width: 1px; height: 1px; overflow: hidden; }

/* --- Chat --- */
.chat-shell { display: flex; flex-direction: column; gap: 1rem; height: calc(100vh - 8rem); }
.chat-transcript {
    flex: 1; overflow-y: auto; padding: 1rem 1.2rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.chat-row { padding: 0.75rem 1rem; margin-bottom: 0.7rem; border-radius: var(--radius); }
.chat-row.chat-user { background: var(--user-bg); border-left: 3px solid var(--sky); }
.chat-row.chat-assistant { background: var(--assistant-bg); border-left: 3px solid var(--accent); }
.chat-row.chat-system {
    background: #fbf7ed; color: var(--muted); font-size: 0.9rem;
    border-left: 3px solid var(--border);
}
.chat-speaker { font-weight: 600; font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--fg); }
.chat-row.chat-assistant .chat-speaker { color: var(--accent); }
.chat-row.chat-user .chat-speaker { color: var(--sky); }
.chat-body { white-space: pre-wrap; }
.chat-thinking .chat-body { color: var(--muted); }

.chat-input { display: flex; gap: 0.6rem; align-items: stretch; }
.chat-textarea {
    flex: 1; padding: 0.85rem; font: inherit; font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm); resize: vertical; min-height: 96px;
    background: var(--surface);
}
.chat-textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.20);
}
.chat-buttons { display: flex; flex-direction: column; gap: 0.5rem; }
.chat-send {
    background: var(--accent); color: white;
    border: none; border-radius: var(--radius-sm); cursor: pointer;
    font-weight: 700; font-size: 1.05rem;
    min-width: 130px; min-height: 56px;
    padding: 0.85rem 1.3rem;
    box-shadow: 0 2px 6px rgba(6, 182, 212, 0.30);
    transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.chat-send:hover { background: var(--accent-hover); box-shadow: 0 3px 10px rgba(6, 182, 212, 0.40); }
.chat-send:active:not(:disabled) { transform: translateY(1px); }
.chat-send:disabled { background: #cbe9ee; box-shadow: none; cursor: not-allowed; color: #fff; }
.chat-mic {
    padding: 0.5rem 1rem; background: var(--surface); color: var(--fg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm); cursor: pointer; font-size: 1.4rem;
    min-width: 130px; min-height: 56px;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.chat-mic:hover { background: var(--bg-soft); border-color: var(--accent); }
.chat-mic:disabled { opacity: 0.5; cursor: not-allowed; }

/* Mobile: stack the buttons under the textarea in a wide row that fills the screen. */
@media (max-width: 640px) {
    .chat-input { flex-direction: column; }
    .chat-buttons { flex-direction: row-reverse; }
    .chat-buttons .chat-send, .chat-buttons .chat-mic { flex: 1; min-width: 0; }
}
.chat-mic:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-mic.active {
    background: #fff7d6; border-color: var(--warm); color: #b45309;
    animation: pulse 1.2s ease-in-out infinite;
}
.chat-toolbar {
    display: flex; align-items: center; gap: 1rem;
    padding: 0.4rem 0; margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}
.voice-toggle { display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.voice-state { color: var(--muted); font-size: 0.85rem; }
.error.small { font-size: 0.85rem; }

/* --- Forms --- */
.settings-form fieldset {
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem 1.2rem; margin-bottom: 1rem; background: var(--surface);
    box-shadow: var(--shadow);
}
.settings-form legend { font-weight: 600; padding: 0 0.5rem; color: var(--accent); }
.settings-form label {
    display: flex; flex-direction: column; gap: 0.3rem;
    margin: 0.6rem 0; font-size: 0.95rem;
}
.settings-form label.inline-label { flex-direction: row; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.settings-form input[type=text],
.settings-form input[type=password],
.settings-form input[type=number],
.settings-form select,
.settings-form textarea {
    padding: 0.55rem; font: inherit; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--bg);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.settings-form input:focus, .settings-form select:focus, .settings-form textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.18);
}
.settings-form .narrow { width: 14rem; }
.settings-form .port { width: 5rem; }
.settings-form .hint { color: var(--muted); font-size: 0.85rem; }
.settings-form .actions { display: flex; gap: 1rem; align-items: center; }
.settings-form .primary {
    padding: 0.65rem 1.2rem; background: var(--accent); color: white;
    border: none; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600;
    transition: background 0.15s ease;
}
.settings-form .primary:hover { background: var(--accent-hover); }
.settings-form .ok { color: var(--ok); }
.settings-form .error { color: var(--error); }

.callout {
    padding: 0.9rem 1.1rem; background: #fff3df; border: 1px solid #f6d49b;
    border-left: 4px solid var(--accent); border-radius: var(--radius);
    color: var(--fg);
}

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

/* --- Stories --- */
.stories-shell {
    display: grid; grid-template-columns: 260px 1fr; gap: 1rem;
    height: calc(100vh - 14rem); min-height: 520px;
}
.stories-list {
    background: white; border: 1px solid var(--border); border-radius: 6px;
    padding: 0.5rem; display: flex; flex-direction: column; min-height: 0;
}
.stories-list ul { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; }
.stories-list li { margin: 0 0 0.3rem 0; }
.stories-list li.selected .list-item { background: var(--user-bg); }
.list-item {
    width: 100%; text-align: left; background: transparent; border: 1px solid transparent;
    padding: 0.5rem 0.6rem; border-radius: 4px; cursor: pointer; font: inherit; color: inherit;
}
.list-item:hover { background: #f6f4ef; }
.list-item .title { display: block; font-weight: 600; }
.list-item .meta { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; }

.recorder {
    display: flex; align-items: center; gap: 0.6rem; padding: 0.3rem 0 0.6rem 0;
    border-bottom: 1px solid var(--border); margin-bottom: 0.5rem;
}
.recorder .record {
    background: #b91c1c; color: white; border: none; padding: 0.55rem 0.9rem;
    border-radius: 4px; cursor: pointer; font-weight: 600;
}
.recorder .record:disabled { background: #a8a29e; }
.recorder .stop {
    background: var(--accent); color: white; border: none; padding: 0.55rem 0.9rem;
    border-radius: 4px; cursor: pointer; font-weight: 600;
}
.recorder .rec-indicator {
    color: #b91c1c; font-weight: 600;
    animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }
.stories-list .empty { color: var(--muted); padding: 0.5rem; }

.story-detail {
    background: white; border: 1px solid var(--border); border-radius: 6px;
    padding: 1rem; display: flex; flex-direction: column; gap: 0.8rem; min-height: 0;
}
.story-detail label { display: flex; flex-direction: column; gap: 0.3rem; }
.story-detail input[type=text] { padding: 0.5rem; font: inherit; border: 1px solid var(--border); border-radius: 4px; }
.story-detail textarea { font: inherit; padding: 0.6rem; border: 1px solid var(--border); border-radius: 4px; resize: vertical; flex: 1; }
.story-detail .audio-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.story-detail .audio-row audio { flex: 1; min-width: 260px; }
.story-detail button { padding: 0.5rem 0.9rem; border: 1px solid var(--border); background: white; border-radius: 4px; cursor: pointer; font: inherit; }
.story-detail button.primary { background: var(--accent); color: white; border-color: var(--accent); font-weight: 600; }
.story-detail button.danger { background: white; color: #b91c1c; border-color: #fca5a5; }
.story-detail .actions { display: flex; gap: 0.8rem; align-items: center; }
.story-detail .empty { color: var(--muted); }
.story-detail .ok { color: var(--ok); }

.status { margin-top: 0.6rem; padding: 0.5rem 0.8rem; background: #eef6ff; border-left: 3px solid var(--accent); border-radius: 0 4px 4px 0; }
.scan-row { display: flex; align-items: center; gap: 0.8rem; margin-top: 0.4rem; flex-wrap: wrap; }

/* --- Eulogy --- */
.eulogy-actions {
    display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.8rem;
}
.eulogy-actions button {
    padding: 0.55rem 0.9rem; border: 1px solid var(--border); background: white;
    border-radius: 4px; cursor: pointer; font: inherit;
}
.eulogy-actions button.primary { background: var(--accent); color: white; border-color: var(--accent); font-weight: 600; }
.eulogy-actions button:disabled { opacity: 0.6; cursor: not-allowed; }
.eulogy-label { display: flex; flex-direction: column; gap: 0.3rem; }
.eulogy-textarea {
    font: inherit; padding: 0.8rem; border: 1px solid var(--border);
    border-radius: 4px; min-height: 360px; font-family: Georgia, serif; line-height: 1.6;
}

/* --- Document --- */
.doc-actions { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.8rem; flex-wrap: wrap; }
.doc-actions .download {
    display: inline-block; padding: 0.7rem 1.2rem; background: var(--accent);
    color: white !important; text-decoration: none !important;
    border-radius: var(--radius-sm); font-weight: 600;
    box-shadow: 0 2px 6px rgba(6, 182, 212, 0.30);
    transition: background 0.15s ease;
}
.doc-actions .download:hover { background: var(--accent-hover); }
.doc-preview {
    background: white; border: 1px solid var(--border); border-radius: 4px;
    padding: 1rem; font-family: ui-monospace, "SF Mono", Consolas, monospace;
    font-size: 0.9rem; line-height: 1.55; white-space: pre-wrap;
    max-height: 70vh; overflow-y: auto;
}

/* --- Voice picker --- */
.voice-select { padding: 0.5rem; font: inherit; border: 1px solid var(--border); border-radius: 4px; }

/* --- Vault --- */
.vault-warning {
    background: #fef3c7; border-left: 4px solid #d97706; padding: 0.8rem 1rem;
    border-radius: 0 4px 4px 0; margin: 0.8rem 0 1.2rem 0;
}
.vault-warning ul { margin: 0.5rem 0 0 0; padding-left: 1.2rem; }
.vault-warning em { font-style: italic; }
.vault-form {
    background: white; border: 1px solid var(--border); border-radius: 6px;
    padding: 1rem 1.2rem; max-width: 560px; display: flex; flex-direction: column; gap: 0.8rem;
}
.vault-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.95rem; }
.vault-form input[type=text], .vault-form input[type=password], .vault-form select {
    padding: 0.55rem; font: inherit; border: 1px solid var(--border); border-radius: 4px;
}
.vault-form .actions { display: flex; gap: 0.8rem; align-items: center; }
.vault-form .primary, .vault-form button:not(.primary):not(.danger) {
    padding: 0.55rem 1rem; border-radius: 4px; cursor: pointer; font: inherit;
    border: 1px solid var(--border); background: white;
}
.vault-form .primary { background: var(--accent); color: white; border-color: var(--accent); font-weight: 600; }
.vault-form .danger { background: white; color: #b91c1c; border: 1px solid #fca5a5; padding: 0.5rem 0.9rem; border-radius: 4px; cursor: pointer; }
.danger-details { margin-top: 0.6rem; color: var(--muted); }
.danger-details summary { cursor: pointer; }
.danger-details p { margin: 0.5rem 0; }

.vault-toolbar { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 1rem; flex-wrap: wrap; }
.vault-toolbar .primary { padding: 0.55rem 0.9rem; background: var(--accent); color: white; border: none; border-radius: 4px; cursor: pointer; font-weight: 600; }
.vault-toolbar button:not(.primary) { padding: 0.55rem 0.9rem; background: white; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }

.vault-editor {
    background: white; border: 1px solid var(--border); border-radius: 6px;
    padding: 1rem 1.2rem; margin-bottom: 1.2rem;
    display: flex; flex-direction: column; gap: 0.6rem;
}
.vault-editor label { display: flex; flex-direction: column; gap: 0.25rem; }
.vault-editor input[type=text], .vault-editor select, .vault-editor textarea {
    padding: 0.5rem; font: inherit; border: 1px solid var(--border); border-radius: 4px;
}
.vault-editor .field-row { display: flex; gap: 0.5rem; align-items: center; margin: 0.25rem 0; flex-wrap: wrap; }
.vault-editor .field-row input { flex: 1; min-width: 140px; }
.vault-editor .actions { display: flex; gap: 0.6rem; align-items: center; margin-top: 0.6rem; }
.vault-editor .actions .primary { background: var(--accent); color: white; border: none; padding: 0.55rem 1rem; border-radius: 4px; cursor: pointer; font-weight: 600; }
.vault-editor .actions button:not(.primary) { background: white; border: 1px solid var(--border); padding: 0.55rem 1rem; border-radius: 4px; cursor: pointer; }

.vault-list h3 { margin: 1.2rem 0 0.4rem 0; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.vault-list ul { list-style: none; padding: 0; margin: 0; }
.vault-list li {
    background: white; border: 1px solid var(--border); border-radius: 6px;
    padding: 0.8rem 1rem; margin-bottom: 0.6rem;
}
.entry-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.entry-head .actions { display: inline-flex; gap: 0.6rem; }
.entry-fields { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 0.8rem; margin: 0.5rem 0 0 0; font-size: 0.9rem; }
.entry-fields dt { color: var(--muted); }
.entry-fields dd { margin: 0; }
.entry-fields code { background: #f3f4f6; padding: 0.05rem 0.35rem; border-radius: 3px; word-break: break-all; font-family: ui-monospace, Consolas, monospace; }
.entry-notes { margin: 0.5rem 0 0 0; color: var(--fg); white-space: pre-wrap; font-size: 0.9rem; }
.link-button.danger { color: #b91c1c; }
.empty { color: var(--muted); font-style: italic; padding: 1rem 0; }

#blazor-error-ui {
    background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,0.2);
    display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
