@font-face {
    font-family: "Fraunces";
    font-style: normal;
    font-weight: 300 600;
    font-display: swap;
    src: url("../fonts/fraunces-roman.woff2") format("woff2");
}

@font-face {
    font-family: "Fraunces";
    font-style: italic;
    font-weight: 400 600;
    font-display: swap;
    src: url("../fonts/fraunces-italic.woff2") format("woff2");
}

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 400 600;
    font-display: swap;
    src: url("../fonts/inter-regular.woff2") format("woff2");
}

@font-face {
    font-family: "JetBrains Mono";
    font-style: normal;
    font-weight: 400 500;
    font-display: swap;
    src: url("../fonts/jetbrainsmono-regular.woff2") format("woff2");
}

:root {
    /* cover / page / rule are the leather-and-paper ground; thread is the
       brass streak-marker, ember the wax-seal "today", fountain a quiet
       teal-ink accent for links. */
    --cover: #2b2420;
    --page: #382f27;
    --page-raised: #443a30;
    --rule: #5c4d3d;
    --rule-soft: #4a3f33;
    --ink: #ece2d0;
    --ink-dim: #9c8a70;
    --thread: #c98a3e;
    --thread-bright: #dba158;
    --fountain: #6fa39a;
    --ember: #c1543f;

    --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
    --font-body: "Inter", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-mono: "JetBrains Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--cover);
    color: var(--ink);
    font-family: var(--font-body);
}

a {
    font-family: inherit;
}

:focus-visible {
    outline: 2px solid var(--fountain);
    outline-offset: 2px;
}

/* ---------- Landing page ---------- */

.landing-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    padding: 1.5rem;
}

.landing-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    max-width: 26rem;
}

.landing-mark {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 8px;
    background: var(--cover);
    border: 1px solid var(--rule);
    margin-bottom: 1.25rem;
    position: relative;
}

.landing-mark::before {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    background: var(--thread);
}

.landing-title {
    margin: 0 0 0.6rem;
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 500;
    font-size: 2.4rem;
    letter-spacing: 0.01em;
    color: var(--ink);
}

.landing-tagline {
    margin: 0 0 1.75rem;
    color: var(--ink-dim);
    font-size: 0.95rem;
    line-height: 1.5;
}

.landing-streak {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 2rem;
}

.landing-streak .day-cell {
    position: relative;
    width: 1.6rem;
    aspect-ratio: 1 / 1;
    border-radius: 4px;
    background: var(--page);
    border: 1px solid transparent;
}

.landing-streak .day-cell.has-note {
    background: var(--thread);
}

.landing-streak .day-cell.is-today {
    border-color: var(--ember);
}

.landing-signin {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.6rem;
    border-radius: 6px;
    background: var(--thread);
    color: var(--cover);
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    transition: background 0.15s ease;
}

.landing-signin:hover {
    background: var(--thread-bright);
}

/* ---------- Year page ---------- */

.year-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 1.25rem 1.75rem;
}

.year-header {
    display: flex;
    align-items: baseline;
    gap: 0.9rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--rule-soft);
    margin-bottom: 1.1rem;
}

.year-header h1 {
    margin: 0;
    min-width: 6.5rem;
    text-align: center;
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 500;
    font-size: 2.1rem;
    letter-spacing: 0.01em;
    color: var(--ink);
}

.year-nav {
    color: var(--ink-dim);
    text-decoration: none;
    font-size: 1.3rem;
    line-height: 1;
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s ease, color 0.15s ease;
}

.year-nav:hover {
    background: var(--page);
    color: var(--thread-bright);
}

.year-key {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1.1rem;
    font-size: 0.78rem;
    color: var(--ink-dim);
}

.key-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.key-swatch {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 2px;
    background: var(--page-raised);
    flex: none;
}

.key-swatch.written {
    background: var(--thread);
}

.key-swatch.streak {
    background: var(--page-raised);
    position: relative;
    width: 1.1rem;
}

.key-swatch.streak::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--thread) 0 40%, transparent 40% 60%, var(--thread) 60% 100%);
}

.key-swatch.today {
    background: transparent;
    border: 2px solid var(--ember);
}

kbd {
    background: var(--page);
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 0.05rem 0.35rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--ink);
}

.grid-scroll {
    overflow: auto;
    flex: 1;
}

.year-grid {
    display: grid;
    gap: 3px;
    align-items: stretch;
}

.corner {
    position: sticky;
    left: 0;
    background: var(--cover);
    z-index: 2;
}

.day-col-header {
    text-align: center;
    color: var(--ink-dim);
    font-size: 0.68rem;
    padding-bottom: 0.3rem;
}

.month-label {
    position: sticky;
    left: 0;
    background: var(--cover);
    display: flex;
    align-items: center;
    padding-right: 0.7rem;
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-dim);
    z-index: 1;
}

.day-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    background: var(--page);
    border-radius: 4px;
    color: var(--ink-dim);
    text-decoration: none;
    font-size: 0.72rem;
    border: 1px solid transparent;
    transition: background 0.12s ease;
}

.day-cell:hover {
    background: var(--page-raised);
    color: var(--ink);
}

.day-cell.empty {
    background: transparent;
}

.day-cell.has-note {
    background: var(--thread);
    color: var(--cover);
    font-weight: 600;
}

.day-cell.has-note:hover {
    background: var(--thread-bright);
}

/* The signature: consecutive journalled days are stitched together with a
   brass thread, so a writing streak reads as an unbroken line across the
   grid rather than a row of disconnected dots. */
.day-cell.chain-left::before {
    content: "";
    position: absolute;
    left: -4px;
    top: 50%;
    width: 7px;
    height: 3px;
    background: var(--thread);
    transform: translateY(-50%);
}

.day-cell.is-today {
    border-color: var(--ember);
    font-weight: 700;
    color: var(--ink);
}

.day-cell.has-note.is-today {
    color: var(--cover);
}

/* ---------- Day page ---------- */

.day-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 1.25rem 1.75rem;
}

.day-header {
    display: flex;
    align-items: baseline;
    gap: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--rule-soft);
    margin-bottom: 1.1rem;
}

.day-header h1 {
    margin: 0;
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 500;
    font-size: 1.6rem;
    color: var(--ink);
}

.back-link {
    color: var(--ink-dim);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 0.3rem 0.6rem;
    margin-left: -0.6rem;
    border-radius: 4px;
    transition: background 0.15s ease, color 0.15s ease;
}

.back-link:hover {
    background: var(--page);
    color: var(--thread-bright);
}

.save-status {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.8rem;
    color: var(--ink-dim);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-size: 0.78rem;
    color: var(--ink-dim);
}

.user-logout {
    color: var(--fountain);
    text-decoration: none;
}

.user-logout:hover {
    color: var(--thread-bright);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ink-dim);
    flex: none;
}

.save-status[data-state="saved"] .status-dot {
    background: var(--fountain);
}

.save-status[data-state="editing"] .status-dot,
.save-status[data-state="saving"] .status-dot {
    background: var(--thread);
    animation: pulse 1.2s ease-in-out infinite;
}

.save-status[data-state="error"] .status-dot {
    background: var(--ember);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
    .status-dot {
        animation: none !important;
    }
}

.editor-split {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    min-height: 0;
}

#editor {
    background: var(--page);
    color: var(--ink);
    border: 1px solid var(--rule);
    border-radius: 6px;
    padding: 1rem 1rem 1rem 3.25rem;
    background-image: linear-gradient(
        to right,
        transparent 0,
        transparent calc(3rem - 1px),
        var(--rule) calc(3rem - 1px),
        var(--rule) 3rem,
        transparent 3rem
    );
    background-attachment: local;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    line-height: 1.6;
    resize: none;
    outline: none;
}

.preview {
    background: var(--page);
    border: 1px solid var(--rule);
    border-radius: 6px;
    padding: 1rem 1.25rem;
    overflow-y: auto;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.preview-block {
    display: grid;
    grid-template-columns: 2.75rem 1fr;
    gap: 0.6rem;
    align-items: start;
}

.preview-time {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--ink-dim);
    text-align: right;
    white-space: nowrap;
    padding-top: 0.2rem;
}

.preview-body > *:first-child {
    margin-top: 0;
}

.preview-body > *:last-child {
    margin-bottom: 0;
}

.preview h1, .preview h2, .preview h3 {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 600;
    margin-top: 0.5em;
    margin-bottom: 0.4em;
    color: var(--ink);
}

.preview code {
    background: var(--cover);
    padding: 0.1em 0.35em;
    border-radius: 3px;
    font-family: var(--font-mono);
}

.preview pre {
    background: var(--cover);
    padding: 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
}

.preview pre code {
    background: none;
    padding: 0;
}

.preview blockquote {
    border-left: 3px solid var(--thread);
    margin-left: 0;
    padding-left: 0.9rem;
    color: var(--ink-dim);
}

.preview a {
    color: var(--fountain);
}

.preview img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    display: block;
    margin: 0.4em 0;
}

@media (max-width: 720px) {
    .editor-split {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }

    .year-key {
        display: none;
    }
}
