:root {
  --bg: #07070d;
  --panel: rgba(18, 18, 28, 0.55);
  --panel-brd: rgba(255, 255, 255, 0.08);
  --panel-hi: rgba(255, 255, 255, 0.14);
  --text: #eef0f7;
  --text-dim: #9aa0b5;
  --accent: #ffb454;
  --accent-2: #6ce5ff;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ---------- Stage / Canvas ---------- */
#stage { position: fixed; inset: 0; cursor: none; }

#sim, #glow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
#glow {
  mix-blend-mode: screen;
  pointer-events: none;
  opacity: 1;
  filter: blur(4px) brightness(1.18);
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 120% at 50% 38%, transparent 55%, rgba(0,0,0,0.55) 100%),
    linear-gradient(to bottom, rgba(10,12,24,0.25), transparent 22%);
  z-index: 2;
  transition: box-shadow 1.3s ease;   /* mood states fade in/out like atmosphere */
}

#cursor-ring {
  position: absolute;
  top: 0; left: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 5;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 0 12px rgba(255,255,255,0.3);
  transition: border-color .18s ease, box-shadow .18s ease;   /* glows in the held material's colour */
}

/* "Get in your element" — the invitation that breathes over the finished oasis */
#cine-cta {
  position: absolute; left: 0; right: 0; top: 34%;
  text-align: center; pointer-events: none;
  opacity: 0; transition: opacity 1.8s ease; z-index: 4;
}
#cine-cta .cta-title {
  font-size: clamp(24px, 4.4vw, 56px); font-weight: 800; letter-spacing: 0.03em;
  color: #eef4ff;
  text-shadow: 0 2px 34px rgba(150,186,255,0.55), 0 1px 6px rgba(0,0,0,0.45);
}
#cine-cta .cta-sub {
  margin-top: 12px; font-size: clamp(11px, 1.3vw, 14px);
  letter-spacing: 0.26em; text-transform: uppercase;
  color: rgba(206,220,246,0.72); animation: ctaPulse 2.6s ease-in-out infinite;
}
@keyframes ctaPulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

/* ---------- Shared panel ---------- */
.panel {
  position: fixed;
  z-index: 10;
  background: var(--panel);
  border: 1px solid var(--panel-brd);
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 1px 0 var(--panel-hi);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
}

/* ---------- Top bar ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  pointer-events: none;
}
.brand {
  display: flex; align-items: center; gap: 13px; pointer-events: auto;
  background: none; border: none; padding: 5px 7px; margin: -5px -7px;
  border-radius: 12px; cursor: pointer; font: inherit; color: inherit;
  text-align: left; transition: background .15s ease;
}
.brand:hover { background: rgba(255,255,255,0.06); }
.brand:hover .brand-text h1 { filter: brightness(1.12); }
.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 6px);
  gap: 3px;
  padding: 9px;
  border-radius: 12px;
  background: linear-gradient(150deg, rgba(255,180,84,0.22), rgba(108,229,255,0.16));
  border: 1px solid var(--panel-brd);
}
.brand-mark span {
  width: 6px; height: 6px; border-radius: 2px;
  background: var(--accent);
  animation: fall 2.4s infinite ease-in-out;
}
.brand-mark span:nth-child(2){ background: var(--accent-2); animation-delay: .3s; }
.brand-mark span:nth-child(3){ background: #ff7a7a; animation-delay: .6s; }
@keyframes fall {
  0%, 100% { transform: translateY(0); opacity: .5; }
  50% { transform: translateY(3px); opacity: 1; }
}
.brand-text h1 {
  font-size: 18px; font-weight: 700; letter-spacing: -0.02em;
  background: linear-gradient(90deg, #fff, #cfd5ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-text p { font-size: 11px; color: var(--text-dim); letter-spacing: .04em; }

.stats { display: flex; gap: 10px; pointer-events: auto; }
.stat {
  display: flex; flex-direction: column; align-items: center;
  min-width: 64px; padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--panel-brd);
  border-radius: 12px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.stat-val { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 9px; text-transform: uppercase; letter-spacing: .12em; color: var(--text-dim); }

.topbar-right { display: flex; align-items: center; gap: 10px; pointer-events: auto; }
.trophy-btn {
  position: relative;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 13px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--panel-brd);
  color: var(--accent); cursor: pointer;
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  transition: background .14s ease, border-color .14s ease, transform .1s ease;
}
.trophy-btn:hover { background: rgba(255,180,84,0.14); border-color: rgba(255,180,84,0.4); }
.trophy-btn:active { transform: scale(0.96); }
.trophy-btn svg { width: 16px; height: 16px; fill: currentColor; }
.trophy-count { font-size: 13px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.trophy-btn.has-new::after {
  content: ""; position: absolute; top: -3px; right: -3px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent-2); border: 2px solid var(--bg);
  box-shadow: 0 0 8px var(--accent-2);
}

/* "Next challenge" nudge in the top bar */
.next-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--panel-brd);
  color: var(--text-dim); cursor: pointer;
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  transition: background .14s ease, border-color .14s ease, transform .1s ease;
  max-width: 230px; overflow: hidden;
}
.next-chip:hover { background: rgba(255,180,84,0.1); border-color: rgba(255,180,84,0.34); }
.next-chip:active { transform: scale(0.97); }
.next-chip .nc-label { font-size: 9px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.next-chip .nc-icon { font-size: 14px; }
.next-chip .nc-title { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 860px) { .next-chip { display: none !important; } }

/* Challenge tier headers */
.challenge-tier {
  display: flex; align-items: center; justify-content: space-between;
  margin: 14px 2px 5px; padding-bottom: 4px;
  border-bottom: 1px solid var(--panel-brd);
  font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent);
}
.challenge-tier:first-child { margin-top: 2px; }
.challenge-tier-count { color: var(--text-dim); font-weight: 700; letter-spacing: .04em; }

.panel-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--text-dim); text-align: center; margin-bottom: 10px;
}

/* ---------- Material palette ---------- */
#palette {
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  padding: 12px 12px 12px;
  width: 274px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  gap: 9px;
  overflow: hidden;
}
.palette-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.palette-head .panel-title { margin-bottom: 0; text-align: left; }
.palette-book {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 10px;
  border: 1px solid var(--panel-brd);
  background: rgba(255,180,84,0.12);
  color: var(--accent);
  cursor: pointer;
  transition: background .14s ease, border-color .14s ease, transform .1s ease;
  flex: 0 0 auto;
}
.palette-book:hover { background: rgba(255,180,84,0.22); border-color: var(--accent); }
.palette-book svg { width: 16px; height: 16px; fill: currentColor; }

/* search */
.palette-search { position: relative; display: flex; align-items: center; }
.palette-search .search-ic {
  position: absolute; left: 9px; width: 14px; height: 14px;
  fill: var(--text-dim); pointer-events: none;
}
#mat-search {
  width: 100%; padding: 8px 28px 8px 28px;
  border-radius: 10px; border: 1px solid var(--panel-brd);
  background: rgba(255,255,255,0.04); color: var(--text);
  font-family: var(--font); font-size: 12px; outline: none;
  transition: border-color .14s ease, background .14s ease;
}
#mat-search::placeholder { color: var(--text-dim); }
#mat-search:focus { border-color: var(--accent-2); background: rgba(255,255,255,0.07); }
.search-clear {
  position: absolute; right: 6px; width: 20px; height: 20px;
  border: none; border-radius: 6px; background: transparent;
  color: var(--text-dim); font-size: 16px; line-height: 1; cursor: pointer;
  display: none;
}
.search-clear.show { display: block; }
.search-clear:hover { color: var(--text); }

/* category tabs */
.palette-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.ptab {
  flex: 1 1 auto; padding: 6px 8px; border-radius: 9px;
  border: 1px solid var(--panel-brd); background: rgba(255,255,255,0.02);
  color: var(--text-dim); font-size: 10px; font-weight: 700; letter-spacing: .03em;
  text-transform: uppercase; cursor: pointer; white-space: nowrap;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.ptab:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.ptab.active { background: var(--accent-2); color: #04222b; border-color: var(--accent-2); }

/* material grid */
#material-grid-wrap {
  flex: 1 1 auto; overflow-y: auto; overflow-x: hidden;
  min-height: 64px; max-height: 48vh; padding-right: 2px;
}
.material-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.mat-empty { padding: 20px 6px; text-align: center; color: var(--text-dim); font-size: 11px; }
/* sticky, click-to-collapse sub-section headers — turn each long tab into a scannable table of contents */
.mat-sec {
  position: sticky; top: 0; z-index: 2; width: 100%;
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 4px 5px; margin-top: 8px; cursor: pointer; border: 0;
  font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-dim); background: linear-gradient(rgb(22,22,32) 66%, rgba(22,22,32,0));
}
.mat-sec:first-child { margin-top: 0; }
.mat-sec:hover { color: var(--text); }
.mat-sec-caret { width: 7px; height: 7px; border-right: 2px solid; border-bottom: 2px solid; transform: rotate(45deg); opacity: .55; transition: transform .15s; }
.mat-sec.collapsed .mat-sec-caret { transform: rotate(-45deg); }
.material-grid + .mat-sec { margin-top: 4px; }
/* recent-picks strip (zero-config favourites), pinned above the grid */
.recent-strip { flex: 0 0 auto; display: flex; align-items: center; gap: 5px; overflow-x: auto; overflow-y: hidden; padding: 3px 0 8px; margin-bottom: 2px; touch-action: pan-x; border-bottom: 1px solid var(--panel-brd); }
.recent-strip[hidden] { display: none; }
.recent-strip .mat { flex: 0 0 auto; width: 38px; height: 38px; padding: 0; justify-content: center; }
.recent-strip .mat .mat-name { display: none; }
.mat {
  display: flex; flex-direction: row; align-items: center; gap: 8px; min-width: 0;
  padding: 7px 8px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.025);
  cursor: pointer; text-align: left;
  transition: transform .1s ease, background .15s ease, border-color .15s ease;
}
.mat:hover { background: rgba(255,255,255,0.08); transform: translateY(-1px); }
.mat.active {
  border-color: var(--swatch);
  background: rgba(255,255,255,0.1);
  box-shadow: inset 0 0 0 1px var(--swatch);
}
.mat-swatch {
  width: 24px; height: 24px; border-radius: 7px; flex: 0 0 auto;
  background: var(--swatch-bg);
  box-shadow: inset 0 -4px 7px rgba(0,0,0,0.35), inset 0 2px 3px rgba(255,255,255,0.25);
}
.mat-swatch.rainbow {
  background: linear-gradient(120deg,#ff5d5d,#ffd24d,#5dff9b,#5dc9ff,#b86cff,#ff5d5d);
  background-size: 300% 300%;
  animation: huecycle 4s linear infinite;
}
@keyframes huecycle { 0%{background-position:0% 50%} 100%{background-position:300% 50%} }
.mat-name {
  font-size: 11px; line-height: 1.12; color: var(--text-dim); letter-spacing: .01em;
  text-align: left; overflow: hidden;
}
.mat.active .mat-name { color: var(--text); font-weight: 600; }

/* selected-material description — fixed height so it never reflows/jitters */
.palette-desc {
  border-top: 1px solid var(--panel-brd); padding-top: 9px;
  display: flex; flex-direction: column; gap: 3px;
  height: 90px; flex: 0 0 auto; overflow: hidden;   /* room for a full 3-line blurb + the whisper hint (was 64px → clipped the 3rd line) */
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 13px), transparent);   /* a rare extra-long blurb trails off in a soft fade instead of a hard mid-word cut */
          mask-image: linear-gradient(to bottom, #000 calc(100% - 13px), transparent);
}
.mat-desc-name { font-size: 12px; font-weight: 700; color: var(--text); }
.mat-desc-text { font-size: 10px; line-height: 1.4; color: var(--text-dim); }
.mat-whisper { color: var(--accent); font-style: italic; opacity: .9; }

/* ---------- Side panel (forces + scene) ---------- */
#sidepanel {
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  padding: 14px;
  width: 158px;
  display: flex; flex-direction: column; gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label {
  font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em;
  display: flex; justify-content: space-between; align-items: center;
}
.field-label em { font-style: normal; color: var(--accent-2); font-weight: 700; }

.compass {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 5px;
  width: 110px; margin: 0 auto;
}
.cmp {
  display: grid; place-items: center;
  aspect-ratio: 1; border-radius: 9px;
  border: 1px solid var(--panel-brd);
  background: rgba(255,255,255,0.03);
  color: var(--text-dim); font-size: 15px; cursor: pointer;
  transition: all .12s ease;
}
.cmp:hover { background: rgba(255,255,255,0.1); color: var(--text); }
.cmp.active { background: var(--accent-2); color: #04222b; border-color: var(--accent-2); font-weight: 700; }
/* place compass buttons: up, left, zero, right, down */
.cmp:nth-child(1){ grid-area: 1 / 2; }
.cmp:nth-child(2){ grid-area: 2 / 1; }
.cmp:nth-child(3){ grid-area: 2 / 2; }
.cmp:nth-child(4){ grid-area: 2 / 3; }
.cmp:nth-child(5){ grid-area: 3 / 2; }

.seg { display: flex; gap: 4px; width: 100%; }
.seg button {
  flex: 1 1 0; min-width: 0; padding: 6px 2px; border-radius: 8px;
  border: 1px solid var(--panel-brd); background: rgba(255,255,255,0.03);
  color: var(--text-dim); font: 700 9px var(--font); letter-spacing: 0;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: clip;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.seg button:hover { background: rgba(255,255,255,0.09); color: var(--text); }
.seg button.active { background: var(--accent-2); color: #04222b; border-color: var(--accent-2); }

.btn-col { display: flex; flex-direction: column; gap: 7px; }
.btn-row { display: flex; gap: 7px; }
.btn-row .mini { flex: 1; justify-content: center; }
/* mobile-only chrome — the summon FAB + sheet backdrop are revealed by the ≤820px sheet model below */
#summon, #sheet-backdrop { display: none; }
.mini {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--panel-brd);
  background: rgba(255,255,255,0.03);
  color: var(--text); font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .14s ease, border-color .14s ease;
}
.mini:hover { background: rgba(255,255,255,0.1); border-color: var(--panel-hi); }
.mini svg { width: 16px; height: 16px; fill: currentColor; flex: 0 0 auto; }
.mini.on { background: var(--accent); color: #2a1800; border-color: var(--accent); }

/* ---------- Dock ---------- */
#dock {
  bottom: calc(22px + env(safe-area-inset-bottom));   /* clear the iOS home indicator */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
}
.dock-group { display: flex; align-items: center; gap: 8px; }
.dock-divider { width: 1px; height: 26px; background: var(--panel-brd); margin: 0 4px; }
.ctrl {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 42px; min-width: 42px; padding: 0 12px;
  border: 1px solid var(--panel-brd);
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  color: var(--text);
  cursor: pointer;
  transition: background .14s ease, transform .1s ease, border-color .14s ease;
}
.ctrl:hover { background: rgba(255,255,255,0.1); border-color: var(--panel-hi); }
.ctrl:active { transform: scale(0.94); }
.ctrl svg { width: 20px; height: 20px; fill: currentColor; }
.ctrl-text { font-size: 13px; font-weight: 600; }
.ctrl-text svg { width: 17px; height: 17px; }

#btn-play .ic-play { display: none; }
#btn-play.paused .ic-pause { display: none; }
#btn-play.paused .ic-play { display: block; }
#btn-play { color: var(--accent); }

.dock-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .1em; }
.dock-readout {
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  min-width: 22px; text-align: center; color: var(--accent-2);
}

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 120px; height: 5px; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent-2), rgba(255,255,255,0.12));
  outline: none; cursor: pointer;
}
#wind { width: 100%; background: linear-gradient(90deg, #6ce5ff, rgba(255,255,255,0.15), #ffb454); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 17px; height: 17px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent-2);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4); cursor: grab;
}
input[type="range"]::-moz-range-thumb {
  width: 17px; height: 17px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent-2); cursor: grab;
}

/* ---------- Hint ---------- */
#hint {
  position: fixed;
  bottom: 80px; left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  font-size: 12px; color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--panel-brd);
  border-radius: 999px;
  padding: 8px 18px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  white-space: nowrap;
  transition: opacity .6s ease, transform .6s ease;
}
#hint.hide { opacity: 0; transform: translate(-50%, 10px); pointer-events: none; }
#hint kbd {
  font-family: var(--font); font-size: 11px; color: var(--text);
  background: rgba(255,255,255,0.08); border: 1px solid var(--panel-brd);
  border-radius: 6px; padding: 1px 6px; margin: 0 1px;
}

/* ---------- Alchemy booklet ---------- */
.booklet {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.booklet.hidden { display: none; }
.booklet-backdrop {
  position: absolute; inset: 0;
  background: rgba(4, 4, 10, 0.62);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.booklet-panel {
  position: relative; z-index: 1;
  width: min(420px, 92vw);
  max-height: min(78vh, 680px);
  display: flex; flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.booklet-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding: 16px 16px 10px;
  border-bottom: 1px solid var(--panel-brd);
}
.booklet-head h2 {
  font-size: 17px; font-weight: 700; letter-spacing: -0.02em;
  background: linear-gradient(90deg, #fff, #ffd4a0);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.booklet-head p { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.booklet-close {
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--panel-brd);
  background: rgba(255,255,255,0.04);
  color: var(--text); font-size: 22px; line-height: 1; cursor: pointer;
}
.booklet-close:hover { background: rgba(255,255,255,0.1); }
.booklet-tabs {
  display: flex; gap: 6px; padding: 10px 16px 0;
}
.btab {
  flex: 1; padding: 8px 10px; border-radius: 10px 10px 0 0;
  border: 1px solid transparent; border-bottom: none;
  background: transparent; color: var(--text-dim);
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  cursor: pointer;
}
.btab.active {
  color: var(--text);
  background: rgba(255,255,255,0.05);
  border-color: var(--panel-brd);
}
.booklet-body {
  flex: 1; overflow-y: auto; overflow-x: hidden; touch-action: pan-y;   /* restore iOS momentum scroll (html/body set touch-action:none) */
  padding: 12px 16px 8px;
  border-top: 1px solid var(--panel-brd);
}
.booklet-body.hidden { display: none; }
.booklet-foot {
  padding: 10px 16px 14px;
  border-top: 1px solid var(--panel-brd);
}
.reveal-toggle {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--text-dim); cursor: pointer;
}
.reveal-toggle input { accent-color: var(--accent); }

.recipe-group { margin-bottom: 14px; }
.recipe-group-title {
  font-size: 9px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--accent-2); margin-bottom: 7px;
}
.recipe {
  display: grid; grid-template-columns: auto 1fr;
  gap: 10px; align-items: start;
  padding: 9px 10px; margin-bottom: 6px;
  border-radius: 12px;
  border: 1px solid var(--panel-brd);
  background: rgba(255,255,255,0.03);
}
.recipe.locked { opacity: 0.72; }
.recipe.unlocked { border-color: rgba(255,180,84,0.25); }
.recipe.starter { border-color: rgba(108,229,255,0.22); }
.recipe-badge {
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center; font-size: 14px;
  background: rgba(255,255,255,0.06);
}
.recipe.unlocked .recipe-badge { background: rgba(255,180,84,0.16); }
.recipe-name { font-size: 12px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.recipe-formula { font-size: 11px; color: var(--accent-2); line-height: 1.35; }
.recipe-note { font-size: 10px; color: var(--text-dim); margin-top: 3px; line-height: 1.35; }
.recipe-formula.unknown { color: var(--text-dim); font-style: italic; }

/* progress bar */
.booklet-head-text { min-width: 0; }
.booklet-progress {
  margin-top: 7px; height: 5px; width: 170px; max-width: 100%;
  border-radius: 999px; background: rgba(255,255,255,0.09); overflow: hidden;
}
#discover-bar {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  border-radius: 999px; transition: width .45s ease;
}

/* ingredient chips */
.recipe-main { min-width: 0; }
.recipe-group-count { float: right; color: var(--text-dim); letter-spacing: .04em; font-weight: 700; }
.recipe-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 5px 0 3px; }
.ing {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 7px 2px 3px; border-radius: 999px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--panel-brd);
  font-size: 10px; font-weight: 600; color: var(--text); white-space: nowrap;
}
.ing-sw {
  width: 13px; height: 13px; border-radius: 4px; flex: 0 0 auto;
  box-shadow: inset 0 -2px 3px rgba(0,0,0,0.35), inset 0 1px 2px rgba(255,255,255,0.25);
}
.ing-sw-q {
  display: grid; place-items: center; font-size: 9px; font-weight: 800;
  color: var(--text-dim); background: rgba(255,255,255,0.08); box-shadow: none;
}
.ing-q { color: var(--text-dim); padding-right: 5px; }
.ing-x { color: var(--text-dim); padding-right: 7px; }
.ing-op { font-size: 10px; color: var(--text-dim); font-weight: 700; }
.ing-arrow { color: var(--accent); padding: 0 2px; font-size: 12px; }

/* NEW badge + highlight */
.recipe-new {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  border-radius: 999px; font-size: 8px; font-weight: 800; letter-spacing: .08em;
  background: var(--accent); color: #2a1800; vertical-align: middle;
}
.recipe.is-new { border-color: rgba(255,180,84,0.5); box-shadow: 0 0 0 1px rgba(255,180,84,0.22); }
.locked-name { color: var(--text-dim); }
.recipe-note.unknown { font-style: italic; color: var(--text-dim); }

.mat-entry {
  display: grid; grid-template-columns: 32px 1fr;
  gap: 10px; align-items: start;
  padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.mat-entry:last-child { border-bottom: none; }
.mat-entry-swatch {
  width: 32px; height: 32px; border-radius: 9px;
  box-shadow: inset 0 -4px 7px rgba(0,0,0,0.35), inset 0 2px 3px rgba(255,255,255,0.25);
}
.mat-entry-name { font-size: 12px; font-weight: 700; color: var(--text); }
.mat-entry-desc { font-size: 10px; color: var(--text-dim); line-height: 1.4; margin-top: 2px; }

/* ---------- Challenges modal ---------- */
.challenges-panel {
  position: relative; z-index: 1;
  width: min(440px, 92vw); max-height: min(80vh, 720px);
  display: flex; flex-direction: column; padding: 0; overflow: hidden;
}
.challenge {
  display: grid; grid-template-columns: 36px 1fr 26px;
  gap: 11px; align-items: center;
  padding: 11px 12px; margin-bottom: 7px;
  border-radius: 12px; border: 1px solid var(--panel-brd);
  background: rgba(255,255,255,0.03);
  transition: border-color .15s ease, background .15s ease;
}
.challenge.done { border-color: rgba(108,229,255,0.3); background: rgba(108,229,255,0.06); }
.challenge-icon { font-size: 21px; text-align: center; filter: grayscale(0.65); opacity: .75; }
.challenge.done .challenge-icon { filter: none; opacity: 1; }
.challenge-title { font-size: 13px; font-weight: 700; color: var(--text); }
.challenge.done .challenge-title { color: var(--accent-2); }
.challenge-desc { font-size: 11px; color: var(--text-dim); line-height: 1.35; margin-top: 2px; }
.challenge-check {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 800;
  border: 1.5px solid var(--panel-brd); color: transparent;
}
.challenge.done .challenge-check { background: var(--accent-2); color: #04222b; border-color: var(--accent-2); }

/* ---------- About modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 45;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(4, 4, 10, 0.64);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
}
.about-panel {
  position: relative; z-index: 1;
  width: min(420px, 92vw);
  padding: 32px 30px 26px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.about-close { position: absolute; top: 12px; right: 12px; }
.about-mark {
  display: grid; grid-template-columns: repeat(3, 9px); gap: 5px;
  padding: 12px; border-radius: 16px; margin-bottom: 16px;
  background: linear-gradient(150deg, rgba(255,180,84,0.22), rgba(108,229,255,0.16));
  border: 1px solid var(--panel-brd);
}
.about-mark span {
  width: 9px; height: 9px; border-radius: 3px;
  background: var(--accent); animation: fall 2.4s infinite ease-in-out;
}
.about-mark span:nth-child(2){ background: var(--accent-2); animation-delay: .3s; }
.about-mark span:nth-child(3){ background: #ff7a7a; animation-delay: .6s; }
.about-title {
  font-size: 26px; font-weight: 800; letter-spacing: -0.02em;
  background: linear-gradient(90deg, #fff, #ffd4a0);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.about-tag { font-size: 12px; color: var(--text-dim); letter-spacing: .06em; margin-top: 3px; }
.about-body {
  font-size: 12.5px; line-height: 1.6; color: var(--text); opacity: .92;
  margin: 18px 0 4px; max-width: 340px;
}
.about-body em { color: var(--accent-2); font-style: normal; }
.about-sign { font-size: 12px; color: var(--text-dim); margin: 14px 0 20px; }
.about-sign strong { color: var(--text); font-weight: 700; }
.about-links { display: flex; flex-direction: column; align-items: center; gap: 13px; width: 100%; }
.about-cta {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 24px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #ff8f5a);
  color: #2a1800; font-size: 13.5px; font-weight: 800; letter-spacing: .02em;
  text-decoration: none; box-shadow: 0 8px 24px rgba(255,150,70,0.3);
  transition: transform .12s ease, box-shadow .15s ease;
}
.about-cta:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(255,150,70,0.42); }
.about-arrow { font-weight: 700; font-size: 15px; }
.about-link2 {
  font-size: 11.5px; color: var(--text-dim); text-decoration: none;
  border-bottom: 1px solid transparent; transition: color .14s ease, border-color .14s ease;
}
.about-link2:hover { color: var(--text); border-color: var(--panel-hi); }

/* ---------- Author credit ---------- */
#credit {
  position: fixed; right: 14px; bottom: 12px; z-index: 8;
  font-size: 11px; letter-spacing: .02em; color: var(--text-dim);
  text-decoration: none; opacity: 0.55;
  padding: 4px 8px; border-radius: 999px;
  background: rgba(10, 12, 24, 0.35);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: opacity .2s ease, color .2s ease;
  pointer-events: auto;
}
#credit strong { color: var(--text); font-weight: 600; }
#credit:hover { opacity: 1; color: var(--text); }
@media (max-width: 680px) { #credit { display: none; } }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  #palette { width: 252px; }
  #sidepanel { width: 140px; }
}
/* ====== Mobile / portrait-tablet / landscape-PHONE: canvas is the star; menus become summoned bottom-sheets.
   Gated on width OR height so a short LANDSCAPE phone (wide but ≤600 tall) gets sheets instead of cramped rails. ====== */
@media (max-width: 820px), (max-height: 600px) {
  #stats { display: none; } .brand-text p { display: none; } #hint { display: none; }
  /* the 2-segment summon FAB, thumb-reachable above the dock; content inline + centred so the label never wraps */
  #summon {
    display: flex; position: fixed; left: 10px; bottom: calc(86px + env(safe-area-inset-bottom));
    z-index: 47; border-radius: 14px; overflow: hidden; padding: 0;
  }
  .summon .seg {
    display: flex; align-items: center; justify-content: center; white-space: nowrap;
    min-height: 44px; padding: 0 16px; font-size: 13px; font-weight: 600;
    background: transparent; color: var(--text-dim); border: 0; cursor: pointer;
  }
  .summon .seg.on { background: var(--accent-2); color: #04222b; }
  /* the dimming backdrop behind an open sheet */
  #sheet-backdrop { display: block; position: fixed; inset: 0; background: rgba(4,4,10,.5); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 45; }
  body.sheet-open #sheet-backdrop { opacity: 1; pointer-events: auto; }
  body.sheet-open #dock { display: none; }   /* the sheet's own controls + backdrop-tap suffice — avoids z-index fighting */
  body.sheet-open #summon { display: none; }   /* the open sheet IS the menu; close it by swiping the handle, tapping the backdrop, or Esc */
  body.modal-open #summon { display: none; }   /* don't float the FAB over the About / Challenges modals */
  /* keep the control dock compact so it never overflows a narrow screen */
  #dock { max-width: calc(100vw - 16px); gap: 6px; padding: 7px 10px; }
  #dock .dock-label { display: none; }
  #dock #brush { width: 76px; }
  #dock .dock-divider { margin: 0 2px; }
  /* both panels become full-width bottom-sheets, slid off-screen until summoned */
  #palette, #sidepanel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    transform: translateY(110%); width: 100%; max-width: none; max-height: 72vh;
    border-radius: 18px 18px 0 0; padding-top: 24px; z-index: 46;
    transition: transform .26s cubic-bezier(.32,.72,0,1);
  }
  #palette::before, #sidepanel::before { content: ""; position: absolute; top: 9px; left: 50%; transform: translateX(-50%); width: 36px; height: 4px; border-radius: 3px; background: var(--panel-hi); }
  body.sheet-open[data-sheet="mat"]   #palette   { transform: translateY(0); }
  body.sheet-open[data-sheet="force"] #sidepanel { transform: translateY(0); }
  #palette.dragging, #sidepanel.dragging { transition: none; }
  #material-grid-wrap { max-height: 46vh; touch-action: pan-y; }
  .material-grid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); }   /* adapts: ~3 cols on a phone, more across a wide landscape sheet */
  .mat { min-height: 44px; } .mini { min-height: 44px; }
  .btn-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }   /* Forces scene buttons as a 2-col tile grid */
  .btn-row { grid-column: 1 / -1; }
}
@media (min-width: 681px) and (max-width: 820px) and (min-height: 601px) { #palette, #sidepanel { max-height: 60vh; } }   /* portrait tablet: a shorter sheet */
@media (max-height: 600px) { #palette, #sidepanel { max-height: 94vh; } #material-grid-wrap { max-height: 66vh; } }   /* landscape phone: use most of the scarce height */
@media (min-width: 821px) and (max-width: 1024px) and (min-height: 601px) { .mat { min-height: 44px; } .mini { min-height: 44px; } }   /* landscape tablet keeps the desktop rails with bigger touch targets */

/* === Accessibility (production-readiness review) === */
/* Keyboard-only focus ring — :focus-visible never matches mouse/touch, so pointer users stay ring-free while keyboard
   users get a clear ring on every control (sliders, buttons, links). */
button:focus-visible, a:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent-2); outline-offset: 2px;
}
/* Honour the OS "reduce motion" setting — neutralise the looping decorative animations (CTA pulse, falling dots, rainbow
   hue-cycle) for photosensitive / motion-sensitive users. Panel-slide transitions are kept (brief, non-flashing); the
   full-screen flash + screen-shake are gated in JS via prefersReducedMotion(). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
