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

:root {
  --bg: #111;
  --surface: #1e1e1e;
  --border: #333;
  --text: #e0e0e0;
  --text-muted: #888;
  --primary: #4a9eff;
  --primary-hover: #6ab0ff;
  --danger: #e05555;
  --radius: 8px;
  --gap: 16px;
}

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--gap);
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  letter-spacing: 0.02em;
}

.topbar-nav {
  display: flex;
  gap: 4px;
}

.topbar-nav a {
  color: var(--text-muted);
  font-size: 14px;
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}

.topbar-nav a:hover,
.topbar-nav a.active {
  background: var(--border);
  color: var(--text);
}

/* ── Container ── */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ── Kindle preview frame ── */
.kindle-wrap {
  display: flex;
  justify-content: center;
}

.kindle-frame {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 3 / 4;
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.kindle-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  image-rendering: pixelated;
}

/* ── Status row ── */
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 4px;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  margin-right: 6px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #444; color: var(--text); }

.btn-full { width: 100%; }

.btn-row {
  display: flex;
  gap: 8px;
}

/* ── Form ── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-group:last-of-type { margin-bottom: 0; }

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

input[type="text"],
input[type="number"],
select,
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  padding: 10px 12px;
  width: 100%;
  font-family: inherit;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

textarea { resize: vertical; min-height: 100px; }

select option { background: var(--surface); }

/* ── Layout picker ── */
.layout-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.layout-option {
  position: relative;
}

.layout-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.layout-option label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.layout-option input:checked + label {
  border-color: var(--primary);
  background: rgba(74, 158, 255, 0.08);
  color: var(--text);
}

.layout-preview {
  width: 48px;
  height: 64px;
  border: 1px solid currentColor;
  border-radius: 3px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0.7;
}

.lp-header { height: 12px; background: currentColor; opacity: 0.5; }
.lp-footer { height: 8px; background: currentColor; opacity: 0.3; margin-top: auto; }
.lp-body { flex: 1; display: flex; }
.lp-full { flex: 1; background: currentColor; opacity: 0.15; margin: 2px; border-radius: 1px; }
.lp-half { flex: 1; background: currentColor; opacity: 0.15; margin: 2px; border-radius: 1px; }

/* htmx loading indicator */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request.htmx-indicator { display: inline; }
