:root {
  --paper: #fffdf9;
  --canvas: #f3eeea;
  --ink: #302c31;
  --muted: #756d74;
  --muted-strong: #5f575e;
  --wine: #70415d;
  --wine-soft: #f2e8ee;
  /* Service chrome is kept light; text, labels and messages keep their contrast. */
  --line: #ede6e9;
  /* Field borders identify where to type, so they keep 3:1 (WCAG 1.4.11);
     button and chip outlines are identified by their text and stay lighter. */
  --field: #9b8e95;
  --field-strong: #83767e;
  --outline: #b1a5ab;
  --ok: #3f6b54;
  --danger: #972f40;
  --focus: 0 0 0 3px #d9c2cf;
  --shadow: 0 6px 22px rgba(58, 35, 45, .05);
  --article-font: Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 17px/1.55 Arial, Helvetica, sans-serif; }
button, input, textarea, select { font: inherit; }
a { color: var(--wine); }
:focus-visible { outline: 3px solid var(--wine); outline-offset: 2px; }

/* Buttons: one filled primary, outline secondary, borderless ghost for utilities. */
button { cursor: pointer; border: 0; border-radius: 10px; padding: 10px 16px; min-height: 44px; background: var(--wine); color: #fff; font-weight: 700; }
button.secondary { background: #fff; color: var(--wine); border: 1px solid var(--outline); }
button.ghost { background: transparent; color: var(--wine); font-weight: 600; padding: 10px 12px; }
@media (hover: hover) { button.ghost:hover, button.secondary:hover { background: var(--wine-soft); } }
button.small { min-height: 36px; padding: 5px 10px; font-size: 15px; }
button:disabled { opacity: .45; cursor: default; }
.button-link { display: inline-flex; align-items: center; min-height: 44px; padding: 10px 16px; border-radius: 10px; background: var(--wine); color: #fff; font-weight: 700; text-decoration: none; }
.button-link.secondary-link { background: #fff; color: var(--wine); border: 1px solid var(--outline); }
.quiet-link { display: inline-flex; align-items: center; min-height: 44px; color: var(--muted-strong); font-size: 15px; }

/* Top bar */
.top { padding: 12px max(20px, calc((100% - 1240px) / 2)); background: var(--paper); border-bottom: 1px solid var(--line); display: flex; gap: 14px; align-items: center; justify-content: space-between; }
.brand { font: 700 22px var(--article-font); margin-right: auto; }
.brand small { display: block; font: 14px Arial, Helvetica, sans-serif; color: var(--muted); margin-top: 1px; }
#account { gap: 4px; }

/* Layout */
.shell { max-width: 1240px; margin: 20px auto; padding: 0 20px; display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 24px; }
.panel, .card { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.panel { padding: 14px 10px; height: max-content; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.panel h2 { font: 700 19px var(--article-font); margin: 2px 8px 10px; }
.section h2 { font: 700 20px var(--article-font); margin: 0 0 10px; }

/* Article list: title first; status and date quiet; counts quieter. */
.draft-list { display: grid; gap: 2px; }
.draft { width: 100%; text-align: left; background: transparent; color: var(--ink); border-radius: 10px; padding: 10px 10px 10px 12px; font-weight: 400; border-left: 3px solid transparent; }
.draft:hover { background: #f7f2f4; }
.draft.active { background: var(--wine-soft); border-left-color: var(--wine); }
.draft strong, .draft span { display: block; }
.draft strong { font-weight: 700; line-height: 1.35; }
.draft-meta { font-size: 14px; color: var(--muted); margin-top: 3px; }
.draft-counts { font-size: 13px; color: var(--muted); }
.draft.active .draft-meta, .draft.active .draft-counts { color: var(--muted-strong); }
.main { min-width: 0; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.editor { display: grid; gap: 16px; }
.section { padding: 20px 22px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-head h2 { margin: 0; }

/* Status bar: stage and publishing live here, quietly, above the article. */
.status-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; padding: 2px 4px; }
.status-main { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-width: 0; }
.status-actions { justify-content: flex-end; }
.status-bar .notice { flex-basis: 100%; margin: 0; }
.badge { display: inline-block; border-radius: 99px; padding: 4px 11px; background: var(--wine-soft); color: var(--wine); font-size: 14px; font-weight: 700; }
.notice { padding: 10px 14px; border-radius: 10px; background: #fff3dc; color: #724e16; font-size: 15px; }

/* The article sheet */
.paper { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 30px 40px 26px; }
.title-field { margin-bottom: 8px; }
.title-input { display: block; width: calc(100% + 20px); margin: 0 -10px; padding: 6px 10px; border: 1px solid transparent; border-radius: 8px; background: transparent; resize: none; overflow: hidden; min-height: 0; font: 700 32px/1.25 var(--article-font); color: var(--ink); }
.title-input:hover { border-color: var(--line); }
.title-input:focus { outline: none; border-color: var(--wine); background: #fff; box-shadow: var(--focus); }

details.meta { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 6px 0 18px; }
details.meta > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-height: 48px; cursor: pointer; font-weight: 700; color: var(--muted-strong); list-style: none; }
details.meta > summary::-webkit-details-marker { display: none; }
details.meta > summary::before { content: "▸"; color: var(--wine); font-size: 14px; }
details.meta[open] > summary::before { content: "▾"; }
details.meta > summary .muted { font-weight: 400; font-size: 15px; }
.meta-body { padding: 4px 0 8px; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 700; }
.hint { font-size: 14px; color: var(--muted); }
.error-text { color: var(--danger); }
input, textarea, select { width: 100%; border: 1px solid var(--field); border-radius: 10px; background: #fff; padding: 10px 12px; color: var(--ink); min-height: 44px; }
@media (hover: hover) { input:hover, textarea:hover, select:hover { border-color: var(--field-strong); } }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--wine); box-shadow: var(--focus); }
textarea { min-height: 76px; resize: none; overflow: hidden; line-height: 1.55; }
::placeholder { color: #8a8189; }
.actions, .inline-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-row { margin-top: 2px; }
.save-state { font-size: 14px; color: var(--muted); }
.save-state.ok { color: var(--ok); }
.save-state.error { color: var(--danger); }
.save-state:empty { display: none; }
.inline-row:not(:has(> :not(.save-state:empty))) { display: none; }
.address { white-space: pre-line; overflow-wrap: anywhere; }

/* Blocks: no cards; a block shows its tools quietly and lights up while in use. */
.blocks { display: grid; gap: 4px; }
.block { position: relative; padding: 6px 12px 10px; margin: 0 -12px; border-radius: 12px; border: 1px solid transparent; }
.block:hover, .block:focus-within { border-color: var(--line); background: #fffefb; }
.block-head { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.block-type { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: .02em; cursor: default; }
.block-tools { margin-left: auto; display: flex; align-items: center; gap: 2px; opacity: .6; transition: opacity .15s; }
.block:hover .block-tools, .block:focus-within .block-tools { opacity: 1; }
.icon-button, details.menu > summary { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 10px; background: transparent; color: var(--wine); border: 0; cursor: pointer; }
.icon-button:hover:not(:disabled), details.menu > summary:hover { background: var(--wine-soft); }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu .icon { stroke-width: 3.2; }
.menu-list { position: absolute; right: 0; top: 46px; z-index: 5; min-width: 200px; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(58, 35, 45, .16); }
.menu-item { display: block; width: 100%; text-align: left; background: transparent; font-weight: 600; }
.menu-item:hover { background: #fbeef0; }
.danger-text { color: var(--danger); }
.block-foot { display: flex; justify-content: flex-end; }
.link-form { display: grid; gap: 8px; margin-top: 10px; }
.link-form:empty { display: none; }

/* Article text is edited in place: it reads like the paragraph it is and turns
   into a visible field only under the cursor. */
.prose { display: block; min-height: 0; margin: 0 -10px; width: calc(100% + 20px); padding: 6px 10px; border: 1px solid transparent; border-radius: 8px; background: transparent; font: 19px/1.7 var(--article-font); cursor: text; transition: border-color .15s, background-color .15s; }
.prose:hover { border-color: var(--line); }
.prose:focus { outline: none; border-color: var(--wine); background: #fff; box-shadow: var(--focus); }
.quote-text { font-style: italic; border-left: 3px solid var(--wine-soft); }
.inline-input { border-color: transparent; background: transparent; font-style: italic; color: var(--muted-strong); padding-left: 10px; }
.inline-input:hover { border-color: var(--line); }

/* Photo and video: the picture dominates, the caption sits right under it. */
.media-photo { display: block; width: 100%; max-height: 560px; object-fit: contain; border-radius: 10px; background: #f6f1f3; }
.media-video { display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 10px; background: #f6f1f3; }
.media-placeholder { padding: 28px 16px; background: #f6f1f3; border-radius: 10px; color: var(--muted-strong); text-align: center; overflow-wrap: anywhere; }
.caption { display: block; width: 100%; min-height: 0; margin-top: 6px; padding: 6px 10px; border: 1px solid transparent; background: transparent; text-align: center; font: italic 16px/1.5 var(--article-font); color: var(--muted-strong); }
.caption:hover { border-color: var(--line); }
.caption:placeholder-shown { font-style: normal; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { min-height: 44px; padding: 8px 14px; border-radius: 99px; background: #fff; color: var(--wine); border: 1px solid var(--outline); font-weight: 600; font-size: 15px; }
.chip:hover { background: var(--wine-soft); }
.chip.on { background: var(--wine-soft); border-color: var(--wine); }
.field-label { font-weight: 700; display: block; }
.palette-chip { display: inline-flex; align-items: center; gap: 10px; }
.swatch { width: 16px; height: 16px; border-radius: 50%; margin-left: 4px; flex: none; }
details.advanced { margin-top: 8px; }
details.advanced > summary { display: inline-flex; align-items: center; min-height: 44px; cursor: pointer; color: var(--muted-strong); font-size: 15px; }
details.advanced .field { margin: 6px 0 4px; }

.links { margin: 8px 0 0; padding: 0; list-style: none; font-size: 15px; color: var(--muted-strong); }
.links li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; overflow-wrap: anywhere; }

.composer { margin-top: 22px; padding-top: 16px; border-top: 1px dashed var(--line); }
.composer-title { font-weight: 700; color: var(--muted-strong); margin-bottom: 4px; }

.preview-frame { width: 100%; height: 700px; border: 1px solid var(--line); border-radius: 12px; background: #fff; margin-top: 10px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 10; max-width: 460px; background: #302c31; color: #fff; border-radius: 12px; padding: 13px 16px; box-shadow: var(--shadow); display: none; white-space: pre-line; overflow-wrap: anywhere; cursor: pointer; }
.toast.show { display: block; }
.muted { color: var(--muted); }
.back { display: none; }

/* Video format: the frame in the editor follows the chosen format. */
.media-video.format-vertical { aspect-ratio: 9 / 16; width: min(100%, 340px); margin: 0 auto; }
.media-video.format-square { aspect-ratio: 1 / 1; width: min(100%, 460px); margin: 0 auto; }
.video-format { margin-top: 10px; }
.video-format-title { font-weight: 700; font-size: 15px; color: var(--muted-strong); }
.video-format .chips { margin-top: 6px; }
.warn-text { color: #7a5412; margin-top: 6px; }
.format-dialog { border: 1px solid var(--line); border-radius: 16px; padding: 22px; max-width: min(92vw, 420px); background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px rgba(40, 25, 32, .25); }
.format-dialog::backdrop { background: rgba(40, 30, 36, .35); }
.format-dialog h2 { font: 700 21px var(--article-font); margin: 0 0 6px; }
.format-options { display: grid; gap: 8px; margin: 14px 0 8px; }
.format-options button { min-height: 52px; font-size: 17px; }

/* Slider: photos in order, each with its own move/remove controls. */
.gallery-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.gallery-item { display: grid; grid-template-columns: 28px 112px 1fr; align-items: center; gap: 10px; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.gallery-number { font: 700 18px var(--article-font); color: var(--muted-strong); text-align: center; }
.gallery-thumb { width: 112px; height: 84px; object-fit: cover; border-radius: 8px; background: #f6f1f3; }
.gallery-thumb.media-placeholder { display: flex; align-items: center; justify-content: center; padding: 0; }
.gallery-tools { display: flex; align-items: center; justify-content: flex-end; gap: 2px; flex-wrap: wrap; }
@media (max-width: 800px) {
  .gallery-item { grid-template-columns: 24px 84px 1fr; gap: 8px; }
  .gallery-thumb { width: 84px; height: 64px; }
}

/* Letters */
.panel-second { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.badge.ready { background: #e7f1e9; color: var(--ok); }
.email-title { font: 700 24px/1.3 var(--article-font); margin: 0 0 6px; }
.email-actions { margin-top: 8px; padding-top: 14px; border-top: 1px dashed var(--line); }
.email-actions .hint { flex-basis: 100%; }
.email-frame { height: 900px; background: #f3eeea; }
.email-photo { display: block; max-width: 100%; max-height: 420px; object-fit: contain; border-radius: 10px; background: #f6f1f3; margin: 0 auto; }
.email-source { font-size: 14px; color: var(--muted); margin-top: 6px; text-align: center; }
.chooser { display: grid; gap: 10px; }
.chooser-articles { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.chooser-articles button { width: 100%; text-align: left; }
.photo-dialog { width: min(96vw, 720px); max-height: 92vh; overflow: auto; }
.photo-dialog details { border-top: 1px solid var(--line); }
.photo-dialog summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; min-height: 48px; cursor: pointer; font-weight: 700; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; padding: 4px 0 12px; }
.photo-pick { position: relative; padding: 0; min-height: 0; border: 3px solid transparent; border-radius: 10px; background: #f6f1f3; overflow: hidden; }
.photo-pick img { display: block; width: 100%; height: 100px; object-fit: cover; }
.photo-pick.on { border-color: var(--wine); }
.photo-pick.on::after { content: "✓"; position: absolute; right: 6px; top: 4px; width: 26px; height: 26px; border-radius: 50%; background: var(--wine); color: #fff; font-size: 16px; line-height: 26px; text-align: center; }
.photo-dialog .actions { position: sticky; bottom: 0; padding-top: 10px; background: var(--paper); }

@media (hover: none) {
  .block-tools { opacity: 1; }
}
@media (max-width: 800px) {
  body { font-size: 16px; }
  .top { padding: 8px 12px; gap: 8px; }
  .brand { font-size: 19px; }
  .brand small { display: none; }
  /* The account line (GetCourse login, user, exit) gets a row of its own. */
  .top { flex-wrap: wrap; row-gap: 0; }
  .top > .actions { gap: 2px; flex-wrap: nowrap; flex: 1 1 0; min-width: 0; justify-content: flex-end; }
  #account { flex-basis: 100%; justify-content: flex-end; gap: 2px; }
  .top button { padding: 8px 12px; }
  #reload-list { display: none; }
  #new-email { padding: 8px 10px; }
  #account .muted { display: none; }
  .shell { grid-template-columns: 1fr; padding: 0 8px; margin: 8px auto; gap: 10px; }
  .panel { position: static; max-height: none; }
  .shell.editing .panel { display: none; }
  .shell:not(.editing) .main { display: none; }
  .back { display: inline-flex; margin-left: -8px; }
  .status-bar { padding: 0 2px; }
  .status-actions { width: 100%; }
  .status-actions > * { flex: 1 1 auto; }
  .paper { padding: 16px 14px; border-radius: 12px; }
  .title-input { font-size: 25px; }
  .prose { font-size: 18px; }
  .block { padding: 2px 8px 8px; margin: 0 -8px; }
  .section { padding: 14px 12px; }
  .preview-frame { height: 620px; }
  .toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}
