/* Syzygy — claymorphic surfaces on a Swiss grid skeleton, Rising Tides palette.
   Layout/typography stay Swiss (grid lines, mono micro-labels, numbered cells);
   surfaces are clay: puffy radii, inner-light/inner-dark double shadows. */

:root {
  --bg: #0b0710;
  --bg-lift: #170d22;
  --clay: #1c1029;
  --clay-deep: #140a1c;
  --ink: #f3ead4;
  --ink-soft: #d9ceb4;
  --muted: rgba(243, 234, 212, 0.62);
  --muted-2: rgba(243, 234, 212, 0.38);
  --rule: rgba(243, 234, 212, 0.18);
  --violet: #8500d7;
  --magenta: #e100c3;
  --gold: #c9a85f;
  --display: "Archivo Black", Impact, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --gutter: 16px;
  --clay-hi: #201232;

  /* Clay recipe: light breathes in top-left, mass sinks bottom-right */
  --clay-raised:
    inset 5px 5px 10px rgba(255, 255, 255, 0.05),
    inset -7px -7px 14px rgba(0, 0, 0, 0.5),
    10px 14px 30px rgba(0, 0, 0, 0.55);
  --clay-pressed:
    inset 7px 7px 14px rgba(0, 0, 0, 0.55),
    inset -4px -4px 10px rgba(255, 255, 255, 0.04);
  --emboss: 3px 4px 0 rgba(0, 0, 0, 0.45), 8px 12px 24px rgba(0, 0, 0, 0.5);
}

/* Light mode: same clay, warm Rising Tides cream. Toggled via data-theme. */
[data-theme="light"] {
  --bg: #ece2ca;
  --bg-lift: #f8f2e3;
  --clay: #f3ead4;
  --clay-hi: #fbf6e9;
  --clay-deep: #e3d7b9;
  --ink: #1a0f26;
  --ink-soft: #43335a;
  --muted: rgba(26, 15, 38, 0.62);
  --muted-2: rgba(26, 15, 38, 0.4);
  --rule: rgba(26, 15, 38, 0.18);
  --gold: #9c7c35;
  --clay-raised:
    inset 4px 4px 8px rgba(255, 255, 255, 0.85),
    inset -6px -7px 12px rgba(151, 127, 87, 0.32),
    10px 14px 30px rgba(120, 100, 70, 0.3);
  --clay-pressed:
    inset 6px 6px 12px rgba(151, 127, 87, 0.35),
    inset -3px -3px 8px rgba(255, 255, 255, 0.7);
  --emboss: 2px 3px 0 rgba(151, 127, 87, 0.35), 6px 10px 20px rgba(120, 100, 70, 0.3);
}

/* The logo asset is pure white; flip it to ink on light clay */
[data-theme="light"] #rt-logo {
  filter: invert(1);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-lift) 0%, var(--bg) 60%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
}

main#syzygy-app {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  column-gap: var(--gutter);
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px calc(48px + env(safe-area-inset-bottom));
}

main#syzygy-app > * {
  grid-column: 1 / -1;
}

.micro {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Masthead ─────────────────────────────────────────────── */
header#masthead {
  display: grid;
  grid-template-columns: subgrid;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
}

#rt-logo {
  grid-column: span 3;
  height: 40px;
  width: auto;
  justify-self: start;
}

#masthead .micro:nth-of-type(1) {
  display: none;
}

#masthead .index {
  grid-column: span 2;
  justify-self: end;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--clay);
  box-shadow: var(--clay-raised);
  color: var(--gold);
}

#theme-toggle {
  grid-column: span 1;
  justify-self: end;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--clay);
  box-shadow: var(--clay-raised);
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

#theme-toggle:active {
  box-shadow: var(--clay-pressed);
}

/* ── Wordmark ─────────────────────────────────────────────── */
section#wordmark {
  padding: 44px 0 32px;
}

h1#workspace-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(3.4rem, 16vw, 9.5rem);
  line-height: 0.88;
  letter-spacing: -0.045em;
  text-transform: uppercase;
  color: var(--ink);
  /* soft clay emboss on the type itself */
  text-shadow: var(--emboss);
}

h1#workspace-title .y {
  color: var(--violet);
  text-shadow: var(--emboss), 0 0 34px rgba(133, 0, 215, 0.45);
}

/* Three clay celestial bodies aligned on one rule: sun, earth, moon.
   Syzygy is the alignment that raises the highest tides. */
#alignment {
  position: relative;
  height: 40px;
  margin-top: 28px;
  display: flex;
  align-items: center;
  gap: clamp(40px, 12vw, 120px);
}

#alignment::before {
  content: "";
  position: absolute;
  inset: 50% 0 auto 0;
  height: 1px;
  background: var(--rule);
}

#alignment .body {
  position: relative;
  border-radius: 50%;
  box-shadow:
    inset -3px -4px 6px rgba(0, 0, 0, 0.45),
    inset 2px 3px 5px rgba(255, 255, 255, 0.25),
    5px 8px 16px rgba(0, 0, 0, 0.55);
}

#alignment .sun {
  width: 24px;
  height: 24px;
  background: radial-gradient(circle at 32% 28%, #e8cf92, var(--gold) 65%);
}

#alignment .earth {
  width: 16px;
  height: 16px;
  background: radial-gradient(circle at 32% 28%, #b04df0, var(--violet) 70%);
}

#alignment .moon {
  width: 10px;
  height: 10px;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 253, 0.9), var(--ink) 70%);
}

p#definition {
  margin: 24px 0 0;
  max-width: 46ch;
  color: var(--ink-soft);
  font-size: 15px;
}

p#definition .micro {
  color: var(--gold);
  text-transform: none;
}

/* ── Nav: numbered clay cards on the grid ─────────────────── */
main#syzygy-app > nav {
  display: grid;
  grid-template-columns: subgrid;
  row-gap: var(--gutter);
  padding: 26px 0;
}

main#syzygy-app > nav a {
  grid-column: span 3;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 96px;
  padding: 16px 18px;
  border-radius: 22px;
  background: linear-gradient(145deg, var(--clay-hi), var(--clay-deep));
  box-shadow: var(--clay-raised);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 16px;
  transition: transform 120ms ease;
}

main#syzygy-app > nav a::before {
  content: attr(data-idx);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--muted-2);
}

main#syzygy-app > nav a:hover {
  transform: translateY(-2px);
}

main#syzygy-app > nav a:active {
  transform: translateY(1px);
  box-shadow: var(--clay-pressed);
}

/* ── Page agent: clay slab, carved input, squishy button ──── */
#studio-workspace {
  padding-top: 8px;
}

#page-agent,
#generate-panel {
  display: grid;
  grid-template-columns: subgrid;
  grid-column: 1 / -1;
  row-gap: 14px;
  padding: 22px 20px 24px;
  border-radius: 28px;
  background: linear-gradient(150deg, var(--clay-hi), var(--clay-deep));
  box-shadow: var(--clay-raised);
}

#page-agent > *,
#generate-panel > * {
  grid-column: 1 / -1;
}

#page-agent label,
#generate-panel label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

#agent-task,
#gen-prompt,
#gen-format {
  width: 100%;
  padding: 15px 18px;
  border: 0;
  border-radius: 18px;
  background: var(--bg);
  box-shadow: var(--clay-pressed);
  color: var(--ink);
  font-family: var(--sans);
  /* 16px floor stops iOS Safari zooming the viewport on focus */
  font-size: 16px;
}

#agent-task::placeholder,
#gen-prompt::placeholder {
  color: var(--muted-2);
}

#agent-task:focus,
#gen-prompt:focus,
#gen-format:focus {
  outline: 2px solid var(--violet);
  outline-offset: -1px;
}

#agent-run,
#gen-run {
  min-height: 52px;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(145deg, #9a1cf0, var(--violet));
  box-shadow:
    inset 3px 3px 6px rgba(255, 255, 255, 0.22),
    inset -4px -5px 10px rgba(0, 0, 0, 0.35),
    8px 12px 24px rgba(133, 0, 215, 0.35);
  color: #fff;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 120ms ease;
}

#agent-run:hover,
#gen-run:hover {
  background: linear-gradient(145deg, #f23bd8, var(--magenta));
}

#agent-run:active,
#gen-run:active {
  transform: translateY(1px);
  box-shadow: var(--clay-pressed);
}

#agent-run:disabled,
#gen-run:disabled {
  opacity: 0.55;
}

#agent-log,
#gen-log {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  max-height: 45vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  counter-reset: step;
}

#agent-log li,
#gen-log li {
  counter-increment: step;
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg);
  box-shadow: var(--clay-pressed);
  font-size: 14px;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

#agent-log li::before,
#gen-log li::before {
  content: counter(step, decimal-leading-zero);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--gold);
  padding-top: 2px;
}

#generate-panel {
  margin-top: 20px;
}

#gen-format {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

/* ── ≥760px: 12 columns, asymmetric composition ───────────── */
@media (min-width: 760px) {
  main#syzygy-app {
    grid-template-columns: repeat(12, 1fr);
    padding-left: 24px;
    padding-right: 24px;
  }

  #rt-logo {
    grid-column: span 3;
    height: 48px;
  }

  #masthead .micro:nth-of-type(1) {
    display: block;
    grid-column: span 5;
  }

  #masthead .index {
    grid-column: span 3;
  }

  section#wordmark {
    padding: 64px 0 44px;
  }

  p#definition {
    font-size: 16px;
  }

  main#syzygy-app > nav a {
    grid-column: span 3;
    min-height: 116px;
  }

  #page-agent {
    padding: 28px;
  }

  #agent-task {
    grid-column: 1 / 10;
  }

  #agent-run {
    grid-column: 10 / -1;
  }

  #agent-log {
    grid-column: 1 / 10;
  }

  #gen-format {
    grid-column: 1 / 4;
  }

  #gen-prompt {
    grid-column: 4 / 10;
  }

  #gen-run {
    grid-column: 10 / -1;
  }

  #gen-log {
    grid-column: 1 / 10;
  }
}

/* ── Studio screens (clay slabs on the same grid) ─────────── */
main#syzygy-app[data-screen]:not([data-screen=""]) section#wordmark {
  padding: 20px 0 16px;
}

main#syzygy-app[data-screen]:not([data-screen=""]) h1#workspace-title {
  font-size: clamp(2rem, 7vw, 3.4rem);
}

main#syzygy-app[data-screen]:not([data-screen=""]) #alignment,
main#syzygy-app[data-screen]:not([data-screen=""]) p#definition {
  display: none;
}

.screen {
  display: grid;
  grid-template-columns: subgrid;
  grid-column: 1 / -1;
  row-gap: 20px;
  padding-top: 8px;
}

.screen > * {
  grid-column: 1 / -1;
}

.panel {
  display: grid;
  row-gap: 12px;
  padding: 22px 20px 24px;
  border-radius: 28px;
  background: linear-gradient(150deg, var(--clay-hi), var(--clay-deep));
  box-shadow: var(--clay-raised);
}

.panel label,
.section-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

h2.section-title {
  margin: 10px 0 0;
  font-weight: 400;
}

.panel input,
.panel select {
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-radius: 16px;
  background: var(--bg);
  box-shadow: var(--clay-pressed);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
}

.panel input:focus,
.panel select:focus {
  outline: 2px solid var(--violet);
  outline-offset: -1px;
}

.panel input[type="file"] {
  padding: 12px;
  font-size: 14px;
}

.panel button {
  min-height: 48px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(145deg, #9a1cf0, var(--violet));
  box-shadow:
    inset 3px 3px 6px rgba(255, 255, 255, 0.22),
    inset -4px -5px 10px rgba(0, 0, 0, 0.35),
    8px 12px 24px rgba(133, 0, 215, 0.35);
  color: #fff;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
}

.panel button:hover {
  background: linear-gradient(145deg, #f23bd8, var(--magenta));
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.btn-row button {
  flex: 1 1 200px;
}

.status {
  margin: 0;
  min-height: 1.2em;
  font-size: 14px;
  color: var(--gold);
}

/* rows: clay list entries */
.rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px 16px;
  border-radius: 18px;
  background: linear-gradient(150deg, var(--clay-hi), var(--clay-deep));
  box-shadow: var(--clay-raised);
}

.row-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.row-main strong {
  overflow-wrap: anywhere;
}

.dim {
  color: var(--muted);
  font-size: 13px;
}

.btn-sm {
  padding: 10px 14px;
  border: 0;
  border-radius: 12px;
  background: var(--clay);
  box-shadow: var(--clay-raised);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
}

.btn-sm:active {
  box-shadow: var(--clay-pressed);
}

.btn-sm.accent {
  background: linear-gradient(145deg, #9a1cf0, var(--violet));
  color: #fff;
}

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg);
  box-shadow: var(--clay-pressed);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

.pill.posted { color: #4ade80; }
.pill.failed { color: var(--red); }

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
}

/* media grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.cell {
  margin: 0;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(150deg, var(--clay-hi), var(--clay-deep));
  box-shadow: var(--clay-raised);
}

.cell img {
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  display: block;
}

.cell figcaption {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cell.audio {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
}

.audio-glyph {
  font-size: 2rem;
  color: var(--gold);
}

/* preset chips */
#gen-presets li { list-style: none; }
.chips button.pill { border: 0; cursor: pointer; }
.chips button.pill.active {
  background: linear-gradient(145deg, #9a1cf0, var(--violet));
  color: #fff;
}
