/* graphical crayon — off-white paper, hand-drawn furniture, everything lowercase */

:root {
  --paper:        #f6f3ea;
  --paper-deep:   #efeade;
  --ink:          #1c1a16;
  --ink-soft:     #5d5548;
  --ink-faint:    #8c8171;
  --line:         #d9d2c2;

  --sw:   50px;   /* swatch / button size */
  --gap:  12px;   /* gap inside a rail group */
  --rail-x: 34px; /* rail distance from the left edge */
  --rail-w: 118px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--paper);
  touch-action: manipulation;          /* no double tap zoom */
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  color: var(--ink);
  font-family: 'Yomogi', 'Comic Sans MS', cursive;
  font-size: 15px;
  text-transform: lowercase;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select { font: inherit; text-transform: lowercase; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }

/* ---------------------------------------------------------------- stage */

#stage {
  position: fixed;
  inset: 0;
  /* dvh follows the browser chrome as it slides away on a phone */
  height: 100vh;
  height: 100dvh;
}

/* ---------------------------------------------------------------- title */

#titlebar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 6;
}

#title {
  pointer-events: auto;
  -webkit-user-select: text;
  user-select: text;
  min-width: 90px;
  max-width: 60vw;
  padding: 4px 14px 6px;
  font-size: clamp(21px, 2.2vw, 30px);
  line-height: 1.25;
  color: var(--ink-soft);
  opacity: .42;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  outline: none;
  caret-color: var(--ink-soft);
  transition: opacity .18s ease;
}

#title:hover { opacity: .62; }
#title:focus { opacity: .82; }
#title.named { opacity: .66; }

#title:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-faint);
}

/* the wrapper only matters on a small screen, where it gathers the controls
   into a block under the sheet. on a wide one it may as well not exist. */
#controls { display: contents; }

/* ----------------------------------------------------------------- rail */

/* four groups, one gap inside a group and twice that between them */
#rail {
  position: fixed;
  left: var(--rail-x);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: calc(var(--gap) * 2);
  z-index: 5;
}

.rail-group {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.swatch,
.rail-btn {
  position: relative;
  width: var(--sw);
  height: var(--sw);
  display: grid;
  place-items: center;
  border-radius: 2px;
  transition: transform .16s cubic-bezier(.2,.9,.3,1.2);
}

.swatch svg.rf,
.rail-btn svg.rf {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

/* --tilt and --nudge are dealt out per button in js, so no two of them lean
   by quite the same amount. gated on a real pointer: a touch screen would
   otherwise leave the last thing you tapped stuck in its hover pose. */
@media (hover: hover) {
  .swatch:hover,
  .rail-btn:hover {
    transform: translate(var(--nudge, 3px), var(--lift, 0px)) rotate(var(--tilt, -1.2deg));
  }
  #transport .rail-btn:hover {
    transform: translateY(calc(var(--lift, -3px))) rotate(var(--tilt, -1.2deg));
  }
}

/* touch gets a press instead */
.swatch:active,
.rail-btn:active { transform: scale(0.93) rotate(var(--tilt, -1.2deg)); }

.swatch[aria-checked="true"] { transform: translateX(7px) rotate(var(--tilt-on, -2deg)); }
.swatch[aria-checked="true"]:hover { transform: translateX(9px) rotate(calc(var(--tilt-on, -2deg) * 1.25)); }

.rail-btn[disabled] { cursor: default; }
.rail-btn[disabled]:hover { transform: none; }

.swatch:focus-visible,
.rail-btn:focus-visible,
.chip:focus-visible { outline: 2px dashed var(--ink-soft); outline-offset: 4px; }

.text-btn > span {
  position: relative;
  font-size: 15px;
  color: #26231d;              /* same weight as the drawn icons */
  line-height: 1;
}

/* fallback when rough.js could not load */
.no-rough.swatch { border: 1px solid var(--ink); background: var(--fallback, transparent); }
.no-rough.rail-btn,
.no-rough.chip { border: 1px solid var(--ink-faint); background: rgba(255,255,255,.5); }

/* --------------------------------------------------------------- canvas */

/* fixed insets rather than a grid item, so the area has a real size before
   javascript ever measures it */
#canvasWrap {
  position: fixed;
  top: 74px;
  bottom: 88px;
  left: var(--rail-w);
  right: var(--rail-w);
  display: grid;
  place-items: center;
}

#canvasBox {
  position: relative;
  width: 160px;
  height: 90px;
  cursor: none;
  touch-action: none;
}

#canvasBox canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* the sketched border sits above the paper, where it can be seen */
#canvasBox > svg.rf {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 4;
}

#paper   { z-index: 1; }
#art     { z-index: 2; }
#overlay { z-index: 3; pointer-events: none; }

/* ------------------------------------------------------------ transport */

#transport {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  gap: calc(var(--gap) * 2);
  z-index: 7;
}

.rail-row {
  display: flex;
  gap: var(--gap);
}

/* ---------------------------------------------------------------- chips */

.chip {
  position: relative;
  padding: 9px 18px 11px;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1;
}

.chip svg.rf { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.chip > span { position: relative; }
.chip:hover { color: var(--ink); }

.chip.small { padding: 7px 13px 9px; font-size: 13.5px; }

/* ------------------------------------------------------------- settings */

#settings {
  position: fixed;
  top: 0; right: 0;
  width: 344px;
  max-width: 92vw;
  height: 100%;
  z-index: 20;
  background: var(--paper-deep);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 40px -26px rgba(28,26,22,.5);
  transform: translateX(102%);
  transition: transform .28s cubic-bezier(.2,.8,.25,1);
  display: flex;
  flex-direction: column;
}

#settings.open { transform: none; }

.set-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.set-title { font-size: 17px; color: var(--ink); }

.x { font-size: 22px; line-height: 1; color: var(--ink-faint); padding: 0 4px; }
.x:hover { color: var(--ink); }

.set-body { flex: 1 1 auto; overflow-y: auto; padding: 4px 18px 40px; }

.set-block { padding: 16px 0; border-bottom: 1px dashed var(--line); }
.set-block:last-child { border-bottom: 0; }

.set-block h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: .06em;
  color: var(--ink-faint);
}

.params { display: flex; flex-direction: column; gap: 9px; }

.row {
  display: grid;
  grid-template-columns: 104px 1fr 46px;
  align-items: center;
  gap: 9px;
}

.row label { font-size: 13px; color: var(--ink-soft); }
.row .val { font-size: 12px; color: var(--ink-faint); text-align: right; font-variant-numeric: tabular-nums; }
.row.wide { grid-template-columns: 104px 1fr; }
.row.wide .val { display: none; }

.row select {
  width: 100%;
  padding: 5px 7px;
  background: rgba(255,255,255,.6);
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 13px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: ew-resize;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--line);
  border-radius: 2px;
}
input[type="range"]::-moz-range-track { height: 2px; background: var(--line); border-radius: 2px; }

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.5px solid var(--ink-soft);
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.5px solid var(--ink-soft);
}

.toggle {
  justify-self: start;
  width: 40px; height: 20px;
  border-radius: 11px;
  border: 1.5px solid var(--ink-faint);
  position: relative;
  background: rgba(255,255,255,.5);
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--ink-faint);
  transition: transform .16s ease, background-color .16s ease;
}
.toggle[aria-pressed="true"]::after { transform: translateX(19px); background: var(--ink); }

.voice-tabs { display: flex; gap: 9px; margin-bottom: 10px; }

.voice-tab {
  width: 34px; height: 34px;
  border-radius: 3px;
  border: 1px solid var(--ink);
  opacity: .45;
  transition: opacity .15s ease, transform .15s ease;
}
.voice-tab:hover { opacity: .8; }
.voice-tab[aria-selected="true"] { opacity: 1; transform: translateY(-3px) rotate(-2deg); box-shadow: 0 3px 0 -1px rgba(28,26,22,.35); }

.hint { margin: 0 0 12px; font-size: 12px; color: var(--ink-faint); line-height: 1.5; }
.actions { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 12px; }

/* ---------------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translate(-50%, 14px);
  padding: 9px 16px 11px;
  background: rgba(28,26,22,.9);
  color: var(--paper);
  border-radius: 4px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 40;
}
/* the toast sits over the lower part of the sheet, so it must never swallow a
   stroke aimed at the paper behind it. only its button takes taps. */
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-action { pointer-events: auto; }

.toast-action {
  margin-left: 12px;
  padding: 3px 10px 4px;
  color: var(--paper);
  font-size: 13px;
  border: 1px solid rgba(246,243,234,.55);
  border-radius: 3px;
}
.toast-action:hover { background: rgba(246,243,234,.16); }

/* --------------------------------------------------------------- narrow ---
   one layout for both: on a small screen the stage becomes an ordinary
   column, the sheet takes whatever height is left, and every control moves
   into a wrapped block underneath where a thumb can reach it. */

/* a tall screen is better served by the stacked layout whatever its size: the
   side rail costs width the sheet needs, and the sheet is always 16:9. */
@media (max-width: 860px), (max-height: 560px), (orientation: portrait) {
  :root { --sw: 58px; --gap: 8px; }

  #stage {
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
             env(safe-area-inset-bottom) env(safe-area-inset-left);
  }

  #titlebar {
    position: static;
    height: auto;
    flex: 0 0 auto;
    padding: 10px 12px 4px;
  }

  #title { font-size: 20px; max-width: 78vw; }

  /* the sheet sits up under the title and the slack falls between it and the
     controls, rather than stranding the sheet in the middle of the screen */
  #canvasWrap {
    position: static;
    flex: 1 1 auto;
    min-height: 0;
    align-items: start;
    padding: 4px 8px;
  }

  #controls { margin-top: auto; }

  /* rail and transport dissolve, so their groups wrap as one set */
  #controls {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: var(--gap) calc(var(--gap) * 2);
    padding: 10px 8px 14px;
  }

  #rail, #transport {
    display: contents;
  }

  .rail-group, .rail-row {
    flex-direction: row;
    gap: var(--gap);
  }

  /* the picked crayon lifts instead of stepping sideways */
  .swatch[aria-checked="true"] {
    transform: translateY(-5px) rotate(var(--tilt-on, -2deg));
  }

  /* clear of the sheet above and the controls below */
  #toast { bottom: calc(var(--controls-h, 200px) + 16px); max-width: 88vw; }

  #settings { width: 100%; max-width: 100%; }
}

/* a phone on its side has almost no height to give away */
@media (max-height: 560px) {
  :root { --sw: 42px; --gap: 6px; }
  #titlebar { padding: 4px 12px 0; }
  #title { font-size: 17px; }
  #canvasWrap { padding: 2px 8px; }
  #controls { padding: 6px 8px 8px; }
}

@media (max-height: 400px) {
  #title { font-size: 15px; }
  #titlebar { padding: 2px 12px 0; }
}

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