:root {
  color-scheme: light;
  --canvas: #eff1e8;
  --paper: #fcfcf7;
  --input: #ffffff;
  --border: #d8ddd0;
  --border-strong: #bcc5b5;
  --ink: #17251e;
  --muted: #536258;
  --rail: #182920;
  --rail-ink: #f1f5e7;
  --rail-muted: #bdccbc;
  --acid: #d2ed84;
  --acid-ink: #1d3316;
  --accent: #36653c;
  --preview: #dfebdc;
  --bubble: #ffffff;
  --danger: #a73333;
  --radius: 16px;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #1c2420;
  --paper: #232d26;
  --input: #18201b;
  --border: #3c4b40;
  --border-strong: #657567;
  --ink: #edf5e9;
  --muted: #b2c2b3;
  --rail: #121a15;
  --rail-muted: #b9cbb9;
  --accent: #bde391;
  --preview: #17231c;
  --bubble: #283a2d;
  --danger: #ffaaa5;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 300px; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .52; }
button, a, input, textarea, select, [contenteditable] { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }

.workspace { min-height: 100dvh; display: grid; grid-template-columns: minmax(182px, 15.8vw) minmax(0, 1fr) clamp(300px, 29vw, 420px); }
.library { padding: max(22px, env(safe-area-inset-top)) 17px 18px max(17px, env(safe-area-inset-left)); background: var(--rail); color: var(--rail-ink); }
.brand { display: flex; align-items: center; gap: 10px; margin: 0 0 25px 2px; font-size: 16px; color: inherit; font-weight: 730; letter-spacing: -.035em; text-decoration: none; }
.brand-symbol, .avatar { display: grid; place-items: center; flex: 0 0 auto; width: 33px; height: 33px; border-radius: 11px; background: var(--acid); color: var(--acid-ink); font: 750 22px/1 system-ui; }
.new-post { width: 100%; color: var(--rail-ink); background: #24392c; border: 1px solid #526857; border-radius: 11px; min-height: 43px; text-align: left; padding: 8px 11px; font-weight: 650; }
.new-post span { color: var(--acid); margin-right: 7px; font-size: 18px; }
.new-post:hover { background: #304938; }
.library-title { color: var(--rail-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .11em; font-weight: 680; margin: 32px 0 12px 4px; }
.post-list { display: grid; gap: 4px; }
.post-list button { border: 1px solid transparent; color: inherit; background: transparent; text-align: left; border-radius: 10px; padding: 9px 8px; min-width: 0; display: grid; gap: 4px; }
.post-list button:hover, .post-list button[aria-current="true"] { background: #2c4333; }
.post-list button[aria-current="true"] { border-color: #536a52; }
.post-list strong { font-size: 13px; line-height: 1.35; font-weight: 640; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-list small, .library p { font-size: 11px; color: var(--rail-muted); }
.library p { padding: 7px 4px; }
.library-toggle { display: none; }

.main { min-width: 0; }
.topbar { position: sticky; z-index: 2; top: 0; display: flex; align-items: center; gap: 14px; justify-content: space-between; padding: max(14px, env(safe-area-inset-top)) clamp(14px, 3vw, 38px) 14px; background: var(--canvas); border-bottom: 1px solid var(--border); min-height: 67px; }
.topbar-home { font-weight: 720; letter-spacing: -.02em; }
.topbar-actions { display: flex; align-items: center; flex: 0 0 auto; gap: 8px; }
.status { text-align: end; margin-left: auto; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; max-width: 46ch; }
.status[data-error="true"] { color: var(--danger); }
.primary, .secondary, .quiet, .add-item { min-height: 38px; border-radius: 10px; padding: 7px 13px; font-weight: 680; border: 1px solid transparent; }
.primary { color: var(--acid-ink); background: var(--acid); border-color: #a2c35e; }
.primary:hover:enabled { background: #def6a4; }
.secondary, .add-item { color: var(--ink); border-color: var(--border-strong); background: var(--paper); }
.secondary:hover:enabled, .add-item:hover:enabled, .quiet:hover:enabled { background: var(--preview); }
.quiet { background: transparent; color: var(--ink); border-color: var(--border); }
.danger { color: var(--danger); }
.preview-toggle, .close-preview { display: none; }

.editor { display: grid; align-content: start; gap: 22px; max-width: 950px; padding: 29px clamp(12px, 3vw, 38px) max(30px, env(safe-area-inset-bottom)); margin-inline: auto; }
.editor-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.editor-heading h1 { margin-bottom: 6px; font-size: clamp(24px, 3.4vw, 42px); letter-spacing: -.058em; line-height: 1.06; }
.editor-heading p, .hint { font-size: 12px; color: var(--muted); line-height: 1.46; }
.editor-heading .editor-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.editor-heading .quiet { min-height: 34px; padding: 5px 9px; font-size: 12px; }
.settings, .message, .auth-message { border: 1px solid var(--border); background: var(--paper); border-radius: var(--radius); padding: 15px; box-shadow: 0 2px 4px #15201306; }
.auth-message { color: var(--muted); line-height: 1.55; max-width: 48ch; }
.settings { display: grid; gap: 12px; }
.messages { display: grid; gap: 15px; }
.panel-head, .list-head, .block-head { display: flex; align-items: center; justify-content: space-between; min-width: 0; gap: 9px; }
.panel-head h2 { font-size: 17px; letter-spacing: -.03em; }
.panel-head .hint { padding-top: 3px; }
.message { display: grid; gap: 12px; }
.message-head { padding: 0 0 8px; border-bottom: 1px solid var(--border); }
.message-label { font-weight: 740; font-size: 15px; overflow-wrap: anywhere; }
.kind { display: block; color: var(--muted); font-size: 11px; font-weight: 610; margin-top: 3px; }
.mini-actions { display: flex; gap: 2px; flex: 0 0 auto; }
.icon { display: grid; place-items: center; background: transparent; border: 1px solid transparent; color: var(--muted); font-size: 16px; font-weight: 690; width: 29px; min-height: 31px; border-radius: 7px; }
.icon:hover:enabled { background: var(--canvas); border-color: var(--border); color: var(--ink); }
.icon.danger:hover:enabled { color: var(--danger); }
.drag-grip { cursor: grab; padding: 3px 4px; color: var(--muted); font-size: 17px; letter-spacing: -.18em; flex: 0 0 auto; user-select: none; touch-action: none; }
.drag-grip:active { cursor: grabbing; }
.block-head-left { min-width: 0; display: flex; align-items: center; gap: 6px; }
.block-head-left strong { font-size: 13px; overflow-wrap: anywhere; }
.message.drag-over, .block.drag-over { outline: 2px solid var(--accent); outline-offset: 2px; }

.block-list, .nested-list, .block-fields { display: grid; gap: 8px; }
.block { display: grid; gap: 7px; min-width: 0; padding: 8px 9px 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--input); }
.block .field input:not([type="checkbox"]), .block .field textarea, .block .field select, .block .text-editor { background: var(--paper); }
.add-item { justify-self: start; width: max-content; max-width: 100%; font-size: 12px; min-height: 34px; padding: 6px 10px; }
.subpanel { border: 1px solid var(--border); border-radius: 10px; padding: 8px; display: grid; gap: 7px; min-width: 0; }
.subpanel .subpanel { padding: 7px; }
.subpanel-title { font-size: 11px; color: var(--muted); font-weight: 730; }
details.advanced { padding: 8px 0 0; border-top: 1px solid var(--border); }
details .field { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 650; width: max-content; max-width: 100%; }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span.label { font-size: 12px; font-weight: 670; }
.field input:not([type="checkbox"]), .field textarea, .field select, .text-editor { width: 100%; min-height: 37px; outline-offset: 1px; color: var(--ink); background: var(--input); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; }
.field textarea { min-height: 104px; resize: vertical; }
.field textarea.code { font: 12px/1.45 ui-monospace, "Cascadia Code", Consolas, monospace; }
.field .title-input { font-size: 17px; font-weight: 670; letter-spacing: -.02em; }
.field-row { display: flex; flex-wrap: wrap; gap: 8px; }
.field-row > .field { flex: 1 1 115px; }
.check { display: flex; gap: 6px; align-items: center; width: fit-content; color: var(--ink); font-size: 12px; min-height: 27px; }
.check input { accent-color: var(--accent); inline-size: 16px; block-size: 16px; margin: 0; }
.file-upload { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.file-upload small { color: var(--muted); overflow-wrap: anywhere; min-width: 0; }
.file-upload small[data-error="true"] { color: var(--danger); }
.field-help { font-size: 11px; line-height: 1.4; color: var(--muted); }
.text-toolbar { display: flex; flex-wrap: wrap; gap: 4px; }
.text-toolbar button { min-width: 29px; min-height: 30px; padding: 3px 6px; font-size: 12px; }
.text-editor { min-height: 52px; white-space: pre-wrap; overflow-wrap: anywhere; }
.text-editor:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.text-token { display: inline-block; background: var(--preview); border-radius: 4px; color: var(--ink); padding: 0 3px; user-select: all; }
.text-editor [data-rich-type="spoiler"], .bubble [data-rich-type="spoiler"] { background: var(--preview); border-radius: 3px; }
.text-editor [data-rich-type="url"], .bubble [data-rich-type="url"] { color: var(--accent); text-decoration: underline; }
.deliver-options { display: grid; gap: 13px; }

.preview-pane { position: sticky; top: 0; height: 100dvh; min-width: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 13px; padding: max(19px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(15px, env(safe-area-inset-bottom)) 16px; border-left: 1px solid var(--border); background: var(--paper); }
.preview-heading { display: flex; align-items: center; justify-content: space-between; }
.preview-heading h2 { font-size: 13px; letter-spacing: -.015em; }
.preview-chat { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 240px; position: relative; overflow: hidden; background: var(--preview); border: 1px solid var(--border); border-radius: 16px; }
.chat-profile { position: relative; z-index: 1; display: flex; gap: 9px; align-items: center; padding: 10px 11px; border-bottom: 1px solid var(--border); background: var(--paper); min-width: 0; }
.chat-profile .avatar { width: 31px; height: 31px; border-radius: 50%; }
.chat-profile div { min-width: 0; display: grid; gap: 2px; }
.chat-profile strong { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-profile span:not(.avatar) { color: var(--muted); font-size: 10px; }
.preview-messages { overflow: auto; padding: 17px 12px; display: grid; align-content: end; align-content: safe end; justify-items: start; gap: 5px; min-width: 0; scrollbar-width: thin; }
.chat-empty { color: var(--muted); font-size: 12px; padding: 10px; text-align: center; justify-self: center; }
.bubble { display: grid; gap: 7px; width: fit-content; min-width: 62px; max-width: min(100%, 310px); border-radius: 11px 11px 11px 3px; padding: 9px; background: var(--bubble); color: var(--ink); overflow-wrap: anywhere; font-size: 13px; white-space: pre-wrap; }
.bubble.has-media { width: 100%; }
.bubble .bubble-time { font-size: 9px; color: var(--muted); justify-self: end; }
.bubble p, .bubble pre, .bubble blockquote { margin: 0; min-width: 0; }
.bubble h3 { line-height: 1.2; font-size: 18px; margin: 0; }
.bubble blockquote { padding: 5px 0 5px 8px; border-left: 2px solid var(--accent); }
.bubble hr { margin: 2px 0; border: 0; border-top: 1px solid var(--border); width: 100%; }
.bubble pre { white-space: pre-wrap; font-size: 11px; background: var(--canvas); border-radius: 6px; padding: 6px; }
.bubble img { width: 100%; height: auto; max-height: 240px; object-fit: contain; border-radius: 6px; background: transparent; }
.bubble.sticker { background: transparent; width: min(65%, 160px); box-shadow: none; padding: 0; }
.bubble.sticker img { object-position: bottom left; }
.bubble .feature-preview { color: var(--muted); font-size: 11px; background: var(--canvas); border-radius: 6px; border: 1px dashed var(--border-strong); padding: 6px 8px; }
.preview-gallery { display: grid; gap: 4px; grid-auto-flow: column; grid-auto-columns: 81%; overflow: auto; scroll-snap-type: x mandatory; }
.preview-gallery img { scroll-snap-align: start; }
.preview-collage { display: grid; gap: 4px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 85px), 1fr)); }
.preview-button-row { display: flex; flex-wrap: wrap; gap: 4px; }
.preview-button-row[data-align="left"] { justify-content: start; }
.preview-button-row[data-align="center"] { justify-content: center; }
.preview-button-row[data-align="right"] { justify-content: end; }
.preview-button-row .preview-button { background: var(--preview); color: var(--accent); padding: 6px 8px; border-radius: 6px; text-align: center; font-size: 11px; font-weight: 650; }
.preview-button-row:not([data-align]) .preview-button { flex: 1; }
.preview-table { border-collapse: collapse; width: 100%; }
.preview-table td, .preview-table th { border: 1px solid var(--border); padding: 4px; }
.emoji-results { display: grid; gap: 5px; }
.emoji-results:empty, .modal-status:empty { display: none; }
.emoji-results h3 { color: var(--muted); font-size: 12px; }
.modal-status { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.modal-status[data-error="true"] { color: var(--danger); }
.delivery { display: grid; gap: 6px; }

.modal { color: var(--ink); background: var(--paper); border: 1px solid var(--border); border-radius: 17px; width: min(560px, calc(100vw - 24px)); max-height: min(88dvh, 680px); padding: 0; box-shadow: 0 12px 50px #16241735; overflow: auto; }
.modal::backdrop { background: #12251980; }
.modal-inner { padding: 16px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 13px; }
.modal-head h2 { font-size: 20px; letter-spacing: -.035em; }
.modal-inner .close-dialog { font-size: 19px; min-height: 28px; width: 33px; padding: 2px; flex: 0 0 auto; }
.palette { display: grid; gap: 14px; }
.palette-category { display: grid; gap: 5px; }
.palette-category h3 { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.palette-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(123px, 1fr)); gap: 5px; }
.palette-options button { text-align: left; }
.modal-controls { display: grid; gap: 10px; }
.modal-controls > .primary { justify-self: end; }
.actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }

@media (max-width: 1090px) {
  .workspace { grid-template-columns: minmax(165px, 18vw) minmax(0, 1fr) minmax(270px, 26vw); }
  .editor { padding-inline: 15px; }
  .topbar { padding-inline: 15px; }
}
@media (max-width: 890px) {
  .workspace { grid-template-columns: minmax(158px, 21vw) minmax(0, 1fr); }
  .preview-toggle, .close-preview { display: inline-block; }
  .preview-pane { display: none; position: fixed; z-index: 4; inset: 0 0 0 auto; width: min(100%, 395px); box-shadow: -12px 0 40px #1624172a; }
  .preview-pane[data-open="true"] { display: grid; }
}
@media (max-width: 590px) {
  .workspace { display: block; }
  .library { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); align-items: center; gap: 6px; }
  .brand { margin: 0; font-size: 13px; gap: 5px; }
  .brand-symbol { width: 25px; height: 25px; border-radius: 7px; font-size: 18px; }
  .new-post, .library-toggle { color: var(--rail-ink); border: 1px solid #526857; border-radius: 8px; background: #24392c; font-size: 11px; font-weight: 650; padding: 4px 6px; min-height: 33px; }
  .new-post span { margin-right: 1px; font-size: 13px; }
  .library-toggle { display: inline-block; }
  .library-title { display: none; }
  .post-list { display: none; grid-column: 1 / -1; max-height: 35dvh; overflow: auto; }
  .post-list[data-open="true"] { display: grid; }
  .topbar { min-height: 49px; padding: 5px 10px; gap: 5px; }
  .topbar-home { display: none; }
  .status { margin: 0 auto 0 0; text-align: start; font-size: 10px; }
  .topbar .primary, .topbar .quiet, .close-preview { font-size: 12px; min-height: 36px; padding: 6px 9px; }
  .editor { padding: 16px 9px max(25px, env(safe-area-inset-bottom)); gap: 16px; }
  .editor-heading { flex-wrap: wrap; gap: 8px; }
  .editor-heading h1 { font-size: 27px; }
  .editor-heading .editor-tools { justify-content: start; }
  .settings, .message, .auth-message { padding: 10px; }
  .block { padding-inline: 6px; }
  .preview-pane { border-left: 0; }
  .field input:not([type="checkbox"]), .field textarea, .field select, .text-editor { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
