:root {
  --bg: #07080d;
  --panel: #0c0e16;
  --line: #1d2030;
  --text: #e9e7f2;
  --muted: #8a8ba3;
  --accent: #ff8a3d;
  --sel: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
}

/* ---------- side panel ---------- */
#panel > * { flex: none; }
#panel {
  width: 276px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 18px;
  background:
    radial-gradient(120% 50% at 0% 0%, rgba(255, 120, 40, 0.10), transparent 60%),
    linear-gradient(180deg, #0e1019, #0a0b12);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  scrollbar-width: thin;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 {
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 24px;
  line-height: 1;
  margin: 0;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #ffd27a, #ff7a2f 55%, #ff4d6d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 12px; letter-spacing: 0.02em; }
.logo {
  width: 34px; height: 34px; flex: none;
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px;
}
.logo i { border-radius: 3px; }
.logo i:nth-child(1) { background: #e0c07a; }
.logo i:nth-child(2) { background: #3f7fe0; }
.logo i:nth-child(3) { background: #ff6a1f; box-shadow: 0 0 10px #ff6a1f; }
.logo i:nth-child(4) { background: #54c35a; }

.label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: -6px;
}

.palette {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.el {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 7px 7px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #11131d;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
  touch-action: manipulation;
}
.el:hover { background: #171a27; border-color: #2c3048; }
.el:active { transform: scale(0.97); }
.el .sw {
  width: 18px; height: 18px; flex: none;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.el .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.el kbd { font-size: 9.5px; padding: 1px 4px; color: var(--muted); }
.el.sel {
  border-color: var(--c, #fff);
  background: color-mix(in srgb, var(--c, #fff) 16%, #11131d);
  box-shadow: 0 0 0 1px var(--c, #fff), 0 0 18px -4px var(--c, #fff);
}

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid #2a2d40;
  background: #141624;
  color: #c9c8da;
}

.desc {
  min-height: 54px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #10121b;
  border: 1px solid var(--line);
  font-size: 12.5px;
  line-height: 1.45;
  color: #c4c3d6;
}
.desc b { color: var(--text); font-weight: 600; }

.controls { display: flex; flex-direction: column; gap: 10px; }
.brush { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.brush input { flex: 1; min-width: 60px; accent-color: var(--accent); }
.brush output { width: 22px; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }

.buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.buttons button {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 6px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #141725;
  color: var(--text);
  font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}
.buttons button:hover { background: #1b1f31; }
.buttons svg { width: 16px; height: 16px; fill: currentColor; flex: none; }
#pauseBtn .i-play { display: none; }
#pauseBtn.paused { background: #3a2412; border-color: #7a4520; color: #ffc48f; }
#pauseBtn.paused .i-play { display: block; }
#pauseBtn.paused .i-pause { display: none; }

.tips ul { margin: 10px 0 10px; padding-left: 16px; color: #b9b8cb; font-size: 12.5px; line-height: 1.42; }
.tips li { margin-bottom: 2px; }
.tips li::marker { color: #50536c; }
.tips b { font-weight: 600; }
.c-water { color: #6aa8ff; } .c-lava { color: #ff7a2f; } .c-oil { color: #d59a4e; }
.c-acid { color: #a6ff4d; } .c-glass { color: #aee6ea; } .c-plant { color: #62d168; }
.c-ice { color: #b5e6ff; } .c-powder { color: #c9c7d8; }
.keys { display: flex; flex-direction: column; gap: 6px; font-size: 11.5px; color: var(--muted); }

/* ---------- stage ---------- */
#stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background:
    radial-gradient(70% 60% at 50% 40%, #121525, transparent 70%),
    var(--bg);
}

#frame {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 0 1px #23263a, 0 30px 80px -20px rgba(0, 0, 0, 0.8), 0 0 120px -40px rgba(255, 110, 40, 0.35);
  touch-action: none;
  cursor: none;
  background: #0b0d16;
}

#frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#sim { image-rendering: pixelated; image-rendering: crisp-edges; }
#glow { mix-blend-mode: screen; pointer-events: none; opacity: 0.95; }

#cursor {
  position: absolute;
  left: 0; top: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  display: none;
  transform: translate(-50%, -50%);
}
#cursor.on { display: block; }

#hud {
  position: absolute;
  top: 8px; left: 10px;
  display: flex; gap: 10px;
  font: 500 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: rgba(230, 230, 245, 0.7);
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}

#pausedTag {
  position: absolute;
  top: 8px; right: 10px;
  padding: 4px 9px;
  border-radius: 6px;
  background: rgba(255, 138, 61, 0.18);
  border: 1px solid rgba(255, 138, 61, 0.5);
  color: #ffc48f;
  font: 600 11px/1 Inter, sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  pointer-events: none;
  display: none;
}
#pausedTag.on { display: block; }

#hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(10, 11, 20, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #e6e4f2;
  font-size: 12.5px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.6s, transform 0.6s;
  animation: hint-in 0.6s 0.8s both;
}
#hint.gone { opacity: 0; transform: translate(-50%, 8px); }
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- narrow screens / phones ---------- */
@media (max-width: 820px) {
  #app { flex-direction: column; }
  #stage { order: 1; padding: 6px 6px 4px; }
  #panel {
    order: 2;
    width: auto;
    gap: 8px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
    background: linear-gradient(180deg, #0e1019, #0a0b12);
  }
  .brand, .tips, .label, .desc { display: none; }
  .palette { grid-template-columns: repeat(7, 1fr); gap: 4px; }
  .el {
    flex-direction: column;
    gap: 3px;
    padding: 6px 2px 5px;
    font-size: 10px;
    border-radius: 8px;
    text-align: center;
  }
  .el .sw { width: 20px; height: 20px; }
  .el .nm { width: 100%; }
  .el kbd { display: none; }
  .controls { flex-direction: row; align-items: center; gap: 8px; }
  .brush { flex: 1; font-size: 12px; gap: 6px; }
  .buttons { display: flex; gap: 4px; }
  .buttons button { padding: 8px 10px; }
  .buttons button span { display: none; }
  .buttons svg { width: 18px; height: 18px; }
  #frame { border-radius: 8px; cursor: default; }
  #hint { font-size: 11.5px; bottom: 10px; }
}

@media (max-width: 820px) and (min-width: 560px) {
  .buttons button span { display: inline; }
}
