/* ============================================================
   Mandala Studio — styles
   A calm, dark control panel next to a bright, focused stage.
   ============================================================ */

:root {
  --bg: #0e1016;
  --panel: #161a24;
  --panel-2: #1e2430;
  --line: #2a3140;
  --text: #e7ecf4;
  --muted: #8a94a6;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* --------------------------------------------------- Panel --------------- */
.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 22px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow);
}
.brand h1 { font-size: 17px; margin: 0; letter-spacing: 0.3px; }
.brand p { margin: 2px 0 0; font-size: 11px; color: var(--muted); letter-spacing: 0.4px; }

.panel-scroll {
  overflow-y: auto;
  padding: 8px 16px 28px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.panel-scroll::-webkit-scrollbar { width: 8px; }
.panel-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.group { padding: 16px 0; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: none; }
.group h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  margin: 0 0 12px;
}

/* Fields */
.field { display: block; margin-bottom: 14px; }
.field > span {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text);
  margin-bottom: 6px;
}
.field em { color: var(--accent-2); font-style: normal; font-size: 11.5px; }

select, input[type="number"] {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 13px;
  outline: none;
}
select:focus, input[type="number"]:focus { border-color: var(--accent); }

textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 13px;
  outline: none;
  resize: vertical;
  font-family: inherit;
}
textarea:focus { border-color: var(--accent); }

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); cursor: pointer;
}

.check {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; margin: 4px 0 14px; cursor: pointer;
}
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Buttons */
.btn-row { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.btn {
  flex: 1;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.btn:hover { background: #262d3b; border-color: #38445a; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #9b6bff);
  border: none; color: #fff; font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.small { flex: 0 0 auto; padding: 9px 12px; }

.seed .seed-row { display: flex; gap: 8px; }
.seed .seed-row input { flex: 1; }

/* Colors */
.color-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.color-field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.color-field.wide { width: 100%; margin-top: 10px; }
input[type="color"] {
  width: 46px; height: 34px; padding: 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); cursor: pointer;
}
.color-field.wide input[type="color"] { width: 100%; }

/* Palette family tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tab {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 11.5px;
  cursor: pointer;
}
.tab.active { color: #fff; background: var(--accent); border-color: var(--accent); }

/* Palette cards */
.palette-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.palette {
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px;
  cursor: pointer;
  transition: border-color .15s ease, transform .05s ease;
}
.palette:hover { border-color: #47526a; }
.palette.active { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2) inset; }
.palette .swatches { display: flex; height: 26px; border-radius: 6px; overflow: hidden; }
.palette .swatches span { flex: 1; }
.palette-name {
  font-size: 10.5px; color: var(--muted); margin-top: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Painting mode */
.segmented {
  display: flex; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-bottom: 12px;
}
.seg {
  flex: 1; background: transparent; border: none; color: var(--muted);
  padding: 8px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.seg.active { background: var(--accent); color: #fff; }

.hint { font-size: 11.5px; color: var(--muted); line-height: 1.5; margin: 0 0 10px; }

.mswatches { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 6px; }
.mswatch {
  width: 34px; height: 34px; border-radius: 8px;
  border: 2px solid transparent; cursor: pointer; padding: 0;
  box-shadow: 0 0 0 1px var(--line);
}
.mswatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent-2); }
.mswatch.eraser { background: var(--panel-2); color: var(--muted); font-size: 16px; }

.hidden { display: none !important; }

/* --------------------------------------------------- Stage --------------- */
.stage {
  position: relative;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 800px at 70% -10%, #1a2030 0%, transparent 60%),
    radial-gradient(900px 700px at 20% 120%, #171b26 0%, transparent 55%),
    #0b0d12;
  min-width: 0;
  overflow: hidden;
}

.stage-tools {
  position: absolute; top: 14px; right: 14px;
  display: flex; gap: 8px; z-index: 10;
}
.tool {
  width: 40px; height: 40px; border-radius: 10px;
  background: rgba(30, 36, 48, 0.8);
  border: 1px solid var(--line);
  color: var(--text); font-size: 18px; cursor: pointer;
  backdrop-filter: blur(6px);
}
.tool:hover { background: rgba(44, 52, 68, 0.9); }
#btnPanel { display: none; }

.mandala-wrap {
  width: min(92vh, 92%);
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
}
#svg {
  width: 100%;
  height: 100%;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.stage.manual #svg .cell { cursor: crosshair; }

.manual-hint {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(20, 24, 34, 0.9);
  border: 1px solid var(--line);
  padding: 9px 16px; border-radius: 999px;
  font-size: 12.5px; color: var(--muted);
  backdrop-filter: blur(6px);
}

/* --------------------------------------------------- Responsive ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .panel {
    position: fixed; inset: 0 auto 0 0;
    width: min(88vw, 360px);
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: var(--shadow);
  }
  body.panel-open .panel { transform: translateX(0); }
  #btnPanel { display: grid; place-items: center; }
  .mandala-wrap { width: min(92vw, 92vh); }
}
