/*
 * The wall (/wall): a full-screen canvas with a thin layer of chrome over it. Class prefix `wl-`.
 * The wall itself (stone, thread, drawings) is painted by wall.js; this file styles the chrome:
 * the title plaque, the drawing tools, the comments sheet and the dialogs. All of it uses the
 * site's theme variables (--bg, --ink, --gold…), which theme.js flips for the light/dark toggle.
 * Fonts come from references.css.
 */
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #1A150D;
}

.wl, .wl *, .wl *::before, .wl *::after { box-sizing: border-box; }

.wl {
  --wl-panel: color-mix(in srgb, var(--bg, #EDE3C7) 96%, transparent);
  --wl-rule: color-mix(in srgb, var(--gold, #C8922E) 42%, transparent);
  --wl-shadow: 0 18px 38px -20px rgba(20, 15, 8, 0.7);
  --wl-safe-b: env(safe-area-inset-bottom, 0px);
  --wl-nav: 73px;
  position: fixed;
  inset: 0;
  overflow: hidden;
  color: var(--ink, #2A2418);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 17.5px;
  line-height: 1.45;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.wl [hidden] { display: none !important; }

.wl-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
  cursor: grab;
}
.wl[data-grabbing] .wl-canvas { cursor: grabbing; }
.wl[data-mode="pick"] .wl-canvas { cursor: pointer; }
.wl[data-mode="draw"] .wl-canvas { cursor: crosshair; }
.wl[data-mode="draw"][data-ring] .wl-canvas { cursor: none; }

/* Fine grain over the stone, as on the rest of the site. Plain blending and no blur anywhere in
   this file: the canvas underneath repaints on every frame of a drag, and blend modes and
   backdrop filters over it are paid for each time. */
.wl-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.16 0 0 0 0 0.14 0 0 0 0 0.09 0 0 0 0.24 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
}

.wl :focus-visible { outline: 2px solid var(--gold, #C8922E); outline-offset: 2px; }
.wl-icon svg, .wl-brush svg, .wl-swatch svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- top */
.wl-top { position: absolute; top: 0; left: 0; right: 0; z-index: 5; -webkit-user-select: none; user-select: none; }
.wl-top > nav { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; background: var(--bg, #EDE3C7) !important; }

/* The page title, set small beside the wall's own carved inscription. */
.wl-plaque {
  position: absolute;
  top: calc(var(--wl-nav) + 14px);
  left: max(18px, env(safe-area-inset-left, 0px));
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 14px 7px;
  border: 1px solid var(--wl-rule);
  border-radius: 2px;
  background: var(--wl-panel);
  box-shadow: var(--wl-shadow);
  white-space: nowrap;
}
.wl-plaque h1 {
  margin: 0;
  font-family: Cinzel, serif;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.wl-count { font-style: italic; font-size: 16px; color: var(--ink2, #5C5238); font-variant-numeric: tabular-nums; }
.wl-count:empty { display: none; }
.wl-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--gold, #C8922E);
  font-family: Cinzel, serif;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}
.wl-link:hover { color: var(--ink, #2A2418); }

/* Shown instead of the header while drawing. */
.wl-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: calc(58px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px));
  background: var(--wl-panel);
  border-bottom: 1px solid var(--line, rgba(42, 36, 24, 0.18));
}
.wl-bar-tools { display: flex; align-items: center; gap: 2px; }

.wl[data-mode="draw"] .wl-top,
.wl[data-mode="draw"] .wl-plaque,
.wl[data-mode="draw"] .wl-foot,
.wl[data-mode="draw"] .wl-zoom { display: none; }

/* ------------------------------------------------------------ buttons */
.wl-btn {
  min-height: 42px;
  padding: 11px 20px 10px;
  border: 1px solid transparent;
  border-radius: 2px;
  font-family: Cinzel, serif;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.22s, border-color 0.22s, color 0.22s, filter 0.22s;
}
.wl-btn-gold { background: var(--gold, #C8922E); color: #1C1407; }
.wl-btn-gold:hover { filter: brightness(1.1); }
.wl-btn-quiet {
  background: color-mix(in srgb, var(--bg, #EDE3C7) 70%, transparent);
  color: var(--ink, #2A2418);
  border-color: color-mix(in srgb, var(--gold, #C8922E) 55%, transparent);
}
.wl-btn-quiet:hover { border-color: var(--gold, #C8922E); color: var(--gold, #C8922E); }
.wl-btn-large { min-height: 52px; padding: 16px 30px 15px; font-size: 12.5px; box-shadow: 0 14px 30px -12px rgba(20, 15, 8, 0.8); }
.wl-btn:disabled { opacity: 0.45; cursor: default; filter: none; }

.wl-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: none;
  color: var(--ink, #2A2418);
  cursor: pointer;
  touch-action: manipulation;
}
.wl-icon:hover:not(:disabled) { color: var(--gold, #C8922E); background: color-mix(in srgb, var(--gold, #C8922E) 10%, transparent); }
.wl-icon:disabled { opacity: 0.3; cursor: default; }
.wl-icon[data-armed] { color: #B3361F; }

/* --------------------------------------------------------------- foot */
.wl-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(22px + var(--wl-safe-b));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  pointer-events: none;
}
.wl-foot > * { pointer-events: auto; }

/* Hints and toasts are ink on any theme, so they read on the stone. */
.wl-hint, .wl-toast {
  margin: 0;
  padding: 8px 16px 7px;
  border-radius: 2px;
  background: rgba(33, 27, 18, 0.9);
  color: #ECE0C2;
  font-size: 16.5px;
  text-align: center;
  text-wrap: balance;
}
.wl-hint { max-width: 34em; }
.wl-hint:empty { display: none; }
.wl-toast {
  position: absolute;
  top: calc(var(--wl-nav) + 16px);
  left: 50%;
  z-index: 8;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(30em, calc(100vw - 28px));
  border: 1px solid rgba(200, 146, 46, 0.6);
  pointer-events: none;
}
.wl[data-mode="draw"] .wl-toast { top: calc(72px + env(safe-area-inset-top, 0px)); }

.wl-zoom {
  position: absolute;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(22px + var(--wl-safe-b));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--wl-rule);
  border-radius: 2px;
  background: var(--wl-panel);
}
.wl-zoom .wl-icon + .wl-icon { border-top: 1px solid var(--line, rgba(42, 36, 24, 0.18)); }
@media (pointer: coarse) { .wl-zoom { display: none; } }

/* --------------------------------------------------------------- chip */
.wl-chip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 4;
  width: max-content;
  max-width: min(300px, calc(100vw - 24px));
  padding: 11px 13px 13px;
  border: 1px solid var(--wl-rule);
  border-radius: 2px;
  background: var(--bg2, #F4ECD6);
  box-shadow: var(--wl-shadow);
  will-change: transform;
}
.wl-chip-text { margin: 0 0 10px; }
.wl-chip-text b { display: block; font-family: Cinzel, serif; font-size: 13px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; }
.wl-chip-text small { display: block; margin-top: 2px; font-size: 15.5px; font-style: italic; color: var(--ink2, #5C5238); }
.wl-chip-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.wl-chip-actions:empty { display: none; }
.wl-chip .wl-btn { min-height: 36px; padding: 9px 13px 8px; font-size: 10.5px; }

/* --------------------------------------------------------------- dock */
.wl-dock {
  --wl-dock-side: bottom;
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 5;
  transform: translateX(-50%);
  display: grid;
  gap: 9px;
  width: min(100%, 780px);
  padding: 10px 12px calc(10px + var(--wl-safe-b));
  background: color-mix(in srgb, var(--bg, #EDE3C7) 96%, transparent);
  border-top: 1px solid var(--wl-rule);
}

.wl-brushes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.wl-brush {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 50px;
  padding: 5px 2px 4px;
  border: 1px solid transparent;
  border-radius: 2px;
  background: none;
  color: var(--ink2, #5C5238);
  font: inherit;
  font-size: 15px;
  line-height: 1.1;
  cursor: pointer;
  touch-action: manipulation;
}
.wl-brush:hover { color: var(--ink, #2A2418); }
.wl-brush[aria-checked="true"] {
  border-color: color-mix(in srgb, var(--gold, #C8922E) 75%, transparent);
  background: color-mix(in srgb, var(--gold, #C8922E) 14%, transparent);
  color: var(--ink, #2A2418);
}
.wl-brush[aria-checked="true"] svg { color: var(--gold, #C8922E); }

.wl-sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; }
.wl-slider { display: flex; align-items: center; gap: 9px; min-width: 0; }
.wl-slider-name { flex: 0 0 auto; font-size: 15.5px; color: var(--ink2, #5C5238); }
.wl-slider-value { flex: 0 0 2.6ch; font-size: 15.5px; text-align: right; font-variant-numeric: tabular-nums; }
.wl-slider input[type="range"] {
  flex: 1 1 0;
  min-width: 0;
  height: 30px;
  margin: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  touch-action: pan-y;
  cursor: pointer;
}
.wl-slider input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: color-mix(in srgb, var(--ink, #2A2418) 32%, transparent); }
.wl-slider input[type="range"]::-moz-range-track { height: 2px; background: color-mix(in srgb, var(--ink, #2A2418) 32%, transparent); }
.wl-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -9px;
  border: 2px solid var(--bg, #EDE3C7);
  border-radius: 50%;
  background: var(--gold, #C8922E);
  box-shadow: 0 0 0 1px var(--gold, #C8922E);
}
.wl-slider input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid var(--bg, #EDE3C7);
  border-radius: 50%;
  background: var(--gold, #C8922E);
  box-shadow: 0 0 0 1px var(--gold, #C8922E);
}

.wl-colours {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 3px;
  overflow-x: auto;
  scrollbar-width: none;
  touch-action: pan-x;
}
.wl-colours::-webkit-scrollbar { display: none; }
.wl-swatch {
  position: relative;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--ink, #2A2418) 35%, transparent);
  border-radius: 50%;
  background: var(--wl-swatch, transparent);
  cursor: pointer;
  touch-action: manipulation;
}
.wl-swatch[aria-checked="true"],
.wl-swatch-own[data-active] { border: 2px solid var(--bg, #EDE3C7); box-shadow: 0 0 0 2px var(--gold, #C8922E); }
.wl-swatch-own {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-style: dashed;
  color: var(--ink, #2A2418);
}
.wl-swatch-own[data-picked] { border-style: solid; }
.wl-swatch-own[data-picked] svg { display: none; }
.wl-swatch-own input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.wl-swatch-own svg { width: 18px; height: 18px; }
/* The eraser has no colour. */
.wl-dock[data-erasing] .wl-colours { opacity: 0.4; }

@media (min-width: 860px) and (min-height: 561px) {
  .wl-dock {
    bottom: 16px;
    padding: 12px 16px;
    border: 1px solid var(--wl-rule);
    border-radius: 2px;
    box-shadow: var(--wl-shadow);
  }
  .wl-brush { flex-direction: row; gap: 8px; min-height: 42px; font-size: 16.5px; }
}

/* A phone on its side: the tools stand beside the spot instead of under it. */
@media (orientation: landscape) and (max-height: 560px) {
  .wl-dock {
    --wl-dock-side: right;
    top: calc(58px + env(safe-area-inset-top, 0px));
    left: auto;
    right: 0;
    bottom: 0;
    transform: none;
    align-content: start;
    width: calc(236px + env(safe-area-inset-right, 0px));
    padding: 8px calc(10px + env(safe-area-inset-right, 0px)) calc(8px + var(--wl-safe-b)) 10px;
    border-top: 0;
    border-left: 1px solid var(--wl-rule);
    overflow-y: auto;
    scrollbar-width: none;
  }
  .wl-brushes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .wl-brush { min-height: 44px; }
  .wl-sliders { grid-template-columns: 1fr; }
  .wl-colours { flex-wrap: wrap; overflow: visible; }
  .wl-swatch { width: 30px; height: 30px; }
}

/* ---------------------------------------------------------- brush ring */
.wl-ring {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  border: 1px solid rgba(33, 27, 18, 0.85);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 252, 240, 0.75);
  pointer-events: none;
  will-change: transform;
}

/* ------------------------------------------------------------ comments */
/* A side sheet (a bottom sheet on a phone). Each comment is a knot on a gold thread. */
.wl-notes {
  position: absolute;
  top: var(--wl-nav);
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  width: min(390px, 100vw);
  background:
    radial-gradient(120% 60% at 100% 0%, color-mix(in srgb, var(--gold, #C8922E) 10%, transparent), transparent 60%),
    var(--bg2, #F4ECD6);
  box-shadow: -40px 0 70px -40px rgba(20, 15, 8, 0.55), -1px 0 0 color-mix(in srgb, var(--gold, #C8922E) 35%, transparent);
  -webkit-user-select: text;
  user-select: text;
  animation: wl-notes-in 0.42s cubic-bezier(0.2, 0.75, 0.3, 1);
}
@keyframes wl-notes-in { from { transform: translateX(40px); opacity: 0; } }
.wl-notes-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 10px 12px 18px;
  border-bottom: 1px solid var(--line, rgba(42, 36, 24, 0.18));
}
.wl-notes-thumb {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border: 1px solid var(--wl-rule);
  background: #E8DDBE;
}
.wl-notes-title { flex: 1 1 0; min-width: 0; }
.wl-notes-title h2 {
  margin: 0;
  overflow: hidden;
  font-family: Cinzel, serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}
.wl-notes-title p { margin: 2px 0 0; font-size: 15.5px; font-style: italic; color: var(--ink2, #5C5238); }

.wl-notes-list {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 18px 18px 18px 42px;
  overflow-y: auto;
  list-style: none;
  overscroll-behavior: contain;
}
.wl-notes-list:empty { display: none; }
/* The thread the comments are tied on. */
.wl-notes-list::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 23px;
  width: 1.5px;
  background: linear-gradient(var(--gold, #C8922E), color-mix(in srgb, var(--gold, #C8922E) 35%, transparent));
}
.wl-notes-list li { position: relative; margin: 0 0 16px; overflow-wrap: anywhere; }
.wl-notes-list li::before {
  content: "";
  position: absolute;
  top: 0.5em;
  left: -23.5px;
  width: 8px;
  height: 8px;
  border: 1.5px solid var(--gold, #C8922E);
  border-radius: 50%;
  background: var(--bg2, #F4ECD6);
}
.wl-notes-list li[data-mine]::before { background: var(--gold, #C8922E); }
.wl-notes-list li p { margin: 0; }
.wl-notes-list li small { display: block; margin-top: 1px; font-size: 14.5px; font-style: italic; color: var(--ink3, #8A7E60); }
.wl-notes-empty { flex: 1 1 auto; margin: 0; padding: 22px 18px; font-style: italic; color: var(--ink2, #5C5238); }

.wl-notes-form { padding: 12px 18px calc(14px + var(--wl-safe-b)); border-top: 1px solid var(--line, rgba(42, 36, 24, 0.18)); }
.wl-notes-form .wl-field { margin-bottom: 8px; }
.wl-notes-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wl-notes-left { font-size: 15px; color: var(--ink3, #8A7E60); font-variant-numeric: tabular-nums; }

.wl[data-notes] .wl-zoom { display: none; }

@media (max-width: 720px) {
  .wl-notes {
    top: auto;
    left: 0;
    width: 100%;
    max-height: 62dvh;
    border-top: 1px solid var(--wl-rule);
    box-shadow: 0 -30px 50px -30px rgba(20, 15, 8, 0.6);
    animation-name: wl-notes-up;
  }
  @keyframes wl-notes-up { from { transform: translateY(40px); opacity: 0; } }
  .wl[data-notes] .wl-foot, .wl[data-notes] .wl-plaque { display: none; }
}

/* -------------------------------------------------------------- sheets */
.wl-sheet {
  width: min(440px, calc(100vw - 28px));
  max-height: calc(100dvh - 40px);
  padding: 24px 24px 22px;
  border: 1px solid var(--wl-rule);
  border-radius: 2px;
  background: var(--bg2, #F4ECD6);
  color: var(--ink, #2A2418);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 18px;
  line-height: 1.5;
  box-shadow: 0 30px 60px -30px rgba(20, 15, 8, 0.8);
  -webkit-user-select: text;
  user-select: text;
}
.wl-sheet::backdrop { background: rgba(23, 18, 10, 0.5); }
.wl-sheet h2 { margin: 0 0 12px; font-family: Cinzel, serif; font-weight: 600; font-size: 16px; letter-spacing: 0.16em; text-transform: uppercase; }
.wl-sheet p { margin: 0 0 14px; }
.wl-sheet ul { margin: 0 0 18px; padding-left: 1.1em; }
.wl-sheet li { margin-bottom: 7px; }
.wl-sheet li::marker { color: var(--gold, #C8922E); }
.wl-field { display: block; margin-bottom: 16px; }
.wl-field span { display: block; margin-bottom: 6px; font-size: 15.5px; color: var(--ink2, #5C5238); }
.wl-field input, .wl-field textarea {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--ink, #2A2418) 30%, transparent);
  border-radius: 2px;
  background: color-mix(in srgb, var(--bg, #EDE3C7) 55%, transparent);
  color: var(--ink, #2A2418);
  font: inherit;
  font-size: 18px;
  resize: none;
}
.wl-field input:focus, .wl-field textarea:focus { border-color: var(--gold, #C8922E); outline: none; }
.wl-field input::placeholder, .wl-field textarea::placeholder { color: var(--ink3, #8A7E60); }
.wl-sheet-error { margin: 0 0 10px; color: #B3361F; font-size: 16px; }
html[data-theme="dark"] .wl-sheet-error, html[data-theme="dark"] .wl-icon[data-armed] { color: #F0A08A; }
.wl-sheet-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }

.wl-noscript { position: absolute; inset: 40% 20px auto; text-align: center; color: #ECE0C2; }

@media (max-width: 560px) {
  .wl-plaque { left: 12px; gap: 10px; padding: 7px 11px 6px; }
  .wl-plaque h1 { font-size: 12.5px; letter-spacing: 0.18em; }
  .wl-sliders { gap: 6px 12px; }
  .wl-bar { gap: 4px; padding-left: 10px; padding-right: 10px; }
  .wl-bar .wl-btn { padding: 11px 13px 10px; }
  .wl-bar .wl-icon { width: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .wl-btn { transition: none; }
  .wl-notes { animation: none; }
}
