*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --border: rgba(0,0,0,0.10);
  --border-strong: rgba(0,0,0,0.18);
  --text: #1a1a1a;
  --text-muted: #666;
  --text-hint: #999;
  --accent: #1a1a1a;
  --accent-text: #fff;
  --radius: 10px;
  --sidebar-w: 320px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.subtitle {
  font-size: 12px;
  color: var(--text-hint);
  margin-top: 2px;
}

h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-hint);
  margin-bottom: 10px;
}

section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.field-group label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.req { color: #c0392b; }

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="url"] {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus {
  border-color: var(--accent);
}

select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
  cursor: pointer;
}

select:focus {
  border-color: var(--accent);
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

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

button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  transition: background 0.12s, opacity 0.12s;
}

button:hover { background: var(--bg); }
button:active { opacity: 0.75; }

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

button.primary:hover { opacity: 0.85; background: var(--accent); }

.instructions {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.instructions ol {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.instructions code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: "SF Mono", "Fira Mono", monospace;
  font-size: 11px;
}

.note {
  font-size: 12px;
  color: var(--text-hint);
  line-height: 1.5;
}

.affiliate-links {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}

.affiliate-links h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-hint);
  margin-bottom: 8px;
}

.device-links-group {
  margin-bottom: 10px;
}

.device-links-group h4 {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.device-links-group ul {
  list-style: none;
  padding-left: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.device-links-group a {
  font-size: 12px;
  color: var(--text-hint);
  text-decoration: none;
  transition: color 0.15s;
}

.device-links-group a:hover {
  color: var(--text-muted);
  text-decoration: underline;
}

/* ── Preview area ─────────────────────────────────────── */

.preview-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.device-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.device-screen {
  position: relative;
  width: 240px;
  height: 400px;
  border-radius: 12px;
  overflow: hidden;
  border: 1.5px solid var(--border-strong);
  box-shadow: 0 4px 24px rgba(0,0,0,0.10);
  background-image: 
    linear-gradient(45deg, #e0e0e0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e0e0e0 75%),
    linear-gradient(45deg, #e0e0e0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e0e0e0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px, 8px -8px, -8px 8px;
  background-color: #f5f5f5;
}

/* Simulated book text background */
.book-text-sim {
  position: absolute;
  inset: 0;
  background: #f8f6f0;
  padding: 20px 16px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 10px;
  line-height: 1.7;
  color: #2a2a2a;
  overflow: hidden;
  user-select: none;
  pointer-events: none;
}

#out-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.frame-label {
  font-size: 11px;
  color: var(--text-hint);
  text-align: center;
}

/* ── QR scratch space ─────────────────────────────────── */

#qr-scratch {
  position: absolute;
  left: -9999px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ── Responsive ───────────────────────────────────────── */

@media (max-width: 680px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .preview-area { padding: 24px 16px; }
}
