:root {
  --bg: #f7f4ef;
  --panel: #fffdf9;
  --ink: #1f1f1f;
  --muted: #6c665f;
  --line: #ded2c5;
  --accent: #d94f72;
  --accent-dark: #b73758;
  --grid-border: #f4a7a7;
  --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(1180px, 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: 720px;
  margin: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.45;
}

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

.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;
}

.button:hover {
  border-color: #c7b8a6;
  background: #fff8f1;
}

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

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

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

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

.input-panel label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

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

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

.input-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}

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

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

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

.cards {
  display: grid;
  gap: 18px;
}

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

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

.card-title {
  min-width: 0;
}

.card-title h2 {
  margin: 0 0 3px;
  font-size: 22px;
  letter-spacing: 0.04em;
}

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

.card-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.bend-control {
  display: grid;
  min-width: 190px;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

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

.bend-control input:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

.puzzle-wrap {
  overflow-x: auto;
  padding-bottom: 2px;
}

.puzzle-canvas {
  display: block;
  width: min(100%, 720px);
  height: auto;
  border-radius: 6px;
  background: #fff;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px dashed #c8b8a5;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.4);
  text-align: center;
  padding: 24px;
}

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

  .topbar,
  .card-header {
    display: grid;
  }

  .actions {
    justify-content: stretch;
  }

  .form-actions,
  .card-controls,
  .card-actions {
    display: grid;
    justify-content: stretch;
  }

  .bend-control {
    min-width: 0;
  }

  .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%;
  }
}
