:root {
  --bg: #161616;
  --panel: #1f1f1f;
  --panel-alt: #262626;
  --border: #3a3a3a;
  --text: #eaeaea;
  --muted: #9a9a9a;
  --accent: #00b8d4;
  --accent-text: #04222a;
  --error: #ff6b6b;
  --radius: 10px;
  --gap: 14px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* The browser's default `[hidden] { display: none }` rule has the same
   specificity as class selectors like `.input-row { display: grid }` below
   and loses to them if it merely relies on source order, so pin it with
   !important -- otherwise toggling `el.hidden = true` on a flex/grid child
   silently does nothing. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  padding: 16px 16px 4px;
  text-align: center;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

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

.layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--gap);
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- preview ---------- */

.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dropzone {
  position: relative;
  background: var(--panel);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  min-height: 240px;
}

.dropzone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: var(--panel-alt);
}

#previewCanvas {
  display: block;
  width: 100%;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 20px;
  pointer-events: none;
}

.placeholder p {
  margin: 0;
  line-height: 1.5;
}

.info-bar {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.2em;
}

.info-bar.error {
  color: var(--error);
}

/* ---------- controls ---------- */

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.field-group {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.field-group h2 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 8px 0 0;
  word-break: break-word;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 10px 0 0;
  line-height: 1.4;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.input-row + .input-row {
  margin-top: 10px;
}

.input-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.input-field.full {
  width: 100%;
}

input[type="number"],
input[type="text"] {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
  min-height: 44px;
  width: 100%;
}

input[type="number"]:focus,
input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

input[type="number"]:disabled,
input[type="text"]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input[type="radio"]:disabled + span,
label:has(input[type="radio"]:disabled) {
  opacity: 0.5;
}

.radio-row,
.radio-col {
  display: flex;
  gap: 16px;
  color: var(--text);
  font-size: 0.92rem;
}

.radio-col {
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.radio-row {
  flex-wrap: wrap;
  row-gap: 8px;
}

.radio-row label,
.radio-col label,
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}

input[type="radio"],
input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex: none;
}

.checkbox-row {
  margin-top: 12px;
  font-size: 0.92rem;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 600;
  min-height: 46px;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn.full {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-secondary {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn + .btn {
  margin-top: 10px;
}

/* ---------- status bar ---------- */

.status-bar {
  padding: 10px 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

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

/* ---------- wide screens: two-column layout ---------- */

@media (min-width: 880px) {
  .layout {
    flex-direction: row;
    align-items: flex-start;
  }

  .preview-panel {
    flex: 1 1 60%;
    position: sticky;
    top: var(--gap);
  }

  .controls-panel {
    flex: 1 1 40%;
    max-width: 420px;
  }

  .dropzone {
    min-height: 420px;
  }
}

/* ---------- light mode ---------- */

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f4f5;
    --panel: #ffffff;
    --panel-alt: #f0f0f2;
    --border: #d9d9df;
    --text: #1a1a1a;
    --muted: #666670;
    --accent: #007b8f;
    --accent-text: #ffffff;
  }
}
