* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #1e1e2e;
  --surface: #282840;
  --border: #3a3a5c;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #7c3aed;
  --error: #ef4444;
  --success: #22c55e;
  --header-bg: #16162a;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
}

header label {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

header button {
  padding: 0.4rem 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

header button:hover {
  opacity: 0.9;
}

main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0;
  height: calc(100vh - 49px);
}

.panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.panel-header .hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.template-panel {
  grid-row: 1 / 3;
}

/* Mirrored code editor used for syntax highlighting. */
.code-editor {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.code-mirror,
.code-input {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  tab-size: 2;
}

.code-mirror {
  overflow: auto;
  pointer-events: none;
  background: var(--bg);
}

.code-mirror code.hljs {
  display: block;
  min-height: 100%;
  background: transparent;
  padding: 0;
}

.code-input {
  overflow: auto;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  z-index: 1;
  white-space: pre;
}

.code-input::selection {
  background: rgba(124, 58, 237, 0.35);
}

.code-input::-moz-selection {
  background: rgba(124, 58, 237, 0.35);
}

.code-input::placeholder {
  color: transparent;
}

textarea {
  flex: 1;
  padding: 0.75rem;
  background: var(--bg);
  color: var(--text);
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  tab-size: 2;
}

textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.5;
}

.output-content {
  flex: 1;
  padding: 0.75rem;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.output-content.error {
  color: var(--error);
}

@media (max-width: 768px) {
  html, body {
    overflow: auto;
  }

  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 200px 200px;
    height: auto;
    min-height: calc(100vh - 49px);
  }

  .template-panel {
    grid-row: 1 / 2;
    min-height: 300px;
  }

  .data-panel textarea {
    min-height: 180px;
  }

  .output-panel {
    min-height: 200px;
  }

  .panel:last-child {
    border-bottom: none;
  }
}
