:root {
  --linen: #FAF6EF; --linen-deep: #F3ECDF; --ink: #3A3630; --ink-soft: #6E675C;
  --thread: #C2542E; --thread-soft: #E0805E; --paper: #FDFCFA;
  --yellow: #FFF2B3; --pink: #FFD9E6; --blue: #D1E8FF; --green: #D6F5D4;
  --orange: #FFE3C4; --purple: #E8DBFF;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Nunito', -apple-system, sans-serif; color: var(--ink); background: var(--linen);
  -webkit-font-smoothing: antialiased; display: flex; flex-direction: column;
}
.hand { font-family: 'Caveat', cursive; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* top bar */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: rgba(250,246,239,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(58,54,48,.08); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 800; }
.brand img { border-radius: 7px; }
.beta { color: var(--thread); font-size: 1.15rem; transform: rotate(-4deg); }
.bar-right { display: flex; align-items: center; gap: 12px; }
#search {
  font: inherit; padding: 8px 12px; border-radius: 999px; border: 1px solid rgba(58,54,48,.15);
  background: var(--paper); min-width: 220px;
}
.install { font: inherit; font-size: .85rem; font-weight: 700; padding: 6px 12px; border-radius: 999px; border: 1px solid rgba(194,84,46,.5); background: transparent; color: var(--thread); }
.install:hover { background: rgba(194,84,46,.08); }
.env { font-size: .75rem; color: var(--ink-soft); padding: 3px 8px; border: 1px dashed rgba(58,54,48,.25); border-radius: 999px; }

/* welcome + loading */
.welcome { max-width: 560px; margin: 12vh auto; padding: 0 24px; text-align: center; }
.welcome h1 { font-family: 'Caveat', cursive; font-size: clamp(2.4rem, 6vw, 3.6rem); margin: 0 0 12px; }
.welcome p { color: var(--ink-soft); font-size: 1.1rem; }
.hint { color: var(--thread); font-size: 1.4rem; }
.loading { margin: 12vh auto; text-align: center; color: var(--ink-soft); }
.spinner {
  width: 34px; height: 34px; border-radius: 50%; margin: 0 auto 14px;
  border: 3px solid rgba(194,84,46,.2); border-top-color: var(--thread); animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* shell */
#main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.shell { display: grid; grid-template-columns: 220px 1fr; flex: 1; min-height: 0; }
.rail {
  border-right: 1px solid rgba(58,54,48,.08); background: var(--linen-deep); padding: 12px 8px; overflow: auto;
}
.rail-item {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink); font-weight: 600;
}
.rail-item:hover { background: rgba(58,54,48,.06); }
.rail-item.selected { background: rgba(194,84,46,.14); }
.rail-item .count { float: right; color: var(--ink-soft); font-weight: 400; }
.rail-item.pinned { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-head { margin: 16px 10px 6px; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }

.table { padding: 18px 20px 40px; overflow: auto; background:
  repeating-linear-gradient(0deg, rgba(194,84,46,.05) 0 28px, transparent 28px 56px),
  repeating-linear-gradient(90deg, rgba(194,84,46,.05) 0 28px, transparent 28px 56px), var(--linen); }
.table-title { font-family: 'Caveat', cursive; font-size: 2rem; margin: 0 0 12px; }
.lanes { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(180px, 1fr); gap: 12px; margin-bottom: 18px; overflow-x: auto; }
.lane { background: rgba(255,255,255,.55); border-radius: 10px; padding: 8px; min-height: 60px; border: 2px dashed transparent; }
.dragging .lane, .dragging .cards { border-color: rgba(194,84,46,.25); }
.drop-here { border-color: var(--thread) !important; background: rgba(194,84,46,.08); }
.cards { border: 2px dashed transparent; border-radius: 12px; min-height: 80px; }
[draggable="true"] { cursor: grab; }
.lane h4 { margin: 0 0 6px; font-size: .8rem; color: var(--ink-soft); }
.lane .chip { display: block; background: var(--paper); border-radius: 7px; padding: 6px 8px; margin: 4px 0; font-size: .9rem; cursor: pointer; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.card {
  background: var(--paper); border-radius: 12px; padding: 14px 14px 12px; position: relative; cursor: pointer;
  box-shadow: 0 3px 10px rgba(58,54,48,.10); border: 1px solid rgba(58,54,48,.06);
  transition: transform .12s ease;
}
.card:hover { transform: translateY(-2px); }
.card::after {
  content: ""; position: absolute; inset: 5px; border-radius: 8px; pointer-events: none;
  border: 1.5px dashed rgba(0,0,0,.13);
}
.card.t-yellow { background: var(--yellow); } .card.t-pink { background: var(--pink); }
.card.t-blue { background: var(--blue); } .card.t-green { background: var(--green); }
.card.t-orange { background: var(--orange); } .card.t-purple { background: var(--purple); }
.card h3 { margin: 0 0 4px; font-size: 1.05rem; overflow-wrap: anywhere; }
.card p { margin: 0; font-size: .92rem; overflow-wrap: anywhere; color: rgba(58,54,48,.85); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.card .threads { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.card .threads span, .ed-threads span { font-size: .72rem; background: rgba(0,0,0,.07); border-radius: 999px; padding: 2px 8px; }
.card .stamp { margin-top: 6px; font-size: .75rem; color: var(--ink-soft); }
.card .thumb { display: block; width: 100%; max-height: 160px; object-fit: cover; border-radius: 8px; margin-bottom: 8px; }
.ed-image { display: block; max-width: 100%; max-height: 360px; border-radius: 10px; margin: 0 0 12px; }
.card.photo { padding: 0; overflow: hidden; min-height: 200px; }
.card.photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card.photo h3 { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: 28px 14px 12px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.6); background: linear-gradient(to bottom, rgba(0,0,0,0), rgba(0,0,0,.55)); }
.empty { color: var(--ink-soft); text-align: center; margin: 60px 0; }
.cards.calendar { display: block; }
.cal-nav { display: flex; gap: 8px; margin-bottom: 10px; }
.cal-nav button { font: inherit; border-radius: 999px; border: 1px solid rgba(58,54,48,.25); background: var(--paper); padding: 4px 12px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); padding: 4px 6px; }
.day { background: rgba(255,255,255,.6); border-radius: 8px; min-height: 84px; padding: 4px 6px; border: 1px solid rgba(58,54,48,.06); }
.day.pad { background: transparent; border: 0; }
.day.today { border-color: var(--thread); box-shadow: inset 0 0 0 1px var(--thread); }
.day .num { font-size: .8rem; color: var(--ink-soft); margin-bottom: 2px; }
.day .chip { display: block; background: var(--paper); border-radius: 6px; padding: 3px 6px; margin: 2px 0; font-size: .8rem; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day .chip.t-yellow { background: var(--yellow); } .day .chip.t-pink { background: var(--pink); } .day .chip.t-blue { background: var(--blue); }
.day .chip.t-green { background: var(--green); } .day .chip.t-orange { background: var(--orange); } .day .chip.t-purple { background: var(--purple); }
@media (max-width: 720px) { .day { min-height: 56px; padding: 2px 4px; } .day .chip { font-size: .7rem; } }

/* editor */
.editor { position: fixed; inset: 0; background: rgba(0,0,0,.3); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.editor-card {
  width: min(720px, 100%); max-height: 90vh; overflow: auto; background: var(--paper); border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.3); padding: 18px 20px;
}
.editor-card.t-yellow { background: var(--yellow); } .editor-card.t-pink { background: var(--pink); }
.editor-card.t-blue { background: var(--blue); } .editor-card.t-green { background: var(--green); }
.editor-card.t-orange { background: var(--orange); } .editor-card.t-purple { background: var(--purple); }
.editor-head { display: flex; align-items: center; gap: 10px; }
.ed-title { flex: 1; min-width: 0; font: inherit; font-size: 1.4rem; font-weight: 800; border: 0; background: transparent; color: var(--ink); }
.icon-btn { border: 0; background: rgba(0,0,0,.08); border-radius: 50%; width: 32px; height: 32px; }
.ed-meta { font-size: .85rem; color: var(--ink-soft); margin: 4px 0 10px; }
.ed-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; font-size: 1.05rem; min-height: 80px; }
.ed-body .h1 { font-size: 1.7rem; font-weight: 800; } .ed-body .h2 { font-size: 1.35rem; font-weight: 800; } .ed-body .h3 { font-size: 1.1rem; font-weight: 700; }
.ed-checklist { margin-top: 12px; }
.ed-checklist div { padding: 3px 0; }
.ed-threads { margin-top: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.readonly-note { font-size: .78rem; color: var(--ink-soft); margin: 0; }
.table-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.table-head .table-title { margin: 0; }
.head-right { display: inline-flex; align-items: center; gap: 10px; }
.updated { font: inherit; font-size: .78rem; color: var(--ink-soft); background: transparent; border: 0; padding: 4px 6px; border-radius: 999px; }
.updated:hover { background: rgba(58,54,48,.06); color: var(--ink); }
.jot, .save { font: inherit; font-weight: 700; padding: 8px 14px; border-radius: 999px; border: 0; background: var(--thread); color: #fff; }
.jot:hover, .save:hover { background: #a8471f; }
.ed-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 0 0 8px; }
.ed-tools button { font: inherit; font-size: .85rem; min-width: 32px; padding: 4px 8px; border-radius: 8px; border: 1px solid rgba(58,54,48,.2); background: var(--paper); }
.ed-tools button:hover { background: rgba(58,54,48,.06); }
.ed-tools .sep { width: 1px; height: 20px; background: rgba(58,54,48,.2); margin: 0 4px; }
.ed-rich { min-height: 160px; padding: 10px 12px; border-radius: 10px; border: 1px solid rgba(58,54,48,.15); background: rgba(255,255,255,.6); outline: none; white-space: pre-wrap; }
.ed-rich:focus { border-color: rgba(194,84,46,.5); }
.ed-rich .line { min-height: 1.5em; }
.ed-rich .line.h1 { font-size: 1.7rem; font-weight: 800; } .ed-rich .line.h2 { font-size: 1.35rem; font-weight: 800; } .ed-rich .line.h3 { font-size: 1.1rem; font-weight: 700; }
.ed-rich a { color: var(--thread); }
.ed-text { width: 100%; min-height: 160px; font: inherit; font-size: 1.05rem; line-height: 1.5; padding: 10px 12px; border-radius: 10px;
  border: 1px solid rgba(58,54,48,.15); background: rgba(255,255,255,.6); color: var(--ink); resize: vertical; }
.ed-threads select, .ed-threads .x { font: inherit; font-size: .8rem; border-radius: 999px; border: 1px solid rgba(58,54,48,.2); background: var(--paper); padding: 2px 8px; }
.thread-row { display: inline-flex; align-items: center; gap: 6px; background: rgba(0,0,0,.07); border-radius: 999px; padding: 3px 4px 3px 10px; font-size: .8rem; }
.thread-row .x { border: 0; background: transparent; padding: 0 4px; cursor: pointer; }
.ed-lanes { margin-top: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 10px; border-radius: 10px; background: rgba(0,0,0,.05); }
.lane-head { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }
.lane-row { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; }
.lane-row select { font: inherit; font-size: .8rem; border-radius: 999px; border: 1px solid rgba(58,54,48,.2); background: var(--paper); padding: 2px 8px; }
.ed-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.ed-actions { display: inline-flex; gap: 8px; }
.done { font: inherit; font-weight: 700; padding: 8px 14px; border-radius: 999px; border: 1px solid rgba(58,54,48,.25); background: var(--paper); color: var(--ink); }
.done:hover { background: rgba(58,54,48,.06); }
.add-item { display: flex; gap: 6px; margin-top: 6px; }
.add-item input { flex: 1; font: inherit; font-size: .95rem; padding: 6px 10px; border-radius: 8px; border: 1px solid rgba(58,54,48,.15); background: rgba(255,255,255,.6); }
.add-item button { font: inherit; font-size: .85rem; border-radius: 999px; border: 1px solid rgba(58,54,48,.25); background: var(--paper); padding: 4px 12px; }
.check.live { cursor: pointer; } .check.live:hover { background: rgba(0,0,0,.05); border-radius: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 30; max-width: 90vw; overflow-wrap: anywhere;
}

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .rail { display: flex; gap: 6px; overflow-x: auto; border-right: 0; border-bottom: 1px solid rgba(58,54,48,.08); padding: 8px; }
  .rail-item { width: auto; white-space: nowrap; }
  .rail-head, .rail-item .count { display: none; }
  #search { min-width: 0; width: 140px; }
}
