/* Emotional Support Rock: Rock Designer.
   Standalone page. Tokens come from the brand brief in CLAUDE.md. */

:root {
  /* color */
  --sand: #EFE9DF;
  --paper: #F8F5EF;
  --ink: #2F3336;
  --ink-muted: #5E5A55;
  --stone: #8C867E;   /* fills only, never text */
  --moss: #56664A;
  --blush: #E7B7A3;
  --river: #A9BDBF;
  --hairline: #D6CEC1;

  /* type */
  --serif: "Fraunces", Georgia, serif;
  --sans: "DM Sans", system-ui, sans-serif;

  /* shape */
  --r-sm: 6px;
  --r-md: 16px;
  --r-pill: 999px;

  /* space */
  --s1: 4px; --s2: 8px; --s3: 16px; --s4: 24px; --s5: 32px; --s6: 48px;
  --gutter: clamp(16px, 4vw, 48px);
  --max: 1280px;

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--sand);
  color: var(--ink);
  font: 400 16px/24px var(--sans);
  -webkit-font-smoothing: antialiased;
}
h1, p, fieldset, legend { margin: 0; padding: 0; }
fieldset { border: 0; min-width: 0; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: var(--r-sm); }

.label {
  font: 600 12px/16px var(--sans);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.headline {
  font: 500 clamp(36px, 4vw, 52px)/1.05 var(--serif);
  letter-spacing: -0.02em;
}

/* ---------- header and footer ---------- */
.site-header {
  max-width: var(--max);
  margin: 0 auto;
  padding: var(--s4) var(--gutter) 0;
}
.brand { display: flex; align-items: center; gap: var(--s2); color: var(--ink); }
.brand-mark { flex: none; }
.brand-word { font: 500 18px/24px var(--serif); }

.site-footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: var(--s6) var(--gutter) var(--s5);
  border-top: 1px solid var(--hairline);
  font: 400 12px/18px var(--sans);
  color: var(--ink-muted);
  display: grid;
  gap: var(--s1);
}

/* ---------- layout ---------- */
.designer {
  max-width: var(--max);
  margin: 0 auto;
  padding: var(--s5) var(--gutter) var(--s6);
  display: grid;
  gap: var(--s4) var(--s6);
  grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr);
  grid-template-areas:
    "rock intro"
    "rock controls";
  grid-template-rows: auto 1fr;
  align-items: start;
}
.intro { grid-area: intro; display: grid; gap: var(--s2); }
.subhead { font: 400 20px/28px var(--serif); color: var(--ink); }
.controls { grid-area: controls; }

/* the rock with its name card directly underneath, kept in view while the controls scroll */
.rock-col {
  grid-area: rock;
  position: sticky;
  top: var(--s4);
  height: clamp(520px, calc(100vh - 110px), 900px); /* header + top padding, so the name card shows on load */
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

/* ---------- stage ---------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: var(--r-md);
}
#rock-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#rock-canvas:active { cursor: grabbing; }
.no-webgl-note { display: none; }
.stage.no-webgl { display: grid; place-items: center; background: var(--paper); }
.stage.no-webgl #rock-canvas { display: none; }
.stage.no-webgl .no-webgl-note { display: block; max-width: 28ch; text-align: center; font: 400 20px/28px var(--serif); }

/* ---------- controls ---------- */
.controls { display: grid; gap: var(--s4); }
.control { display: grid; gap: var(--s2); }
.control-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s3);
}
legend.control-head { width: 100%; margin-bottom: var(--s2); }
.value { font: 400 15px/20px var(--sans); color: var(--ink); text-align: right; }
.ends {
  display: flex;
  justify-content: space-between;
  font: 400 12px/16px var(--sans);
  color: var(--ink-muted);
  margin-top: calc(var(--s1) * -1);
}

/* range: moss fill, paper thumb */
.range {
  --fill: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.range:focus-visible { outline: none; }
.range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: var(--r-pill);
  background: linear-gradient(to right, var(--moss) var(--fill), var(--hairline) var(--fill));
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px; height: 24px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--moss);
  box-shadow: 0 1px 3px rgba(47, 51, 54, .22);
}
.range:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--ink); outline-offset: 2px; }
.range::-moz-range-track { height: 6px; border-radius: var(--r-pill); background: var(--hairline); }
.range::-moz-range-progress { height: 6px; border-radius: var(--r-pill); background: var(--moss); }
.range::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--moss);
  box-shadow: 0 1px 3px rgba(47, 51, 54, .22);
}
.range:focus-visible::-moz-range-thumb { outline: 2px solid var(--ink); outline-offset: 2px; }

/* stone swatches: a radio group with visible names */
.swatches { display: flex; flex-wrap: wrap; gap: var(--s2); }
.swatch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: 6px 14px 6px 6px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  background: transparent;
  font: 400 14px/20px var(--sans);
  color: var(--ink);
  cursor: pointer;
}
.swatch input {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.chip {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--b), var(--a) 75%);
  box-shadow: inset 0 0 0 1px rgba(47, 51, 54, .12);
}
.swatch:hover { background: var(--paper); }
.swatch:has(input:checked) {
  background: var(--paper);
  border-color: var(--moss);
  box-shadow: inset 0 0 0 1px var(--moss);
}
.swatch:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 3px; }

/* ---------- name card ---------- */
.namecard {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: var(--s4);
  display: grid;
  gap: var(--s2);
}
.rock-name { font: 500 36px/40px var(--serif); letter-spacing: -0.01em; }
.rock-line { font: 400 16px/24px var(--sans); color: var(--ink); max-width: 52ch; }
.rock-name.is-new { animation: name-in 360ms ease-out; }
@keyframes name-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .rock-name.is-new { animation: none; } }
.namecard-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }

.btn {
  font: 600 15px/20px var(--sans);
  padding: 12px 20px;
  border-radius: var(--r-md);
  border: 1px solid var(--moss);
  cursor: pointer;
}
.btn-primary { background: var(--moss); color: var(--paper); }
.btn-primary:hover { background: #475639; }
.btn-quiet { background: transparent; color: var(--moss); }
.btn-quiet:hover { background: var(--sand); color: var(--ink); }

.link-btn {
  font: 600 14px/20px var(--sans);
  color: var(--moss);
  background: none;
  border: 0;
  padding: var(--s2) 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-btn:hover { color: var(--ink); }
.start-over-phone { display: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- tabs (phone only) ---------- */
[hidden] { display: none !important; }
.tabs { display: none; }

/* ---------- phone: everything on one screen, one control at a time ---------- */
@media (max-width: 860px) {
  .site-header { padding-top: var(--s3); }
  .brand-mark { width: 40px; height: 30px; }

  /* the tool fills the screen under the 46px header: intro, rock, name strip, tabs, one control */
  .designer {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--s3);
    min-height: max(540px, calc(100vh - 46px));
    min-height: max(540px, calc(100svh - 46px));
    padding-top: var(--s3);
    padding-bottom: var(--s3);
  }
  .intro { gap: var(--s1); }
  .headline { font-size: 30px; }
  .subhead { font-size: 16px; line-height: 22px; }

  .rock-col { position: static; height: auto; flex: 1 0 auto; gap: var(--s2); }
  .stage { flex: 1; min-height: 180px; }

  /* the name card becomes a slim strip: label and Different name on one row, then the name and its line */
  .namecard {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0 var(--s3);
    padding: 12px var(--s3);
  }
  .rock-name { grid-column: 1 / -1; font-size: 22px; line-height: 26px; }
  /* room for three lines, so most slider moves don't nudge the rock */
  .rock-line { grid-column: 1 / -1; font-size: 13px; line-height: 18px; min-height: 54px; margin-top: var(--s1); }
  .namecard-actions { grid-column: 2; grid-row: 1; margin: 0; }
  .namecard .start-over { display: none; }
  .start-over-phone { display: block; margin: calc(var(--s2) * -1) 0 0; text-align: center; }
  .namecard .btn { padding: 6px 12px; font-size: 13px; line-height: 18px; }

  .controls { gap: var(--s3); }
  .tabs {
    display: flex;
    border-bottom: 1px solid var(--hairline);
  }
  .tab {
    flex: 1;
    min-height: 44px;
    padding: var(--s2) var(--s1);
    border: 0;
    background: transparent;
    font: 600 12px/16px var(--sans);
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ink-muted);
    cursor: pointer;
  }
  .tab[aria-selected="true"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--moss); }
  .tab:focus-visible { outline-offset: -2px; }

  /* every panel gets the same height, so the rock doesn't jump when tabs change */
  .control { min-height: 96px; align-content: start; }
  .control-head .label {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .control-head { justify-content: center; }
  .value { font: 400 16px/22px var(--serif); text-align: center; }

  .swatches { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--s1); }
  .swatch {
    flex-direction: column;
    gap: var(--s1);
    padding: 6px 2px;
    border-radius: var(--r-md);
    font-size: 12px;
    line-height: 16px;
    text-align: center;
  }
  .chip { width: 32px; height: 32px; }
}

/* short phones: drop the eyebrow and subhead so the rock keeps its room */
@media (max-width: 860px) and (max-height: 720px) {
  .intro .label, .subhead { display: none; }
  .designer { gap: var(--s2); }
}
