/* =============================================================================
   Mark Up (pages/markup.html) as a scribe's desk: a ruled sheet on wood to
   write on, sample texts, a brass seal to mark it up; the result a leaf of
   vellum with the chosen word's catalogue card in the margin. Words keep
   V4's meanings - one analysis, several (green), none (red) - in scribal
   pigments: ink, verdigris, rubric. Tokens come from catalogue.css.
   ============================================================================= */

:root, :root[data-theme="dark"] { --desk-verdigris: #6fc3a0; }
:root[data-theme="light"]        { --desk-verdigris: #1f7a5c; }

/* ---- The desk ------------------------------------------------------------ */
.desk {
  margin-top: var(--space-4); padding: 1.3rem 1.3rem 1.1rem; border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .07), transparent 8px),
    linear-gradient(90deg, var(--cat-wood-lo), var(--cat-wood) 12px, var(--cat-wood-hi) 48%, var(--cat-wood) calc(100% - 12px), var(--cat-wood-lo));
  box-shadow: 0 14px 30px rgba(0, 0, 0, .35), inset 0 -6px 0 var(--cat-wood-lo);
}
.desk__sheet { position: relative; transform: rotate(-.25deg); }
.desk__text {
  display: block; width: 100%; min-height: 11rem; resize: vertical; box-sizing: border-box;
  padding: .9rem 3.4rem .9rem 3.2rem; border: 0; border-radius: 2px; outline: none;   /* right: the margin line; left: the keyboard */
  color: var(--cat-ink); font-family: var(--font-syriac); font-size: 1.55rem; line-height: 2.4rem;
  background:
    linear-gradient(90deg, transparent calc(100% - 2.6rem), var(--cat-red) calc(100% - 2.6rem), var(--cat-red) calc(100% - 2.6rem + 1.5px), transparent calc(100% - 2.6rem + 1.5px)),
    repeating-linear-gradient(180deg, transparent 0 calc(2.4rem - 1px), var(--cat-rule) calc(2.4rem - 1px) 2.4rem),
    linear-gradient(180deg, var(--cat-paper-hi), var(--cat-paper));
  background-position: 0 0, 0 .9rem, 0 0;
  background-attachment: local, local, local;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 18px rgba(0, 0, 0, .35);
}
.desk__text::placeholder { color: var(--cat-ink-muted); opacity: .7; font-family: 'Courier Prime', ui-monospace, monospace; font-size: 1rem; }
.desk__text:focus-visible { box-shadow: 0 0 0 2px var(--color-border-focus), 0 8px 18px rgba(0, 0, 0, .35); }
.desk__kb { position: absolute; top: .6rem; left: .6rem; border: 0; background: transparent; color: var(--cat-ink-muted); }
.desk__kb:hover { color: var(--cat-ink); }

.desk__tools { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem 1.2rem; margin-top: 1.1rem; }
.desk__samples { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-inline-end: auto; }
.desk__label { color: #f3e6cc; font-size: var(--font-size-sm); text-shadow: 0 1px 1px rgba(0, 0, 0, .4); }
.desk__sample {
  padding: .15rem .7rem; border: 0; border-radius: 2px; cursor: pointer;
  font: .82rem/1.5 'Courier Prime', ui-monospace, monospace; color: var(--cat-ink);
  background: color-mix(in srgb, var(--cat-manila) 30%, var(--cat-paper-hi));
  box-shadow: 0 1px 2px rgba(0, 0, 0, .35);
  transition: transform .12s ease;
}
.desk__sample:nth-child(2n) { transform: rotate(-1deg); }
.desk__sample:nth-child(2n+1) { transform: rotate(.8deg); }
.desk__sample:hover, .desk__sample:focus-visible { transform: translateY(-2px) rotate(0); }
.desk__sample:focus-visible { outline: 2px solid var(--color-border-focus); outline-offset: 2px; }
.desk__switch { display: inline-flex; align-items: center; gap: .45rem; color: #f3e6cc; font-size: var(--font-size-sm); font-weight: 600; text-shadow: 0 1px 1px rgba(0, 0, 0, .4); }
.desk__switch input { accent-color: #d9bb72; width: 1rem; height: 1rem; }

/* The seal: a round brass stamp. */
.desk__seal {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 6.4rem; height: 3.1rem; padding: 0 1.2rem; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--cat-brass); color: var(--cat-brass-ink);
  font: 700 .9rem/1 'Courier Prime', ui-monospace, monospace; letter-spacing: .08em; text-transform: uppercase;
  box-shadow: 0 3px 0 #7a5d24, 0 6px 12px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .5), inset 0 0 0 3px rgba(122, 93, 36, .35);
  transition: transform .08s ease, box-shadow .08s ease;
}
.desk__seal:hover { filter: brightness(1.06); }
.desk__seal:active { transform: translateY(3px); box-shadow: 0 0 0 #7a5d24, 0 2px 4px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .5), inset 0 0 0 3px rgba(122, 93, 36, .35); }
.desk__seal:focus-visible { outline: 2px solid var(--color-border-focus); outline-offset: 3px; }

/* ---- The leaf ------------------------------------------------------------ */
.leaf-reader { margin-top: var(--space-6); grid-template-columns: minmax(0, 3fr) minmax(17rem, 2fr); scroll-margin-top: 1rem; }
.leaf-reader[hidden] { display: none; }
.mleaf {
  min-width: 0; padding: 1rem 1.6rem 1.6rem; border-radius: 3px; color: var(--cat-ink);
  background:
    radial-gradient(ellipse at 50% 0%, transparent 60%, color-mix(in srgb, var(--cat-manila) 18%, transparent) 100%),
    linear-gradient(180deg, var(--cat-paper-hi), var(--cat-paper));
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 12px 26px rgba(0, 0, 0, .4);
}
.mleaf__head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1.2rem;
  padding-bottom: .5rem; margin-bottom: .6rem; border-bottom: 1.5px solid var(--cat-red);
  font-size: var(--font-size-xs); color: var(--cat-ink-muted);
}
.mleaf__count { font-family: 'Courier Prime', ui-monospace, monospace; font-size: .8rem; }
.mleaf__key { display: inline-flex; flex-wrap: wrap; gap: .3rem 1rem; }
.mleaf__key-item { display: inline-flex; align-items: center; gap: .35rem; }
.mleaf__swatch { width: .8rem; height: .8rem; border-radius: 50%; }
.mleaf__swatch--one  { background: var(--cat-ink); }
.mleaf__swatch--many { background: var(--desk-verdigris); }
.mleaf__swatch--none { background: var(--cat-rubric); }
.leaf-reader .mleaf__text { padding: 0; background: none; border: 0; }
.leaf-reader .reader__line { font-size: 1.7rem; line-height: 2.6; color: var(--cat-ink); }

/* The words: ink, verdigris, rubric (V4: plain, green, red). */
.leaf-reader .tok { color: var(--cat-ink); border-radius: 3px; padding: 0 3px; }
.leaf-reader .tok--many { color: var(--desk-verdigris); }
.leaf-reader .tok--none { color: var(--cat-rubric); text-decoration: underline dotted 1px; text-underline-offset: .35em; }
.leaf-reader .tok:hover { background: color-mix(in srgb, var(--cat-ink) 8%, transparent); outline: 0; }
.leaf-reader .tok--on { background: color-mix(in srgb, var(--cat-manila) 45%, transparent); outline: 0; box-shadow: 0 0 0 1px color-mix(in srgb, var(--cat-manila) 80%, transparent); }
.leaf-reader .tok:focus-visible { outline: 2px solid var(--color-border-focus); outline-offset: 1px; }
.leaf-reader .tok-punct { color: var(--cat-rubric); }

/* ---- The margin card ------------------------------------------------------ */
.margin-card {
  position: sticky; top: 1rem; padding: .9rem 1rem 1.6rem; border-radius: 4px; color: var(--cat-ink);
  background:
    repeating-linear-gradient(180deg, transparent 0 calc(1.5rem - 1px), var(--cat-rule) calc(1.5rem - 1px) 1.5rem),
    linear-gradient(180deg, var(--cat-paper-hi), var(--cat-paper));
  box-shadow: 0 1px 1px rgba(0, 0, 0, .2), 0 10px 22px var(--cat-shadow);
  max-height: calc(100vh - 2rem); overflow-y: auto; transform: rotate(.4deg);
}
.margin-card::after {   /* the punched hole */
  content: ''; position: absolute; bottom: .5rem; left: 50%; width: .75rem; height: .75rem; margin-left: -.375rem;
  border-radius: 50%; background: var(--color-bg); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .6);
}
.margin-card__hint { margin: 1.2rem 0; color: var(--cat-ink-muted); font: .9rem/1.5rem 'Courier Prime', ui-monospace, monospace; text-align: center; }
.margin-card__close { display: none; }
.margin-card .text-muted { color: var(--cat-ink-muted) !important; }
.margin-card .word-card { margin: 0 0 .7rem; padding: 0; background: none; border: 0; border-radius: 0; }
.margin-card .word-card + .word-card { padding-top: .6rem; border-top: 1px dashed color-mix(in srgb, var(--cat-ink-muted) 40%, transparent); }
.margin-card .word-card summary {
  padding-bottom: .25rem; margin-bottom: .2rem; border-bottom: 1.5px solid var(--cat-red);
  list-style-position: inside;
}
.margin-card .word-card summary .syriac { font-size: 2rem; line-height: 1.5; color: var(--cat-ink); }
.margin-card .word-card summary .text-muted { font-family: 'Courier Prime', ui-monospace, monospace; }
.margin-card .word-card__dl { font-size: .85rem; line-height: 1.5rem; gap: 0 .9rem; }
.margin-card .word-card__dl dt { color: var(--cat-ink-muted); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; }
.margin-card .word-card__dl dd { font-family: 'Courier Prime', ui-monospace, monospace; }
.margin-card .word-card__dl dd .syriac, .margin-card .word-card__dl dd [lang="syr"] { font-family: var(--font-syriac); font-size: 1.25rem; }
.margin-card a { color: var(--color-link); }

@media (max-width: 760px) {
  .leaf-reader { grid-template-columns: minmax(0, 1fr); }
  .mleaf { padding: .8rem 1rem 1.2rem; }
  /* On a phone the card rises from the bottom when a word is chosen. */
  .margin-card {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 900;
    max-height: 62vh; border-radius: 14px 14px 0 0; transform: translateY(105%);
    transition: transform .25s ease; box-shadow: 0 -10px 30px rgba(0, 0, 0, .5);
  }
  .margin-card.is-open { transform: none; }
  .margin-card::after { display: none; }
  .margin-card__close {
    display: block; position: sticky; top: 0; margin: -.4rem -.4rem 0 auto; float: right;
    width: 2rem; height: 2rem; border: 0; border-radius: 50%; cursor: pointer;
    background: color-mix(in srgb, var(--cat-ink) 10%, transparent); color: var(--cat-ink); font-size: 1.3rem; line-height: 1;
  }
  .desk { padding: 1rem .8rem .9rem; }
  .desk__text { padding-left: 2.8rem; font-size: 1.4rem; }
}
@media (prefers-reduced-motion: reduce) { .margin-card, .desk__sample, .desk__seal { transition: none; } }
