:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --text: #1f2330;
  --muted: #6b7185;
  --border: #dde0e8;
  --accent: #4b3fd1;
  --accent-text: #ffffff;
  --hover: #eceef4;
  --warn: #b26a00;
  --warn-bg: #fff4e0;
  --link: #1a6fc2;
  --divider: #d3d7e2;
  --left: 50%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15171e;
  --panel: #1d2029;
  --text: #e4e6ee;
  --muted: #8d93a8;
  --border: #2e3240;
  --accent: #7d72ff;
  --hover: #272b37;
  --warn: #ffb547;
  --warn-bg: #3a2c12;
  --link: #6db3ff;
  --divider: #2e3240;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

button, select, input {
  font: inherit;
  color: inherit;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  white-space: nowrap;
}

.brand span {
  color: var(--accent);
}

.toolbar, .actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.actions {
  margin-left: auto;
  gap: 8px;
}

.tool, .ghost, .tool-select {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.tool-select {
  border-color: var(--border);
  background: var(--panel);
}

.tool:hover, .ghost:hover, .tool.active {
  background: var(--hover);
  border-color: var(--border);
}

.primary {
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}

.primary:hover { filter: brightness(1.1); }

.check {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, var(--left)) 8px minmax(0, 1fr);
  min-height: 0;
}

.workspace.resizing {
  cursor: col-resize;
  user-select: none;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

.pane-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

.hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

kbd {
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
}

.editor-host {
  position: relative;
  flex: 1;
  min-height: 0;
}

.editor-surface {
  position: absolute;
  inset: 0;
}

.plain-editor {
  width: 100%;
  height: 100%;
  padding: 12px;
  border: 0;
  outline: none;
  resize: none;
  background: var(--panel);
  color: var(--text);
  font: 14px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace;
}

.divider {
  position: relative;
  background: var(--divider);
  cursor: col-resize;
  touch-action: none;
}

.divider::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 32px;
  transform: translate(-50%, -50%);
  border-left: 2px dotted var(--muted);
}

.divider:hover, .divider:focus-visible, .resizing .divider {
  background: var(--accent);
  outline: none;
}

.preview-scroll {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background: var(--bg);
}

.post {
  max-width: 760px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  font-family: "Open Sans", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.post:empty::before {
  content: "Your post preview appears here.";
  color: var(--muted);
}

.post > :first-child { margin-top: 0; }
.post > :last-child { margin-bottom: 0; }
.post p { margin: 0 0 .8em; }
.post h1, .post h2, .post h3, .post h4, .post h5, .post h6 { margin: 1em 0 .4em; line-height: 1.25; }
.post h1 { font-size: 1.7em; }
.post h2 { font-size: 1.4em; }
.post h3 { font-size: 1.2em; }
.post h4 { font-size: 1.05em; }
.post h5 { font-size: .95em; }
.post h6 { font-size: .85em; color: var(--muted); }
.post ul, .post ol { margin: 0 0 .8em; padding-left: 1.6em; }
.post li > ul, .post li > ol { margin: .2em 0; }
.post hr { margin: 1em 0; border: 0; border-top: 1px solid var(--border); }
.post a { color: var(--link); }
.post .emoji { font-size: 1.15em; line-height: 1; }

.status {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 4px 12px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}

.warnings {
  position: relative;
}

.warnings[hidden] { display: none; }

.warnings summary {
  color: var(--warn);
  cursor: pointer;
  list-style: none;
}

.warnings summary::-webkit-details-marker { display: none; }

.warnings ol {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 10;
  width: max-content;
  max-width: 70vw;
  max-height: 50vh;
  margin: 0;
  padding: 8px;
  overflow: auto;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
}

.warnings li button {
  width: 100%;
  padding: 4px 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.warnings li button:hover { background: var(--warn-bg); }
.warnings b { color: var(--warn); }

.picker {
  position: fixed;
  z-index: 20;
  width: 320px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

.picker-search {
  width: 100%;
  margin-bottom: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 240px;
  overflow: auto;
}

.picker-grid button {
  height: 34px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
}

.picker-grid button:hover, .picker-grid button:focus-visible { background: var(--hover); }

.picker-name {
  height: 18px;
  margin-top: 6px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

.cheatsheet {
  width: min(640px, 92vw);
  max-height: 85vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
}

.cheatsheet::backdrop { background: rgba(0, 0, 0, .35); }

.sheet { padding: 16px 20px 20px; }

.sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet h2 { margin: 0; font-size: 18px; }
.sheet h3 { margin: 18px 0 6px; font-size: 14px; }
.sheet table { width: 100%; border-collapse: collapse; }
.sheet th, .sheet td { padding: 5px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.sheet th { color: var(--muted); font-weight: 600; font-size: 12px; }
.sheet ul { margin: 0; padding-left: 1.2em; }
.sheet li { margin: 3px 0; }

.sheet code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--hover);
  font-family: ui-monospace, monospace;
  font-size: 12.5px;
}

.toast {
  position: fixed;
  bottom: 48px;
  left: 50%;
  z-index: 30;
  padding: 8px 16px;
  transform: translateX(-50%);
  border-radius: 6px;
  background: var(--text);
  color: var(--panel);
  font-weight: 600;
}

@media (max-width: 760px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .divider { display: none; }
  .actions { margin-left: 0; }
  .hint { display: none; }
}
