:root {
    --paper: #efe8d6;
    --ink: #2a2418;
    --muted: #7a705f;
    --line: rgba(42, 36, 24, 0.1);
    --note: #f6e27a;
    --shadow: 0 8px 24px rgba(60, 40, 10, 0.08);
    --bar: rgba(239, 232, 214, 0.86);
    --accent: #2a2418;
    --danger: #9a3b2f;
    --sans: "Avenir Next", "Segoe UI", system-ui, sans-serif;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --mono: "IBM Plex Mono", ui-monospace, monospace;
    --hand: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    font-family: var(--sans);
    color: var(--ink);
    background: var(--paper);
    overflow: hidden;
}
body.is-plain { overflow: auto; }

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

#app { height: 100%; position: relative; }

.topbar {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.mark {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    font-weight: 700;
    letter-spacing: 0.08em;
    font-size: 13px;
}
.mark-note {
    width: 16px; height: 16px;
    background: var(--note);
    box-shadow: 1px 1px 0 rgba(0,0,0,.12);
    transform: rotate(-4deg);
}
.mark-word { opacity: 0.8; }

.crumbs {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    font-size: 13px;
    color: var(--muted);
}
.crumbs a, .crumbs button {
    background: none;
    border: 0;
    padding: 0;
    color: inherit;
    text-decoration: none;
}
.crumbs a:hover, .crumbs button:hover { color: var(--ink); }
.crumbs .sep { opacity: 0.4; }
.crumbs .current { color: var(--ink); font-weight: 600; }
.crumb-more { position: relative; }
.crumb-menu {
    position: absolute;
    top: 120%;
    left: 0;
    background: #fffaf0;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    padding: 6px 0;
    min-width: 180px;
    z-index: 30;
}
.crumb-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 6px 12px;
    background: none;
    border: 0;
}

.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn, .text-btn, .avatar {
    background: transparent;
    border: 0;
    border-radius: 999px;
    color: var(--ink);
}
.icon-btn {
    width: 34px; height: 34px;
    position: relative;
    display: grid;
    place-items: center;
}
.icon-btn:hover, .text-btn:hover, .avatar:hover { background: rgba(42,36,24,.06); }
.text-btn { padding: 4px 10px; font-size: 13px; }
.avatar {
    width: 32px; height: 32px;
    background: #f6e27a;
    font-size: 13px;
    font-weight: 700;
}
.badge {
    position: absolute;
    top: 2px; right: 2px;
    background: var(--ink);
    color: var(--paper);
    border-radius: 8px;
    font-size: 10px;
    min-width: 14px;
    padding: 0 4px;
    line-height: 14px;
}
.hidden { display: none !important; }

.profile-wrap { position: relative; }
.menu {
    position: absolute;
    right: 0; top: 40px;
    background: #fffaf0;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    min-width: 200px;
    padding: 8px 0;
    z-index: 40;
}
.menu button, .menu a {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    padding: 8px 14px;
    text-decoration: none;
    font-size: 13px;
}
.menu button:hover, .menu a:hover { background: rgba(42,36,24,.05); }

.board-titlebar {
    position: absolute;
    top: 52px; left: 16px; right: 16px;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    pointer-events: none;
}
.board-titlebar > * { pointer-events: auto; }
.nav-cluster, .zoom-cluster {
    display: flex;
    align-items: center;
    gap: 2px;
    color: var(--muted);
    font-size: 12px;
}
#zoom-label { min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; }

.canvas {
    position: absolute;
    inset: 0;
    overflow: hidden;
    cursor: grab;
    touch-action: none;
    background-color: var(--paper);
    background-image: radial-gradient(rgba(42,36,24,.07) 1px, transparent 1px);
    background-size: 28px 28px;
}
.canvas.is-panning { cursor: grabbing; }
.canvas.is-dropping { cursor: copy; }
.world {
    position: absolute;
    left: 0; top: 0;
    z-index: 1;
    transform-origin: 0 0;
    will-change: transform;
}
.board-watermark {
    position: absolute;
    left: 50%;
    top: 46%;
    z-index: 0;
    margin: 0;
    max-width: 70%;
    transform: translate(-50%, -50%);
    font-family: var(--serif);
    font-weight: 500;
    font-size: clamp(28px, 5vw, 56px);
    letter-spacing: -0.03em;
    line-height: 1.15;
    text-align: center;
    color: var(--ink);
    opacity: 0.12;
    pointer-events: none;
    user-select: none;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}
.create-chip {
    position: absolute;
    z-index: 18;
    transform: translate(-50%, -50%);
    border: 1px solid var(--line);
    background: #fffaf0;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 13px;
    box-shadow: var(--shadow);
    white-space: nowrap;
}
.create-chip:hover { background: #fff; }

.hint {
    position: absolute;
    left: 50%;
    top: 62%;
    z-index: 1;
    transform: translate(-50%, -50%);
    color: var(--muted);
    font-family: var(--serif);
    font-size: 20px;
    pointer-events: none;
    opacity: 0.7;
}

.note {
    position: absolute;
    background: var(--note);
    color: var(--ink);
    padding: 12px 14px 16px;
    box-shadow: 1px 2px 0 rgba(255,255,255,.35) inset, 2px 6px 16px rgba(60,40,10,.12);
    border-radius: 1px;
    overflow: hidden;
    user-select: none;
    cursor: grab;
    background-image: linear-gradient(180deg, rgba(255,255,255,.22), transparent 28%);
}
.note.is-image { padding: 0; background: #f3ead0; }
.note.is-image img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}
.note.is-image .note-face {
    position: absolute;
    left: 8px; right: 8px; bottom: 8px;
    background: rgba(246,226,122,.9);
    padding: 4px 6px;
}
.note.selected {
    outline: 2px solid rgba(42,36,24,.55);
    outline-offset: 2px;
    z-index: 8;
}
.note.drop-target {
    outline: 2px dashed #2a2418;
    outline-offset: 4px;
    box-shadow: 0 0 0 6px rgba(246,226,122,.5), 2px 6px 16px rgba(60,40,10,.12);
}
.note-face {
    white-space: pre-wrap;
    word-break: break-word;
    pointer-events: none;
}
.note textarea.face-edit {
    position: absolute;
    inset: 8px;
    width: calc(100% - 16px);
    height: calc(100% - 16px);
    border: 0;
    resize: none;
    background: transparent;
    outline: none;
    padding: 0;
}
.note-door {
    position: absolute;
    right: 6px; bottom: 6px;
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: rgba(42,36,24,.08);
    padding: 2px 6px;
    color: inherit;
    text-decoration: none;
    pointer-events: auto;
    cursor: pointer;
    z-index: 2;
}
.note-door:hover {
    background: rgba(42,36,24,.16);
    text-decoration: underline;
}
.handle {
    position: absolute;
    width: 10px; height: 10px;
    background: #fff;
    border: 1px solid rgba(42,36,24,.45);
    border-radius: 1px;
}
.handle.se { right: -5px; bottom: -5px; cursor: nwse-resize; }

.guides { position: absolute; inset: 0; pointer-events: none; }
.guide-x, .guide-y {
    position: absolute;
    background: rgba(180, 40, 40, .45);
}
.guide-x { height: 1px; left: 0; right: 0; }
.guide-y { width: 1px; top: 0; bottom: 0; }
.marquee {
    position: absolute;
    border: 1px dashed rgba(42,36,24,.45);
    background: rgba(246,226,122,.15);
    pointer-events: none;
}

.toolbar {
    position: absolute;
    z-index: 25;
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    align-items: center;
    max-width: min(960px, calc(100vw - 24px));
    overflow-x: auto;
    padding: 6px 8px;
    background: #fffaf0;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    border-radius: 18px;
}
.toolbar button, .toolbar select {
    border: 0;
    background: transparent;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
}
.toolbar button:hover { background: rgba(42,36,24,.06); }
.swatch {
    width: 16px; height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,.15);
    padding: 0 !important;
}

.panel, .sheet {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: min(380px, 100%);
    background: #fffaf0;
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow);
    z-index: 30;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sheet { width: min(420px, 100%); }
.panel-head, .sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 8px;
}
.panel-head h2, .sheet-head h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}
.panel-body, .sheet-body {
    padding: 8px 18px 24px;
    overflow: auto;
    flex: 1;
}
.detail-edit {
    min-height: 180px;
    border: 1px solid var(--line);
    padding: 10px;
    background: #fff;
    outline: none;
    font-family: var(--serif);
    line-height: 1.45;
}
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.stack input, .stack textarea, .stack select {
    border: 1px solid var(--line);
    background: #fff;
    padding: 8px 10px;
}
.primary {
    background: var(--ink);
    color: var(--paper);
    border: 0;
    padding: 8px 14px;
    border-radius: 999px;
}
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.list { list-style: none; padding: 0; margin: 0; }
.list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}
.inbox-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
    cursor: grab;
}
.inbox-item.is-preview { background: rgba(246,226,122,.18); margin: 0 -18px; padding: 12px 18px; }
.inbox-swatch { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 3px; box-shadow: 1px 1px 0 rgba(0,0,0,.12); }
.inbox-preview {
    margin-top: 8px;
    padding: 10px 12px;
    min-height: 72px;
    box-shadow: var(--shadow);
    font-family: var(--serif);
    white-space: pre-wrap;
}
.inbox-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.share-modes { display: grid; gap: 8px; }
.share-mode {
    display: block;
    text-align: left;
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    padding: 10px 12px;
    border-radius: 2px;
}
.share-mode strong { display: block; font-size: 14px; }
.share-mode span { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.4; }
.share-mode.is-on { outline: 2px solid var(--ink); background: #fff6d2; }
.people-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    padding: 6px 0;
    font-size: 13px;
}
.comment, .activity-row { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.role-pill {
    display: inline-block;
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
    border: 1px solid var(--line);
    padding: 1px 6px;
    border-radius: 999px;
}
.modal {
    position: absolute;
    inset: 0;
    background: rgba(42,36,24,.18);
    z-index: 50;
    display: grid;
    place-items: center;
}
.dialog {
    background: #fffaf0;
    padding: 22px 24px;
    width: min(440px, calc(100% - 32px));
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
}
.dialog h2 { margin: 0 0 8px; font-size: 18px; font-family: var(--serif); font-weight: 500; }
.dialog p { margin: 0 0 16px; color: var(--muted); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

.toast {
    position: absolute;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    background: var(--ink);
    color: var(--paper);
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 13px;
    z-index: 60;
}

.auth-card {
    position: absolute;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    background: #fffaf0;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    padding: 12px 14px;
    z-index: 22;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    width: min(520px, calc(100% - 24px));
}
.auth-card input { flex: 1 1 160px; border: 1px solid var(--line); padding: 7px 10px; background: #fff; }
.auth-card p { margin: 0; font-size: 13px; flex: 1 1 100%; }
.auth-card .muted { color: var(--muted); }
.plain h2 { font-size: 18px; font-family: var(--serif); font-weight: 500; margin: 28px 0 8px; }
.plain .muted { color: var(--muted); font-size: 13px; }
.plain .stack { display: grid; gap: 10px; max-width: 420px; }
.plain label { display: grid; gap: 4px; font-size: 13px; }
.plain input, .plain textarea, .plain select {
    border: 1px solid var(--line);
    padding: 7px 10px;
    background: #fff;
}
.admin-nav { display: flex; gap: 12px; margin: 12px 0 20px; font-size: 14px; }
.admin-nav a { text-decoration: none; color: var(--muted); }
.admin-nav a.is-on { color: var(--ink); font-weight: 600; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.admin-page { max-width: 840px; }

.plain { max-width: 680px; margin: 40px auto; padding: 0 20px 60px; }
.plain-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.lede { color: var(--muted); font-size: 16px; }
.sessions, .mail-list { list-style: none; padding: 0; }
.sessions li, .mail-list li {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}
.sessions li.is-revoked { opacity: 0.55; }
.mail-list pre {
    white-space: pre-wrap;
    font-size: 13px;
    background: #fff;
    padding: 10px;
    border: 1px solid var(--line);
}

.font-georgia { font-family: var(--serif); }
.font-system { font-family: var(--sans); }
.font-serif { font-family: "Times New Roman", Times, serif; }
.font-mono { font-family: var(--mono); }
.font-hand { font-family: var(--hand); }

.compat-banner {
    display: none;
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 8px;
    text-align: center;
    font-size: 12px;
    background: rgba(42,36,24,.08);
    z-index: 12;
}
@media (max-width: 720px) {
    .compat-banner { display: block; }
    .board-watermark { font-size: 28px; }
    .nav-cluster { display: none; }
}

.save-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: transparent;
    margin-left: 8px;
}
.save-dot.busy { background: #c9a227; }
.save-dot.ok { background: #6a8f4e; }
.save-dot.err { background: var(--danger); }

.remind-pop {
    position: absolute;
    z-index: 35;
    width: min(320px, calc(100vw - 24px));
    background: #fffaf0;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    padding: 12px 14px;
    border-radius: 8px;
}
.remind-form { margin-top: 8px; }
.remind-row, .history-row, .deleted-item {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: flex-start;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
}
.deleted-item { align-items: center; }
.version-preview {
    min-height: 120px;
    padding: 12px 14px;
    margin: 0 0 16px;
    box-shadow: var(--shadow);
    font-family: var(--serif);
    white-space: pre-wrap;
    max-height: 280px;
    overflow: auto;
}
.mail-list { display: block; }
.mail-list li { display: block; }
