:root {
  --bg: #ffffff;
  --fg: #191919;
  --muted: #787774;
  --line: #ececeb;
  --soft: #f7f7f5;
  --hover: #f1f1ef;
  --accent: #2383e2;
  --danger: #d44c47;
  --tile-gap: 2px;
  --radius: 8px;

  --s-idea: #9b9a97;
  --s-plan: #cb912f;
  --s-prod: #9065b0;
  --s-final: #d9730d;
  --s-changes: #d44c47;
  --s-sched: #337ea9;
  --s-posted: #448361;

  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191919;
    --fg: #e9e9e7;
    --muted: #9b9b98;
    --line: #2f2f2f;
    --soft: #202020;
    --hover: #2a2a2a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 14px; line-height: 1.45; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { position: relative; min-height: 100vh; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }

/* Toolbar */
.toolbar { display: flex; align-items: center; gap: 2px; padding: 6px 8px 0; }
.tool {
  display: inline-grid; place-items: center; width: 28px; height: 28px;
  border: 0; background: transparent; border-radius: 6px; cursor: pointer; color: var(--muted);
}
.tool:hover { background: var(--hover); color: var(--fg); }
.tool[aria-pressed="true"], .tool[aria-expanded="true"] { background: var(--hover); color: var(--fg); }
.tool svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.status { margin-left: auto; font-size: 12px; color: var(--muted); padding-right: 4px; }
.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.popover {
  position: absolute; top: 38px; left: 8px; z-index: 20; min-width: 200px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 8px;
}
.pop-title { font-size: 12px; color: var(--muted); padding: 2px 6px 6px; }
.check { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.check:hover { background: var(--hover); }
.check .dot { width: 8px; height: 8px; border-radius: 50%; }

.arrange-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  margin: 6px 8px 0; padding: 8px 10px; background: var(--soft); border-radius: var(--radius); font-size: 13px;
}
.arrange-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 6px;
  padding: 6px 12px; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn.primary:hover { opacity: .88; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

/* Profile */
.profile { padding: 8px 16px 14px; border-bottom: 1px solid var(--line); }
.handle { font-weight: 700; font-size: 17px; margin-bottom: 10px; }
.profile-row { display: flex; align-items: center; gap: 16px; }
.avatar {
  flex: 0 0 auto; width: 64px; height: 64px; border-radius: 50%; overflow: hidden;
  background: var(--soft); border: 1px solid var(--line);
  display: grid; place-items: center; font-weight: 700; font-size: 15px; letter-spacing: .04em;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.name { font-size: 13px; margin-bottom: 6px; }
.counts { display: flex; gap: 18px; flex-wrap: wrap; }
.counts div { display: flex; flex-direction: column; line-height: 1.2; }
.counts b { font-size: 15px; font-weight: 600; }
.counts span { font-size: 12.5px; color: var(--fg); }
.bio { margin-top: 10px; white-space: pre-line; font-size: 13px; }
.bio a { text-decoration: none; }
.bio a.mention { color: #00376b; }
.bio a.link { color: #00376b; font-weight: 600; }
@media (prefers-color-scheme: dark) { .bio a.mention, .bio a.link { color: #e0f1ff; } }
.bio a:hover { text-decoration: underline; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--tile-gap); }
.tile {
  position: relative; aspect-ratio: var(--tile-aspect, 3 / 4); overflow: hidden;
  background: var(--soft); cursor: pointer; border: 0; padding: 0; display: block; width: 100%;
}
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.tile:hover::after { content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.08); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tile .badge {
  position: absolute; top: 6px; right: 6px; width: 18px; height: 18px; color: #fff;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.45));
}
.tile .badge svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; }
.tile .stage {
  position: absolute; left: 6px; bottom: 6px; display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 7px 2px 6px; border-radius: 999px; font-size: 11px; font-weight: 500;
  background: rgba(255,255,255,.92); color: #37352f; box-shadow: 0 1px 3px rgba(0,0,0,.18);
  max-width: calc(100% - 12px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .stage b { font-weight: 600; }
.tile { container-type: inline-size; }
@container (max-width: 175px) { .st-name { display: none; } }
.tile .stage i { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.tile.placeholder {
  display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
  padding: 12px 10px; gap: 4px;
}
.tile.placeholder .ph-title { font-size: 12px; font-weight: 600; line-height: 1.25; color: #37352f;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.tile.placeholder .ph-sub { font-size: 11px; color: #787774; }
.tile.placeholder .badge { color: #37352f; filter: none; }

/* Arrange mode */
.arranging .tile { cursor: grab; animation: wiggle .28s ease-in-out infinite alternate; }
.arranging .tile:nth-child(2n) { animation-delay: -.14s; }
.arranging .tile.dragging { opacity: .35; animation: none; }
.arranging .tile.over { outline: 2px solid var(--accent); outline-offset: -2px; }
@keyframes wiggle { from { transform: rotate(-.4deg); } to { transform: rotate(.4deg); } }
@media (prefers-reduced-motion: reduce) { .arranging .tile { animation: none; } }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.empty b { color: var(--fg); display: block; margin-bottom: 4px; }

/* Detail */
.detail {
  position: fixed; inset: 0; z-index: 30; background: var(--bg);
  display: flex; flex-direction: column;
}
.detail-top { display: flex; align-items: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
.detail-handle { font-weight: 600; font-size: 14px; flex: 1; }
.detail-scroll { flex: 1; overflow-y: auto; }
.media { position: relative; background: #000; aspect-ratio: 4 / 5; max-height: 70vh; overflow: hidden; width: 100%; }
.track { display: flex; height: 100%; transition: transform .28s ease; }
.slide { flex: 0 0 100%; height: 100%; display: grid; place-items: center; }
.slide img, .slide video { width: 100%; height: 100%; object-fit: contain; }
.slide.none { background: var(--soft); color: var(--muted); font-size: 13px; text-align: center; padding: 20px; }
.nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.9); display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.25); color: #191919;
}
.nav svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; }
.nav.prev { left: 8px; } .nav.next { right: 8px; }
.dots { position: absolute; bottom: 10px; left: 0; right: 0; display: flex; justify-content: center; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.5); }
.dots i.on { background: #fff; }
.detail-body { padding: 12px 16px 16px; }
.meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.pill i { width: 7px; height: 7px; border-radius: 50%; }
.fmt { font-size: 12px; }
.post-title { font-size: 15px; font-weight: 600; margin: 8px 0 6px; }
.caption { white-space: pre-wrap; font-size: 13.5px; }
.caption .tags { color: #00376b; }
@media (prefers-color-scheme: dark) { .caption .tags { color: #8fb6e8; } }
.caption.missing { color: var(--muted); font-style: italic; }
.brief { margin-top: 10px; padding: 8px 10px; background: var(--soft); border-radius: 6px; font-size: 12.5px; }
.brief b { font-weight: 600; }
.notes { margin-top: 12px; padding: 10px 12px; border-radius: 6px; background: #fdebec; color: #5d1715; }
@media (prefers-color-scheme: dark) { .notes { background: #3a2323; color: #f2c4c2; } }
.notes-label { font-size: 12px; font-weight: 600; margin-bottom: 4px; display: block; }
.notes-text { white-space: pre-wrap; font-size: 13px; }
.changes { margin-top: 12px; }
.changes textarea {
  width: 100%; font: inherit; font-size: 13px; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); resize: vertical;
}
.row-end { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.actions { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.actions:empty { display: none; }
.actions .btn { flex: 1; padding: 9px 12px; }

.toast {
  position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%); z-index: 50;
  background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100% - 32px);
}

@media (max-width: 380px) {
  .profile { padding: 6px 12px 12px; }
  .avatar { width: 54px; height: 54px; }
  .counts { gap: 12px; }
}
