/* Vasecreator v2: tokens, layout (desktop and phone), top bar, chips,
   history, dialogs and shared buttons. The step frame and the controls live
   in panels.css. */

/* Inter, served from the site itself (vendor/inter, SIL Open Font License):
   one variable file for every weight, a second for the wider Latin letters. */
@font-face {
  font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url('../vendor/inter/inter-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url('../vendor/inter/inter-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

:root {
  --c-primary: rgb(139,197,193); --c-primary-light: rgb(93,138,139); --c-primary-dark: rgb(26,47,48);
  --c-text: rgb(18,47,45); --c-text-2: rgba(18,47,45,.7); --c-surface: rgba(248,248,248,.9); --c-card: rgba(255,255,255,.72);
  --c-border: rgba(0,0,0,.1); --c-input-bg: rgba(255,255,255,.85); --c-input-border: rgba(0,0,0,.15);
  --c-accent: #3fa66a; --c-warn: #e0a100; --c-error: #d64545;
  --radius-card: 12px; --radius-ctl: 8px; --font: 'Inter', system-ui, sans-serif;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --shadow-1: 0 1px 3px rgba(0,0,0,.05); --shadow-2: 0 4px 8px rgba(0,0,0,.08); --shadow-3: 0 10px 20px rgba(0,0,0,.12);
  --topbar-h: 64px; --sidebar-w: 320px; --rightcol-w: 132px;

  /* Derived layout values (not part of the shared token set). */
  --gap: var(--space-4);
  --content-top: calc(var(--gap) * 2 + var(--topbar-h));
  --focus-ring: 0 0 0 4px rgba(139,197,193,.5);
  --ctl-h: 40px;
  --c-primary-dark-hover: rgb(44,76,78);
  --c-warn-bg: rgba(224,161,0,.16);
  --c-error-bg: rgba(214,69,69,.12);
  --c-error-text: #a52a2a;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--c-text);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  /* v1's animated WebGL gradient, as plain CSS: primary-light to primary with a
     soft light patch, so there is no second WebGL context (research §9.2). */
  background-color: var(--c-primary);
  background-image:
    radial-gradient(ellipse 70% 60% at 22% 80%, rgba(255,255,255,.22), transparent 70%),
    radial-gradient(ellipse 60% 55% at 80% 18%, rgba(93,138,139,.35), transparent 70%),
    linear-gradient(120deg, var(--c-primary-light) 0%, var(--c-primary) 55%, rgb(168,214,210) 100%);
  background-attachment: fixed;
}

h1, h2, h3, p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

[hidden] { display: none !important; }

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

:focus-visible {
  outline: 2px solid var(--c-primary-dark);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}
:focus:not(:focus-visible) { outline: none; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--ctl-h);
  padding: 0 var(--space-4);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-ctl);
  background: rgba(255,255,255,.85);
  color: var(--c-text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: background-color .15s ease, box-shadow .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:hover { background: #fff; box-shadow: var(--shadow-2); border-color: rgba(0,0,0,.16); }
.btn:active { transform: translateY(1px); box-shadow: var(--shadow-1); }
.btn:disabled { opacity: .45; cursor: default; box-shadow: none; transform: none; background: rgba(255,255,255,.6); }

.btn-primary {
  background: var(--c-primary-dark);
  border-color: var(--c-primary-dark);
  color: #fff;
}
.btn-primary:hover { background: var(--c-primary-dark-hover); border-color: var(--c-primary-dark-hover); }

.btn-icon {
  width: var(--ctl-h);
  padding: 0;
}
.btn-icon svg { width: 20px; height: 20px; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.btn-ghost:hover { background: rgba(0,0,0,.05); box-shadow: none; border-color: transparent; }

.btn-danger { color: var(--c-error-text); }

.icon-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border: 1px solid var(--c-border); border-radius: var(--radius-ctl);
  background: rgba(255,255,255,.7);
  font-size: 20px; line-height: 1; color: var(--c-text-2);
  cursor: pointer;
}
.icon-close:hover { background: #fff; color: var(--c-text); }

/* A long press on a phone shows an icon button's name (ui/press-label.js, D49):
   above the button, or below it when there's no room (the top bar). */
.press-label {
  position: fixed;
  z-index: 200;
  max-width: calc(100vw - 16px);
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--c-primary-dark);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  box-shadow: var(--shadow-3);
}

/* ---------- Top bar ---------- */

.topbar {
  position: fixed;
  top: var(--gap);
  left: var(--gap);
  right: var(--gap);
  height: var(--topbar-h);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-3) 0 var(--space-4);
  background: var(--c-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-1);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.topbar-brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.logo-button {
  flex: none;
  width: 44px; height: 44px;
  padding: 2px;
  border: 0;
  border-radius: var(--radius-ctl);
  background: none;
  cursor: pointer;
}
.flowerpot-logo { display: block; width: 100%; height: 100%; fill: var(--c-text); transition: transform .3s ease; }
.logo-button:hover .flowerpot-logo { transform: scale(1.08); }

.topbar-titles {
  display: flex;
  align-items: baseline;
  gap: var(--space-4);
  min-width: 0;
}
.app-title { font-size: 20px; font-weight: 700; white-space: nowrap; }

.creator-credit {
  display: flex; align-items: center; gap: 3px;
  font-size: 13px; white-space: nowrap; color: var(--c-text);
}
.creator-credit a { color: var(--c-text); font-weight: 500; text-decoration: none; border-bottom: 1px solid transparent; }
.creator-credit a:hover { border-bottom-color: var(--c-primary-light); }
.heart-icon {
  width: 14px; height: 14px; fill: var(--c-primary-dark);
  animation: heartbeat 4s infinite; transform-origin: center;
}
@keyframes heartbeat {
  0%, 28%, 70%, 100% { transform: scale(1); }
  14%, 42% { transform: scale(1.1); }
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.topbar-actions .sep { width: var(--space-2); }
.label-phone { display: none; }
@media (min-width: 761px) { [data-phone-only] { display: none !important; } }

/* Logo menu and other small menus. */
.menu {
  position: absolute;
  z-index: 80;
  min-width: 200px;
  padding: var(--space-1);
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-ctl);
  box-shadow: var(--shadow-3);
}
#logo-menu { top: calc(100% + 6px); left: 0; }
.menu-item {
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%;
  min-height: 40px;
  padding: 0 var(--space-3);
  border: 0; border-radius: 6px;
  background: none;
  text-align: left; font-size: 14px; font-weight: 500;
  cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: rgba(139,197,193,.22); }
.menu-note { padding: var(--space-2) var(--space-3); font-size: 12px; color: var(--c-text-2); border-top: 1px solid var(--c-border); margin-top: var(--space-1); }
.menu-note a { color: inherit; }

/* ---------- Workspace ---------- */

#view {
  position: fixed;
  inset: 0;
  z-index: 0;
}
#scene {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}
/* The handles module puts its own elements in here; they take pointer events
   themselves, the empty overlay must not block orbiting. */
#overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.webgl-message { display: none; }
.no-webgl .webgl-message {
  display: block;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100% - 32px));
  padding: var(--space-5);
  background: var(--c-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-3);
  text-align: center;
}
.webgl-message h2 { font-size: 18px; margin-bottom: var(--space-2); }
.webgl-message p { font-size: 14px; color: var(--c-text-2); }
.no-webgl #panel, .no-webgl #chips, .no-webgl #rightcol, .no-webgl .topbar-actions { display: none; }

/* The step frame (ui/steps.js): the left panel on desktop, the controls area
   and the bottom bar on a phone. */
#panel {
  position: fixed;
  top: var(--content-top);
  left: var(--gap);
  bottom: var(--gap);
  width: var(--sidebar-w);
  z-index: 10;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-card);
}
#panel > .steps { flex: 1 1 auto; }

#chips {
  position: fixed;
  top: var(--content-top);
  right: calc(var(--gap) * 2 + var(--rightcol-w));
  z-index: 20;
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}

#rightcol {
  position: fixed;
  top: var(--content-top);
  right: var(--gap);
  bottom: var(--gap);
  width: var(--rightcol-w);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
#rightcol > * { pointer-events: auto; }

/* ---------- Chips (design §8.5) ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-ctl);
  background: var(--c-surface);
  box-shadow: var(--shadow-1);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.chip-warnings {
  min-width: 132px;
  cursor: pointer;
}
.chip-warnings:hover { background: #fff; }
/* With no warnings the chip still opens the card, for its rules (D44). */
.chip-warnings.is-none { color: var(--c-text-2); }
.chip-warnings.is-warn { background: rgb(252,241,212); border-color: rgba(224,161,0,.45); }
.chip-warnings.is-error { background: rgb(250,229,229); border-color: rgba(214,69,69,.45); }
.chip-warnings .chip-icon { color: #9a6c00; }
.chip-warnings.is-error .chip-icon { color: var(--c-error-text); }
/* Beads are coloured for one of the warnings. */
.chip-warnings.is-active { border-color: var(--c-primary-dark); box-shadow: inset 0 0 0 1px var(--c-primary-dark), var(--shadow-1); }
.chip-clear {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; margin-right: -4px;
  border-radius: 50%;
  background: var(--c-primary-dark); color: #fff;
  font-size: 13px; line-height: 1;
}

.chip-wrap { position: relative; }

/* On desktop the cards open below the chips over the history column, at the
   right edge of the window, where they stay clear of the pot (D22) as far as
   the window allows: the warnings card holds the rules too (D44), so it is
   tall. It scrolls when the window is short. */
.warn-card {
  position: fixed;
  top: calc(var(--content-top) + 42px);
  right: var(--gap);
  width: 300px;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - var(--content-top) - 42px - var(--gap));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-2);
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-3);
  z-index: 30;
}
.warn-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-1) var(--space-1) var(--space-2) var(--space-2);
  font-size: 13px; font-weight: 600;
}
.warn-card-head .icon-close { width: 32px; height: 32px; font-size: 18px; }
.warn-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }
.warn-item {
  display: flex; align-items: flex-start; gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-ctl);
  background: rgba(0,0,0,.03);
  text-align: left; font-size: 13px; line-height: 1.35;
  cursor: pointer;
}
.warn-item:hover { background: rgba(0,0,0,.06); }
.warn-item[aria-pressed="true"] { border-color: var(--c-primary-dark); background: #fff; }
.warn-item.is-static { cursor: default; }
.warn-item.is-static:hover { background: rgba(0,0,0,.03); }
.warn-dot { flex: none; width: 10px; height: 10px; margin-top: 4px; border-radius: 50%; background: var(--c-warn); }
.warn-item.is-error .warn-dot { background: var(--c-error); }
.warn-item.is-info .warn-dot { background: var(--c-primary-light); }
.warn-item.is-ok { color: var(--c-text-2); }
.warn-item.is-ok .warn-dot { background: var(--c-accent); }
.warn-hint { padding: var(--space-2) var(--space-2) var(--space-1); font-size: 12px; color: var(--c-text-2); }
.warn-none { margin: 0; padding: var(--space-1) var(--space-2) var(--space-2); font-size: 13px; color: var(--c-text-2); }

/* The rules (pattern studio D44): each one's fields sit under its warning's
   line, lined up with the text after the dot. */
.warn-rule-fields {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) var(--space-2) calc(var(--space-3) + 10px + var(--space-2));
  font-size: 13px;
}
.warn-rules { margin-top: var(--space-2); padding-top: var(--space-1); border-top: 1px solid var(--c-border); }
.warn-rules-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  min-height: 32px;
  padding: var(--space-1) var(--space-2);
  border: 0; border-radius: var(--radius-ctl);
  background: none;
  font-size: 13px; font-weight: 600; text-align: left;
  cursor: pointer;
}
.warn-rules-toggle:hover { background: rgba(0,0,0,.04); }
.warn-rules-chevron {
  width: 8px; height: 8px; margin: 0 4px 4px 0;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform .15s;
}
.warn-rules-toggle[aria-expanded="true"] .warn-rules-chevron { margin: 4px 4px 0 0; transform: rotate(-135deg); }
.warn-rules-list { margin-top: var(--space-1); }

/* The size chip opens the size card (issue #5). It shares the warnings
   card's frame, so on a phone it also opens over the controls (D22). */
.chip-size { cursor: pointer; color: var(--c-text); }
.chip-size:hover { background: #fff; }
.chip-size[aria-expanded="true"] { border-color: var(--c-primary-dark); }
.chip-size.is-static { cursor: default; }
.chip-size.is-static:hover { background: var(--c-surface); }
.size-card { width: 260px; }
.size-fields { display: grid; gap: var(--space-2); padding: 0 var(--space-2); }

/* ---------- First-visit tip (issue #2) ---------- */

.designs-tip {
  margin-bottom: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  background: #fff;
  box-shadow: var(--shadow-2);
  font-size: 13px;
  line-height: 1.4;
}
.designs-tip-text { margin: 0 0 var(--space-2); }
.designs-tip-actions { display: flex; gap: var(--space-2); }
/* The link note: the tip's card, one line with a × (any screen size). */
.link-note { display: flex; align-items: center; gap: var(--space-1); padding: var(--space-2) 0 var(--space-2) var(--space-3); }
.link-note .designs-tip-text { flex: 1; min-width: 0; margin: 0; }
.link-note .designs-tip-close { flex: none; width: 44px; height: 44px; border: 0; background: none; }
/* The ring shows where Designs lives: the button on desktop, the logo on a phone. */
.designs-hinted .designs-btn { box-shadow: 0 0 0 3px var(--c-accent); animation: designs-ring 2.4s ease-in-out 3; }
@keyframes designs-ring {
  0%, 100% { box-shadow: 0 0 0 3px var(--c-accent); }
  50% { box-shadow: 0 0 0 6px rgba(63,166,106,.25); }
}

/* ---------- History (design §8.4) ---------- */

.history-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 100%;
  padding: var(--space-2);
  background: var(--c-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-2);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.history-title {
  padding: var(--space-1) var(--space-1) var(--space-2);
  font-size: 13px;
  font-weight: 600;
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 2px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  min-height: 0;
}
.history-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 3px;
  border: 1px solid transparent;
  border-radius: var(--radius-ctl);
  background: transparent;
  font-size: 12px;
  color: var(--c-text-2);
  text-align: left;
  cursor: pointer;
}
.history-item:hover { background: rgba(255,255,255,.7); }
/* Inside the scrolling list an outer ring would be clipped. */
.history-item:focus-visible { outline: 2px solid var(--c-primary-dark); outline-offset: -2px; box-shadow: inset 0 0 0 4px rgba(139,197,193,.6); }
.history-item:disabled { cursor: default; opacity: .6; }
.history-item:disabled:hover { background: transparent; }
.history-item.is-current {
  border-color: var(--c-primary-dark);
  background: #fff;
  color: var(--c-text);
  font-weight: 600;
}
.history-thumb {
  flex: none;
  width: 52px; height: 52px;
  border-radius: 6px;
  /* White beads need a darker ground to read. */
  background: rgb(208,219,218);
  object-fit: contain;
  display: block;
}
.history-thumb.is-empty {
  background:
    linear-gradient(rgba(255,255,255,.6), rgba(255,255,255,.6)),
    repeating-linear-gradient(0deg, rgba(18,47,45,.05) 0 2px, transparent 2px 5px);
}
.history-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.history-more { display: none; }

/* Full history list on a phone, over the controls area and the step bar. */
.history-overlay {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--bottom-chrome, var(--panel-h, 60%));
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: rgb(250,250,250);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  box-shadow: 0 -6px 20px rgba(0,0,0,.12);
}
.history-overlay-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  border-bottom: 1px solid var(--c-border);
}
.history-overlay .history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom));
}
.history-overlay .history-item { flex-direction: column; align-items: center; padding: var(--space-1); min-height: 44px; }
.history-overlay .history-thumb { width: 100%; height: auto; aspect-ratio: 1; }

/* A short confirmation under the top bar ("Saved …"). */
.toast {
  position: fixed;
  top: calc(var(--gap) + var(--topbar-h) + var(--space-2));
  left: 50%;
  z-index: 70;
  max-width: calc(100vw - 32px);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-ctl);
  background: var(--c-primary-dark);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-3);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -4px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.is-shown { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Dialogs ---------- */

dialog {
  padding: 0;
  border: 0;
  border-radius: var(--radius-card);
  background: rgb(250,250,250);
  color: var(--c-text);
  box-shadow: var(--shadow-3);
}
dialog::backdrop {
  background: rgba(18,47,45,.32);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.small-dialog { width: min(400px, calc(100vw - 32px)); }
.small-dialog form { padding: var(--space-5); display: grid; gap: var(--space-4); }
.small-dialog h2 { font-size: 18px; font-weight: 600; }
.small-dialog p { font-size: 14px; color: var(--c-text-2); }
.small-dialog label { display: grid; gap: var(--space-1); font-size: 13px; font-weight: 500; }
.small-dialog input[type="text"] {
  height: 44px;
  padding: 0 var(--space-3);
  border: 1px solid var(--c-input-border);
  border-radius: var(--radius-ctl);
  background: var(--c-input-bg);
  font-size: 15px;
}
.small-dialog input[type="text"]:focus-visible { border-color: var(--c-primary-dark); outline: none; box-shadow: var(--focus-ring); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); }

/* Designs screen (design §8.3). */
#designs {
  width: min(980px, calc(100vw - 32px));
  max-height: min(86vh, 860px);
}
#designs[open] { display: flex; flex-direction: column; }
.designs-head {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-5) var(--space-3);
}
.designs-head h2 { font-size: 22px; font-weight: 700; }
.designs-hint { color: var(--c-text-2); font-size: 14px; margin-left: auto; }
.designs-body { padding: 0 var(--space-5) var(--space-5); overflow-y: auto; }
.designs-row-title {
  margin: var(--space-4) 0 var(--space-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--c-text-2);
}
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: var(--space-3);
}
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  background: #fff;
  box-shadow: var(--shadow-1);
  transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
.tile:hover { box-shadow: var(--shadow-2); border-color: rgba(0,0,0,.18); }
.tile-open {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--radius-card);
  background: none;
  text-align: left;
  cursor: pointer;
}
.tile-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  background: linear-gradient(180deg, rgb(219,228,227), rgb(198,211,210));
  object-fit: contain;
  display: block;
}
.tile-thumb.is-loading { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.tile-text { display: grid; gap: 2px; padding: var(--space-2) var(--space-3) var(--space-3); }
.tile-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-sub { font-size: 12px; color: var(--c-text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile.is-last { border-color: var(--c-primary-light); }
.tile-menu-btn {
  position: absolute;
  right: 6px;
  bottom: 8px;
  width: 36px; height: 36px;
  border: 0; border-radius: var(--radius-ctl);
  background: transparent;
  font-size: 18px; line-height: 1; letter-spacing: 1px;
  color: var(--c-text-2);
  cursor: pointer;
}
.tile-menu-btn:hover { background: rgba(0,0,0,.06); color: var(--c-text); }
/* Inside the tile's width, so the scrolling body never clips it. */
.tile .menu { left: 6px; right: 6px; bottom: 48px; min-width: 0; }
.tile-add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: 160px;
  border: 2px dashed rgba(18,47,45,.28);
  border-radius: var(--radius-card);
  background: rgba(255,255,255,.5);
  color: var(--c-text);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.tile-add:hover { background: #fff; border-color: var(--c-primary-dark); }
.tile-add small { font-weight: 400; color: var(--c-text-2); }
.designs-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
}
.storage-note {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  border-radius: var(--radius-ctl);
  background: rgba(139,197,193,.2);
  font-size: 13px;
}
.storage-note p { flex: 1; }

/* ---------- Phone (design §8.2, D22, D31; journey §7.5; mobile stage) ---------- */

@media (max-width: 760px) {
  :root {
    --gap: var(--space-2);
    --topbar-h: 56px;
    --ctl-h: 44px;
    --content-top: calc(var(--gap) * 2 + var(--topbar-h));
    /* The stage (mobile stage M1): the canvas fills the window and the pot is
       fitted between the top bar and the dock (main.js viewportRect). The
       settings sheet, when open, keeps the journey's one height per screen
       (C26), over the 64 px step bar; the warnings and history lists open at
       that height too. Nothing covers the pot (D22). */
    --bar-h: 64px;
    --controls-h: clamp(220px, 34dvh, 300px);
    --panel-h: calc(var(--controls-h) + var(--bar-h) + env(safe-area-inset-bottom));
    --rightcol-w: 68px;
  }

  /* Glass over the stage, without a backdrop blur: the canvas behind it
     redraws on every orbit frame, and a blur would follow each one. */
  .topbar { padding: 0 var(--space-2); gap: var(--space-2); background: rgba(248,248,248,.86); -webkit-backdrop-filter: none; backdrop-filter: none; box-shadow: 0 1px 6px rgba(0,0,0,.06); }
  .topbar-titles { display: none; }
  .topbar-actions { gap: 6px; }
  .label-desk { display: none; }
  .label-phone { display: inline; }
  .topbar-actions .btn:not(.btn-icon) { padding: 0 var(--space-3); }
  [data-desk-only] { display: none !important; }

  #view { inset: 0; }

  /* The dock or the sheet, over the step bar: as tall as what it holds. */
  #panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: auto;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
  }

  #chips {
    top: calc(var(--content-top) + var(--space-2));
    left: var(--space-2);
    right: auto;
    gap: 6px;
  }
  .chip { height: 30px; padding: 0 var(--space-2); font-size: 12px; }
  .chip-warnings { min-width: 0; }
  /* D22: the list opens over the controls area, never over the pot. */
  .warn-card {
    position: fixed;
    top: auto; left: 0; right: 0; bottom: 0;
    width: auto; max-width: none;
    max-height: var(--bottom-chrome, var(--panel-h));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--space-3) var(--space-3) calc(var(--space-3) + env(safe-area-inset-bottom));
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    background: rgb(250,250,250);
    box-shadow: 0 -6px 20px rgba(0,0,0,.12);
    z-index: 60;
  }
  .warn-card-head { font-size: 16px; }
  .warn-card-head .icon-close { width: 44px; height: 44px; }
  .warn-item { min-height: 44px; padding: var(--space-3); font-size: 15px; align-items: center; }
  .warn-dot { margin-top: 0; }
  .warn-hint { font-size: 13px; }
  .warn-none { font-size: 15px; }
  .warn-rule-fields { padding-right: 0; font-size: 14px; }
  .warn-rules-toggle { min-height: 44px; font-size: 15px; }
  .size-card { width: auto; }
  .size-fields { padding: 0; }

  /* One line with a close button at the top of the controls (C36). */
  .designs-tip {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    min-height: 44px;
    margin-bottom: var(--space-2);
    padding: 0 0 0 var(--space-3);
    border-radius: var(--radius-ctl);
    box-shadow: none;
  }
  .designs-tip-text { flex: 1; min-width: 0; margin: 0; font-size: 12px; line-height: 1.3; }
  .designs-tip-close { flex: none; width: 44px; height: 44px; border: 0; background: none; }
  .designs-hinted .logo-button { border-radius: var(--radius-ctl); box-shadow: 0 0 0 3px var(--c-accent); animation: designs-ring 2.4s ease-in-out 3; }

  #rightcol {
    top: calc(var(--content-top) + var(--space-2));
    bottom: auto;
    right: var(--space-2);
    height: auto;
    width: var(--rightcol-w);
    gap: 6px;
  }
  .history-card { padding: 4px; cursor: pointer; max-height: none; flex: 0 1 auto; overflow: hidden; }
  .history-title { display: none; }
  .history-card .history-list { overflow: hidden; gap: 4px; padding: 0; }
  .history-card li:nth-child(n + 4) { display: none; }
  .history-card .history-item { flex-direction: column; gap: 0; padding: 2px; }
  .history-card .history-thumb { width: 100%; height: auto; aspect-ratio: 1; max-height: 52px; }
  .history-card .history-time { font-size: 11px; }
  .history-more { display: block; font-size: 11px; text-align: center; color: var(--c-text-2); padding-top: 2px; }

  #designs { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .designs-head { flex-wrap: wrap; padding: var(--space-4) var(--space-4) var(--space-2); gap: var(--space-2); }
  .designs-head h2 { font-size: 20px; }
  .designs-hint { order: 3; width: 100%; margin-left: 0; }
  .designs-head .icon-close { margin-left: auto; }
  .designs-body { padding: 0 var(--space-4) var(--space-4); }
  .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
  .tile-add { min-height: 130px; }
}

/* The chips in the phone top bar (mobile stage M2), between the logo and
   undo, where the bar had room: ✓ or a count, and the size without "mm"
   (their accessible names keep the full text). Narrower than 360 px they
   stay under the bar. */
.chip-short { display: none; }
@media (max-width: 760px) and (min-width: 360px) {
  #chips {
    top: calc(var(--gap) + (var(--topbar-h) - 32px) / 2);
    left: calc(var(--gap) + var(--space-2) + 44px + var(--space-2));
    z-index: 55;
  }
  .chip { height: 32px; padding: 0 8px; font-size: 12.5px; }
  .chip-warnings { min-width: 36px; }
  .chip-warnings .chip-long, .chip-size .chip-unit { display: none; }
  .chip-warnings .chip-short { display: inline; font-weight: 600; }
  .chip-warnings.is-none .chip-short { color: color-mix(in srgb, var(--c-accent) 72%, #000); font-size: 15px; }
  #rightcol { top: calc(var(--gap) * 2 + var(--topbar-h) + var(--space-1)); }
}

/* A short screen (a phone held sideways) keeps some room for the pot. */
@media (max-width: 760px) and (max-height: 520px) {
  :root { --controls-h: 160px; }
}

@media (pointer: coarse) {
  :root { --ctl-h: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
