/* Preview: mocks sit on a neutral "light table" so their own colours read true; redline red is
   reserved for comments, the one thing reviewers come here to add. */

:root {
  --table: #e7e8eb;
  --paper: #ffffff;
  --ink: #1f2328;
  --ink-2: #5a6069;
  --ink-3: #868c95;
  --rule: #d3d6db;
  --rule-soft: #e6e8eb;
  --redline: #e0362c;
  --redline-ink: #b42318;
  --redline-wash: #fdeeec;
  --resolved: #9aa0a8;
  --focus: #1f2328;
  --sheet-shadow: 0 1px 2px rgb(20 24 30 / 0.08), 0 10px 28px rgb(20 24 30 / 0.09);
  --float-shadow: 0 2px 6px rgb(20 24 30 / 0.1), 0 16px 40px rgb(20 24 30 / 0.16);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --table: #1b1d21;
    --paper: #26292e;
    --ink: #eceef1;
    --ink-2: #a9aeb6;
    --ink-3: #7c828b;
    --rule: #3b3f46;
    --rule-soft: #31343a;
    --redline: #f0483e;
    --redline-ink: #ff8279;
    --redline-wash: #3a2422;
    --resolved: #6d727b;
    --focus: #eceef1;
    --sheet-shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 10px 28px rgb(0 0 0 / 0.35);
    --float-shadow: 0 2px 6px rgb(0 0 0 / 0.35), 0 16px 40px rgb(0 0 0 / 0.45);
    color-scheme: dark;
  }
}

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

html,
body {
  margin: 0;
  background: var(--table);
  color: var(--ink);
  font-family: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: inherit;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* ---------- Controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--ink-3);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn.primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

.btn.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--ink-2);
}

.btn.quiet:hover {
  color: var(--ink);
  background: var(--rule-soft);
}

.btn.danger,
.btn.confirming {
  color: var(--redline-ink);
}

.btn.confirming {
  border-color: var(--redline);
  background: var(--redline-wash);
}

.btn.icon {
  width: 34px;
  padding: 0;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--ink);
}

.link-btn.danger {
  color: var(--redline-ink);
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}

.input,
.textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  font-size: 15px;
}

.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}

.textarea {
  resize: vertical;
  min-height: 70px;
  line-height: 1.45;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row .input {
  flex: 1;
  min-width: 0;
}

.error {
  color: var(--redline-ink);
  font-size: 14px;
}

.hint {
  color: var(--ink-2);
  font-size: 14px;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.topbar .spacer {
  flex: 1;
}

.topbar .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.wordmark svg {
  width: 20px;
  height: 20px;
}

/* ---------- Gate (password / owner key / errors) ---------- */

.gate {
  width: min(400px, 100%);
  margin: 0 auto;
  padding: 16vh 16px 48px;
  display: grid;
  gap: 18px;
}

.gate h1 {
  font-size: 28px;
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.gate p {
  color: var(--ink-2);
}

.gate form {
  display: grid;
  gap: 12px;
}

/* ---------- Home ---------- */

.home {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 36px 20px 80px;
  display: grid;
  gap: 48px;
}

.drop {
  position: relative;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 14px;
  min-height: 300px;
  padding: 40px;
  border: 2px dashed var(--rule);
  border-radius: 14px;
  transition: border-color 120ms, background-color 120ms;
}

.drop.over {
  border-color: var(--redline);
  background: var(--paper);
}

.drop h1 {
  font-size: clamp(30px, 5vw, 44px);
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.drop .hint {
  max-width: 46ch;
  font-size: 15px;
}

.drop .buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.stage {
  display: grid;
  gap: 22px;
  padding: 28px;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--sheet-shadow);
}

.stage h2 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.strip {
  display: flex;
  gap: 10px;
  overflow: hidden;
  mask-image: linear-gradient(to right, #000 85%, transparent);
}

.strip img {
  flex: none;
  width: 96px;
  height: 72px;
  object-fit: cover;
  object-position: top;
  border-radius: 3px;
  border: 1px solid var(--rule-soft);
  background: var(--table);
}

.stage-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.stage .buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.progress {
  display: grid;
  gap: 8px;
  font-size: 14px;
  color: var(--ink-2);
}

.progress .bar {
  height: 4px;
  border-radius: 2px;
  background: var(--rule-soft);
  overflow: hidden;
}

.progress .bar > div {
  height: 100%;
  width: 0;
  background: var(--redline);
  transition: width 200ms;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head h2 {
  font-size: 17px;
  font-weight: 600;
}

.plist {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}

.plist a {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: baseline;
  gap: 24px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
}

.plist a:hover .pname {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.pname {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pmeta {
  color: var(--ink-2);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pmeta.open {
  color: var(--redline-ink);
  font-weight: 500;
}

/* ---------- Project grid ---------- */

.project {
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 32px 20px 80px;
  display: grid;
  gap: 36px;
}

.project > div:empty {
  display: none;
}

.project-head h1 {
  font-size: clamp(26px, 4vw, 36px);
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.project-head p {
  margin-top: 6px;
  color: var(--ink-2);
}

.panel {
  display: grid;
  gap: 16px;
  max-width: 640px;
  padding: 22px 24px;
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--sheet-shadow);
}

.panel h2 {
  font-size: 17px;
  font-weight: 600;
}

.panel .split {
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--rule-soft);
}

.password-chip {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.group h2 {
  margin-bottom: 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
}

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

.mock {
  display: block;
  text-decoration: none;
}

.thumb {
  aspect-ratio: 4 / 3;
  border-radius: 3px;
  background: var(--paper);
  box-shadow: var(--sheet-shadow);
  overflow: hidden;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}

.mock:hover .thumb {
  outline: 2px solid var(--ink-3);
  outline-offset: 3px;
}

.mock-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.mock-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  padding: 48px 0;
  color: var(--ink-2);
}

.dropveil {
  position: fixed;
  inset: 12px;
  z-index: 50;
  display: grid;
  place-items: center;
  border: 2px dashed var(--redline);
  border-radius: 16px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  font-size: 22px;
  font-weight: 600;
  pointer-events: none;
}

/* ---------- Pins ---------- */

.pin {
  --size: 28px;
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  background: var(--redline);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
  transform: translateY(-100%);
  transform-origin: 0 100%;
  cursor: pointer;
  transition: transform 100ms;
}

.pin.resolved {
  background: var(--resolved);
}

.pin.active {
  z-index: 3;
  transform: translateY(-100%) scale(1.18);
  box-shadow: 0 0 0 2px var(--ink), 0 2px 8px rgb(0 0 0 / 0.35);
}

.pin.ghost {
  opacity: 0.5;
  pointer-events: none;
  transition: none;
}

.pin.draft {
  z-index: 4;
}

/* Small pin used as a count badge and as the thread number in the rail */
.badge {
  display: inline-grid;
  place-items: center;
  flex: none;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 11px 11px 11px 0;
  background: var(--redline);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.badge.resolved {
  background: var(--resolved);
}

/* ---------- Viewer ---------- */

.viewer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.viewer .topbar {
  grid-column: 1 / -1;
}

.vtitle {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.vtitle strong {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vtitle span {
  color: var(--ink-3);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.canvas {
  overflow: auto;
  padding: 32px;
  overscroll-behavior: contain;
}

.sheet {
  position: relative;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: var(--sheet-shadow);
  cursor: crosshair;
}

.sheet.fit {
  max-width: 100%;
}

.sheet img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.composer {
  position: absolute;
  z-index: 5;
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--float-shadow);
  cursor: auto;
}

.composer.docked {
  position: static;
  padding: 14px 20px;
  border-radius: 0;
  border-bottom: 1px solid var(--rule-soft);
  background: var(--redline-wash);
  box-shadow: none;
}

.composer.docked .comment-head {
  margin: 0;
  font-weight: 600;
  font-size: 14px;
}

.composer .buttons,
.reply-form .buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--rule);
  background: var(--paper);
}

.rail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--rule-soft);
}

.rail-head h2 {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}

.rail-head h2 span {
  margin-left: 6px;
  color: var(--ink-3);
  font-weight: 500;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
}

.threads {
  flex: 1;
  overflow: auto;
}

.thread {
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--rule-soft);
  cursor: pointer;
}

.thread.active {
  background: var(--redline-wash);
}

.thread.resolved .body,
.thread.resolved .who {
  color: var(--ink-3);
}

.comment-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.comment-head .badge {
  align-self: center;
  margin-right: 2px;
}

.who {
  font-weight: 600;
  font-size: 14px;
}

.when {
  color: var(--ink-3);
  font-size: 13px;
  white-space: nowrap;
}

.body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14.5px;
}

.reply {
  margin: 12px 0 0 32px;
}

.thread-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 10px 0 0 32px;
}

.reply-form {
  display: grid;
  gap: 8px;
  margin: 12px 0 4px 32px;
  cursor: auto;
}

.rail .empty {
  padding: 28px 20px;
  font-size: 14px;
}

.rail-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--rule-soft);
  font-size: 13px;
  color: var(--ink-2);
}

.rail-foot strong {
  color: var(--ink);
  font-weight: 600;
}

.rail-foot form {
  display: flex;
  gap: 8px;
  width: 100%;
}

.rail-foot .input {
  flex: 1;
  padding: 5px 9px;
  font-size: 14px;
}

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  font-weight: 500;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms, transform 160ms;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Small screens ---------- */

@media (max-width: 860px) {
  .viewer {
    display: block;
    height: auto;
  }

  .canvas {
    padding: 16px;
    overflow-x: auto;
    overflow-y: visible;
  }

  .rail {
    border-left: 0;
    border-top: 1px solid var(--rule);
  }

  .threads {
    overflow: visible;
  }

  .viewer .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 16px;
  }

  .home,
  .project {
    padding-left: 16px;
    padding-right: 16px;
  }

  .drop {
    padding: 28px 22px;
    min-height: 240px;
  }

  .stage {
    padding: 22px 18px;
  }

  .stage-fields {
    grid-template-columns: 1fr;
  }

  .plist a {
    grid-template-columns: 1fr auto;
    gap: 4px 16px;
  }

  .plist .pdate {
    display: none;
  }

  .mocks {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 22px 16px;
  }

  .vtitle span {
    display: none;
  }

  .viewer .topbar {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .viewer .topbar .spacer {
    display: none;
  }

  .viewer .vtitle {
    flex: 1;
  }

  .viewer .topbar .actions {
    width: 100%;
  }
}

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