:root {
  --bg: #f4efe7;
  --card: rgba(255, 252, 247, 0.82);
  --card-strong: #fffaf2;
  --line: rgba(62, 48, 32, 0.12);
  --line-strong: rgba(62, 48, 32, 0.18);
  --text: #261d14;
  --muted: #78695a;
  --accent: #bd7f41;
  --accent-dark: #9d6630;
  --blue: #2f7cff;
  --shadow: 0 20px 60px rgba(88, 63, 31, 0.14);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(244, 202, 150, 0.45), transparent 32%),
    radial-gradient(circle at bottom right, rgba(221, 182, 137, 0.35), transparent 28%),
    linear-gradient(135deg, #f7f1e8 0%, #f1e6d7 54%, #efe4d7 100%);
}

.page-shell {
  position: relative;
  overflow: hidden;
  min-height: 100vh;
  padding: 28px;
}

.bg-orb {
  position: absolute;
  border-radius: 999px;
  filter: blur(18px);
  opacity: 0.6;
  pointer-events: none;
}

.orb-a {
  top: -80px;
  left: -60px;
  width: 260px;
  height: 260px;
  background: rgba(255, 214, 170, 0.65);
}

.orb-b {
  right: 5%;
  bottom: -70px;
  width: 320px;
  height: 320px;
  background: rgba(209, 173, 120, 0.28);
}

.app-card {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: 40px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 36px;
  background: var(--card);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.hero {
  max-width: 820px;
  margin-bottom: 30px;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.45);
}

.hero h1 {
  margin: 0 0 14px;
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
}

.hero p {
  margin: 0;
  max-width: 680px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.75;
}

.panel {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 249, 241, 0.72);
}

.route-panel {
  margin-top: 24px;
}

.panel-top,
.preview-header,
.action-row,
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-top h2,
.preview-header h3,
.controls-card h3 {
  margin: 0 0 4px;
}

.panel-top p,
.hint-text,
.editor-help {
  margin: 0;
  color: var(--muted);
}

.upload-button,
.primary-button,
.download-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s ease, border-color 0.2s ease;
}

.upload-button,
.primary-button {
  border: none;
  cursor: pointer;
  color: #fffdf9;
  background: linear-gradient(135deg, var(--accent) 0%, #d29b5f 100%);
  box-shadow: 0 16px 30px rgba(189, 127, 65, 0.22);
}

.secondary-button,
.download-button {
  border: 1px solid var(--line);
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
}

.upload-button:hover,
.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.download-button:hover:not(.disabled) {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.download-button.disabled {
  pointer-events: none;
  opacity: 0.45;
}

.full-width {
  width: 100%;
}

.file-meta,
.status-text,
.route-meta {
  color: var(--muted);
  font-size: 0.95rem;
}

.config-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(220px, 0.8fr);
  gap: 16px;
  margin-top: 20px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-group span {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.text-input,
.data-output,
input[type="range"],
select {
  width: 100%;
}

.text-input,
.data-output {
  min-height: 50px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.84);
  font: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.text-input:focus,
.data-output:focus {
  border-color: rgba(189, 127, 65, 0.7);
  box-shadow: 0 0 0 4px rgba(189, 127, 65, 0.12);
}

.mode-grid {
  margin-top: 16px;
}

.server-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  flex-wrap: wrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.9rem;
  font-weight: 700;
}

.status-badge.saved {
  color: #20593b;
  background: rgba(228, 247, 234, 0.92);
  border-color: rgba(32, 89, 59, 0.18);
}

.color-input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.84);
  padding: 6px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 0;
  color: var(--muted);
  font-weight: 700;
}

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

.file-meta {
  margin: 20px 0 22px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.preview-card,
.controls-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.5);
}

.point-depth-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(250, 248, 243, 0.88);
}

.point-depth-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.point-depth-header strong {
  color: var(--text);
}

.preview-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 360px;
  padding: 12px;
  margin-top: 14px;
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(244, 234, 219, 0.92)),
    repeating-linear-gradient(
      45deg,
      rgba(193, 162, 122, 0.06),
      rgba(193, 162, 122, 0.06) 12px,
      rgba(255, 255, 255, 0.05) 12px,
      rgba(255, 255, 255, 0.05) 24px
    );
}

.preview-stage span,
.editor-stage > span {
  padding: 0 18px;
  color: var(--muted);
  text-align: center;
}

.preview-stage img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: none;
}

.preview-stage.has-image img,
.editor-stage.has-image img,
.editor-stage.has-image canvas {
  display: block;
}

.preview-stage.has-image span,
.editor-stage.has-image > span {
  display: none;
}

.action-row {
  margin-top: 22px;
}

.error-box {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid rgba(182, 67, 46, 0.18);
  border-radius: 16px;
  color: #8a2f1e;
  background: rgba(255, 240, 235, 0.95);
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(300px, 0.9fr);
  gap: 22px;
  margin-top: 22px;
}

.editor-column,
.control-column {
  min-width: 0;
}

.editor-toolbar {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.map-editor-shell {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.56);
  padding: 18px;
}

.editor-stage-wrap {
  width: 100%;
}

.editor-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 420px;
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(244, 234, 219, 0.92)),
    repeating-linear-gradient(
      45deg,
      rgba(193, 162, 122, 0.06),
      rgba(193, 162, 122, 0.06) 12px,
      rgba(255, 255, 255, 0.05) 12px,
      rgba(255, 255, 255, 0.05) 24px
    );
}

.editor-stage img,
.editor-stage canvas {
  position: absolute;
  inset: 0;
  display: none;
}

.editor-stage img {
  user-select: none;
  pointer-events: none;
}

.editor-stage canvas {
  touch-action: none;
  cursor: crosshair;
}

.editor-help {
  margin-top: 14px;
  line-height: 1.7;
}

.control-column {
  display: grid;
  gap: 16px;
}

.controls-card {
  display: grid;
  gap: 14px;
}

.hint-text {
  font-size: 0.92rem;
  line-height: 1.7;
}

.data-output {
  min-height: 180px;
  padding: 14px 16px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
}

.hidden {
  display: none;
}

@media (max-width: 980px) {
  .app-card {
    padding: 24px;
    border-radius: 28px;
  }

  .config-grid,
  .preview-grid,
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .preview-stage,
  .editor-stage {
    min-height: 280px;
  }
}

@media (max-width: 640px) {
  .page-shell {
    padding: 14px;
  }

  .panel,
  .app-card,
  .map-editor-shell {
    padding: 18px;
  }

  .panel-top,
  .preview-header,
  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .editor-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .upload-button,
  .primary-button,
  .download-button,
  .secondary-button {
    width: 100%;
  }

  .server-actions {
    flex-direction: column;
    align-items: stretch;
  }
}
