:root {
  --bg: #f7f4ef;
  --panel: #fffdf9;
  --ink: #1f1f1f;
  --muted: #6c665f;
  --line: #ded2c5;
  --accent: #d94f72;
  --accent-dark: #b73758;
  --control: #ffffff;
  --shadow: 0 14px 38px rgba(58, 42, 29, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.app {
  min-height: 100vh;
  padding: 28px;
}

.workspace {
  width: min(1260px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 18px;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
  letter-spacing: 0;
}

p {
  max-width: 780px;
  margin: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.45;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.input-panel,
.preview-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
}

.input-panel label,
.range-control span,
.number-control span,
.direction-control legend {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

textarea {
  display: block;
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid #cfc3b5;
  border-radius: 8px;
  background: var(--control);
  color: var(--ink);
  padding: 12px;
  line-height: 1.45;
  outline: none;
}

textarea:focus,
.number-control input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 79, 114, 0.16);
}

.input-meta {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 132px;
  gap: 14px;
  margin-top: 16px;
  align-items: end;
}

.range-control input {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.number-control input {
  width: 100%;
  height: 42px;
  border: 1px solid #cfc3b5;
  border-radius: 8px;
  background: var(--control);
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

.direction-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0 0;
  padding: 0;
  border: 0;
}

.direction-control legend {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.direction-control label {
  position: relative;
  display: block;
  margin: 0;
  cursor: pointer;
}

.direction-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.direction-control span {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  text-align: center;
  padding: 9px 10px;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.direction-control input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.direction-control input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(217, 79, 114, 0.16);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: 10px 16px;
  font-weight: 700;
  transition: background 150ms ease, border-color 150ms ease, transform 150ms ease, opacity 150ms ease;
}

.button:hover:not(:disabled) {
  border-color: #c7b8a6;
  background: #fff8f1;
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

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

.button.primary:hover:not(:disabled) {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.preview-header h2 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: 0;
}

.preview-header span {
  color: var(--muted);
  font-size: 14px;
}

.canvas-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

#spiralCanvas {
  display: block;
  width: 100%;
  max-width: 980px;
  height: auto;
  background: #fff;
}

.status {
  min-height: 26px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.status.error {
  color: #9e263a;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .app {
    padding: 18px;
  }

  .field-grid,
  .direction-control,
  .preview-header,
  .form-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.back-button {
  gap: 8px;
  white-space: nowrap;
}

.back-button::before {
  content: "←";
  font-size: 18px;
  line-height: 1;
}

@media (max-width: 760px) {
  .topbar {
    display: grid;
  }

  .topbar .actions {
    justify-content: stretch;
  }

  .back-button {
    width: 100%;
  }
}
