:root {
  --paper: #f7f1e3;
  --card: #fffdf7;
  --ink: #1a1a1a;
  --muted: #5d5848;
  --line: #ddd3bd;
  --blue: #2b398a;
  --red: #dc2f2f;
  --focus: #2b398a;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 'Work Sans', system-ui, sans-serif;
}

.top {
  text-align: center;
  padding: 28px 16px 8px;
}
.top h1 {
  margin: 0;
  font: 400 clamp(2.2rem, 7vw, 3.4rem)/1 'Shrikhand', cursive;
  color: var(--red);
  text-shadow: 3px 3px 0 var(--blue);
  letter-spacing: 0.5px;
}
.top p { margin: 10px 0 0; color: var(--muted); font-size: 1.05rem; }

.layout {
  display: grid;
  gap: 24px;
  max-width: 1080px;
  margin: 16px auto 0;
  padding: 0 16px;
}
@media (min-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; }
  .stage { position: sticky; top: 16px; }
}

/* Preview: a checkerboard shows where the download will be see-through. */
.frame {
  position: relative;
  /* Shaped like the chosen size, and never taller than the screen. */
  aspect-ratio: var(--ar, 1);
  width: min(100%, calc(72vh * var(--ar, 1)));
  margin: 0 auto;
  border-radius: var(--radius);
  background-color: var(--card);
  background-image:
    linear-gradient(45deg, #eee7d6 25%, transparent 25%, transparent 75%, #eee7d6 75%),
    linear-gradient(45deg, #eee7d6 25%, transparent 25%, transparent 75%, #eee7d6 75%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
  border: 1px solid var(--line);
  overflow: hidden;
}
#preview {
  display: block;
  width: 100%;
  height: 100%;
}
.frame.has-photo #preview { cursor: grab; touch-action: none; }
.frame.has-photo #preview:active { cursor: grabbing; }
.frame.dragover { outline: 3px dashed var(--blue); outline-offset: -8px; }

.drop {
  /* Below the preview, never on it, so the stealie shows in full before a photo is in. */
  display: grid;
  justify-items: center;
  margin: 12px auto 0;
  gap: 2px;
  padding: 12px 26px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.drop-title { font-weight: 600; font-size: 1.05rem; white-space: nowrap; }
.drop-sub { font-size: 0.8rem; opacity: 0.75; }
.has-photo + .drop { display: none; }
@media (hover: none) { .drop-sub { display: none; } }

.sizes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.sizes button {
  display: grid;
  align-content: start;
  gap: 1px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 7px 8px;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.sizes small { font-size: 0.7rem; font-weight: 400; line-height: 1.2; color: var(--muted); }
.sizes button[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: #fff; }
.sizes button[aria-pressed=true] small { color: rgba(255,255,255,0.75); }

.hint { margin: 10px 0 0; text-align: center; color: var(--muted); font-size: 0.9rem; }

.controls { display: grid; gap: 14px; }

.group {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.group h2 { margin: 0 0 12px; font-size: 1.05rem; font-weight: 600; }
.group h3 { margin: 16px 0 8px; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.row-actions { display: flex; gap: 14px; }

.slider { display: grid; grid-template-columns: 3.2em 1fr; align-items: center; gap: 10px; margin: 6px 0; font-size: 0.95rem; }
input[type=range] { width: 100%; accent-color: var(--blue); }

/* The fill's sliders show their own colors on the track. */
.fill-color { margin-top: 12px; }
.matches { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.matches:empty { display: none; }
.matches button {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.2);
  box-shadow: 0 0 0 2px #fff;
  cursor: pointer;
}
.matches button[aria-pressed=true] { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink); }
.fill-color input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  height: 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.fill-color .hue {
  background: linear-gradient(to right, hsl(0,75%,50%), hsl(60,75%,50%), hsl(120,75%,50%), hsl(180,75%,50%), hsl(240,75%,50%), hsl(300,75%,50%), hsl(360,75%,50%));
}
.fill-color input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.fill-color input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
}

.link {
  border: 0;
  background: none;
  padding: 4px 0;
  color: var(--blue);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.chips, .seg { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button, .seg button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  min-height: 40px;
}
.chips button[aria-pressed=true], .seg button[aria-pressed=true] {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
}
.swatches button {
  display: grid;
  justify-items: center;
  gap: 6px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: none;
  padding: 6px 2px;
  font: inherit;
  font-size: 0.8rem;
  color: var(--ink);
  cursor: pointer;
}
.swatches button[aria-pressed=true] { border-color: var(--ink); }
.swatches canvas { width: 56px; height: 56px; }

.colors label.covered { color: var(--muted); }

.team { margin: 14px 0 0; position: relative; }
.team .field { margin: 0; }
.team input[type=search] {
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.team-results {
  display: grid;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}
.team-results button {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.team-results button:first-child { border-top: 0; }
.team-results button:hover, .team-results button:focus-visible { background: var(--paper); }
.team-results .dot { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.2); flex: none; }
.team-results .dot + .dot { margin-left: -10px; margin-right: 6px; }
.fine { margin-top: 12px; }
.fine summary { cursor: pointer; color: var(--blue); font-weight: 500; font-size: 0.92rem; }
.colors {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px 14px;
  margin-top: 12px;
}
.colors label { display: flex; align-items: center; gap: 10px; font-size: 0.92rem; }

input[type=color] {
  width: 40px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  cursor: pointer;
}

.field { display: grid; gap: 4px; margin: 0 0 10px; font-size: 0.9rem; color: var(--muted); }
.field input[type=text], .field select {
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.field-row { display: flex; gap: 14px; align-items: end; }
.field-row .field:first-child { flex: 1; }

.save { display: grid; gap: 10px; }
.primary, .secondary {
  font: inherit;
  font-weight: 600;
  font-size: 1.02rem;
  padding: 14px;
  border-radius: 12px;
  cursor: pointer;
}
.primary { border: 0; background: var(--red); color: #fff; }
.secondary { border: 1px solid var(--ink); background: #fff; color: var(--ink); }
.primary:disabled, .secondary:disabled { opacity: 0.5; cursor: wait; }

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

.foot {
  max-width: 1080px;
  margin: 28px auto 0;
  padding: 0 16px 36px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}
.foot p { margin: 4px 0; }

/* Phones: the preview rides along at the top while the options scroll under it. */
@media (max-width: 859px) {
  .stage {
    position: sticky;
    top: var(--vv-top, 0px);
    z-index: 5;
    margin: 0 -16px;
    padding: 8px 16px 10px;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 12px -8px rgba(0, 0, 0, 0.25);
  }
  .sizes { margin-bottom: 8px; }
  .sizes button { padding: 5px 6px; font-size: 0.8rem; }
  .sizes small { font-size: 0.64rem; }
  .frame { width: min(100%, calc(var(--pv, 36svh) * var(--ar, 1))); }
  /* While typing, only the stealie stays pinned, to leave room above the keyboard. */
  .typing .sizes, .typing .drop, .typing .hint { display: none; }
  .drop { margin-top: 8px; padding: 8px 20px; }
  .drop-title { font-size: 0.95rem; }
  .hint { margin-top: 6px; font-size: 0.8rem; }
}
