/* The editor. */

/* ---------- editor ---------- */
/* Desktop: title and close, then the photo with its buttons and the fields,
   a toolbar over the text and the preview side by side, Save pinned below.
   Phones (see responsive): Details, Text and Preview tabs, the toolbar is a
   menu behind @#, and the Save bar steps aside while the keyboard is open. */
@media (min-width: 901px) { body[data-view="editor"] main { max-width: 1560px; padding: 0 32px; } }
.editor-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.editor-bar h1 { flex: 1; font-size: 26px; letter-spacing: -.02em; margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-x { color: var(--ink); border: 1px solid var(--line); }
.editor-x svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.save-state { color: var(--muted); font-size: 14px; margin-left: auto; text-align: right; }
.editor-head { display: flex; gap: 14px; height: 150px; margin-bottom: 18px; }
.photo-btns { display: flex; flex-direction: column; justify-content: space-between; }
.photo-btns .btn { justify-content: flex-start; }
.editor-fields {
  flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: space-between;
  padding-left: 18px; border-left: 1px solid var(--line);
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field select, .file-input {
  min-height: 42px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); padding: 0 12px;
}
.file-input { display: flex; align-items: center; gap: 2px; }
.file-input input { flex: 1; min-width: 0; border: 0; background: none; outline: none; padding: 10px 0; font-family: ui-monospace, monospace; font-size: 14px; }
.file-input span { color: var(--muted); font-family: ui-monospace, monospace; font-size: 14px; }
.file-input:focus-within, .field select:focus { border-color: var(--strong); }
.photo-thumb {
  height: 100%; aspect-ratio: 4 / 3; flex: none; border-radius: var(--radius); overflow: hidden; background: var(--soft);
  display: grid; place-items: center; grid-template: minmax(0, 1fr) / minmax(0, 1fr); font-size: 13px; color: var(--muted);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.editor-tabs { display: none; flex: 1; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.editor-tabs button {
  flex: 1; border: 0; background: none; color: var(--muted); padding: 7px 4px; border-radius: 999px; cursor: pointer; font: inherit; font-size: 14px; font-weight: 600;
}
.editor-tabs button[aria-selected="true"] { background: var(--strong); color: var(--on-strong); }
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 4px; margin-bottom: 10px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
}
.toolbar-label { font-size: 13px; color: var(--muted); font-weight: 600; padding: 0 8px 0 6px; }
.toolbar-gap { flex: 1; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--ink);
  border-radius: 6px; padding: 6px 10px; font: inherit; font-size: 14px; cursor: pointer;
}
.tool-btn:hover { background: var(--soft); }
.tool-sym { font-family: ui-monospace, monospace; font-size: 13px; color: var(--muted); min-width: 16px; display: inline-grid; place-items: center; }
.tool-sym svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.editor-panes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.pane-write { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 12px; }
.editor-save {
  position: sticky; bottom: 0; z-index: 7; display: flex; align-items: center; gap: 12px;
  margin-top: 20px; padding: 12px 0; padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--paper); border-top: 1px solid var(--line);
}
.ins-btn {
  display: none; width: 44px; height: 44px; flex: none; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font: 600 15px ui-monospace, monospace; cursor: pointer; place-items: center;
}
.ins-btn[aria-expanded="true"] { background: var(--strong); color: var(--on-strong); border-color: var(--strong); }
#src {
  width: 100%; min-height: 62vh; resize: vertical; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  padding: 14px; font: 14px/1.6 ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; tab-size: 2;
}
#src:focus { outline: none; border-color: var(--strong); }
.issues { display: flex; flex-direction: column; gap: 4px; }
.issue { margin: 0; font-size: 13px; color: var(--muted); padding: 6px 10px; border-radius: 6px; background: var(--soft); }
.issue-error { color: var(--danger); font-weight: 600; }
.pane-preview {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 20px; min-width: 0;
}
.preview-head img { width: 100%; max-height: 240px; object-fit: cover; border-radius: 8px; margin-bottom: 14px; }
.preview-head h2 { font-size: 30px; letter-spacing: -.03em; margin: 0 0 8px; line-height: 1.05; }
.preview-head .lede { font-size: 18px; }
.pane-preview .recipe-body { grid-template-columns: 1fr; gap: 24px; margin-top: 18px; }
.pane-preview .step p { font-size: 17px; }

@media (max-width: 900px) {
  /* Fills the screen, so the Save bar sits at the bottom on short tabs too. */
  .editor { min-height: calc(100dvh - 52px); display: flex; flex-direction: column; }
  .editor-save { margin-top: auto; }
  .editor-panes { margin-bottom: 20px; }
  .editor-bar { margin-bottom: 14px; }
  .editor-bar h1 { display: none; }
  .editor-tabs { display: flex; }
  .editor:not([data-tab="details"]) .editor-head,
  .editor[data-tab="details"] .editor-panes,
  .editor:not([data-tab="text"]) .pane-write,
  .editor:not([data-tab="preview"]) .pane-preview { display: none; }
  .editor-panes { grid-template-columns: 1fr; }
  .pane-write { position: static; }
  #src { min-height: calc(100dvh - 210px); resize: none; }
  .editor-head { flex-direction: column; height: auto; gap: 14px; }
  .editor-head .photo-thumb { width: 100%; height: auto; }
  .photo-btns { flex-direction: row; gap: 8px; }
  .photo-btns .btn { flex: 1; justify-content: center; }
  .editor-fields { padding-left: 0; border-left: 0; gap: 14px; }
  .editor:not([data-tab="details"]) #del { display: none; }
  .editor[data-tab="text"] .ins-btn { display: grid; }
  .editor[data-tab="text"] .save-state { margin-left: 0; margin-right: auto; text-align: left; }
  /* The toolbar becomes the @# menu, above the button. */
  .toolbar {
    display: none; position: fixed; z-index: 30; right: 16px; bottom: calc(var(--kb, 0px) + 76px);
    flex-direction: column; align-items: stretch; flex-wrap: nowrap; width: 220px; padding: 6px; margin: 0;
    border-radius: 14px; box-shadow: var(--shadow);
  }
  .editor.ins-open .toolbar { display: flex; }
  .toolbar-label { display: none; }
  .toolbar-gap { flex: none; border-top: 1px solid var(--line); margin: 4px 0; }
  .tool-btn { padding: 10px; font-size: 15px; gap: 10px; }
  .tool-sym { min-width: 22px; }
  /* Typing: no Save bar, only @# just above the keyboard. */
  .editor.kb-open .editor-save { bottom: var(--kb, 0px); background: none; border-top: 0; padding: 8px 0; pointer-events: none; }
  .editor.kb-open .editor-save > :not(.ins-btn) { visibility: hidden; }
  .editor.kb-open .ins-btn { pointer-events: auto; position: absolute; right: 0; bottom: 8px; box-shadow: var(--shadow); }
  .editor.kb-open .toolbar { bottom: calc(var(--kb, 0px) + 64px); }
}
