:root {
  --bg: #0e0e10;
  --surface: #17171b;
  --surface-2: #1f1f25;
  --border: #2c2c34;
  --text: #ececf1;
  --muted: #9a9aa6;
  --accent: #ff3b2f;
  --accent-soft: rgba(255, 59, 47, 0.14);
  --radius: 12px;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: "Space Grotesk", system-ui, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
}

main,
.top {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

.top {
  padding-top: 32px;
  padding-bottom: 16px;
}

.top h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 44px);
  letter-spacing: -0.02em;
}

.top h1 span {
  color: var(--accent);
  text-shadow: 0 0 18px rgba(255, 59, 47, 0.55);
}

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
}

/* Upload */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 28px 20px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.dropzone-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.dropzone-empty strong {
  font-size: 20px;
}

.dropzone-empty span {
  color: var(--muted);
}

.has-image .dropzone {
  padding: 12px;
  border-style: solid;
}

.dropzone-loaded {
  display: flex;
  align-items: center;
  gap: 16px;
}

.dropzone-loaded[hidden],
.dropzone-empty[hidden] {
  display: none;
}

#thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
}

.file-name {
  font-weight: 600;
  word-break: break-all;
}

.file-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-top: 24px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tabs button {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--muted);
  padding: 10px 16px;
  white-space: nowrap;
  font-weight: 600;
}

.tabs button:hover {
  color: var(--text);
}

.tabs button[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.panels {
  padding: 16px 0 48px;
}

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: flex-end;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.control-range {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 8px;
}

.control-range span {
  grid-column: 1 / -1;
}

.control-range input {
  width: 130px;
  accent-color: var(--accent);
}

.control output {
  font-family: var(--mono);
  color: var(--text);
  min-width: 3ch;
  text-align: right;
}

.control-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  color: var(--text);
  padding-bottom: 4px;
}

.control-checkbox input {
  accent-color: var(--accent);
}

select {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
}

.actions {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

/* Stages */
.stage {
  border-radius: var(--radius);
  overflow: hidden;
}

.stage-led {
  display: flex;
  justify-content: center;
  padding: 24px 0;
  background: radial-gradient(ellipse at center, #1b1b20 0%, #09090b 75%);
}

.led-canvas {
  display: block;
  max-width: 100%;
  border-radius: 4px;
  box-shadow: 0 0 0 6px #1d1d1f, 0 20px 60px rgba(0, 0, 0, 0.6);
}

.stage-term {
  height: min(72vh, 760px);
  padding: 10px;
  background: #0a0a0a;
  border: 1px solid var(--border);
}

/* Until a photo is loaded, show a hint instead of the (empty) output. */
.empty {
  display: none;
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

body:not(.has-image) .empty {
  display: block;
}

body:not(.has-image) .stage,
body:not(.has-image) .actions {
  display: none;
}

@media (max-width: 600px) {
  .control-range input {
    width: 100%;
  }
  .control {
    flex: 1 1 140px;
  }
}

.term-host {
  height: 100%;
}

.credit {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.credit a {
  color: var(--accent);
}

body:not(.has-image) .credit {
  display: none;
}

/* AI remix */
.llm-top {
  align-items: flex-start;
}

.llm-prompt {
  flex: 1 1 320px;
}

textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  resize: vertical;
  width: 100%;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-basis: 100%;
}

.chip {
  font-size: 13px;
  padding: 3px 10px;
  border-radius: 999px;
}

.panel > div > .controls {
  margin-top: 8px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hint {
  align-self: center;
  color: var(--muted);
  font-size: 13px;
}

.actions {
  flex-wrap: wrap;
}

.stage-llm {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.llm-status {
  font-family: var(--mono);
  font-size: 13px;
  margin-bottom: 12px;
  color: var(--text);
}

.llm-status::before {
  content: "● ";
  color: var(--accent);
  animation: pulse 1s ease-in-out infinite alternate;
}

.llm-status.error {
  color: var(--accent);
}

.llm-status.error::before {
  content: "✕ ";
  animation: none;
}

@keyframes pulse {
  from { opacity: 0.2; }
  to { opacity: 1; }
}

.llm-main {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.llm-main figure {
  margin: 0;
}

.llm-main img {
  display: block;
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.llm-main figcaption {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.llm-empty {
  color: var(--muted);
  margin: 0;
}

.llm-history {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-top: 16px;
}

.llm-history:empty {
  display: none;
}

.thumb {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  width: 120px;
  flex: none;
  font-size: 11px;
  text-align: left;
}

.thumb.selected {
  border-color: var(--accent);
}

.thumb img {
  width: 100%;
  height: 72px;
  object-fit: cover;
  border-radius: 4px;
  background: #fff;
}

.thumb span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

input[type="password"] {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  width: 150px;
}
