:root {
  --bg: #f3f1ed;
  --surface: #ffffff;
  --line: rgba(31, 29, 26, 0.12);
  --ink: #1f1d1a;
  --muted: #6f6a62;
  --accent: #a8762a;
  --accent-soft: rgba(168, 118, 42, 0.12);
  --on-accent: #ffffff;
  --done: #2f7d4f;
  --declined: #8a847b;
  --danger: #b3412f;
  --shadow: 0 10px 30px rgba(31, 29, 26, 0.14);
  --radius: 10px;
  --chrome: 300px;
  color-scheme: light dark;
}
/* Dark: chosen with the page's toggle, or following the system until the client chooses. */
:root[data-theme="dark"] {
  --bg: #161514;
  --surface: #222120;
  --line: rgba(255, 255, 255, 0.12);
  --ink: #f1eee9;
  --muted: #a39d94;
  --accent: #cf9b4c;
  --accent-soft: rgba(207, 155, 76, 0.16);
  --on-accent: #1a1714;
  --done: #5cb27d;
  --declined: #8d877e;
  --danger: #e0715f;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514;
    --surface: #222120;
    --line: rgba(255, 255, 255, 0.12);
    --ink: #f1eee9;
    --muted: #a39d94;
    --accent: #cf9b4c;
    --accent-soft: rgba(207, 155, 76, 0.16);
    --on-accent: #1a1714;
    --done: #5cb27d;
    --declined: #8d877e;
    --danger: #e0715f;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; font-size: 14px; }

.app { display: grid; grid-template-rows: auto auto 1fr auto; height: 100dvh; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.titles { min-width: 0; flex: 1; }
.brand-logo { display: block; height: 34px; width: auto; max-width: 160px; object-fit: contain; flex: none; }
/* Most logos are drawn for light paper: in dark mode they sit on a light chip so a dark logo stays visible. */
:root[data-theme="dark"] .brand-logo { background: #f3f1ed; padding: 4px 8px; border-radius: 6px; box-sizing: content-box; height: 28px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-logo { background: #f3f1ed; padding: 4px 8px; border-radius: 6px; box-sizing: content-box; height: 28px; } }
.theme-toggle { padding: 8px; }
.theme-toggle.floating { position: fixed; top: 14px; right: 14px; z-index: 5; }
.titles h1 { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titles p { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 8px; flex-shrink: 0; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 500;
}
.button:hover { border-color: var(--accent); }
.button:focus-visible, .thumb:focus-visible, .pin:focus-visible, .nav:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.button.primary:hover { filter: brightness(1.06); }
.button.ghost { background: transparent; border-color: transparent; padding: 0 10px; }
.button.ghost:hover { background: var(--accent-soft); }
.button.danger { color: var(--danger); }

/* Notices */
.banner { display: flex; align-items: center; gap: 8px; padding: 10px 20px; font-size: 14px; background: var(--accent-soft); }
.banner.info { background: transparent; color: var(--muted); }
.banner.approved { color: var(--done); background: rgba(47, 125, 79, 0.1); font-weight: 500; }
.notice { max-width: 380px; margin: 18vh auto 0; padding: 0 20px; display: grid; gap: 14px; text-align: center; }
.notice h1 { font-size: 22px; font-weight: 600; }
.pin-input { text-align: center; font-size: 22px; letter-spacing: 0.4em; padding: 10px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }

/* Stage */
.body { display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
.stage { display: flex; align-items: center; gap: 8px; padding: 16px 12px; min-width: 0; min-height: 0; }
.stage figure { flex: 1; margin: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 0; }
.frame {
  --ratio: 2;
  position: relative;
  width: min(100%, calc((100dvh - var(--chrome)) * var(--ratio)));
  aspect-ratio: var(--ratio);
  background: var(--surface);
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
}
.frame img { display: block; width: 100%; height: 100%; }
.frame.commentable { cursor: crosshair; }
figcaption { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.tag.changed { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav { flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: grid; place-items: center; }
.nav:disabled { opacity: 0.3; cursor: default; }

/* Pins */
.pin {
  position: absolute; transform: translate(-50%, -50%);
  width: 28px; height: 28px; border-radius: 50%; padding: 0;
  display: grid; place-items: center;
  border: 2px solid #fff; background: var(--accent); color: var(--on-accent);
  font-size: 13px; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.pin svg { width: 14px; height: 14px; }
.pin.active { transform: translate(-50%, -50%) scale(1.2); }
.pin.past { width: 22px; height: 22px; background: #fff; color: var(--muted); cursor: default; opacity: 0.9; }
.pin.past.done { color: var(--done); }
.pin.past.open { color: var(--accent); }
.pin.new { background: var(--accent); pointer-events: none; animation: pop 0.15s ease-out; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(0.4); } }
.composer-anchor { position: absolute; width: 0; height: 0; z-index: 2; }
.composer-anchor .pin { left: 0; top: 0; }
.composer {
  position: absolute; left: 20px; top: 20px; width: 280px; max-width: 70vw;
  padding: 12px; display: grid; gap: 8px; cursor: default;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line);
}
.composer.left { left: auto; right: 20px; }
.composer.up { top: auto; bottom: 20px; }
textarea, input[type="text"] { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); resize: vertical; }
textarea:focus, input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.row { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.spacer { flex: 1; }

/* Panel */
.panel { border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; background: var(--bg); }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { font-size: 16px; font-weight: 600; }
.panel h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.panel .close, .panel-toggle { display: none; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.general h3 { margin-bottom: 8px; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.empty { font-size: 14px; }
.comments { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.comment { display: flex; gap: 10px; padding: 10px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); cursor: pointer; }
.comment.past { cursor: default; background: transparent; }
.comment.editing { display: grid; cursor: default; }
.comment p { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.badge { flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--accent); color: var(--on-accent); }
.comment.past .badge { width: auto; padding: 0 6px; border-radius: 6px; background: var(--line); color: var(--muted); }
.status { font-size: 12px; font-weight: 600; margin-top: 4px; }
.status.done { color: var(--done); }
.status.declined { color: var(--declined); }
.status.open { color: var(--accent); }
.general-new { display: grid; gap: 8px; margin-top: 8px; justify-items: end; }

/* Strip */
.strip { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px 14px; border-top: 1px solid var(--line); scrollbar-width: thin; }
.thumb { position: relative; flex-shrink: 0; height: 60px; padding: 0; border: 2px solid transparent; border-radius: 4px; background: none; cursor: pointer; opacity: 0.72; }
.thumb.current { border-color: var(--accent); opacity: 1; }
.thumb:hover { opacity: 1; }
.thumb img { height: 100%; display: block; border-radius: 2px; }
.thumb .count { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.thumb .dot { position: absolute; bottom: 4px; left: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); border: 1.5px solid #fff; }

/* Dialog and toast */
dialog.submit { width: min(440px, calc(100vw - 32px)); border: 0; border-radius: 14px; padding: 22px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
dialog.submit[open] { display: grid; gap: 12px; }
dialog.submit::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog.submit h2 { font-size: 18px; font-weight: 600; }
dialog.submit .close { position: absolute; top: 12px; right: 10px; }
dialog { position: fixed; }
.row.stack { justify-content: stretch; }
.row.stack .button { flex: 1; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--bg); font-size: 14px; box-shadow: var(--shadow); z-index: 10; }

/* Narrow screens: comments in a sheet over the stage */
@media (max-width: 900px) {
  :root { --chrome: 270px; }
  .body { grid-template-columns: 1fr; position: relative; }
  .panel { display: none; }
  .panel.open { display: flex; position: fixed; left: 0; right: 0; bottom: 0; max-height: 70dvh; z-index: 5; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; box-shadow: var(--shadow); background: var(--surface); }
  .panel .close, .panel-toggle { display: inline-flex; }
  .top { padding: 10px 14px; gap: 10px; }
  .actions { gap: 4px; }
  .theme-toggle { padding: 6px; }
  .theme-toggle.floating { top: 10px; right: 10px; }
}
@media (max-width: 600px) {
  .wide-only { display: none; }
  /* Spreads are wide: on a phone they take the full width and change by swiping or from the strip. */
  .stage { padding: 12px; }
  .nav { display: none; }
  .banner { padding: 8px 14px; font-size: 13px; }
  .thumb { height: 48px; }
  .composer { width: 230px; }
}
