/* Packit.
 *
 * The layout rule for this app is that a phone viewport shows the picture and
 * nothing scrolls: the page is exactly one viewport tall, the canvas takes what is
 * left after the top bar, and the controls live in a bottom sheet that slides over
 * the picture rather than pushing it. On a wide screen the same controls become a
 * fixed column beside the canvas instead.
 *
 * House rule carried over from the rest of the ecosystem: the `hidden` attribute
 * must beat any author `display` rule, or a panel with `display: grid` stays visible
 * after being hidden.
 */

[hidden] { display: none !important; }

* { box-sizing: border-box; }

:root {
  --bg: #0b0d16;
  --panel: #141726;
  --panel-2: #1c2033;
  --line: #2a2f47;
  --ink: #e8ecf5;
  --ink-dim: #9aa3bd;
  --accent: #7ef0d0;
  --accent-ink: #06231d;
  --radius: 12px;
  --topbar-h: 52px;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100dvh;
}

/* ------------------------------------------------------------------ topbar -- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.home-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}
.home-btn:hover { border-color: var(--accent); color: var(--accent); }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark { font-size: 20px; color: var(--accent); }
.brand-text { font-weight: 600; display: flex; flex-direction: column; line-height: 1.1; }
.brand-text small { font-weight: 400; font-size: 11px; color: var(--ink-dim); }
.who { margin-left: auto; font-size: 12px; color: var(--ink-dim); white-space: nowrap; }
.who strong { color: var(--ink); }

/* -------------------------------------------------------------- app layout -- */
.app {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 0;
  position: relative;
}

.stage {
  position: relative;
  min-height: 0;
  min-width: 0;
  display: flex;
}
#stage-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.stage-hud {
  position: absolute;
  left: 10px;
  top: 10px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(6, 8, 16, 0.62);
  color: var(--ink-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

/* The controls button sits over the picture; on a wide screen it is hidden
   because the panel is always there. */
.sheet-toggle {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  padding: 11px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
.sheet-toggle[aria-expanded="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ------------------------------------------------------------- the controls -- */
.panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  max-height: 76dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 14px calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  transform: translateY(102%);
  transition: transform 0.22s ease;
}
.panel.is-open { transform: translateY(0); }
.panel-grab {
  width: 40px; height: 4px; margin: 4px auto 10px;
  border-radius: 2px; background: var(--line);
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(4, 6, 12, 0.55);
}

.group { padding: 12px 0; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group h2 {
  margin: 0 0 9px;
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 600;
}
.hint { margin: 7px 0 0; font-size: 12px; color: var(--ink-dim); }

/* ------------------------------------------------------------------- chips -- */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 9px 5px;
  min-width: 62px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--ink-dim);
  font-size: 11px;
  cursor: pointer;
}
.chip canvas { display: block; width: 34px; height: 26px; }
.chip[aria-checked="true"] {
  border-color: var(--accent);
  color: var(--ink);
  background: rgba(126, 240, 208, 0.09);
}
.chip.wide { min-width: 0; padding: 9px 11px; font-size: 12px; }

/* ---------------------------------------------------------------- swatches -- */
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.swatch {
  height: 34px;
  border: 2px solid transparent;
  border-radius: 9px;
  padding: 0;
  cursor: pointer;
  display: flex;
  overflow: hidden;
}
.swatch span { flex: 1; }
.swatch[aria-checked="true"] { border-color: var(--accent); }

/* ------------------------------------------------------------------ fields -- */
.field { display: block; margin-bottom: 12px; }
.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  margin-bottom: 6px;
}
.field output { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; }
.field.inline { display: flex; align-items: center; justify-content: space-between; }
.field.inline .field-label { margin: 0; }

input[type="range"] {
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  accent-color: var(--accent);
}
/* The checkbox itself is small by nature, but it always sits inside its own label,
   so the whole row is the tap target — at 390px wide that is a much better target
   than the box, and sizing the box up a little makes it visible on a phone. */
input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0 8px 0 0;
  accent-color: var(--accent);
}
.field.inline .field-label { gap: 4px; justify-content: flex-start; }
input[type="color"] {
  width: 46px; height: 32px; padding: 0;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
}

/* ----------------------------------------------------------------- buttons -- */
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.btn {
  flex: 1 1 auto;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { flex: 0 0 auto; padding: 6px 11px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ------------------------------------------------------------ draw surface -- */
.drawer { margin-top: 10px; }
.subgroup { margin: 10px 0 0; }
.sub-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 6px;
}
.chips.compact { gap: 5px; }
.chips.compact .chip {
  min-width: 0;
  flex-direction: row;
  padding: 6px 10px;
  font-size: 12px;
}
/* Square, and square on purpose: the pad's transform maps unit space straight to
   pixels, so a point on the pad is literally a point in the shape. A rectangular pad
   would need an intermediate coordinate system and the drag handles would then sit
   somewhere other than where the outline goes. */
#draw-pad {
  width: min(100%, 250px);
  aspect-ratio: 1;
  margin: 10px auto 0;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  touch-action: none;
  display: block;
}

input[type="text"],
select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}
input[type="text"]:focus,
select:focus { outline: 1px solid var(--accent); }
.field.stacked .field-label { justify-content: flex-start; }

.advanced summary {
  cursor: pointer;
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 600;
  margin-bottom: 10px;
}
.advanced .field { margin-bottom: 10px; }

/* ------------------------------------------------------------------ modal -- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: rgba(6, 8, 16, 0.94);
  backdrop-filter: blur(6px);
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 15px; }
.modal-head .btn { margin-left: auto; flex: 0 0 auto; }
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  align-content: start;
}
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  cursor: pointer;
}
.card img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--bg); }
.card-meta { padding: 7px 9px; }
.card-title { font-size: 12px; font-weight: 600; }
.card-by { font-size: 11px; color: var(--ink-dim); }
.card .btn { width: calc(100% - 18px); margin: 0 9px 9px; }
.empty { color: var(--ink-dim); font-size: 13px; grid-column: 1 / -1; }

/* Shared shapes: a preview drawn from the stored outline rather than an image,
   because a shape is points, not pixels. */
.shape-card { cursor: default; }
.shape-preview {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg);
}
.shape-card .card-meta { padding-bottom: 2px; }

/* ------------------------------------------------------------------ toast -- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.5);
}

/* -------------------------------------------------------------------- 404 -- */
body.plain { overflow: auto; display: block; height: auto; }
.notfound { padding: 12vh 24px; text-align: center; }
.notfound h1 { font-size: 22px; margin: 0 0 8px; }
.notfound p { color: var(--ink-dim); }

/* ------------------------------------------------------ wide screens: panel -- */
@media (min-width: 900px) {
  .app { grid-template-columns: 330px 1fr; }
  .panel {
    position: static;
    grid-column: 1;
    grid-row: 1;
    max-height: none;
    height: 100%;
    border-top: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    transform: none;
    box-shadow: none;
    padding: 14px 16px 24px;
  }
  .panel-grab { display: none; }
  .stage { grid-column: 2; grid-row: 1; }
  .sheet-toggle { display: none; }
  .scrim { display: none !important; }
  .modal-body { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}

@media (max-width: 899px) {
  .who { display: none; }
}
