:root {
  --bg: #14141a;
  --panel: #1c1c24;
  --edge: #2c2c38;
  --fg: #e6e6ee;
  --muted: #8b8b9c;
  --accent: #7cc4ff;
  --accent-strong: #2f6fd0;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;               /* the app fits the viewport; no page scroll */
}

header { padding: 8px 18px; flex: 0 0 auto; }
.titlebar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
h1 { margin: 0; font-size: 17px; letter-spacing: 0.5px; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.tagline code { color: var(--accent); }

.tabbar { display: flex; gap: 6px; }
.tabbar button {
  background: #101014; border: 1px solid var(--edge); color: var(--muted);
  border-radius: 7px; padding: 6px 18px; font: inherit; cursor: pointer;
}
.tabbar button:hover { color: var(--fg); border-color: var(--accent); }
.tabbar button.on { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; font-weight: 600; }

/* Fill the viewport below the header; the active tab panel is the flex row. */
main { height: calc(100vh - 50px); min-height: 0; }
.tabpanel { display: none; height: 100%; }
.tabpanel.active {
  display: flex;
  gap: 16px;
  align-items: stretch;
  padding: 8px 18px 14px;
  min-height: 0;
}

/* Left: preview on top, wheels below, both height-capped. */
.stage {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dropzone {
  position: relative;
  border: 1px dashed var(--edge);
  border-radius: 10px;
  padding: 8px;
  background: #101014;
  transition: border-color 0.15s;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.dropzone.drag { border-color: var(--accent); }

.dropzone canvas {
  display: block;
  height: 46vh;                   /* sized by height; width follows aspect */
  width: auto;
  max-width: 100%;
  object-fit: contain;
  border-radius: 6px;
  cursor: pointer;
  touch-action: none;
}
.hint { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.hint b { color: var(--fg); font-weight: 600; }

/* Right: control panel, scrolls internally if it's taller than the viewport. */
.panel {
  flex: 0 0 290px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 0;
  overflow-y: auto;
}

.control { display: flex; flex-direction: column; gap: 4px; }
.control label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.control .val { color: var(--accent); float: right; font-variant-numeric: tabular-nums; }

.row { display: flex; gap: 8px; }
input[type=number], select {
  flex: 1;
  background: #101014;
  border: 1px solid var(--edge);
  color: var(--fg);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
}
input[type=range] { width: 100%; accent-color: var(--accent); margin: 0; }

button, .filebtn {
  background: #262631;
  border: 1px solid var(--edge);
  color: var(--fg);
  border-radius: 6px;
  padding: 7px 10px;
  font: inherit;
  cursor: pointer;
  text-align: center;
}
button:hover, .filebtn:hover { border-color: var(--accent); }
button.primary { background: var(--accent-strong); border-color: var(--accent-strong); font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }

.buttons { flex-direction: row; gap: 8px; }
.buttons > * { flex: 1; }

.dev { border-top: 1px solid var(--edge); padding-top: 9px; }
.devout { font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); white-space: pre-wrap; }
.devout.ok { color: #7ce38b; }
.devout.bad { color: #ff8080; }

.status { min-height: 14px; color: var(--accent); font-size: 11px; }

/* --- badges / segmented / hints --- */
.badge {
  font-size: 11px; font-weight: 700; vertical-align: middle;
  background: var(--accent-strong); color: #fff; border-radius: 5px;
  padding: 1px 6px; letter-spacing: 0.5px;
}
.sub { color: var(--muted); font-size: 10px; }

.segmented { display: flex; border: 1px solid var(--edge); border-radius: 6px; overflow: hidden; }
.segmented button {
  flex: 1; border: none; border-radius: 0; background: #101014; color: var(--muted);
  padding: 7px 6px; border-right: 1px solid var(--edge);
}
.segmented button:last-child { border-right: none; }
.segmented button.on { background: var(--accent-strong); color: #fff; }
.segmented button:hover { color: var(--fg); }
.segmented button.on:hover { color: #fff; }
.segmented button:disabled { opacity: 0.4; cursor: not-allowed; }

.control.disabled { opacity: 0.4; pointer-events: none; }

.toggles { display: flex; gap: 6px; }
.toggles button {
  flex: 1; background: #101014; border: 1px solid var(--edge); color: var(--muted);
  border-radius: 6px; padding: 7px 4px; font: inherit; cursor: pointer;
}
.toggles button:hover { color: var(--fg); border-color: var(--accent); }
.toggles button.on { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }

/* Reset pushed to the very bottom of the panel, away from Export. */
.resetrow { margin-top: auto; padding-top: 10px; }
button.danger { background: #241316; border-color: #5a2a2a; color: #ff9a9a; }
button.danger:hover { border-color: #ff8080; color: #ffc2c2; }

/* Wheels: a bounded strip under the preview. */
.wheelblock { display: flex; gap: 14px; flex: 0 0 auto; align-items: flex-start; }
.wheelcol { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.wheelhdr { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 5px; text-align: center; }
.wheelblock canvas {
  width: auto;
  max-width: 100%;
  max-height: 19vh;               /* keep the wheels compact */
  height: auto;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: #101014;
  display: block;
}
.wheelcol input[type=range] { width: 100%; max-width: 180px; margin-top: 6px; accent-color: var(--accent); }

/* --- Sandbox --- */
.sandbox-canvases { display: flex; gap: 16px; align-items: flex-start; width: 100%; height: 100%; }
.sbcol { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.grainwrap { position: relative; width: min(62vh, 100%); aspect-ratio: 1 / 1; }
.grain {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid var(--edge);
  background: #101014;
  cursor: crosshair;
  touch-action: none;
  display: block;
}
.brushring {
  position: absolute;
  display: none;
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}
.photo {
  max-width: 100%;
  max-height: 62vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border: 1px solid var(--edge);
  border-radius: 6px;
  display: block;
}
.split { position: relative; display: inline-block; max-width: 100%; }
.splitline { position: absolute; left: 0; right: 0; top: 50%; height: 2px; margin-top: -1px; background: rgba(255, 255, 255, 0.7); pointer-events: none; }
.splitlabel {
  position: absolute; left: 6px; font-size: 10px; letter-spacing: 0.6px; text-transform: uppercase;
  color: #fff; background: rgba(0, 0, 0, 0.5); padding: 1px 6px; border-radius: 4px; pointer-events: none;
}
.splitlabel.top { top: 6px; }
.splitlabel.bottom { bottom: 6px; }

/* Narrow screens: stack the panel under the stage and allow scroll. */
@media (max-width: 720px) {
  body { overflow: auto; }
  main { flex-direction: column; height: auto; }
  .panel { flex: 0 0 auto; }
  .dropzone canvas { max-height: 60vh; }
}
