:root {
  --bg: #fafafa;
  --bg-soft: #f5f5f5;
  --panel: #ffffff;
  --panel-alt: #ffffff;
  --ink: #333333;
  --muted: #666666;
  --accent: #333333;
  --line: #e0e0e0;
  --line-strong: #d7d7d7;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.topbar {
  padding: 1rem 1.25rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0.01em;
  font-weight: 600;
}

.topbar p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 420px);
  gap: 0.9rem;
  padding: 1rem 1.1rem 1.1rem;
}

.stage-panel,
.prompt-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stage-panel {
  padding: 0.9rem;
  min-height: 70vh;
}

.drop-zone {
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  min-height: 64vh;
  display: grid;
  place-content: center;
  gap: 0.8rem;
  text-align: center;
  background: #fcfcfc;
  transition: border-color 0.2s ease, transform 0.2s ease;
  color: var(--muted);
}

.drop-zone.dragover {
  border-color: var(--accent);
  transform: scale(1.005);
}

.canvas-wrap {
  display: grid;
  gap: 0.7rem;
  height: 100%;
  animation: fade-up 0.3s ease;
}

.canvas-wrap.hidden,
.drop-zone.hidden {
  display: none;
}

#editorCanvas {
  width: 100%;
  height: min(74vh, 760px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    repeating-conic-gradient(#f8f8f8 0% 25%, #f2f2f2 0% 50%) 50% / 26px 26px;
  touch-action: none;
  cursor: crosshair;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.mobile-size-controls {
  display: none;
  gap: 0.6rem;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fcfcfc;
}

.mobile-size-controls.hidden {
  display: none;
}

.size-control {
  display: grid;
  gap: 0.35rem;
}

.size-control__header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  font-size: 0.82rem;
  color: var(--muted);
}

.size-control__value {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  color: #4a4a4a;
}

.mobile-size-controls input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: #333333;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.prompt-panel {
  padding: 0.9rem;
  display: grid;
  gap: 0.6rem;
  align-content: start;
  background: var(--panel-alt);
}

label {
  font-size: 0.92rem;
  color: #4a4a4a;
}

.prompt-tools {
  display: flex;
  align-items: center;
}

.prompt-preset {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #ffffff;
  color: #333333;
  padding: 0.55rem 0.7rem;
  font: 500 0.88rem "Space Grotesk", sans-serif;
}

.prompt-preset:focus {
  outline: none;
  border-color: #bdbdbd;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.06);
}

textarea {
  width: 100%;
  min-height: 170px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  padding: 0.8rem;
  font: 500 0.92rem/1.35 "IBM Plex Mono", monospace;
  color: #000000;
  background: #ffffff;
}

textarea:focus {
  outline: none;
  border-color: #bdbdbd;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.06);
}

.status {
  min-height: 1.2rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0;
}

.result {
  margin: 0;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem;
  background: #ffffff;
  color: #333333;
  overflow-y: auto;
  font: 500 0.9rem/1.4 "IBM Plex Mono", monospace;
}

.markdown-result {
  white-space: normal;
  font-family: "Space Grotesk", sans-serif;
}

.markdown-result .md-paragraph {
  margin: 0 0 0.75rem;
}

.markdown-result .md-paragraph:last-child {
  margin-bottom: 0;
}

.markdown-result .muted {
  color: var(--muted);
}

.markdown-result .md-heading {
  margin: 0.9rem 0 0.55rem;
  line-height: 1.2;
}

.markdown-result .md-heading:first-child {
  margin-top: 0;
}

.markdown-result .md-heading-1 {
  font-size: 1.25rem;
}

.markdown-result .md-heading-2 {
  font-size: 1.1rem;
}

.markdown-result .md-heading-3 {
  font-size: 1rem;
}

.markdown-result ul,
.markdown-result ol {
  margin: 0 0 0.75rem 1.25rem;
  padding-left: 1rem;
}

.markdown-result li + li {
  margin-top: 0.25rem;
}

.markdown-result .md-blockquote {
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.8rem;
  border-left: 3px solid var(--line-strong);
  background: #fafafa;
  color: #4a4a4a;
}

.markdown-result .md-code {
  margin: 0 0 0.75rem;
  padding: 0.8rem;
  border-radius: 8px;
  background: #f5f5f5;
  overflow-x: auto;
  white-space: pre;
  font: 500 0.86rem/1.45 "IBM Plex Mono", monospace;
}

.markdown-result code {
  padding: 0.12rem 0.3rem;
  border-radius: 5px;
  background: #f2f2f2;
  font: 500 0.88rem/1.4 "IBM Plex Mono", monospace;
}

.markdown-result a {
  color: #2a5bd7;
  text-decoration: underline;
  word-break: break-word;
}

.btn {
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: #333333;
  border-radius: 9px;
  padding: 0.55rem 0.75rem;
  font: 600 0.88rem "Space Grotesk", sans-serif;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.prompt-panel .btn {
  width: 100%;
}

.btn:hover {
  border-color: #bfbfbf;
  background: #f7f7f7;
}

.btn.primary {
  border-color: #333333;
  background: #333333;
  color: #ffffff;
}

.btn.active {
  border-color: #333333;
  background: #333333;
  color: #ffffff;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  #editorCanvas {
    height: min(56vh, 560px);
  }

  .btn {
    min-height: 44px;
    font-size: 0.92rem;
  }

  .mobile-size-controls {
    display: grid;
  }
}
