:root {
  --bg: #1b1d21; --panel: #26292f; --panel2: #2f333a; --line: #3a3f47;
  --ink: #e7e9ec; --muted: #9aa1ab; --accent: #4ea1ff; --accent2: #7bd66b;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.4 system-ui, sans-serif; height: 100vh; display: flex; flex-direction: column;
}
h1 { font-size: 18px; margin: 0 12px 0 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 11px; margin-top: 10px; }

header {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
header label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
input, select, button { font: inherit; color: var(--ink); }
input[type=text], #pet-name, select {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; color: var(--ink);
}
#pet-name { width: 130px; }
button {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #06131f; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }

main { flex: 1; display: grid; grid-template-columns: 200px 1fr 260px; min-height: 0; }
aside { background: var(--panel); padding: 12px; overflow-y: auto; border-right: 1px solid var(--line); }
#preview-pane { border-right: none; border-left: 1px solid var(--line); }

#state-list { display: flex; flex-direction: column; gap: 2px; }
.state-row {
  display: flex; justify-content: space-between; align-items: center;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  padding: 6px 8px; text-align: left; width: 100%;
}
.state-row:hover { background: var(--panel2); }
.state-row.active { background: var(--panel2); border-color: var(--accent); }
.st-label { font-size: 13px; }
.st-badge { font-size: 11px; color: var(--muted); background: var(--bg); border-radius: 10px; padding: 1px 7px; }

#workspace { display: flex; flex-direction: column; min-width: 0; padding: 12px; gap: 10px; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tools { display: flex; gap: 4px; }
.tool.active { border-color: var(--accent); background: var(--panel2); }
.palette { display: flex; gap: 4px; }
.swatch { width: 26px; height: 26px; border-radius: 6px; padding: 0; border: 2px solid var(--line); }
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(78,161,255,.3); }
.swatch.transparent {
  background-image: linear-gradient(45deg,#888 25%,transparent 25%,transparent 75%,#888 75%),
    linear-gradient(45deg,#888 25%,#ccc 25%,#ccc 75%,#888 75%);
  background-size: 10px 10px; background-position: 0 0, 5px 5px; background-color: #ccc;
}
.rng, .chk { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }

.canvas-wrap {
  flex: 1; min-height: 0; overflow: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 12px;
}
/* margin:auto centres when it fits, but keeps top/left edges reachable when
   the zoomed canvas is larger than the viewport (plain center-flex clips them). */
#editor-canvas { image-rendering: pixelated; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.4); display: block; margin: auto; }

.frame-bar { display: flex; align-items: center; gap: 10px; }
/* min-width:0 lets this flex:1 child actually shrink so overflow-x scrolls,
   instead of blowing out the bar and pushing the frame ops off-screen. */
.frame-strip { display: flex; gap: 6px; overflow-x: auto; flex: 1; min-width: 0; padding: 4px 0; }
.frame-cell {
  position: relative; border: 2px solid var(--line); border-radius: 6px; cursor: pointer;
  background: #fff; line-height: 0; flex: 0 0 auto;
}
.frame-cell.active { border-color: var(--accent); }
.frame-cell canvas { image-rendering: pixelated; display: block; border-radius: 4px; }
.frame-idx { position: absolute; top: 1px; left: 3px; font-size: 10px; color: #333; background: rgba(255,255,255,.7); border-radius: 3px; padding: 0 3px; }
.frame-ops { display: flex; gap: 4px; }

#preview-pane .preview-box {
  background: #fff; border-radius: 8px; padding: 10px; display: flex; justify-content: center;
  border: 1px solid var(--line);
}
/* Fill the pane width, keep the 152×75 aspect + crisp pixels. */
#preview-canvas { image-rendering: pixelated; width: 100%; height: auto; display: block; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; }
.modal.show { display: flex; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; max-width: 420px; text-align: center; }
.starters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.starters button { padding: 14px; font-size: 15px; }

/* Game-balance panel */
.bp-box { max-width: 620px; width: 92vw; max-height: 86vh; display: flex; flex-direction: column; text-align: left; }
.bp-title { display: flex; justify-content: space-between; align-items: center; }
.bp-title h2 { margin: 0; }
#bp-close { padding: 4px 10px; }
.bp-title, .bp-box > p, .bp-head { flex: 0 0 auto; }
/* fill remaining box height + become the column that holds head + scroll body */
#balance-panel { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.bp-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.bp-presets { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.bp-presets label { display: flex; align-items: center; gap: 4px; }
.bp-include { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--accent2); }
/* flex:1 + min-height:0 = this is the only part that scrolls */
.bp-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-right: 6px; }
.bp-cat { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; border-bottom: 1px solid var(--line); padding-bottom: 3px; }
.bp-row { display: grid; grid-template-columns: 190px 1fr 84px 30px; align-items: center; gap: 10px; padding: 3px 0; }
.bp-name { font-size: 13px; cursor: help; border-bottom: 1px dotted var(--muted); }
.bp-row input[type=range] { width: 100%; }
.bp-row input[type=number] { width: 100%; background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; color: var(--ink); }
.bp-rst { padding: 2px 6px; font-size: 13px; line-height: 1; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 16px;
  opacity: 0; pointer-events: none; transition: .25s; max-width: 80vw; box-shadow: 0 4px 20px rgba(0,0,0,.5);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: #e0524f; }
.toast.ok { border-color: var(--accent2); }
