:root {
  --bg1: #0f172a;
  --bg2: #312e81;
  --panel: rgba(15, 23, 42, 0.48);
  --panel-strong: rgba(255, 255, 255, 0.2);
  --text: rgba(255, 255, 255, 0.95);
  --muted: rgba(255, 255, 255, 0.7);
  --accent: #a78bfa;
  --accent2: #22d3ee;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
}

button, input { font: inherit; }
button { cursor: pointer; color: var(--text); }

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
}

#slimeCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.topbar {
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: 14px;
  right: 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  z-index: 5;
  pointer-events: none;
}

.top-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 800;
}

h1, h2 {
  margin: 0;
  color: var(--text);
  line-height: 1;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.36rem, 5vw, 2.15rem);
  text-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
}

h2 {
  font-size: 1.12rem;
}

.icon-button, .reset, .tool, .segment, .swatch {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 1.18rem;
}

.icon-button.small {
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
}

.icon-button[aria-pressed="false"] { opacity: 0.55; }

.hint-card {
  position: absolute;
  top: calc(74px + var(--safe-top));
  left: 14px;
  z-index: 4;
  display: flex;
  gap: 4px;
  flex-direction: column;
  width: min(360px, calc(100vw - 28px));
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  color: var(--text);
  background: rgba(15, 23, 42, 0.34);
  backdrop-filter: blur(18px) saturate(1.35);
  -webkit-backdrop-filter: blur(18px) saturate(1.35);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.2);
  transition: transform 300ms ease, opacity 300ms ease;
}

.hint-card span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.25;
}

.tooldock {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.tool {
  min-width: 0;
  height: 58px;
  border-radius: 16px;
  padding: 7px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.tool span { font-size: 1.2rem; line-height: 1; }
.tool b { font-size: 0.66rem; font-weight: 850; line-height: 1; white-space: nowrap; }
.tool.active {
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent), white 14%), color-mix(in srgb, var(--accent2), black 10%));
  border-color: rgba(255, 255, 255, 0.42);
  transform: translateY(-3px);
}

.settings-scrim {
  position: absolute;
  inset: 0;
  z-index: 7;
  background: rgba(2, 6, 23, 0.34);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.panel {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(10px + var(--safe-bottom));
  z-index: 8;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(26px) saturate(1.35);
  -webkit-backdrop-filter: blur(26px) saturate(1.35);
  box-shadow: 0 -18px 60px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255,255,255,0.12);
}

.panel[hidden],
.settings-scrim[hidden] {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.segment {
  height: 42px;
  border-radius: 12px;
  font-size: 0.92rem;
  font-weight: 850;
}

.segment.active {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: rgba(255, 255, 255, 0.42);
}

.palette {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.swatch {
  height: 34px;
  border-radius: 999px;
  background: radial-gradient(circle at 32% 26%, rgba(255,255,255,0.88), transparent 16%),
              linear-gradient(135deg, var(--swatch), color-mix(in srgb, var(--swatch), black 30%));
}

.swatch.active {
  outline: 3px solid rgba(255,255,255,0.42);
  outline-offset: 2px;
}

.slider-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  margin-top: 7px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.reset {
  width: 100%;
  height: 42px;
  margin-top: 12px;
  border-radius: 12px;
  font-weight: 850;
  font-size: 0.86rem;
  background: rgba(255, 255, 255, 0.12);
}

@media (min-width: 720px) {
  .topbar, .tooldock {
    left: 50%;
    right: auto;
    width: min(560px, calc(100vw - 28px));
    transform: translateX(-50%);
  }

  .hint-card {
    left: calc(50% - min(280px, 50vw - 14px));
  }

  .panel {
    left: 50%;
    right: auto;
    width: min(460px, calc(100vw - 28px));
    transform: translateX(-50%);
  }
}

@media (max-height: 620px) {
  .hint-card { opacity: 0; transform: translateY(-12px); pointer-events: none; }
  .tool { height: 52px; border-radius: 14px; }
  .tool b { font-size: 0.61rem; }
  .panel { max-height: calc(100vh - 24px - var(--safe-top) - var(--safe-bottom)); overflow: auto; }
}
