:root {
  --paper: #f2efe7;
  --ink: #242724;
  --muted: #777a70;
  --line: #c9c7bd;
  --bubble: #66c7c2;
  --front: #b7d94b;
  --danger: #ee664f;
  --laser: #f1ad3d;
  --panel: rgba(242, 239, 231, 0.94);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }

#game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 520px;
  isolation: isolate;
  background: var(--paper);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.topbar {
  position: absolute;
  z-index: 4;
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  height: 42px;
  display: flex;
  align-items: center;
  gap: 20px;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 10px;
  line-height: .85;
  letter-spacing: .12em;
  font-weight: 950;
  pointer-events: auto;
}

.brand i {
  width: 26px;
  height: 26px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  box-shadow: inset -5px -5px 0 rgba(102, 199, 194, .75);
}

.stage-readout, .record-readout { display: grid; line-height: 1; }
.stage-readout { margin-left: auto; }
.topbar small { font-size: 8px; letter-spacing: .16em; color: var(--muted); font-weight: 900; }
.topbar strong { font-size: 17px; font-variant-numeric: tabular-nums; }

.icon-button {
  width: 49px;
  height: 32px;
  border: 1.5px solid var(--ink);
  border-radius: 99px;
  background: transparent;
  font-size: 8px;
  font-weight: 950;
  letter-spacing: .08em;
  pointer-events: auto;
}

.meters {
  position: absolute;
  z-index: 3;
  top: max(59px, calc(env(safe-area-inset-top) + 54px));
  left: 50%;
  width: min(360px, calc(100% - 44px));
  transform: translateX(-50%);
  display: grid;
  gap: 4px;
  pointer-events: none;
}

.meter-row { display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 8px; }
.meter-row > span { font-size: 8px; font-weight: 950; letter-spacing: .12em; text-align: right; }
.meter { height: 5px; background: rgba(36, 39, 36, .12); overflow: hidden; border-radius: 99px; }
.meter i { display: block; width: 100%; height: 100%; background: var(--bubble); transform-origin: left; transition: transform .15s linear; }
.front-meter i { background: var(--front); }

.hint, .toast {
  position: absolute;
  z-index: 4;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 11px;
  border: 1px solid rgba(36, 39, 36, .18);
  border-radius: 99px;
  background: var(--panel);
  font-size: 9px;
  line-height: 1;
  font-weight: 850;
  letter-spacing: .06em;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}

.hint { top: max(87px, calc(env(safe-area-inset-top) + 82px)); }
.hint.out { opacity: 0; transform: translate(-50%, -5px); }
.toast { top: 115px; opacity: 0; transform: translate(-50%, -4px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.build-panel {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  width: min(560px, calc(100% - 16px));
  transform: translateX(-50%);
  padding: 8px;
  border: 1.5px solid var(--ink);
  border-radius: 15px;
  background: var(--panel);
  box-shadow: 0 8px 25px rgba(36, 39, 36, .08);
  backdrop-filter: blur(8px);
}

.tool-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.tool {
  position: relative;
  min-width: 0;
  height: 49px;
  padding: 5px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: 1fr auto;
  align-items: center;
  cursor: pointer;
}
.tool:hover, .tool.is-active { border-color: var(--ink); background: white; }
.tool:disabled { opacity: .3; cursor: default; }
.tool > span { font-size: 7px; font-weight: 950; letter-spacing: .08em; text-align: left; }
.tool > b { font-size: 10px; }
.tool-icon { grid-column: 1 / -1; display: block; justify-self: center; }
.deflector-icon { width: 32px; height: 7px; border-radius: 99px; background: var(--ink); transform: rotate(-12deg); }
.fan-icon { font-style: normal; font-weight: 950; font-size: 13px; color: var(--bubble); letter-spacing: -2px; }
.spikes-icon { font-style: normal; font-size: 10px; font-weight: 950; color: var(--danger); letter-spacing: -3px; }
.laser-icon { width: 35px; height: 1px; border-top: 2px dotted var(--laser); position: relative; }
.laser-icon::before, .laser-icon::after { content: ""; position: absolute; top: -4px; width: 6px; height: 6px; border-radius: 50%; background: var(--ink); }
.laser-icon::before { left: -2px; }
.laser-icon::after { right: -2px; }

.edit-row, .action-row { display: flex; align-items: center; gap: 6px; }
.edit-row { margin-top: 6px; }
.edit-row span { font-size: 8px; font-weight: 950; letter-spacing: .1em; margin-right: auto; }
.edit-row button, .quiet-button {
  height: 31px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: transparent;
  font-size: 8px;
  font-weight: 950;
  letter-spacing: .07em;
}
.edit-row .remove { color: var(--danger); border-color: currentColor; }
.action-row { margin-top: 7px; }
.release-button {
  margin-left: auto;
  height: 38px;
  padding: 0 18px;
  border: 0;
  border-radius: 99px;
  background: var(--ink);
  color: var(--paper);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .12em;
}
.release-button:disabled { background: var(--danger); opacity: .45; }

.run-panel {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: max(13px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 7px;
  padding: 5px;
  border: 1px solid rgba(36, 39, 36, .25);
  border-radius: 99px;
  background: var(--panel);
}
.run-panel button {
  min-width: 100px;
  height: 35px;
  border: 0;
  border-radius: 99px;
  background: transparent;
  font-size: 9px;
  font-weight: 950;
  letter-spacing: .08em;
}
.run-panel button:first-child { background: var(--ink); color: var(--paper); }

.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(36, 39, 36, .32);
  backdrop-filter: blur(5px);
}
.overlay[hidden], [hidden] { display: none !important; }
.panel {
  width: min(330px, 100%);
  padding: 28px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 10px 10px 0 var(--ink);
  text-align: center;
}
.eyebrow { margin: 0 0 7px; color: var(--muted); font-size: 9px; font-weight: 950; letter-spacing: .16em; }
.panel h2 { margin: 0 0 19px; font-size: clamp(26px, 8vw, 38px); line-height: .9; letter-spacing: -.04em; }
.result-copy { margin: -8px 0 18px; font-size: 12px; color: var(--muted); }
.panel button { width: 100%; height: 43px; margin-top: 7px; border-radius: 99px; font-size: 10px; font-weight: 950; letter-spacing: .1em; }
.primary-button { border: 0; background: var(--ink); color: var(--paper); }
.secondary-button { border: 1.5px solid var(--ink); background: transparent; }
.text-button { border: 0; background: transparent; color: var(--muted); }

.debug {
  position: absolute;
  z-index: 8;
  top: 106px;
  right: 10px;
  padding: 6px 8px;
  background: rgba(36, 39, 36, .82);
  color: white;
  font: 10px/1.45 ui-monospace, monospace;
  white-space: pre;
  pointer-events: none;
}

@media (max-height: 680px) {
  .topbar { top: 6px; }
  .meters { top: 48px; }
  .hint { top: 66px; }
  .build-panel { bottom: 5px; }
  .tool { height: 42px; }
  .action-row { margin-top: 5px; }
  .release-button { height: 33px; }
}

@media (min-width: 800px) {
  .topbar { left: calc(50% - 295px); right: calc(50% - 295px); }
}

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