:root {
    --paper: #fbf6e9;
    --paper-accent: #f3ead4;
    --ink: #2b261e;
    --ink-muted: #6a6254;
    --line: rgba(90, 106, 168, 0.12);
    --margin-line: rgba(214, 93, 93, 0.35);
    --accent: #3d6eb3;
    --accent-dark: #2c528c;
    --success: #2f7d4b;
    --shadow: rgba(40, 32, 20, 0.12);
    --radius: 12px;
    --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
    --font-hand: "Caveat", cursive;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font-serif);
    color: var(--ink);
    background: #c8b89a;
}

.notebook-bg {
    background:
        radial-gradient(1200px 600px at 20% -10%, rgba(255, 255, 255, 0.35), transparent 55%),
        linear-gradient(135deg, #bfb09a 0%, #a89275 45%, #8f7a62 100%);
    min-height: 100vh;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem clamp(0.75rem, 3vw, 1.5rem) 0.75rem;
    max-width: 1200px;
    margin: 0 auto;
    gap: 1rem;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.brand-mark {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    background: linear-gradient(145deg, var(--accent), #6a9bd4);
    box-shadow: 0 2px 6px var(--shadow);
}

.brand-title {
    font-family: var(--font-hand);
    font-size: clamp(1.5rem, 4.5vw + 0.5rem, 2rem);
    margin: 0;
    line-height: 1;
}

.brand-tag {
    font-size: 0.85rem;
    color: var(--ink-muted);
    letter-spacing: 0.02em;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.user-chip {
    font-size: 0.9rem;
    padding: 0.35rem 0.65rem;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.35);
}

.inline-form {
    margin: 0;
}

.main-wrap {
    max-width: 1200px;
    margin: 0 auto 2rem;
    padding: 0 clamp(0.65rem, 2.5vw, 1rem) 2rem;
}

.sheet-rise {
    animation: sheetIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
    box-shadow:
        0 18px 40px var(--shadow),
        0 2px 8px rgba(0, 0, 0, 0.06);
}

@keyframes sheetIn {
    from {
        opacity: 0;
        transform: translateY(14px) rotate(-0.35deg);
        filter: blur(0.5px);
    }
    to {
        opacity: 1;
        transform: translateY(0) rotate(0);
        filter: none;
    }
}

.notebook-shell {
    background: var(--paper);
    border-radius: var(--radius);
    border: 1px solid rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.notebook-inner {
    display: grid;
    grid-template-columns: 28px 1fr;
    min-height: 420px;
}

.spiral {
    background: repeating-linear-gradient(
        180deg,
        #cfc7b8 0px,
        #cfc7b8 10px,
        #e0d8cc 10px,
        #e0d8cc 20px
    );
    border-right: 1px solid rgba(0, 0, 0, 0.06);
    position: relative;
}
.spiral::after {
    content: "";
    position: absolute;
    top: 16px;
    bottom: 16px;
    left: 50%;
    width: 8px;
    transform: translateX(-50%);
    background: repeating-linear-gradient(
        180deg,
        transparent 0 14px,
        rgba(255, 255, 255, 0.55) 14px 16px
    );
    border-radius: 999px;
    opacity: 0.75;
}

.notebook-body {
    padding: 1.1rem 1.25rem 1.5rem;
    background:
        linear-gradient(90deg, var(--margin-line) 0, var(--margin-line) 2px, transparent 2px) 48px 0 / 100% 100% no-repeat,
        repeating-linear-gradient(
            to bottom,
            transparent 0,
            transparent 27px,
            var(--line) 27px,
            var(--line) 28px
        );
}

.hidden {
    display: none !important;
}

.guest-banner {
    background: rgba(61, 110, 179, 0.1);
    border: 1px solid rgba(61, 110, 179, 0.2);
    border-radius: 8px;
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.85rem;
    font-size: 0.92rem;
    animation: fadeUp 0.4s ease both;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.notebook-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.65rem;
    min-height: 2.2rem;
}

.note-tab {
    font-family: var(--font-hand);
    font-size: clamp(1.1rem, 2.5vw + 0.35rem, 1.35rem);
    padding: 0.2rem 0.75rem 0.35rem;
    background: var(--paper-accent);
    border-radius: 8px 8px 4px 4px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
    user-select: none;
}
.note-tab:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
}
.note-tab.active {
    background: #fff;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.07);
    border-bottom: 2px solid var(--accent);
}

.notebook-toolbar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding-left: 52px;
}

.board {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    overflow-x: visible;
    overflow-y: visible;
    padding: 0.25rem 0.25rem 0.5rem 52px;
    align-items: flex-start;
    scrollbar-gutter: stable;
}

.list-column.sortable-ghost {
    opacity: 0.55;
    outline: 2px dashed var(--accent);
}

.list-column {
    flex: 0 0 auto;
    width: max-content;
    min-width: 240px;
    max-width: min(560px, calc(100vw - 5.5rem));
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    padding: 0.65rem 0.6rem;
    animation: colIn 0.35s ease both;
    max-height: min(92vh, 900px);
    display: flex;
    flex-direction: column;
    overflow-x: visible;
    overflow-y: auto;
    min-height: 0;
}

@keyframes colIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0 0.15rem;
    flex-shrink: 0;
}

.list-title-input {
    font-family: var(--font-hand);
    font-size: clamp(1.15rem, 2.8vw + 0.4rem, 1.45rem);
    margin: 0;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    border: none;
    background: transparent;
    line-height: 1.2;
    padding: 0;
}

.item-list {
    flex: 0 0 auto;
    min-height: 120px;
    min-width: 100%;
    width: max-content;
    max-width: 100%;
    padding: 0.25rem;
    margin: 0 -0.15rem;
    border-radius: 8px;
    overflow: visible;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.list-footer {
    flex-shrink: 0;
}

.todo-item {
    display: flex;
    align-items: flex-start;
    gap: 0.45rem;
    padding: 0.45rem 0.4rem;
    margin-bottom: 0.35rem;
    background: rgba(251, 246, 233, 0.9);
    border-radius: 8px;
    border: 1px dashed rgba(0, 0, 0, 0.06);
    transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
    animation: itemIn 0.28s ease both;
    min-width: 0;
    width: fit-content;
    max-width: 100%;
    box-sizing: border-box;
}

@keyframes itemIn {
    from {
        opacity: 0;
        transform: translateX(-6px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.todo-item.sortable-ghost {
    opacity: 0.55;
    transform: scale(0.98);
}
.todo-item.sortable-drag {
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
}

.todo-item.done {
    opacity: 0.72;
}
.todo-item.done .item-title {
    text-decoration: line-through;
    color: var(--ink-muted);
}

.item-check {
    margin-top: 0.15rem;
    accent-color: var(--accent);
    cursor: pointer;
}

.item-title {
    flex: 0 1 auto;
    min-width: 8.5ch;
    max-width: min(560px, calc(100vw - 8.5rem));
    font-size: 0.98rem;
    line-height: 1.35;
    border: none;
    background: transparent;
    font-family: inherit;
    resize: none;
    min-height: 2.4rem;
    max-height: min(calc(100svh - 7.5rem), calc(100vh - 7.5rem));
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
    overflow-x: hidden;
    overflow-y: hidden;
    box-sizing: border-box;
}

.item-title.is-readonly,
.list-title-input.is-readonly {
    cursor: text;
}

.todo-item.editing {
    box-shadow: 0 0 0 2px rgba(44, 82, 140, 0.18);
}

.btn {
    appearance: none;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    padding: 0.45rem 0.85rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:active {
    transform: translateY(1px);
}
.btn-primary {
    background: linear-gradient(180deg, var(--accent), var(--accent-dark));
    color: #fff;
    box-shadow: 0 3px 10px rgba(44, 82, 140, 0.35);
}
.btn-secondary {
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid rgba(0, 0, 0, 0.08);
    color: var(--ink);
}
.btn-ghost {
    background: rgba(255, 255, 255, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: var(--ink);
}
.btn-small {
    padding: 0.3rem 0.55rem;
    font-size: 0.82rem;
}

.icon-btn {
    padding: 0.2rem 0.45rem;
    font-size: 1rem;
    line-height: 1;
    border-radius: 6px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--ink-muted);
    transition: color 0.15s ease, background 0.15s ease;
}
.icon-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--ink);
}

.toast {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    background: rgba(43, 38, 30, 0.92);
    color: #fff;
    padding: 0.65rem 1rem;
    border-radius: 10px;
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 50;
    max-width: min(360px, calc(100vw - 2rem));
}
.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.auth-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 2rem);
    padding: 2rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--paper);
    border-radius: var(--radius);
    padding: 1.75rem;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.auth-title {
    font-family: var(--font-hand);
    font-size: 2.25rem;
    margin: 0 0 1rem;
}

.auth-error {
    background: rgba(214, 93, 93, 0.12);
    border: 1px solid rgba(214, 93, 93, 0.35);
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    font-size: 0.9rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    margin-top: 1rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.88rem;
    color: var(--ink-muted);
}

.field input {
    font-family: inherit;
    font-size: 1rem;
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: rgba(255, 255, 255, 0.85);
}

.btn-block {
    width: 100%;
    margin-top: 0.25rem;
}

.auth-footer {
    margin: 1rem 0 0;
    font-size: 0.9rem;
    color: var(--ink-muted);
}
.auth-footer a {
    color: var(--accent-dark);
}

.empty-hint {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--ink-muted);
    animation: fadeUp 0.4s ease both;
}

@media (max-width: 720px) {
    .notebook-inner {
        grid-template-columns: 18px 1fr;
    }
    .notebook-body {
        background:
            linear-gradient(90deg, var(--margin-line) 0, var(--margin-line) 2px, transparent 2px) 36px 0 / 100% 100% no-repeat,
            repeating-linear-gradient(
                to bottom,
                transparent 0,
                transparent 27px,
                var(--line) 27px,
                var(--line) 28px
            );
    }
    .notebook-toolbar,
    .board {
        padding-left: 18px;
    }
}

@media (max-width: 640px) {
    .top-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .nav-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .board {
        flex-direction: column;
        align-items: stretch;
        overflow-x: visible;
        padding-right: 0.25rem;
    }

    .list-column {
        flex: 1 1 auto;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        min-height: 0;
        max-height: min(92vh, 900px);
        overflow-y: auto;
    }
}
