:root {
  --bg: #f7f5ff;
  --surface: #ffffff;
  --ink: #151522;
  --muted: #6d6885;
  --line: #e8e2f6;
  --primary: #7b61ff;
  --primary-dark: #2b114f;
  --coral: #ff7a59;
  --cream: #f5e9dd;
  --shadow: 0 18px 50px rgba(43, 17, 79, .12);
  --danger: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(201, 184, 255, .44), transparent 34%),
    linear-gradient(135deg, #ffffff 0%, var(--bg) 54%, #fff7f2 100%);
}

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

.app {
  display: grid;
  grid-template-columns: minmax(340px, 430px) 1fr;
  min-height: 100vh;
}

.panel {
  overflow: auto;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
  font-weight: 900;
}

.brand img {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 12px 26px rgba(123, 97, 255, .24);
}

.tool-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.tool-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 900;
}

.tool-nav a.active {
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), #6244f5);
  color: white;
  box-shadow: 0 10px 22px rgba(123, 97, 255, .20);
}

.hero {
  display: grid;
  gap: 10px;
  margin: 20px 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(123, 97, 255, .12), rgba(255, 122, 89, .08)),
    var(--surface);
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }

h1 {
  color: var(--primary-dark);
  font-size: 30px;
  line-height: 1;
}

h2 {
  color: var(--primary-dark);
  font-size: 22px;
  line-height: 1.1;
}

p, .hint {
  color: var(--muted);
  line-height: 1.45;
}

.hint {
  font-size: 12px;
}

.section {
  margin-top: 22px;
}

.section h2 {
  margin-bottom: 10px;
  color: var(--primary);
  font-size: 12px;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-row h2 {
  margin-bottom: 0;
}

label {
  display: grid;
  gap: 6px;
  margin: 10px 0;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 800;
}

input, select, button {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

input, select {
  padding: 10px 11px;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(123, 97, 255, .13);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.layout-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.layout-card {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 8px 10px;
  border: 1px solid #e4d8c9;
  border-radius: 8px;
  background: rgba(255, 252, 247, .96);
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.layout-card:hover,
.layout-card.active {
  border-color: #2e9f84;
  background: #eefdf8;
}

.layout-card strong,
.layout-card small {
  display: block;
}

.layout-card strong {
  color: #14111f;
  font-size: 15px;
  line-height: 1.1;
}

.layout-card small {
  margin-top: 3px;
  color: #746b5e;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

.layout-thumb {
  display: block;
  width: 42px;
  height: 48px;
  border: 1px solid #d5c7b8;
  background: #fbf6ee;
  position: relative;
}

.layout-thumb::after {
  content: "";
  position: absolute;
  inset: 8px 13px;
  border: 1px solid #b9aa9a;
  background: #eadfd2;
}

.layout-thumb.round::after {
  inset: 8px;
  border-radius: 999px;
}

.layout-thumb.polaroid::after {
  inset: 7px 9px 15px;
  background: white;
  box-shadow: 0 0 0 5px #f5efe7;
}

.layout-thumb.polaroid.tape::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 12px;
  width: 18px;
  height: 7px;
  border-radius: 2px;
  background: rgba(232, 135, 176, .55);
  transform: rotate(-8deg);
  z-index: 1;
}

.layout-thumb.polaroid.hearts {
  background:
    radial-gradient(circle at 9px 9px, #e887b0 0 2px, transparent 3px),
    radial-gradient(circle at 33px 13px, #ff7a59 0 2px, transparent 3px),
    #fbf6ee;
}

.layout-thumb.polaroid.dark {
  background: #191721;
}

.layout-thumb.polaroid.dark::after {
  box-shadow: 0 0 0 5px #191721;
}

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

.check input {
  width: 18px;
  min-height: 18px;
}

button {
  cursor: pointer;
  padding: 0 12px;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), #6244f5);
  color: white;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(123, 97, 255, .24);
}

button.secondary {
  background: white;
  color: var(--primary);
  border-color: var(--line);
  box-shadow: none;
}

button.warning {
  background: var(--coral);
  color: white;
  box-shadow: 0 10px 24px rgba(255, 122, 89, .22);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.photo-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.photo-actions button {
  width: auto;
  min-height: 34px;
}

.photo-repeat-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.photo-repeat-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 84px auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf9;
}

.photo-repeat-row img {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
}

.photo-repeat-row strong,
.photo-repeat-row span {
  display: block;
}

.photo-repeat-row strong {
  color: var(--primary-dark);
  font-size: 13px;
  line-height: 1.15;
}

.photo-repeat-row span {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-repeat-row label {
  margin: 0;
  gap: 4px;
  font-size: 11px;
}

.photo-repeat-row input {
  min-height: 34px;
  padding: 7px 8px;
}

.photo-repeat-row button {
  width: auto;
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.pill, .help-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 900;
}

.help-link {
  color: var(--primary);
}

.status {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid #ddd4ff;
  border-radius: 8px;
  background: #f0ecff;
  color: var(--primary-dark);
  font-size: 13px;
  line-height: 1.35;
}

.preview {
  overflow: auto;
  padding: 22px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .9);
  box-shadow: var(--shadow);
}

.sheet-wrap {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(123, 97, 255, .16), rgba(255, 122, 89, .10)),
    #fbf9ff;
  box-shadow: var(--shadow);
  overflow: auto;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  background: white;
  box-shadow: 0 10px 36px rgba(43, 17, 79, .16);
}

@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .photo-repeat-row { grid-template-columns: 42px minmax(0, 1fr) 78px; }
  .photo-repeat-row button { grid-column: 2 / 4; width: 100%; }
}
