:root {
  --bg: #f4f0e6;
  --panel: rgba(255, 252, 246, 0.82);
  --panel-strong: #fffdf8;
  --panel-border: rgba(74, 58, 39, 0.14);
  --ink: #221b15;
  --muted: #6a5d50;
  --accent: #9d4b2f;
  --accent-strong: #7c351b;
  --shadow: 0 24px 60px rgba(74, 58, 39, 0.16);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(214, 180, 121, 0.25), transparent 26%),
    radial-gradient(circle at top right, rgba(145, 86, 53, 0.12), transparent 22%),
    linear-gradient(180deg, #f7f3ea 0%, #ede4d5 100%);
}

body[data-theme="night"] {
  --bg: #1d1915;
  --panel: rgba(34, 28, 24, 0.84);
  --panel-strong: #27201b;
  --panel-border: rgba(255, 225, 195, 0.1);
  --ink: #f5ebdf;
  --muted: #b8a694;
  --accent: #d27843;
  --accent-strong: #a55429;
  --shadow: 0 28px 70px rgba(0, 0, 0, 0.36);
  background:
    radial-gradient(circle at top left, rgba(210, 120, 67, 0.16), transparent 24%),
    radial-gradient(circle at top right, rgba(255, 208, 159, 0.08), transparent 22%),
    linear-gradient(180deg, #181411 0%, #251c18 100%);
}

button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.page-shell {
  max-width: 1520px;
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.workspace__intro,
.control-rail .panel,
.preview-surface,
.footer,
.dropzone {
  backdrop-filter: blur(22px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  background: rgba(255, 252, 246, 0.7);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand strong,
.panel__title h2,
.preview-rail__header h2,
.workspace__intro h1 {
  letter-spacing: -0.04em;
}

.brand small,
.lede,
.field span,
.preview-meta p,
.footer p,
.dropzone p,
#status-text {
  color: var(--muted);
}

.brand__badge {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-weight: 800;
  color: white;
  background: linear-gradient(135deg, #8e4a22, #d78f49);
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle,
.lang-toggle,
.pill,
.ghost-button,
.primary-button {
  transition:
    transform 180ms ease,
    background 180ms ease,
    color 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.theme-toggle,
.lang-toggle,
.pill {
  padding: 10px 14px;
  border-radius: 999px;
}

.pill.is-active {
  color: white;
  background: linear-gradient(135deg, #35251a, #8a4b28);
  box-shadow: 0 16px 30px rgba(53, 37, 26, 0.22);
}

.theme-toggle,
.lang-toggle,
.pill,
.ghost-button {
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  cursor: pointer;
}

.theme-toggle:hover,
.lang-toggle:hover,
.pill:hover,
.ghost-button:hover,
.primary-button:hover {
  transform: translateY(-1px);
}

.workspace {
  margin-top: 26px;
}

.workspace__intro {
  display: grid;
  grid-template-columns: 1.35fr 0.8fr;
  gap: 24px;
  padding: 28px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  background: rgba(255, 250, 240, 0.65);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.workspace__intro h1 {
  margin: 0;
  max-width: 12ch;
  font-size: clamp(2.5rem, 5vw, 4.6rem);
  line-height: 0.98;
}

.lede {
  max-width: 66ch;
  font-size: 1.04rem;
  line-height: 1.7;
}

.intro-card {
  align-self: end;
  padding: 24px;
  border: 1px solid rgba(157, 75, 47, 0.16);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255, 245, 228, 0.88), rgba(247, 235, 217, 0.72)),
    repeating-linear-gradient(
      45deg,
      rgba(157, 75, 47, 0.04) 0,
      rgba(157, 75, 47, 0.04) 12px,
      transparent 12px,
      transparent 24px
    );
}

.intro-card__label {
  display: inline-flex;
  margin-bottom: 14px;
  padding: 6px 10px;
  border-radius: 999px;
  color: white;
  background: #8b3f1b;
}

.workspace__body {
  display: grid;
  grid-template-columns: minmax(360px, 470px) minmax(0, 1fr);
  gap: 24px;
  margin-top: 24px;
  align-items: start;
}

.control-rail {
  display: grid;
  gap: 18px;
}

.dropzone,
.panel,
.preview-surface,
.footer {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.dropzone {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 28px;
  text-align: center;
  border-radius: var(--radius-xl);
  border-style: dashed;
  cursor: pointer;
}

.dropzone.is-dragging {
  border-color: rgba(157, 75, 47, 0.55);
  background: rgba(255, 244, 228, 0.92);
}

.dropzone__icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  font-size: 2rem;
  color: white;
  background: linear-gradient(135deg, #8b4120, #d58f49);
}

.panel {
  padding: 22px;
  border-radius: var(--radius-lg);
}

.panel__title,
.preview-rail__header,
.metric-row,
.field__row,
.draw-modal__header,
.draw-modal__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel__title {
  margin-bottom: 18px;
}

.panel__title h2,
.preview-rail__header h2,
.preview-placeholder h3,
.draw-modal__header h2 {
  margin: 0;
}

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

.field-grid--stacked {
  grid-template-columns: 1fr;
}

.field {
  display: grid;
  gap: 8px;
}

.field--full {
  grid-column: 1 / -1;
}

.field--compact {
  min-width: 90px;
}

.field input[type="text"],
.field input[type="number"],
.field select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(74, 58, 39, 0.15);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.75);
}

.field input[type="range"] {
  width: 100%;
  accent-color: #9d4b2f;
}

.field output,
.metric-row strong,
.signature-toolbar,
.ghost-button,
.primary-button {
  font-family: "IBM Plex Mono", monospace;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
}

.signature-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.signature-panel {
  margin-bottom: 14px;
}

.is-hidden {
  display: none !important;
}

.ghost-button,
.primary-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 14px;
  cursor: pointer;
}

.ghost-button--input {
  position: relative;
  overflow: hidden;
}

.primary-button {
  border: 1px solid rgba(76, 34, 16, 0.12);
  color: white;
  background: linear-gradient(135deg, var(--accent-strong), #d17846);
  box-shadow: 0 16px 30px rgba(124, 53, 27, 0.24);
}

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

.preview-rail {
  min-width: 0;
}

.preview-actions {
  display: flex;
  align-items: end;
  gap: 12px;
}

.preview-surface {
  margin-top: 18px;
  padding: 22px;
  border-radius: var(--radius-xl);
}

.preview-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 72vh;
  padding: 10px;
  overflow: hidden;
  border-radius: calc(var(--radius-xl) - 6px);
  background:
    linear-gradient(180deg, rgba(99, 81, 60, 0.08), rgba(255, 255, 255, 0.18)),
    repeating-linear-gradient(
      90deg,
      rgba(0, 0, 0, 0.015) 0,
      rgba(0, 0, 0, 0.015) 1px,
      transparent 1px,
      transparent 14px
    );
}

#preview-canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 30px 70px rgba(43, 31, 20, 0.18);
}

.preview-placeholder {
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(420px, calc(100% - 40px));
  padding: 24px;
  text-align: center;
  transform: translate(-50%, -50%);
  border: 1px dashed rgba(74, 58, 39, 0.28);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.75);
}

.signature-overlay {
  position: absolute;
  top: 18%;
  left: 65%;
  width: 180px;
  min-height: 90px;
  display: grid;
  place-items: center;
  padding: 10px;
  border: 1px dashed rgba(157, 75, 47, 0.45);
  border-radius: 18px;
  cursor: grab;
  background: rgba(255, 251, 247, 0.48);
  touch-action: none;
  user-select: none;
  transform-origin: center;
}

.signature-overlay img {
  width: 100%;
  display: block;
  pointer-events: none;
}

.signature-overlay::after {
  content: "Drag | top-right rotate | bottom-right resize";
  position: absolute;
  left: 50%;
  bottom: -28px;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.72rem;
  color: var(--muted);
}

.signature-overlay__content {
  width: 100%;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.signature-overlay__text {
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.1rem;
  color: #91391b;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  pointer-events: none;
}

.signature-handle {
  position: absolute;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(124, 53, 27, 0.18);
  border-radius: 999px;
  background: linear-gradient(135deg, #fff8f1, #f4d8bd);
  color: #8b3f1b;
  box-shadow: 0 8px 18px rgba(74, 58, 39, 0.16);
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
}

.signature-handle--rotate {
  top: -12px;
  right: -12px;
  cursor: alias;
}

.signature-handle--scale {
  right: -12px;
  bottom: -12px;
  cursor: nwse-resize;
}

.preview-meta {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 26px;
  padding: 22px 24px;
  border-radius: var(--radius-xl);
}

.draw-modal {
  width: min(940px, calc(100vw - 32px));
  border: none;
  border-radius: 30px;
  padding: 0;
  background: transparent;
}

.draw-modal::backdrop {
  background: rgba(33, 25, 19, 0.45);
  backdrop-filter: blur(6px);
}

.draw-modal__card {
  padding: 24px;
  border-radius: 30px;
  background: #fffaf3;
  box-shadow: 0 32px 80px rgba(33, 25, 19, 0.2);
}

#draw-canvas {
  width: 100%;
  margin-top: 18px;
  border: 1px solid rgba(74, 58, 39, 0.18);
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 242, 234, 0.92));
  cursor: crosshair;
}

@media (max-width: 1180px) {
  .workspace__intro,
  .workspace__body,
  .footer,
  .topbar {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .topbar__actions,
  .preview-actions {
    flex-wrap: wrap;
  }
}

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

  .workspace__intro,
  .preview-surface,
  .panel,
  .footer,
  .topbar {
    padding: 18px;
  }

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

  .workspace__intro h1 {
    max-width: none;
    font-size: 2.5rem;
  }

  .preview-stage {
    min-height: 54vh;
    padding: 8px;
  }
}
