:root {
    --cork: #c99c6b;
    --cork-speck: #b98a5a;
    --ink: #3b2a1e;
    --ink-soft: #6b5442;
    --on-cork: #2e1f14;
    --on-cork-soft: #4a3423;
    --panel: #fff9ef;
    --panel-line: #e6d8c3;
    --accent: #c23d57;
    --accent-ink: #ffffff;
    --error: #a3122f;
    --handwriting: 'Caveat', 'Segoe Print', 'Bradley Hand', cursive;
    --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --cork: #3a2c20;
        --cork-speck: #46362a;
        --on-cork: #f6e9d8;
        --on-cork-soft: #d8c6b0;
        --panel: #2a2119;
        --panel-line: #4b3c2e;
        --ink-panel: #f6e9d8;
        color-scheme: dark;
    }
}

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

html { height: 100%; }

body {
    margin: 0;
    min-height: 100%;
    font-family: var(--sans);
    color: var(--on-cork);
    background-color: var(--cork);
    background-image: radial-gradient(var(--cork-speck) 1px, transparent 1.5px);
    background-size: 14px 14px;
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

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

button { cursor: pointer; }

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

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 720px;
    margin: 0 auto;
    padding: calc(14px + env(safe-area-inset-top)) 16px 4px;
}

.top h1 {
    margin: 0;
    font: 700 36px/1.1 var(--handwriting);
}

.icon-button {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    font-size: 22px;
}

main {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 16px 16px;
}

.day-heading {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 12px;
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--on-cork-soft);
}

.streak { font-weight: 600; }

.section-title {
    margin: 20px 0 10px;
    font: 700 24px/1.2 var(--handwriting);
}

.empty {
    margin: 8px 0 16px;
    font: 500 22px/1.3 var(--handwriting);
    color: var(--on-cork-soft);
}

.board {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr));
    gap: 18px;
    align-items: start;
}

/* Notes */

.note-yellow { --paper: #ffe27a; --paper-fold: #eec452; }
.note-pink { --paper: #ffc2d4; --paper-fold: #eb9cb4; }
.note-mint { --paper: #b5ebd0; --paper-fold: #8dd2b0; }
.note-blue { --paper: #bfe0ff; --paper-fold: #95c4ee; }
.note-peach { --paper: #ffcfa8; --paper-fold: #eeb081; }

.note {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 150px;
    padding: 14px 12px 8px;
    color: var(--ink);
    background: var(--paper);
    border: 0;
    border-radius: 2px;
    box-shadow: 0 6px 10px -4px rgba(40, 20, 5, 0.45);
    transform: rotate(var(--tilt, 0deg));
}

.note-body {
    flex: 1;
    margin: 0;
    font: 500 23px/1.2 var(--handwriting);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.note-gif {
    display: block;
    width: 100%;
    border-radius: 2px;
}

.note-foot {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px;
    margin-top: auto;
}

.note-meta {
    display: flex;
    flex-direction: column;
    font-size: 11px;
    line-height: 1.35;
    color: var(--ink-soft);
}

.note-status { font-style: italic; }

.note-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-left: auto;
    margin-right: -6px;
}

.note-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-size: 16px;
}

.note-folded {
    align-items: center;
    justify-content: center;
    text-align: center;
    clip-path: polygon(0 0, 100% 0, 100% 78%, 78% 100%, 0 100%);
    box-shadow: none;
}

.note-folded::after {
    content: '';
    position: absolute;
    right: 0;
    bottom: 0;
    width: 22%;
    aspect-ratio: 1;
    background: linear-gradient(135deg, var(--paper-fold) 50%, transparent 50%);
}

.folded-mark { font-size: 32px; }
.folded-from { font: 700 22px/1.1 var(--handwriting); }
.folded-hint { font-size: 12px; color: var(--ink-soft); }

.new-note {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 150px;
    color: var(--on-cork);
    background: transparent;
    border: 2px dashed var(--on-cork-soft);
    border-radius: 2px;
    font: 700 22px/1.1 var(--handwriting);
}

.new-note span { font-size: 36px; line-height: 1; }

.just-stuck { animation: stick 420ms cubic-bezier(0.2, 1.4, 0.4, 1); }
.just-opened { animation: unfold 460ms ease-out; }

@keyframes stick {
    from { opacity: 0; transform: scale(1.35) rotate(8deg); }
    to { opacity: 1; transform: scale(1) rotate(var(--tilt, 0deg)); }
}

@keyframes unfold {
    from { transform: perspective(600px) rotateX(-70deg); transform-origin: top; }
    to { transform: perspective(600px) rotateX(0) rotate(var(--tilt, 0deg)); transform-origin: top; }
}

@media (prefers-reduced-motion: reduce) {
    .just-stuck, .just-opened { animation: none; }
}

/* Tabs */

.tabs {
    position: fixed;
    inset: auto 0 0;
    display: flex;
    justify-content: center;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel);
    border-top: 1px solid var(--panel-line);
}

.tabs a {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    max-width: 240px;
    padding: 8px 4px;
    font-size: 12px;
    color: var(--ink-panel, var(--ink-soft));
    text-decoration: none;
}

.tabs a span { font-size: 20px; line-height: 1.3; filter: grayscale(0.8); }
.tabs a[aria-current='page'] { font-weight: 700; color: var(--ink-panel, var(--ink)); }
.tabs a[aria-current='page'] span { filter: none; }

/* Dialogs */

.sheet {
    width: min(100vw - 24px, 480px);
    max-height: calc(100dvh - 24px);
    padding: 0;
    border: 0;
    background: transparent;
    overflow-y: auto;
}

.sheet::backdrop { background: rgba(30, 18, 8, 0.55); }

.composer-note {
    transform: none;
    padding: 16px;
    gap: 12px;
}

#composer-body {
    width: 100%;
    padding: 0;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: var(--ink);
    font: 500 28px/1.2 var(--handwriting);
}

#composer-body::placeholder { color: var(--ink-soft); }

.composer-gif { position: relative; }
.composer-gif img { display: block; width: 100%; max-height: 220px; object-fit: contain; }
.composer-gif .icon-button {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 36px;
    height: 36px;
    font-size: 16px;
    color: #fff;
    background: rgba(0, 0, 0, 0.6);
}

.composer-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

.swatches { display: flex; flex: 1; gap: 6px; }

.swatch {
    width: 30px;
    height: 30px;
    padding: 0;
    background: var(--paper);
    border: 1px solid rgba(59, 42, 30, 0.45);
    border-radius: 50%;
}

.swatch[aria-pressed='true'] { border: 3px solid var(--ink); }

.tool-button {
    min-width: 44px;
    height: 44px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.5);
    border: 0;
    border-radius: 8px;
    font-weight: 700;
    font-size: 15px;
}

.tool-button[aria-expanded='true'] { background: rgba(255, 255, 255, 0.95); }

.emoji-panel {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 2px;
    max-height: 170px;
    overflow-y: auto;
}

.emoji {
    height: 40px;
    padding: 0;
    border: 0;
    background: transparent;
    font-size: 24px;
}

.gif-panel input, .search {
    width: 100%;
    height: 44px;
    padding: 0 12px;
    color: var(--ink);
    background: #fffdf8;
    border: 1px solid rgba(59, 42, 30, 0.35);
    border-radius: 8px;
}

.search { margin-top: 20px; margin-bottom: 14px; }

.gif-results {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    max-height: 210px;
    margin-top: 8px;
    overflow-y: auto;
}

.gif-choice { padding: 0; border: 0; background: transparent; }
.gif-choice img { display: block; width: 100%; height: 80px; object-fit: cover; }
.gif-message { grid-column: 1 / -1; margin: 6px 0; font-size: 14px; }
.gif-credit { margin: 6px 0 0; font-size: 11px; color: var(--ink-soft); }

.composer-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.composer-actions button {
    min-height: 44px;
    padding: 0 16px;
    color: var(--ink);
    background: transparent;
    border: 0;
    border-radius: 8px;
    font-weight: 600;
}

.composer-actions .button-primary, .button-primary {
    color: var(--accent-ink);
    background: var(--accent);
}

.button-primary:disabled { opacity: 0.7; }

.form-error { margin: 0; color: var(--error); font-size: 14px; font-weight: 600; }

.settings-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 20px;
    color: var(--ink-panel, var(--ink));
    background: var(--panel);
    border-radius: 12px;
}

.settings-body h2 { margin: 0; font: 700 30px/1.1 var(--handwriting); }
.settings-who, .settings-hint { margin: 0; font-size: 14px; }
.settings-hint:empty { display: none; }

.settings-body button {
    width: 100%;
    min-height: 44px;
    background: transparent;
    border: 1px solid var(--panel-line);
    border-radius: 8px;
}

.settings-body form { margin: 0; }

/* Memories */

.calendar {
    padding: 12px;
    color: var(--ink-panel, var(--ink));
    background: var(--panel);
    border-radius: 12px;
}

.calendar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.calendar-head h2 { margin: 0; font: 700 26px/1.1 var(--handwriting); }

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
}

.weekday { text-align: center; font-size: 12px; opacity: 0.75; }

.day-cell {
    aspect-ratio: 1;
    min-height: 36px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 4px;
    font-size: 14px;
}

.day-cell.has-notes { color: var(--ink); background: var(--paper); font-weight: 600; }
.day-cell.is-today { box-shadow: inset 0 0 0 2px var(--accent); }
.day-cell.selected { outline: 2px solid var(--ink-panel, var(--ink)); outline-offset: 1px; }

.toast {
    position: fixed;
    inset: auto 16px calc(84px + env(safe-area-inset-bottom));
    z-index: 10;
    max-width: 480px;
    margin: 0 auto;
    padding: 12px 16px;
    color: #fff;
    background: #2c2118;
    border-radius: 8px;
    text-align: center;
    font-size: 14px;
}

/* Login */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 16px;
}

.login-note {
    width: min(100%, 340px);
    padding: 24px;
    gap: 12px;
    --tilt: -1.5deg;
}

.login-note h1 { margin: 0; font: 700 40px/1.1 var(--handwriting); }
.login-hint { margin: 0; font: 500 22px/1.2 var(--handwriting); }

.login-note label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 14px;
    font-weight: 600;
}

.login-note input {
    height: 44px;
    padding: 0 10px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid rgba(59, 42, 30, 0.4);
    border-radius: 4px;
    font-size: 16px;
}

.login-note button {
    height: 44px;
    margin-top: 4px;
    border: 0;
    border-radius: 6px;
    font-weight: 700;
}
