/* QUILT — textile theme. Deep indigo night, thread gold, fabric cream. */

:root {
  --ink: #171322;
  --ink-2: #1f1930;
  --panel: #261f3a;
  --thread: #d8a94e;
  --thread-2: #f0cd86;
  --fabric: #fff6e4;
  --text: #efe9dc;
  --muted: #9b91ad;
  --red: #b13e53;
  --green: #38b764;
  --serif: 'DM Serif Display', serif;
  --ui: 'Space Grotesk', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.45;
  overflow: hidden;
}

body.scroll {
  overflow: auto;
}

canvas.pix {
  image-rendering: pixelated;
}

h1,
h2,
h3 {
  font-family: var(--serif);
  font-weight: 400;
  margin: 0;
}

a {
  color: var(--thread-2);
}

button {
  font-family: var(--ui);
  cursor: pointer;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--thread);
  color: var(--ink);
  box-shadow:
    0 2px 0 #8c6a26,
    0 6px 14px rgba(0, 0, 0, 0.35);
  transition:
    transform 0.06s ease,
    box-shadow 0.06s ease,
    background 0.15s;
}

.btn:hover {
  background: var(--thread-2);
}

.btn:active {
  transform: translateY(2px);
  box-shadow:
    0 0 0 #8c6a26,
    0 3px 8px rgba(0, 0, 0, 0.35);
}

.btn.ghost {
  background: transparent;
  color: var(--thread-2);
  box-shadow: inset 0 0 0 2px rgba(216, 169, 78, 0.55);
}

.btn.ghost:hover {
  box-shadow: inset 0 0 0 2px var(--thread-2);
  background: rgba(216, 169, 78, 0.08);
}

.btn.small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* ---------- header ---------- */

header.bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(to bottom, rgba(23, 19, 34, 0.95), rgba(23, 19, 34, 0));
  pointer-events: none;
}

header.bar > * {
  pointer-events: auto;
}

.wordmark {
  font-family: var(--serif);
  font-size: 24px;
  letter-spacing: 0.14em;
  color: var(--thread);
  text-decoration: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}

.bar .quilt-name {
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar .stat {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

.bar .spacer {
  flex: 1;
}

.online-chips {
  display: flex;
  align-items: center;
}

.chip {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  margin-left: -7px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  text-transform: uppercase;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  padding: 6px;
  color: var(--muted);
  border-radius: 6px;
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

/* ---------- the map ---------- */

#quilt-map {
  position: fixed;
  inset: 0;
  display: block;
  cursor: grab;
  touch-action: none;
  background:
    radial-gradient(ellipse 120% 80% at 50% -20%, #241c3d 0%, transparent 60%), var(--ink);
}

#quilt-map.dragging {
  cursor: grabbing;
}

.stitch-fab {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  font-size: 16px;
  padding: 14px 26px;
  border-radius: 999px;
  box-shadow:
    0 3px 0 #8c6a26,
    0 12px 34px rgba(0, 0, 0, 0.55);
}

.map-hint {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 24;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  font-family: var(--serif);
  text-align: center;
  pointer-events: none;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
}

/* hover/pinned patch card: a sewn-on label */

.patch-card {
  position: fixed;
  z-index: 30;
  background: var(--fabric);
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 14px;
  max-width: 280px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.patch-card.pinned {
  pointer-events: auto;
}

.patch-card::before {
  content: '';
  position: absolute;
  inset: 3px;
  border: 1px dashed rgba(26, 28, 44, 0.4);
  border-radius: 6px;
  pointer-events: none;
}

.patch-card .alibi {
  font-family: var(--serif);
  font-size: 17px;
  overflow-wrap: anywhere;
}

.patch-card .who {
  font-size: 12px;
  color: #7a6a4d;
  margin-top: 3px;
}

.patch-card .row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* ---------- landing ---------- */

.landing {
  height: 100vh;
  overflow-y: auto;
  text-align: center;
}

.landing .inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 10vh 24px 80px;
}

.landing .pediment {
  font-size: clamp(48px, 10vw, 100px);
  letter-spacing: 0.16em;
  color: var(--thread);
  text-shadow:
    0 3px 0 rgba(0, 0, 0, 0.45),
    0 0 60px rgba(216, 169, 78, 0.25);
}

.landing .sub {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(17px, 3vw, 24px);
  opacity: 0.9;
}

.landing .stitchline {
  margin: 10px auto 0;
  width: min(420px, 80%);
  border-top: 2px dashed rgba(216, 169, 78, 0.5);
}

.landing .how {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin: 44px 0 36px;
  text-align: left;
}

.how .card {
  background: var(--panel);
  border: 1px solid rgba(216, 169, 78, 0.2);
  border-radius: 10px;
  padding: 16px;
}

.how .card b {
  display: block;
  color: var(--thread-2);
  margin-bottom: 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.how .card span {
  color: var(--muted);
  font-size: 14px;
}

.landing form.found {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.landing input[type='text'] {
  min-width: 260px;
}

.recent {
  margin-top: 26px;
  color: var(--muted);
  font-size: 14px;
}

.recent a {
  margin: 0 8px;
}

/* ---------- inputs ---------- */

input[type='text'],
textarea {
  font-family: var(--ui);
  font-size: 16px;
  color: var(--text);
  background: var(--ink-2);
  border: 1px solid rgba(216, 169, 78, 0.35);
  border-radius: 6px;
  padding: 10px 14px;
  outline: none;
}

input[type='text']:focus,
textarea:focus {
  border-color: var(--thread);
  box-shadow: 0 0 0 3px rgba(216, 169, 78, 0.18);
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(13, 10, 20, 0.88);
  backdrop-filter: blur(5px);
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: 18px;
}

.sheet {
  background: var(--panel);
  border: 1px solid rgba(216, 169, 78, 0.35);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  padding: 26px;
  width: min(560px, 94vw);
  max-height: 94vh;
  overflow-y: auto;
}

.sheet h2 {
  color: var(--thread-2);
  font-size: 26px;
  margin-bottom: 4px;
}

.sheet .hint {
  color: var(--muted);
  font-size: 14px;
  margin: 4px 0 16px;
}

.sheet .actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  align-items: center;
  flex-wrap: wrap;
}

.sheet .actions .spacer {
  flex: 1;
}

.field {
  margin: 14px 0;
}

.field label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 7px;
  font-weight: 700;
}

.color-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 2px solid rgba(0, 0, 0, 0.5);
  padding: 0;
}

.swatch.sel {
  outline: 3px solid var(--fabric);
  outline-offset: 1px;
}

.swatch.fabric-swatch {
  background-image: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%);
  background-size: 10px 10px;
}

/* ---------- the stitching room ---------- */

.stitchroom {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(980px, 96vw);
  align-items: center;
}

.stitchroom .brief {
  background: var(--fabric);
  color: var(--ink);
  border-radius: 10px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  max-width: 100%;
}

.stitchroom .brief .k {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #7a6a4d;
  white-space: nowrap;
}

.stitchroom .brief .text {
  font-family: var(--serif);
  font-size: clamp(15px, 2.4vw, 20px);
}

.stitchroom .brief .clock {
  margin-left: auto;
  font-size: 13px;
  color: #7a6a4d;
  white-space: nowrap;
}

.stitch-stage {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

/* the hoop: bleed strips framed around the live canvas */

.hoop {
  position: relative;
  line-height: 0;
  border-radius: 6px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  border: 6px solid #6e5320;
  outline: 2px solid #4a3716;
  background: var(--ink-2);
}

.hoop canvas.bleed {
  display: block;
  width: min(72vh, 78vw, 600px);
  aspect-ratio: 1;
}

.hoop canvas.work {
  position: absolute;
  cursor: crosshair;
  touch-action: none;
  /* inset/size set from JS: the BLEED/(PATCH+2*BLEED) fraction */
}

.toolcol {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 132px;
}

.toolrow {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tool {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--ink-2);
  color: var(--text);
  font-size: 17px;
  display: grid;
  place-items: center;
}

.tool.sel {
  background: var(--thread);
  color: var(--ink);
  border-color: var(--thread);
}

.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-width: 160px;
}

.palette .swatch {
  width: 26px;
  height: 26px;
  border-radius: 5px;
}

.stitchroom .alibi-row {
  display: flex;
  gap: 10px;
  align-items: center;
  width: min(640px, 96vw);
}

.stitchroom .alibi-row input {
  flex: 1;
}

.stitchroom .actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  align-items: center;
}

.stitchroom .meta-note {
  color: var(--muted);
  font-size: 13px;
}

/* ---------- toasts ---------- */

#toasts {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--fabric);
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 500;
  font-size: 14.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: rise 0.25s ease both;
}

.toast.err {
  background: var(--red);
  color: var(--fabric);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  .bar .quilt-name,
  .bar .stat {
    display: none;
  }
  .sheet {
    padding: 18px;
  }
  .stitch-fab {
    bottom: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
