:root {
  color-scheme: light;
  --ink: #123047;
  --ink-soft: #38576d;
  --muted: #60788a;
  --sea: #087fba;
  --sky: #18b7eb;
  --lagoon: #0b9899;
  --foam: #effdff;
  --glass: rgba(247, 254, 250, 0.86);
  --glass-strong: rgba(255, 252, 240, 0.96);
  --sand: #ffe4a8;
  --sand-deep: #efbb5c;
  --coral: #ff5f82;
  --orange: #ff792f;
  --gold: #f5b91d;
  --green: #43b96b;
  --danger: #d94d55;
  --line: rgba(13, 111, 143, 0.22);
  --shadow: 0 18px 46px rgba(18, 48, 71, 0.17);
  --shadow-small: 0 8px 22px rgba(18, 48, 71, 0.13);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --focus: #ff4f84;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  background:
    radial-gradient(circle at 86% 70px, rgba(255, 218, 65, 0.82) 0 62px, transparent 63px),
    radial-gradient(ellipse at 12% 180px, rgba(255, 255, 255, 0.72) 0 80px, transparent 82px),
    linear-gradient(180deg, var(--sky) 0 250px, #56cee8 251px 295px, #fff1c8 296px 100%);
}

body::before {
  content: "";
  position: fixed;
  z-index: 0;
  inset: 264px 0 auto;
  height: 40px;
  pointer-events: none;
  background: radial-gradient(circle at 18px 5px, rgba(255, 255, 255, 0.92) 0 16px, transparent 17px) 0 0 / 36px 36px repeat-x;
}

button, input, select { font: inherit; }
button { touch-action: manipulation; }
h1, h2, h3, p { margin-top: 0; }
a { color: inherit; }

.vfx-lab,
main,
.lab-header,
.lab-footer {
  position: relative;
  z-index: 1;
  width: min(1440px, 100%);
  margin-inline: auto;
  padding: clamp(20px, 4vw, 52px) clamp(14px, 3vw, 38px) 72px;
}

.lab-header,
.hero {
  max-width: 920px;
  margin-bottom: clamp(22px, 4vw, 38px);
  color: #fff;
}

.lab-header {
  width: min(1440px, 100%);
  max-width: 1440px;
  margin-inline: auto;
  padding-bottom: 0;
}

.lab-header__copy { max-width: 900px; }

.header-links {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 18px;
}

.header-links a {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 900;
  text-decoration: none;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 9px 13px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-weight: 900;
  transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

.eyebrow {
  display: inline-flex;
  margin-bottom: 12px;
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2.5rem, 7vw, 5.6rem);
  line-height: 0.92;
  letter-spacing: -0.045em;
  text-shadow: 0 8px 26px rgba(18, 48, 71, 0.3);
}

.lede,
.lab-header > p,
.hero > p {
  max-width: 760px;
  margin-bottom: 0;
  color: rgba(255, 255, 255, 0.95);
  font-size: clamp(1rem, 2vw, 1.2rem);
  font-weight: 700;
}

.lab-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.42fr) minmax(300px, 0.58fr);
  gap: clamp(16px, 2.5vw, 28px);
  align-items: start;
}

.panel,
.stage-panel,
.catalog-shell,
.effects-panel,
.catalog-panel {
  border: 1px solid rgba(239, 187, 92, 0.72);
  border-radius: var(--radius-xl);
  background: var(--glass-strong);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.1);
}

.stage-panel {
  position: sticky;
  top: 12px;
  overflow: clip;
  min-width: 0;
}

.catalog-panel { min-width: 0; overflow: clip; }

.section-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.section-heading h2 { margin: 0; font-size: clamp(1.15rem, 2vw, 1.5rem); }
.section-kicker { margin: 0 0 2px; color: var(--sea); font-size: 0.7rem; font-weight: 950; letter-spacing: 0.06em; text-transform: uppercase; }
.stage-metrics { display: flex; flex-wrap: wrap; gap: 6px; }
.catalog-note { max-width: 290px; margin: 0; color: var(--muted); font-size: 0.76rem; }

.stage-head,
.panel-head,
.catalog-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.stage-head h2,
.panel-head h2,
.catalog-head h2 { margin: 0; font-size: clamp(1.15rem, 2vw, 1.5rem); }

.stage-viewport,
.vfx-stage,
.stage-shell {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 520px;
  aspect-ratio: 16 / 10;
  border: 8px solid rgba(255, 255, 255, 0.62);
  border-radius: 22px;
  background:
    radial-gradient(circle at 28% 20%, rgba(255, 255, 255, 0.5), transparent 28%),
    linear-gradient(180deg, #47d0e8 0 34%, #1fb1ce 35% 42%, #ffe8ae 43% 100%);
}

#vfxCanvasHost {
  position: absolute;
  z-index: 25;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.stage-scene {
  position: absolute;
  z-index: 10;
  inset: 0;
}

#vfxCanvasHost canvas {
  position: absolute;
  z-index: 25;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
  pointer-events: none;
}

.hud,
.stage-hud,
.hud-layer {
  position: absolute;
  z-index: 30;
  inset: 12px 12px auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.hud-item,
.objective-chip,
.currency-chip,
.counter-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 7px 11px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  background: rgba(18, 48, 71, 0.86);
  color: #fff;
  box-shadow: var(--shadow-small);
  font-size: 0.8rem;
  font-weight: 900;
}

.game-board,
.board,
.board-grid,
.stage-board {
  position: absolute;
  z-index: 10;
  top: 20%;
  left: 50%;
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 70px;
  gap: clamp(5px, 1vw, 10px);
  width: min(84%, 620px);
  padding: clamp(10px, 2vw, 18px);
  border: 3px solid rgba(7, 104, 143, 0.28);
  border-radius: 24px;
  background: rgba(255, 244, 211, 0.82);
  box-shadow: 0 18px 34px rgba(18, 48, 71, 0.18), inset 0 0 0 3px rgba(255, 255, 255, 0.48);
  transform: translateX(-50%);
}

.cup-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(4px, 0.8vw, 9px);
  align-items: center;
}

.house {
  display: grid;
  place-items: center;
  min-width: 0;
  border: 2px solid rgba(18, 48, 71, 0.14);
  border-radius: 44% 44% 22px 22px;
  background: radial-gradient(circle, rgba(246, 185, 29, 0.34), transparent 52%), rgba(255, 225, 146, 0.9);
  color: #7e5b1b;
  font-size: 0.64rem;
  font-weight: 900;
  text-align: center;
}

.board-cell,
.cup {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  border: 2px solid rgba(18, 48, 71, 0.14);
  border-radius: 18px 18px 24px 24px;
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.94), rgba(255, 220, 145, 0.9));
  box-shadow: inset 0 -7px 0 rgba(225, 152, 65, 0.16), 0 5px 12px rgba(18, 48, 71, 0.1);
}

.board-cell::after,
.cup::after {
  content: "";
  width: 32%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fff 0 12%, #ff9878 14% 46%, #f25f72 48% 100%);
  box-shadow: 16px 7px 0 -3px #61c7ad, -13px 12px 0 -4px #ffcf38;
}

.cup > span { position: relative; z-index: 2; font-weight: 950; }
.cup--empty { border-style: dashed; opacity: 0.72; }
.cup--empty::after { opacity: 0.18; box-shadow: none; }

.stage-map-node {
  position: absolute;
  z-index: 20;
  right: 5%;
  bottom: 5%;
  display: grid;
  place-items: center;
  width: 64px;
  aspect-ratio: 1;
  border: 4px solid #fff;
  border-radius: 50%;
  background: linear-gradient(145deg, #ffe971, var(--gold));
  box-shadow: 0 0 0 7px rgba(255, 209, 42, 0.28), var(--shadow-small);
  color: #795300;
  font-weight: 950;
}

.map-preview {
  position: absolute;
  z-index: 20;
  left: 4%;
  bottom: 6%;
  display: flex;
  align-items: center;
}

.map-preview .map-node {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  aspect-ratio: 1;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #d2e1df;
  box-shadow: var(--shadow-small);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 950;
}

.map-node--done { background: var(--green) !important; color: #fff !important; }
.map-node--active { background: var(--gold) !important; box-shadow: 0 0 0 6px rgba(245, 185, 29, 0.22) !important; }
.map-node--locked { filter: grayscale(0.6); }
.map-path { width: clamp(16px, 3vw, 42px); height: 5px; background: rgba(18, 48, 71, 0.3); }

.coach,
.tide-coach,
.coach-card {
  position: absolute;
  z-index: 35;
  right: 12px;
  bottom: 12px;
  width: min(240px, 44%);
  padding: 12px 14px 12px 56px;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 18px;
  background: rgba(239, 253, 255, 0.94);
  box-shadow: var(--shadow-small);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 750;
}

.coach::before,
.tide-coach::before,
.coach-card::before {
  content: "🐚";
  position: absolute;
  left: 10px;
  top: 50%;
  display: grid;
  place-items: center;
  width: 38px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #9fe7e3;
  transform: translateY(-50%);
}

.coach-avatar {
  position: absolute;
  left: 10px;
  top: 50%;
  display: grid;
  place-items: center;
  width: 38px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #9fe7e3;
  color: #096b71;
  font-size: 0.68rem;
  font-weight: 950;
  transform: translateY(-50%);
}

.coach-card:has(.coach-avatar)::before { display: none; }
.coach-card strong, .coach-card span { display: block; }
.coach-card span { color: var(--muted); font-size: 0.7rem; }

.result-modal,
.stage-modal,
.modal-layer {
  position: absolute;
  z-index: 60;
  inset: 50% auto auto 50%;
  width: min(360px, calc(100% - 32px));
  padding: 24px;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 24px;
  background: rgba(255, 250, 232, 0.96);
  box-shadow: 0 24px 64px rgba(18, 48, 71, 0.3);
  text-align: center;
  transform: translate(-50%, -50%);
}

.result-preview {
  position: absolute;
  z-index: 35;
  inset: 50% auto auto 50%;
  display: none;
  width: min(360px, calc(100% - 32px));
  padding: 22px;
  border: 3px solid #fff;
  border-radius: 24px;
  background: rgba(255, 250, 232, 0.96);
  box-shadow: 0 24px 64px rgba(18, 48, 71, 0.3);
  text-align: center;
  transform: translate(-50%, -50%);
}

.result-preview strong, .result-preview span { display: block; }
.result-preview span { margin-top: 5px; color: var(--muted); font-size: 0.78rem; }
.result-preview.is-visible { display: block; }

.stage-overlay,
.effect-overlay,
.vfx-overlay {
  position: absolute;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.stage-title,
.combo-title,
.effect-label {
  padding: 8px 18px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--coral), var(--orange));
  box-shadow: 0 8px 0 rgba(183, 61, 74, 0.3), 0 18px 34px rgba(18, 48, 71, 0.2);
  color: #fff;
  font-size: clamp(1.15rem, 3vw, 2rem);
  font-weight: 950;
  text-transform: uppercase;
  transform: rotate(-2deg);
}

.control-bar,
.filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px 18px 18px;
  border-top: 1px solid var(--line);
  background: rgba(238, 253, 252, 0.6);
}

.control-bar { grid-template-columns: auto auto minmax(140px, 1fr) minmax(160px, 1fr); }

.catalog-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1.45fr) repeat(2, minmax(120px, 0.75fr));
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(238, 253, 252, 0.6);
}

.field,
.control-field,
.control-bar label,
.filters label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--ink-soft);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.02em;
}

#effectSearch,
#effectGroup,
#effectPriority,
#qualitySelect,
input[type="search"],
select {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid rgba(18, 48, 71, 0.22);
  border-radius: 12px;
  outline: none;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  font-weight: 750;
}

.toggle,
.motion-toggle {
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 9px !important;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
}

#reduceMotionToggle,
input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--lagoon);
}

button,
.button {
  min-height: 44px;
  padding: 9px 15px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--sea), var(--lagoon));
  box-shadow: 0 7px 16px rgba(8, 127, 186, 0.23);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, filter 150ms ease;
}

button:hover { filter: brightness(1.06) saturate(1.05); transform: translateY(-1px); }
button:active { transform: translateY(1px) scale(0.98); }
button:disabled { cursor: not-allowed; filter: grayscale(0.55); opacity: 0.55; transform: none; }
#playAllButton { background: linear-gradient(135deg, var(--orange), var(--coral)); }
#stopButton { background: var(--ink); }

.button-row,
.control-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  grid-column: 1 / -1;
}

.status-row,
.runtime-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
}

.status-chip,
#runtimeStatus {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid rgba(12, 141, 145, 0.26);
  border-radius: 999px;
  background: rgba(12, 141, 145, 0.12);
  color: #096b71;
  font-size: 0.74rem;
  font-weight: 900;
}

.status-chip::before,
#runtimeStatus::before {
  content: "";
  width: 8px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(67, 185, 107, 0.16);
}

.stage-metrics .status-chip::before { display: none; }
.runtime-status { margin: 0; border-radius: 0 !important; width: 100% !important; }

.status-chip.is-error,
#runtimeStatus.is-error { border-color: rgba(217, 77, 85, 0.3); background: rgba(217, 77, 85, 0.1); color: #a3303b; }
.status-chip.is-error::before,
#runtimeStatus.is-error::before { background: var(--danger); }

.catalog-shell,
.effects-panel { overflow: hidden; }

#effectGrid,
.effect-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  max-height: min(900px, calc(100vh - 80px));
  overflow: auto;
  padding: 16px;
  scrollbar-color: rgba(8, 127, 186, 0.42) transparent;
}

.effect-card {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 8px;
  min-height: 190px;
  padding: 15px;
  border: 1px solid rgba(18, 48, 71, 0.14);
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, #fff 0%, #fffaf0 100%);
  box-shadow: 0 5px 15px rgba(18, 48, 71, 0.08);
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.effect-card:hover,
.effect-card.is-active {
  border-color: rgba(8, 127, 186, 0.46);
  box-shadow: 0 11px 26px rgba(18, 48, 71, 0.14);
  transform: translateY(-2px);
}

.effect-card.is-active { outline: 3px solid rgba(24, 183, 235, 0.2); }
.effect-card[data-group="UI"],
.effect-card.ui { background: linear-gradient(145deg, #fff 0%, #edfcff 100%); }
.effect-card[hidden] { display: none; }

.effect-id {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font: 900 0.7rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.04em;
}

.effect-card h3,
.effect-name { margin: 0; font-size: 1rem; line-height: 1.25; }
.effect-card p,
.effect-description { margin: 0; color: var(--muted); font-size: 0.82rem; }

.effect-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 0.68rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.effect-meta > span,
.priority-chip,
.group-chip {
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(246, 185, 29, 0.18);
  color: #7d5900;
}

.effect-card button,
.effect-play { justify-self: start; min-height: 38px; padding: 7px 13px; font-size: 0.78rem; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

@media (max-width: 1020px) {
  .lab-layout { grid-template-columns: 1fr; }
  .stage-panel { position: relative; top: auto; }
  #effectGrid, .effect-grid { max-height: none; }
}

@media (max-width: 680px) {
  .vfx-lab, main { padding-inline: 10px; padding-bottom: 42px; }
  body::before { display: none; }
  .panel, .stage-panel, .catalog-shell, .effects-panel, .catalog-panel { border-radius: 20px; }
  .control-bar, .filters { grid-template-columns: 1fr; padding: 12px; }
  .button-row, .control-actions { grid-column: auto; }
  .stage-viewport, .vfx-stage, .stage-shell { min-height: 390px; border-width: 5px; }
  .game-board, .board, .board-grid, .stage-board { top: 23%; width: 94%; grid-template-columns: 52px minmax(0, 1fr) 52px; gap: 4px; padding: 8px; border-radius: 18px; }
  .board-cell, .cup { border-radius: 12px 12px 16px 16px; }
  .coach, .tide-coach, .coach-card { width: 58%; padding-left: 48px; }
  #effectGrid, .effect-grid { grid-template-columns: 1fr; padding: 12px; }
  .catalog-toolbar { grid-template-columns: 1fr; }
}

/* Mobile landscape: stage remains readable while controls stay reachable below it. */
@media (orientation: landscape) and (max-height: 620px) {
  body { background-position: center top; }
  .vfx-lab, main { padding-top: 14px; }
  .lab-header, .hero { margin-bottom: 14px; }
  .lab-header h1, .hero h1 { font-size: clamp(2rem, 8vh, 3rem); }
  .lab-header .lede, .hero .lede { font-size: 0.9rem; }
  .lab-layout { grid-template-columns: minmax(0, 1.2fr) minmax(290px, 0.8fr); gap: 12px; }
  .stage-panel { position: relative; top: auto; }
  .stage-viewport, .vfx-stage, .stage-shell { min-height: 300px; max-height: 68vh; }
  .control-bar, .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 10px; gap: 8px; }
  .button-row, .control-actions { grid-column: 1 / -1; }
  #effectGrid, .effect-grid { max-height: 82vh; grid-template-columns: 1fr; padding: 10px; }
  .effect-card { min-height: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  button:hover,
  .effect-card:hover,
  .effect-card.is-active { transform: none; }
}

body.reduce-motion *,
body.is-reduced-motion * {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

@media print {
  body { background: #fff; }
  body::before { display: none; }
  .vfx-lab, main { width: 100%; padding: 0; }
  .lab-header, .hero { color: var(--ink); }
  .lab-header > p, .hero > p { color: var(--ink-soft); }
  .lab-layout { display: block; }
  .stage-panel { position: static; break-inside: avoid; margin-bottom: 20px; }
  #effectGrid, .effect-grid { max-height: none; overflow: visible; grid-template-columns: repeat(3, 1fr); }
  button { box-shadow: none; }
}
