@font-face {
  font-family: "Rethink Sans";
  src: url("fonts/rethink-sans-latin-ext.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
  unicode-range: U+0100-02BA, U+1E00-1E9F, U+1EF2-1EFF, U+20A0-20AB, U+20AD-20C0;
}
@font-face {
  font-family: "Rethink Sans";
  src: url("fonts/rethink-sans-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122;
}
@font-face {
  font-family: "Shrikhand";
  src: url("fonts/shrikhand-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+1E00-1E9F, U+1EF2-1EFF;
}
@font-face {
  font-family: "Shrikhand";
  src: url("fonts/shrikhand-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F;
}
@font-face {
  font-family: "IM Fell DW Pica";
  src: url("fonts/im-fell-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IM Fell DW Pica";
  src: url("fonts/im-fell-italic.woff2") format("woff2");
  font-style: italic;
}

:root {
  --ground: #b9c6f5;
  --ink: #241a5e;
  --ink-soft: #40377a;
  --poppy: #cf2620;
  --poppy-dark: #ab1b17;
  --paper: #ffffff;
  --sun: #ffc933;
  --error: #9b1111;
}

* {
  box-sizing: border-box;
  margin: 0;
}
[hidden] {
  display: none !important;
}

body {
  background: var(--ground);
  color: var(--ink);
  font: 500 1.0625rem/1.5 "Rethink Sans", "Noto Sans", sans-serif;
  min-height: 100svh;
}

h1 {
  font-size: clamp(2rem, 1.4rem + 2.6vw, 3.5rem);
  font-weight: 800;
  line-height: 1.04;
  letter-spacing: -0.03em;
  text-wrap: balance;
}
h1:focus {
  outline: none;
}
.lede {
  font-size: 1.1875rem;
  margin-top: 0.75rem;
  max-width: 34rem;
  text-wrap: pretty;
}
.shop {
  font-weight: 700;
  margin-bottom: 1.25rem;
}

.make {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 100svh;
  padding: 1.5rem 1.25rem 0;
}
.wire {
  width: 100%;
  height: clamp(130px, 38vw, 180px);
  margin: 0.5rem 0;
}
.garden {
  width: calc(100% + 2.5rem);
  height: 210px;
  margin: 1rem -1.25rem 0;
  align-self: end;
}

.form {
  display: grid;
  gap: 1.75rem;
}
.field {
  border: 0;
  padding: 0;
  min-width: 0;
}
.field > label,
.field > .label,
legend,
.photo-edit label {
  display: block;
  font-weight: 700;
  padding: 0;
  margin-bottom: 0.5rem;
}
.label span {
  font-weight: 500;
}
.hint {
  color: var(--ink-soft);
  font-size: 0.9375rem;
  margin-top: 0.5rem;
}
.error {
  color: var(--error);
  font-weight: 700;
  margin-top: 0.5rem;
}
.error:empty {
  display: none;
}

input[type="text"] {
  width: 100%;
  height: 3.75rem;
  padding: 0 1.125rem;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  font: 600 1.375rem/1 "Rethink Sans", "Noto Sans", sans-serif;
}
input[aria-invalid="true"] {
  border-color: var(--error);
}
input[type="range"] {
  width: 100%;
  height: 2.75rem;
  accent-color: var(--poppy);
}

.choices,
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
}
.choices label,
.sizes label {
  position: relative;
  cursor: pointer;
}
.choices input,
.sizes input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.choices span,
.sizes span {
  display: block;
  padding: 0.625rem 1.125rem;
  border: 2px solid var(--ink);
  border-radius: 99px;
  font-weight: 600;
}
.choices input:checked + span,
.sizes input:checked + span {
  background: var(--ink);
  color: var(--paper);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0.5rem 1.375rem;
  border: 2px solid var(--ink);
  border-radius: 14px;
  font: 700 1.0625rem/1.2 "Rethink Sans", sans-serif;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.15s;
}
.button:active {
  transform: translateY(2px);
}
.button:disabled {
  cursor: progress;
  opacity: 0.75;
}
.primary {
  background: var(--poppy);
  border-color: var(--poppy);
  color: #fff;
  min-height: 3.75rem;
  font-size: 1.1875rem;
}
.quiet {
  background: transparent;
  color: var(--ink);
}
.link {
  min-height: 2.75rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: 700 1.0625rem/1.2 "Rethink Sans", sans-serif;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  cursor: pointer;
}
@media (hover: hover) {
  .primary:hover {
    background: var(--poppy-dark);
    border-color: var(--poppy-dark);
  }
  .quiet:hover,
  .choices label:hover input:not(:checked) + span,
  .sizes label:hover input:not(:checked) + span {
    background: #d3dcfa;
  }
}
:focus-visible,
input:focus-visible + span {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.photo-edit {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  gap: 1.125rem;
  align-items: center;
}
#crop {
  width: 148px;
  height: 148px;
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
}
#crop:active {
  cursor: grabbing;
}

.result {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
  padding: 1.25rem 1.25rem 3rem;
}
.stage {
  display: grid;
  place-items: center;
}
.frame {
  position: relative;
  width: min(100%, calc(68svh * var(--ratio, 0.8)));
  aspect-ratio: var(--ratio, 0.8);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 18px 40px -14px rgb(36 26 94 / 0.55);
}
.frame > * {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.frame.growing #card {
  clip-path: circle(0 at 50% 38%);
}
.frame.open #card {
  clip-path: circle(120% at 50% 38%);
  transition: clip-path 0.9s cubic-bezier(0.6, 0, 0.2, 1);
}

.panel {
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
}
.sizes {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  border: 0;
  padding: 0;
  margin: 1.25rem 0;
}
.sizes legend {
  float: left;
  margin: 0 0.5rem 0 0;
}
.actions {
  display: flex;
  gap: 0.625rem;
}
.actions .button {
  flex: 1;
  padding-inline: 0.5rem;
  white-space: nowrap;
}
.actions.can-share #save {
  background: transparent;
  border-color: var(--ink);
  color: var(--ink);
}
.status {
  font-weight: 700;
  margin-top: 0.75rem;
}
.status:empty {
  display: none;
}
.caption {
  margin: 1.25rem 0;
  padding: 1rem 1.125rem 0.375rem;
  border-radius: 14px;
  background: #d3dcfa;
  overflow-wrap: anywhere;
}
.again {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}
.history {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 72px));
  gap: 0.625rem;
  margin-top: 1.25rem;
}
.history button {
  width: 100%;
  aspect-ratio: 0.8;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  overflow: hidden;
  cursor: pointer;
}
.history button[aria-pressed="true"] {
  box-shadow: 0 0 0 3px var(--ground), 0 0 0 6px var(--ink);
}
.history canvas {
  display: block;
  width: 100%;
  height: 100%;
}

dialog {
  width: min(92vw, 30rem);
  margin: auto;
  padding: 1rem;
  border: 0;
  border-radius: 20px;
  background: var(--ground);
  color: var(--ink);
}
dialog::backdrop {
  background: rgb(20 12 56 / 0.75);
}
video {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  margin-bottom: 1rem;
  border-radius: 12px;
  background: var(--ink);
  object-fit: cover;
}
video.mirrored {
  transform: scaleX(-1);
}
.noscript {
  padding: 1.25rem;
}

@media (min-width: 600px) {
  .history {
    grid-template-columns: repeat(8, minmax(0, 60px));
  }
}

/* A phone held sideways: card and controls side by side. */
@media (min-width: 560px) and (max-width: 899px) and (max-height: 500px) {
  .result {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
  }
  .stage {
    position: sticky;
    top: 1.25rem;
  }
  .frame {
    width: calc((100svh - 2.5rem) * var(--ratio, 0.8));
  }
  .panel {
    margin: 0;
  }
  .history {
    grid-template-columns: repeat(4, minmax(0, 72px));
  }
}

@media (min-width: 900px) {
  .make {
    grid-template-columns: minmax(0, 1fr) 25rem;
    grid-template-rows: auto minmax(150px, 1fr) auto;
    column-gap: clamp(2.5rem, 6vw, 6rem);
    padding: 3rem clamp(2rem, 6vw, 6rem) 0;
  }
  .intro h1 {
    max-width: 15em;
  }
  .wire {
    height: 100%;
    min-height: 150px;
    max-height: 300px;
    align-self: center;
  }
  .form {
    grid-column: 2;
    grid-row: 1 / 3;
    align-self: center;
  }
  .garden {
    grid-column: 1 / -1;
    width: calc(100% + 2 * clamp(2rem, 6vw, 6rem));
    margin: 0 calc(-1 * clamp(2rem, 6vw, 6rem));
    height: clamp(150px, 25svh, 230px);
  }
  .result {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: clamp(2rem, 5vw, 5rem);
    align-items: center;
    min-height: 100svh;
    padding: 2rem clamp(2rem, 6vw, 6rem);
  }
  .frame {
    width: min(100%, calc(88svh * var(--ratio, 0.8)));
  }
  .panel {
    margin: 0;
  }
}

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