:root {
  --bg: #f6f1e9;
  --panel: #fffdf8;
  --ink: #1f2d3d;
  --muted: #5a6776;
  --accent: #ba3f1d;
  --border: #e2d9cc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 15%, #fef7ec 0, #f6f1e9 45%),
    radial-gradient(circle at 80% 85%, #ece6df 0, #f6f1e9 40%);
  min-height: 100vh;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(43, 26, 6, 0.08);
}

.controls {
  padding: 20px;
}

h1 {
  margin: 0;
  font-size: 1.6rem;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
}

.field-group {
  margin-top: 14px;
}

.field-group label,
fieldset label {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 6px;
}

input[type="file"],
input[type="number"] {
  width: 100%;
  border: 1px solid #d5c8b8;
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  background: #fff;
}

.adjust-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
  margin-bottom: 8px;
}

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

.split-grid {
  margin-top: 18px;
  display: grid;
  gap: 12px;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

legend {
  font-weight: 700;
  padding: 0 6px;
}

.controls-top {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.icon-btn {
  padding: 6px 8px;
  font-size: 0.9rem;
  background: #f0ebe3;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  flex: 1;
  transition: all 0.2s ease;
}

.icon-btn:hover:not(:disabled) {
  background: #e8ddf5;
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.drop-zone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  background: #fafaf8;
  transition: all 0.2s ease;
  cursor: pointer;
}

.drop-zone:hover {
  border-color: var(--accent);
  background: #fff5f0;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: #fff5f0;
  box-shadow: 0 0 0 3px rgba(186, 63, 29, 0.1);
}

.drop-zone input {
  display: none;
}

.drop-hint {
  pointer-events: none;
  color: var(--muted);
  font-size: 0.85rem;
  display: block;
}

.with-tooltip {
  position: relative;
  cursor: help;
}

.tooltip {
  display: none;
  position: absolute;
  background: var(--ink);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  white-space: nowrap;
  z-index: 1000;
  bottom: 125%;
  left: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 8px;
  border: 4px solid transparent;
  border-top-color: var(--ink);
}

.with-tooltip:hover .tooltip {
  display: block;
}

.actions {
  margin-top: 18px;
  display: flex;
  gap: 10px;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

#resetBtn {
  background: #ded7cc;
  color: var(--ink);
  flex: 1;
}

.toggle-btn {
  background: #f0ebe3;
  color: var(--ink);
  flex: 1;
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

.export-section {
  margin-top: 18px;
  padding: 12px;
  background: #fafaf8;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.export-header {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 10px;
  color: var(--ink);
}

.export-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.export-btn {
  padding: 8px 10px;
  font-size: 0.85rem;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
}

.export-btn:nth-child(1) {
  grid-column: 1 / 3;
}

.export-presets {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.share-section {
  margin-top: 18px;
  padding: 12px;
  background: #fafaf8;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.share-header {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--ink);
}

.share-copy {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.share-btn {
  width: 100%;
  background: #2f6d5f;
  color: #fff;
  margin-bottom: 8px;
}

.share-link-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

#shareLinkInput {
  width: 100%;
  border: 1px solid #d5c8b8;
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  background: #fff;
}

.copy-share-btn {
  background: #ded7cc;
  color: var(--ink);
}

.export-presets label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.preset-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.preset-btn {
  padding: 6px 8px;
  font-size: 0.75rem;
  background: #e8dfd5;
  color: var(--ink);
  border-radius: 6px;
}

.hint {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.preview {
  display: flex;
  justify-content: center;
  align-items: start;
  padding: 20px;
  overflow: auto;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
}

#mockupCanvas {
  width: min(1200px, 100%);
  height: auto;
  background: #fff;
  border-radius: 12px;
  border: 1px solid #d9d0c3;
  display: block;
}

.loading-indicator {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.loading-indicator.show {
  opacity: 1;
}

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

  .preview {
    position: static;
    max-height: none;
    margin-top: 20px;
  }

  .tooltip {
    white-space: normal;
    max-width: 150px;
  }

  .export-buttons {
    grid-template-columns: 1fr;
  }

  .export-btn:nth-child(1) {
    grid-column: auto;
  }

  .preset-buttons {
    grid-template-columns: 1fr;
  }

  .share-link-row {
    grid-template-columns: 1fr;
  }
}
