:root {
  color-scheme: light;
  --page-bg: #f5f6f2;
  --panel-bg: #ffffff;
  --ink: #151713;
  --muted: #6c7068;
  --border: #d9ddd2;
  --accent: #168f82;
  --accent-strong: #0b5f57;
  --shadow: 0 18px 48px rgba(28, 31, 24, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page-bg);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC",
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 420px;
  gap: 24px;
  min-height: 100vh;
  padding: 24px;
}

.preview-pane {
  display: grid;
  place-items: center;
  min-width: 0;
}

.preview-frame {
  display: grid;
  place-items: center;
  width: min(100%, 620px);
  max-height: calc(100vh - 48px);
  padding: 14px;
  background: #171916;
  box-shadow: var(--shadow);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100vh - 76px);
  object-fit: contain;
  background: #000;
}

.controls-pane {
  align-self: start;
  display: grid;
  gap: 14px;
  width: 100%;
  padding: 18px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.control-block {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.control-grid.compact {
  grid-template-columns: 1fr 1fr;
}

.field-label {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

.field-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.font-status {
  color: var(--accent-strong);
  font-size: 11px;
  line-height: 1.2;
}

.font-status.is-loading {
  color: var(--muted);
}

.font-status.is-error {
  color: #a64231;
}

textarea,
input[type="text"],
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcf8;
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 168px;
  padding: 12px;
  line-height: 1.65;
  resize: vertical;
}

.secondary-textarea {
  min-height: 108px;
}

input[type="text"],
select {
  min-height: 42px;
  padding: 0 11px;
}

textarea:focus,
input[type="text"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 143, 130, 0.13);
}

.field-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.toggle-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcf8;
  cursor: pointer;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.toggle-row span {
  display: grid;
  gap: 2px;
}

.toggle-row strong {
  font-size: 14px;
  font-weight: 700;
}

.toggle-row small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.segmented,
.icon-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #eef1ea;
}

.segmented button,
.icon-group button {
  min-height: 34px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segmented button.is-active,
.icon-group button.is-active {
  background: #fff;
  color: var(--accent-strong);
  box-shadow: 0 1px 4px rgba(28, 31, 24, 0.13);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="color"] {
  width: 100%;
  min-height: 42px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcf8;
}

input[type="color"]:disabled {
  opacity: 0.45;
}

.size-note {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcf8;
  color: var(--muted);
  font-size: 13px;
}

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

.generate-button,
.download-button {
  min-height: 48px;
  border: 0;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}

.generate-button {
  background: var(--accent);
  color: #fff;
}

.download-button {
  border: 1px solid var(--accent);
  background: #fff;
  color: var(--accent-strong);
}

.generate-button:active,
.download-button:active {
  transform: translateY(1px);
}

.save-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcf8;
}

.save-panel[hidden] {
  display: none;
}

.save-panel__text {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.save-panel__text strong {
  color: var(--ink);
  font-size: 13px;
}

.save-link {
  display: grid;
  place-items: center;
  min-height: 40px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: none;
}

#generatedImage {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border: 1px solid #111;
  background: #000;
}

@media (max-width: 860px) {
  body {
    background: #ffffff;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 100dvh;
    padding: 0;
  }

  .preview-pane {
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 42dvh;
    padding: env(safe-area-inset-top) 12px 12px;
    background: var(--page-bg);
    border-bottom: 1px solid var(--border);
  }

  .preview-frame {
    width: min(100%, 330px);
    max-height: 40dvh;
    padding: 8px;
    box-shadow: 0 10px 24px rgba(28, 31, 24, 0.18);
  }

  canvas {
    max-height: calc(40dvh - 16px);
  }

  .controls-pane {
    border: 0;
    box-shadow: none;
    padding: 16px 14px calc(18px + env(safe-area-inset-bottom));
  }

  .control-grid {
    grid-template-columns: 1fr;
  }

  .control-grid.compact {
    grid-template-columns: 1fr 1fr;
  }

  textarea {
    min-height: 150px;
  }

  #generatedImage {
    max-height: 56dvh;
  }
}
