/* ============================================================
   Scriptorium — a scribe's desk: dark walnut chrome, a bright
   page in the middle, rubric red as the single accent.
   ============================================================ */

:root {
  --walnut-900: #211d1a;   /* deepest desk surface   */
  --walnut-800: #2a2521;   /* panels                 */
  --walnut-700: #352f29;   /* raised controls        */
  --walnut-600: #443c34;   /* borders, dividers      */
  --bone:       #e9e2d3;   /* primary text           */
  --bone-dim:   #9a917f;   /* secondary text         */
  --rubric:     #b3282d;   /* red ink accent         */
  --rubric-dim: #8f1d1d;   /* red ink on symbols     */
  --select:     #c99a3f;   /* gilt selection outline */

  --font-ui: system-ui, "Segoe UI", sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--bone);
  background: var(--walnut-900);
}

body { display: flex; flex-direction: column; }

/* ---------------- toolbar ---------------- */

#toolbar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: var(--walnut-800);
  border-bottom: 1px solid var(--walnut-600);
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 4px;
  min-width: 0;
}

.site-back-link {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  padding: 4px 8px;
  border: 1px solid var(--walnut-600);
  border-radius: 999px;
  color: var(--select);
  background: linear-gradient(180deg, rgba(68, 60, 52, 0.7), rgba(33, 29, 26, 0.45));
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.05em;
}
.site-back-link:hover { color: var(--rubric); border-color: var(--rubric-dim); }
.site-back-link:focus-visible { outline: 2px solid var(--select); outline-offset: 1px; }

.wordmark {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.06em;
  font-variant: small-caps;
}
.rubric { color: var(--rubric); }

.tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 14px;
  border-left: 1px solid var(--walnut-600);
}

.group-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--bone-dim);
  margin-right: 4px;
}

button {
  font: inherit;
  color: var(--bone);
  background: var(--walnut-700);
  border: 1px solid var(--walnut-600);
  border-radius: 3px;
  padding: 4px 9px;
  cursor: pointer;
}
button:hover { background: var(--walnut-600); }
button:focus-visible { outline: 2px solid var(--select); outline-offset: 1px; }
button:disabled { opacity: 0.4; cursor: default; }
button.danger:hover { background: var(--rubric-dim); border-color: var(--rubric); }

.ink-btn.active { border-color: var(--select); background: var(--walnut-600); }
.ink-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  vertical-align: -1px;
  margin-right: 3px;
  border: 1px solid var(--walnut-900);
}
.ink-dot-black { background: #111; }
.ink-dot-red   { background: var(--rubric); }

#zoom-label { min-width: 42px; text-align: center; color: var(--bone-dim); }

/* ---------------- three-column layout ---------------- */

#layout {
  flex: 1;
  display: flex;
  min-height: 0; /* allow children to scroll */
}

#palette, #inspector {
  width: 230px;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--walnut-800);
  padding: 10px;
}
#palette   { border-right: 1px solid var(--walnut-600); }
#inspector {
  border-left: 1px solid var(--walnut-600);
  display: flex;
  flex-direction: column;
}

.panel { margin-bottom: 16px; }

.panel-title {
  font-family: var(--font-display);
  font-variant: small-caps;
  letter-spacing: 0.08em;
  font-size: 14px;
  color: var(--rubric);
  border-bottom: 1px solid var(--walnut-600);
  padding-bottom: 4px;
  margin-bottom: 8px;
}

.muted { color: var(--bone-dim); line-height: 1.5; }
.keys  { font-size: 11px; }
.hidden { display: none; }

/* ---------------- palette ---------------- */

.palette-category {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--bone-dim);
  margin: 12px 0 6px;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 2px;
  background: var(--bone);          /* symbols are dark ink — show on light chip */
  border: 1px solid var(--walnut-600);
  border-radius: 3px;
  cursor: pointer;
}
.palette-item img {
  max-width: 100%;
  height: 34px;
  object-fit: contain;
}
.palette-item span {
  font-size: 9px;
  color: #3a332c;
  text-align: center;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.palette-item:hover { border-color: var(--select); }
.palette-item.armed {
  outline: 2px solid var(--rubric);
  outline-offset: -1px;
}

/* ---------------- canvas ---------------- */

#canvas-wrap {
  flex: 1;
  overflow: auto;
  display: flex; /* with margin:auto on the page, centers without clipping when zoomed */
  padding: 32px;
  background:
    radial-gradient(ellipse at 50% 0%, #2c2723 0%, var(--walnut-900) 70%);
}

#page {
  margin: auto;
  background: #fff;
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
}
#page.placing { cursor: crosshair; }

#staff-layer { pointer-events: none; }       /* staves are locked */
#objects-layer image { cursor: grab; }
#objects-layer image:active { cursor: grabbing; }
#selection-layer { pointer-events: none; }

/* ---------------- inspector forms ---------------- */

.props label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
  color: var(--bone-dim);
  font-size: 11px;
}

.props input, .props select {
  font: inherit;
  color: var(--bone);
  background: var(--walnut-900);
  border: 1px solid var(--walnut-600);
  border-radius: 3px;
  padding: 4px 6px;
  width: 100%;
}
.props input:focus-visible, .props select:focus-visible {
  outline: 2px solid var(--select);
  outline-offset: 0;
}
.props input[readonly] { color: var(--bone-dim); }
.props input[type="color"] { padding: 1px 2px; height: 27px; }

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.row2 button { width: 100%; }

.props label.check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.props label.check input { width: auto; }

.book-promo {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--walnut-600);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.book-promo-text {
  margin: 0;
  color: var(--bone-dim);
  line-height: 1.5;
  text-align: center;
}

.book-promo-text strong {
  color: var(--bone);
  font-weight: 600;
}

.book-promo-cover {
  display: block;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--walnut-600);
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(201, 154, 63, 0.28), 0 8px 20px rgba(0, 0, 0, 0.28);
  padding: 6px;
    background: #2b2118;
    border: 1px solid #b58d46;
    box-shadow:
        inset 0 0 0 1px rgba(255,220,150,.15),
        0 6px 20px rgba(0,0,0,.35);
}

.book-promo-cover img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.book-promo-link {
  color: var(--select);
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.book-promo-link:hover { color: var(--rubric); }
.book-promo-link:focus-visible,
.book-promo-cover:focus-visible {
  outline: 2px solid var(--select);
  outline-offset: 2px;
}

/* ---------------- small screens ---------------- */

@media (max-width: 900px) {
  #layout { flex-direction: column; }
  #palette, #inspector {
    width: 100%;
    max-height: 30vh;
    border: none;
    border-bottom: 1px solid var(--walnut-600);
  }
  .palette-grid { grid-template-columns: repeat(6, 1fr); }
  .book-promo { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .palette-item,
  button,
  .site-back-link,
  .book-promo-cover,
  .book-promo-link {
    transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.12s, filter 0.12s;
  }

  .book-promo-cover:hover {
    transform: translateY(-2px);
    filter: brightness(1.05);
  }
}

/* ---------------- about and contextual help ---------------- */

.help-button {
  white-space: nowrap;
  padding: 3px 7px;
  color: var(--bone-dim);
  background: transparent;
}
.help-button:hover { color: var(--bone); }

#help-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: min(820px, calc(100vh - 32px));
  padding: 0;
  color: var(--bone);
  background: var(--walnut-800);
  border: 1px solid var(--walnut-600);
  border-radius: 6px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.7);
}

#help-dialog::backdrop {
  background: rgba(14, 12, 10, 0.76);
  backdrop-filter: blur(2px);
}

.help-dialog-shell {
  display: flex;
  flex-direction: column;
  max-height: min(820px, calc(100vh - 32px));
}

.help-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--walnut-600);
  background: linear-gradient(180deg, var(--walnut-700), var(--walnut-800));
}

.help-dialog-header h2 {
  margin: 1px 0 0;
  font-family: var(--font-display);
  font-variant: small-caps;
  font-size: 28px;
  font-weight: 400;
  letter-spacing: 0.07em;
}

.help-kicker {
  margin: 0;
  color: var(--select);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.help-close {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.help-dialog-body {
  overflow-y: auto;
  padding: 8px 22px 24px;
  scroll-behavior: smooth;
}

.help-section {
  padding: 15px 0 13px;
  border-bottom: 1px solid rgba(68, 60, 52, 0.72);
  scroll-margin-top: 12px;
}

.help-section:last-of-type { border-bottom: 0; }

.help-section h3 {
  margin: 0 0 7px;
  color: var(--rubric);
  font-family: var(--font-display);
  font-variant: small-caps;
  font-size: 18px;
  letter-spacing: 0.05em;
}

.help-section p,
.help-section li {
  color: var(--bone-dim);
  line-height: 1.65;
}

.help-section p { margin: 7px 0; }
.help-section ol { margin: 8px 0 0; padding-left: 22px; }
.help-section strong { color: var(--bone); }

.help-section.context-highlight {
  animation: help-highlight 1.2s ease-out;
}

.help-context-note {
  margin: 18px 0 0;
  padding: 10px 12px;
  color: var(--bone-dim);
  background: var(--walnut-900);
  border-left: 3px solid var(--select);
  line-height: 1.5;
}

@keyframes help-highlight {
  0% { background: rgba(201, 154, 63, 0.22); }
  100% { background: transparent; }
}
