/* =========================================================================
 * ASTRA — style.css
 * Deep-space dark theme, glassmorphic control panel, custom controls.
 * ========================================================================= */

:root {
  --bg: #05060c;
  --glass: rgba(15, 17, 28, 0.72);
  --glass-2: rgba(255, 255, 255, 0.05);
  --line: rgba(255, 255, 255, 0.09);
  --txt: #e9ecff;
  --dim: #8b92b6;
  --dim-2: #5d6488;
  --acc-a: #38e1ff;
  --acc-b: #b06cff;
  --acc: linear-gradient(120deg, var(--acc-a), var(--acc-b));
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --radius: 16px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

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

#gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  touch-action: none;
  cursor: crosshair;
}

/* ============================ panel ============================ */
.panel {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 332px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 10;
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s;
  overflow: hidden;
}
.hide-ui .panel { transform: translateX(-118%); opacity: 0; pointer-events: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; }
.logo {
  font-size: 22px;
  background: var(--acc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 10px rgba(120, 180, 255, 0.5));
}
.panel-head h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 5px;
  font-weight: 700;
}
.tag { margin: 1px 0 0; font-size: 9.5px; letter-spacing: 2px; color: var(--dim); text-transform: uppercase; }

.icon-btn, .panel-toggle {
  background: var(--glass-2);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 7px 9px;
  transition: background 0.15s, transform 0.15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }

.panel-toggle {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 12;
  display: none;
  font-size: 18px;
  padding: 10px 12px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.hide-ui .panel-toggle { display: block; }

.panel-body {
  padding: 6px 16px 4px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.panel-body::-webkit-scrollbar { width: 8px; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.16); border-radius: 8px; }

.block { padding: 13px 0; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: 0; }
.block-title {
  font-size: 10.5px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dim { color: var(--dim-2); text-transform: none; letter-spacing: 0; }

/* ---- chips (presets + tools) ---- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  font-size: 12px;
  border-radius: 999px;
  background: var(--glass-2);
  border: 1px solid var(--line);
  color: var(--txt);
  cursor: pointer;
  transition: all 0.14s;
  user-select: none;
}
.chip:hover { background: rgba(255, 255, 255, 0.11); transform: translateY(-1px); }
.chip.active {
  background: var(--acc);
  color: #04060e;
  font-weight: 650;
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(120, 150, 255, 0.35);
}
.chip .k {
  font-size: 9px;
  opacity: 0.6;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 0 3px;
  line-height: 1.4;
}
.chip.active .k { opacity: 0.8; }

.blurb { margin: 10px 2px 12px; font-size: 11.5px; line-height: 1.5; color: var(--dim); min-height: 17px; }

/* ---- buttons ---- */
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.btn {
  flex: 1 1 auto;
  padding: 9px 10px;
  font-size: 12px;
  border-radius: 10px;
  background: var(--glass-2);
  border: 1px solid var(--line);
  color: var(--txt);
  cursor: pointer;
  transition: all 0.14s;
  white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--acc); color: #04060e; font-weight: 650; border-color: transparent; }
.btn.active { background: rgba(255, 255, 255, 0.16); box-shadow: inset 0 0 0 1px var(--line); }

/* ---- sliders ---- */
.row {
  display: grid;
  grid-template-columns: 64px 1fr 46px;
  align-items: center;
  gap: 10px;
  margin: 9px 0;
}
.row label { font-size: 11.5px; color: var(--dim); }
.val { font-size: 11px; text-align: right; color: var(--txt); font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 0 0 3px rgba(120, 170, 255, 0.25), 0 0 10px rgba(120, 170, 255, 0.5);
  transition: transform 0.1s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.18); }
input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 0 0 3px rgba(120, 170, 255, 0.25), 0 0 10px rgba(120, 170, 255, 0.5);
}

/* ---- matrix ---- */
.mx-tools { display: flex; gap: 5px; }
.mini {
  background: var(--glass-2);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 7px;
  width: 24px;
  height: 22px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.14s;
}
.mini:hover { background: rgba(255, 255, 255, 0.13); }

.matrix { display: grid; gap: 3px; margin: 2px 0 4px; }
.mcorner { width: 18px; }
.mhead { height: 18px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }
.mcell {
  aspect-ratio: 1 / 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.86);
  border-radius: 5px;
  cursor: ns-resize;
  user-select: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  transition: outline-color 0.1s;
  outline: 1px solid transparent;
}
.mcell:hover { outline-color: rgba(255, 255, 255, 0.55); }
.hint { margin: 8px 2px 0; font-size: 10px; line-height: 1.45; color: var(--dim-2); }

/* ---- palettes ---- */
.palettes { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 4px; }
.pal {
  width: 38px;
  height: 20px;
  border-radius: 6px;
  border: 1px solid var(--line);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s, box-shadow 0.12s;
}
.pal:hover { transform: translateY(-1px); }
.pal.active { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--acc-a); }

/* ---- seed ---- */
.seed-row { display: flex; gap: 6px; margin-bottom: 8px; }
#seedInput {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--txt);
  font-size: 12px;
  letter-spacing: 1px;
  padding: 8px 11px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  outline: none;
}
#seedInput:focus { border-color: var(--acc-a); box-shadow: 0 0 0 3px rgba(56, 225, 255, 0.15); }
#seedDice { flex: 0 0 auto; }

/* ---- footer ---- */
.panel-foot {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--dim);
}
.stat b { color: var(--txt); font-variant-numeric: tabular-nums; }

/* ============================ intro ============================ */
.intro {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, rgba(20, 24, 48, 0.55), rgba(3, 4, 9, 0.86));
  backdrop-filter: blur(6px);
  transition: opacity 0.7s ease, visibility 0.7s;
  padding: 24px;
}
.intro.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-card {
  max-width: 540px;
  text-align: center;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 44px 40px 34px;
  box-shadow: var(--shadow);
  animation: rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(22px) scale(0.98); } }
.intro-logo {
  font-size: 46px;
  background: var(--acc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 22px rgba(120, 180, 255, 0.6));
}
.intro-card h2 { margin: 8px 0 2px; font-size: 38px; letter-spacing: 12px; font-weight: 800; }
.intro-sub { margin: 0 0 22px; font-size: 12px; letter-spacing: 4px; text-transform: uppercase; color: var(--dim); }
.intro-text { font-size: 14.5px; line-height: 1.7; color: #c3c9ec; margin: 0 auto 26px; max-width: 460px; }
.intro-text em { color: var(--acc-a); font-style: normal; }
.begin {
  background: var(--acc);
  color: #04060e;
  border: 0;
  font-size: 15px;
  font-weight: 700;
  padding: 13px 26px;
  border-radius: 12px;
  cursor: pointer;
  letter-spacing: 0.4px;
  box-shadow: 0 10px 30px rgba(120, 150, 255, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}
.begin:hover { transform: translateY(-2px); box-shadow: 0 14px 38px rgba(120, 150, 255, 0.55); }
.intro-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: center;
  margin-top: 26px;
  font-size: 11px;
  color: var(--dim);
}
kbd {
  background: var(--glass-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 10px;
  color: var(--txt);
}

/* ============================ toast ============================ */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translate(-50%, 16px);
  background: var(--glass);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  color: var(--txt);
  padding: 11px 20px;
  border-radius: 12px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 40;
  letter-spacing: 0.3px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================ fallback ============================ */
.fallback {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--bg);
  color: var(--txt);
  padding: 24px;
}
.fallback h2 { font-weight: 700; letter-spacing: 1px; }
.fallback p { color: var(--dim); }

/* ============================ responsive ============================ */
@media (max-width: 720px) {
  .panel {
    left: 0; right: 0; top: auto; bottom: 0;
    width: auto;
    max-height: 62vh;
    border-radius: 18px 18px 0 0;
    border-left: 0; border-right: 0; border-bottom: 0;
  }
  .hide-ui .panel { transform: translateY(118%); }
  .panel-toggle { top: auto; bottom: 16px; left: 16px; }
  .intro-card { padding: 34px 24px 28px; }
  .intro-card h2 { font-size: 30px; letter-spacing: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.05ms !important; }
}
