/* Page layout: stage (craft mat) on the left, control rail on the right; stacks on phones. */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { touch-action: manipulation; }              /* no double-tap zoom delay on buttons */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }   /* no enlarged text when the phone is turned sideways */
@media (pointer: fine) { html { overscroll-behavior: none; } }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--f-body);
  -webkit-tap-highlight-color: transparent;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
[hidden] { display: none !important; }
h2, p { margin: 0; }

:root { --rail-w: 372px; --actions-bottom: 16px; }
/* short landscape screens (phones on their side): a slimmer panel leaves the squishy room */
@media (min-width: 821px) and (max-height: 520px) { :root { --rail-w: 300px; } }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rail-w);
  overflow: hidden;
}
/* collapsed: the panel slides out (transform only), then its column is removed
   and the squishy glides into the new space (see ui/panel.js and Renderer.tick) */
.app[data-panel="closed"] { grid-template-columns: minmax(0, 1fr) 0px; }
@media (min-width: 821px) {
  .rail { transition: transform .4s var(--ease-drawer); }
  .app:is([data-panel="closing"], [data-panel="opening"], [data-panel="closed"]) .rail { transform: translateX(100%); }
}

/* Registered so the tint can crossfade when the squishy's color changes */
@property --tint { syntax: '<color>'; inherits: true; initial-value: #f7c6d4; }

/* Seamless photo sweep: tinted paper, a soft spotlight behind the squishy,
   a darker floor where the paper curves away, and fine grain so it reads as paper, not a gradient. */
.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background-color: color-mix(in oklab, var(--tint) 16%, var(--mat));
  background-image:
    radial-gradient(ellipse 62% 55% at 50% 44%, var(--sweep-light), transparent 72%),
    linear-gradient(to bottom, transparent 58%, var(--sweep-floor) 100%);
  transition: --tint .6s var(--ease-out);
}
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.4 -.35'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.rail {
  width: var(--rail-w);
  min-width: var(--rail-w);
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding-block: 22px 32px;
  padding-left: max(18px, env(safe-area-inset-left, 0px));
  padding-right: max(18px, env(safe-area-inset-right, 0px));
}

/* Phones: the squishy gets the whole screen; the rail becomes a bottom sheet
   whose squishy row peeks out. Tap the handle or swipe up for everything else. */
.sheet-handle { display: none; }

@media (max-width: 820px) {
  :root { --peek: 152px; --actions-bottom: 36px; }   /* clear the sheet's rounded top edge */
  .app {
    grid-template-columns: 1fr;
    height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  .stage { height: calc(100% - var(--peek) + 20px); }

  .rail {
    position: fixed;
    z-index: 20;
    left: 0; right: 0; bottom: 0;
    height: min(84dvh, 760px);
    gap: 22px;
    padding-block: 0 calc(28px + env(safe-area-inset-bottom, 0px));
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -1px 0 var(--line), 0 -10px 30px rgba(27, 40, 36, .08);
    overflow: hidden;
    overscroll-behavior: contain;
    transform: translateY(calc(100% - var(--peek) - env(safe-area-inset-bottom, 0px)));
    transition: transform .5s var(--ease-drawer);
  }
  .rail[data-open="true"] { transform: none; overflow-y: auto; }
  .rail[data-snap] { transition: transform .2s var(--ease-out); }   /* let go without moving it: back quickly */
  /* closed: the sheet takes up-and-down drags on its top section, the squishy row keeps sideways scrolling */
  .rail[data-open="false"] :is(.sheet-peek, #squishy-picker) { touch-action: pan-x; }
  .rail { width: auto; min-width: 0; }

  /* collapsed on a phone: the sheet drops away and leaves only its handle */
  .app[data-panel="closed"] { grid-template-columns: 1fr; }
  .app[data-panel="closed"] .stage { height: 100%; }
  .app[data-panel="closed"] .rail { transform: translateY(calc(100% - 30px - env(safe-area-inset-bottom, 0px))); }
  .app[data-panel="closed"] { --actions-bottom: 46px; }

  .sheet-handle {
    all: unset;
    display: grid;
    place-items: center;
    flex: none;
    height: 32px;
    margin-inline: -18px;
    cursor: grab;
    touch-action: none;
  }
  .sheet-handle span { width: 40px; height: 5px; border-radius: 999px; background: var(--line); transition: background-color .2s var(--ease-out); }
  .sheet-handle:focus-visible span { background: var(--accent); }

  /* the squishy picker becomes a swipeable row in the peek */
  .sheet-peek { margin-top: -6px; }
  #squishy-picker {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 152px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    margin-inline: -18px;
    padding-inline: 18px;
    scroll-padding-inline: 18px;
  }
  #squishy-picker::-webkit-scrollbar { display: none; }
  #squishy-picker .card { scroll-snap-align: start; }
}
