/* Happy Accidents: a dark studio set with one lit canvas on an easel. */

/* Fonts are served from here (SIL Open Font License), so nothing loads from elsewhere. */
@font-face {
  font-family: 'Caprasimo';
  src: url(fonts/caprasimo.woff2) format('woff2');
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'Figtree';
  src: url(fonts/figtree.woff2) format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: 'Figtree';
  src: url(fonts/figtree-italic.woff2) format('woff2');
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'Mrs Saint Delafield';
  src: url(fonts/mrs-saint-delafield.woff2) format('woff2');
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --set: #15110e;
  --set-glow: rgba(255, 226, 180, 0.07);
  --panel: #1f1915;
  --line: rgba(241, 233, 220, 0.14);
  --ink: #f1e9dc;
  --ink-soft: #cdbfab;
  --muted: #9a8a76;
  --wood-hi: #b08455;
  --wood: #86603a;
  --wood-lo: #5a3d24;
  --red: #c9321f;
  --red-hi: #dc4632;
  --red-ink: #fff3e8;
  --cad: #f2c21a;
  --label: #f6f3ec;
  --label-ink: #1f1b17;
  --label-muted: #6b6259;
  --wall: #2a231d;
  --display: 'Caprasimo', 'Cooper Black', 'Georgia', serif;
  --body: 'Figtree', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --gutter: 16px;
}

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

html {
  height: 100%;
  background: var(--set);
}

body {
  height: 100%;
  margin: 0;
  background: var(--set);
  color: var(--ink);
  font: 400 15px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.noscript {
  margin: 0;
  padding: 24px 16px;
  text-align: center;
  color: var(--ink);
}

button {
  font: 600 14px/1 var(--body);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}

button:hover {
  background: rgba(241, 233, 220, 0.07);
  border-color: rgba(241, 233, 220, 0.3);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
canvas:focus-visible,
input:focus-visible {
  outline: 2px solid var(--cad);
  outline-offset: 2px;
}

button.primary {
  background: var(--red);
  border-color: var(--red);
  color: var(--red-ink);
}

button.primary:hover {
  background: var(--red-hi);
  border-color: var(--red-hi);
}

button.quiet {
  border-color: transparent;
  color: var(--ink-soft);
}

button.quiet:hover {
  color: var(--ink);
  border-color: var(--line);
}

button.small {
  padding: 8px 10px;
  font-size: 13px;
}

button[aria-pressed='true'] {
  border-color: var(--cad);
  color: var(--cad);
}

button[aria-pressed='true']::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cad);
  animation: breathe 1.6s ease-in-out infinite;
}

@keyframes breathe {
  50% {
    opacity: 0.3;
  }
}

kbd {
  font: 600 11px/1 var(--body);
  padding: 3px 5px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

/* ——— layout ——— */

.app {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100%;
  padding-inline: var(--gutter);
  padding-block: 12px 20px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

.mark {
  margin: 0;
  font: 400 26px/1 var(--display);
  letter-spacing: 0.01em;
  color: var(--ink);
}

.episode {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.top-actions {
  display: flex;
  gap: 4px;
}

@media (max-width: 959px) {
  .top {
    flex-wrap: nowrap;
    align-items: flex-start;
  }

  .brand {
    flex-direction: column;
    gap: 6px;
    min-width: 0;
  }

  .mark {
    font-size: 23px;
  }

  .top-actions button {
    padding: 8px 8px;
  }

  .hint {
    bottom: 22px;
    padding: 6px 10px;
    font-size: 12px;
  }
}

.count:not(:empty) {
  font-size: 12px;
  min-width: 20px;
  padding: 3px 6px;
  border-radius: 10px;
  background: rgba(241, 233, 220, 0.1);
  color: var(--ink);
}

.stage {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: radial-gradient(ellipse 70% 60% at 50% 42%, var(--set-glow), transparent 70%);
  padding-top: 14px;
}

.easel {
  position: relative;
  width: 100%;
  max-width: 100%;
}

.easel canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  touch-action: none;
  cursor: crosshair;
  border-radius: 2px;
  background: #f2efe6;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5),
    4px 4px 0 0 #d8d1c2,
    4px 4px 0 1px rgba(0, 0, 0, 0.45),
    0 34px 70px -28px rgba(0, 0, 0, 0.95);
  position: relative;
  z-index: 1;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.clamp {
  position: absolute;
  left: 50%;
  top: -14px;
  width: 22px;
  height: 26px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, var(--wood-lo), var(--wood-hi) 45%, var(--wood) 70%, var(--wood-lo));
  border-radius: 3px 3px 0 0;
  z-index: 2;
}

.ledge {
  position: relative;
  z-index: 2;
  height: 14px;
  margin: -3px -3% 0;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--wood-hi), var(--wood) 45%, var(--wood-lo));
  box-shadow: 0 10px 22px -8px rgba(0, 0, 0, 0.8);
}

.hint {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  margin: 0;
  padding: 9px 14px;
  width: max-content;
  max-width: calc(100% - 32px);
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  background: rgba(21, 17, 14, 0.78);
  border-radius: 6px;
  pointer-events: none;
  transition: opacity 0.5s;
}

.hint.gone {
  opacity: 0;
}

/* ——— the tray: voice, palette, actions ——— */

.tray {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.voice {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.line {
  margin: 0;
  min-height: 2.7em;
  font: italic 500 19px/1.35 var(--body);
  color: var(--ink);
  text-wrap: pretty;
  transition: opacity 0.25s;
}

.line.swap {
  opacity: 0;
}

.tool {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
  min-height: 1.3em;
}

.palette-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.loaded {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.loaded-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 6px;
}

/* A wooden palette with a thumb hole. */
.palette {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 9px 8px;
  padding: 14px 46px 14px 16px;
  background:
    radial-gradient(ellipse 120% 80% at 30% 20%, rgba(255, 235, 200, 0.18), transparent 60%),
    repeating-linear-gradient(100deg, rgba(0, 0, 0, 0.05) 0 2px, transparent 2px 9px),
    linear-gradient(160deg, #c49a68, #9b7045 60%, #7d5634);
  border-radius: 38px 64px 52px 30px / 40px 44px 60px 36px;
  box-shadow: inset 0 1px 0 rgba(255, 240, 215, 0.35), 0 12px 24px -12px rgba(0, 0, 0, 0.8);
}

.palette::after {
  content: '';
  position: absolute;
  right: 16px;
  top: 50%;
  width: 24px;
  height: 30px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--set);
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.7), 0 1px 0 rgba(255, 240, 215, 0.25);
}

.dab {
  --c: #888;
  width: 32px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 52% 48% 60% 40% / 55% 60% 40% 45%;
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.6) 0 7%, transparent 20%),
    radial-gradient(circle at 60% 75%, rgba(0, 0, 0, 0.18), transparent 60%),
    var(--c);
  box-shadow: inset 0 -3px 4px rgba(0, 0, 0, 0.25), 0 2px 2px rgba(40, 20, 5, 0.35);
}

.dab:nth-child(3n) {
  border-radius: 45% 55% 42% 58% / 60% 44% 56% 40%;
}

.dab:nth-child(3n + 1) {
  border-radius: 60% 40% 55% 45% / 45% 55% 45% 55%;
}

.dab:hover {
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.6) 0 7%, transparent 20%),
    radial-gradient(circle at 60% 75%, rgba(0, 0, 0, 0.18), transparent 60%),
    var(--c);
  transform: translateY(-2px);
}

.dab[aria-checked='true'] {
  box-shadow: 0 0 0 2px #fff6e8, 0 0 0 4px #1b1410, 0 4px 6px rgba(40, 20, 5, 0.4);
  transform: translateY(-2px);
}

.dab.surprise {
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.6) 0 7%, transparent 20%),
    conic-gradient(from 20deg, #f2c21a, #c9321f, #7e1b2e, #15418a, #3f5c23, #c48a33, #f2c21a);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.keys {
  display: none;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  gap: 4px 10px;
  flex-wrap: wrap;
  align-items: center;
}

.keys span {
  white-space: nowrap;
}

.keys kbd {
  margin-right: 4px;
}

.jd-foot {
  margin: 0;
  padding: 4px 0 calc(4px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.jd-foot a {
  color: inherit;
  text-decoration: none;
  border-radius: 2px;
}

.jd-foot a:hover,
.jd-foot a:focus-visible {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.jd-foot a:focus-visible {
  outline: 2px solid var(--cad);
  outline-offset: 2px;
}

/* Wide screens: canvas on the left, the painter's tray on the right, all in one screen. */
@media (min-width: 960px) {
  .app {
    display: grid;
    height: 100%;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: 36px;
    row-gap: 8px;
    padding-inline: 28px;
  }

  .top {
    grid-column: 1 / -1;
  }

  .stage {
    align-items: center;
    padding-block: 18px 12px;
    min-height: 0;
  }

  .easel {
    width: auto;
  }

  .tray {
    justify-content: center;
    gap: 26px;
    padding-bottom: 24px;
  }

  .voice {
    min-height: 8.5em;
    justify-content: flex-end;
  }

  .keys {
    display: flex;
  }
}

/* ——— overlays ——— */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
  background: rgba(10, 8, 6, 0.78);
  backdrop-filter: blur(4px);
  overflow-y: auto;
  animation: fade 0.25s ease-out;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.sheet {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.sheet-title,
.wall-title {
  margin: 0;
  font: 400 24px/1.1 var(--display);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input {
  width: 100%;
  font: 500 16px/1.2 var(--body);
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  background: var(--set);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
}

#artistName {
  font: 400 30px/1 'Mrs Saint Delafield', cursive;
  color: #e36a55;
  padding-block: 8px 4px;
}

.with-button {
  display: flex;
  gap: 8px;
}

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* The finished piece, framed, with a museum label beside it. */
.placard {
  display: flex;
  gap: 28px;
  align-items: center;
  width: min(1120px, 100%);
  margin: auto;
}

.frame {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: clamp(10px, 2.2vw, 22px);
  background: linear-gradient(135deg, #3a2a1d, #20170f 55%, #3a2a1d);
  border-radius: 2px;
  box-shadow:
    inset 0 0 0 2px rgba(255, 220, 170, 0.12),
    inset 0 0 0 clamp(6px, 1.2vw, 12px) #2a1e14,
    0 30px 60px -20px rgba(0, 0, 0, 0.9);
}

.frame img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  max-width: 100%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
}

.placard-side {
  flex: 0 0 290px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.label {
  background: var(--label);
  color: var(--label-ink);
  padding: 20px 20px 18px;
  border-radius: 2px;
  box-shadow: 0 10px 24px -12px rgba(0, 0, 0, 0.8);
  font-size: 13px;
  line-height: 1.45;
}

.label p {
  margin: 0;
}

.label-artist {
  font-weight: 700;
  font-size: 15px;
}

.label-title {
  font-size: 15px;
  margin-bottom: 10px !important;
}

.label-title cite {
  font-style: italic;
  font-weight: 500;
}

.label-medium {
  color: var(--label-muted);
  margin-bottom: 12px !important;
}

.label-note {
  margin-bottom: 8px !important;
  text-wrap: pretty;
}

.label-credit {
  margin-top: 12px !important;
  padding-top: 10px;
  border-top: 1px solid rgba(31, 27, 23, 0.15);
  color: var(--label-muted);
  font-size: 12px;
}

.placard-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.save-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

@media (max-width: 820px) {
  .placard {
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
  }

  .placard-side {
    flex-basis: auto;
  }
}

.wall {
  width: min(1100px, 100%);
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px clamp(16px, 3vw, 32px) 28px;
  border-radius: 10px;
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 226, 180, 0.08), transparent 60%), var(--wall);
  border: 1px solid var(--line);
}

.wall-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.wall-empty,
.wall-note {
  margin: 0;
  color: var(--ink-soft);
}

.wall-note {
  font-size: 12px;
  color: var(--muted);
}

.wall-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 28px 24px;
}

.wall-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wall-open {
  display: block;
  padding: 8px;
  border: 0;
  border-radius: 2px;
  background: linear-gradient(135deg, #3a2a1d, #20170f 55%, #3a2a1d);
  box-shadow: 0 16px 30px -14px rgba(0, 0, 0, 0.9);
}

.wall-open:hover {
  background: linear-gradient(135deg, #4a3624, #2a1e14 55%, #4a3624);
  transform: translateY(-2px);
}

.wall-open img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
}

.wall-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.wall-meta p {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink-soft);
}

.wall-meta cite {
  display: block;
  font-style: italic;
  font-weight: 500;
  color: var(--ink);
}

.wall-meta button {
  flex: none;
  padding: 6px 8px;
  font-size: 12px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
