:root {
  color-scheme: light;
  --ink: #1c2024;
  --muted: #667078;
  --line: #d8dde0;
  --surface: #ffffff;
  --canvas: #edf0ef;
  --accent: #d94d36;
  --accent-dark: #ad3828;
  --green: #24765b;
  --blue: #316fa3;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { max-width: 100%; overflow-x: hidden; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
}

button, input { font: inherit; }

.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: #202528;
  color: #fff;
  border-bottom: 3px solid var(--accent);
}

.brand { font-size: 21px; font-weight: 760; }
.connection { display: flex; align-items: center; gap: 8px; color: #ced5d7; font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #54c49b; }

.workspace {
  width: 100%;
  min-height: calc(100vh - 102px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  max-width: 1280px;
  margin: 0 auto;
  background: var(--surface);
  border-inline: 1px solid var(--line);
}

.image-workspace { min-width: 0; padding: 34px clamp(24px, 5vw, 64px) 42px; border-right: 1px solid var(--line); }
.setup-panel { min-width: 0; padding: 34px 30px; background: #f8f9f8; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.step-label { display: block; margin-bottom: 7px; color: var(--accent); font-size: 12px; font-weight: 750; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 24px; line-height: 1.2; }

.secondary-button, .primary-button {
  border: 0;
  border-radius: 4px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.secondary-button { padding: 10px 14px; color: var(--blue); border: 1px solid #9bb7cc; background: #fff; }
.secondary-button:hover { background: #eef6fb; }
.primary-button { width: 100%; min-height: 48px; padding: 12px 16px; color: #fff; background: var(--accent); }
.primary-button:hover:not(:disabled) { background: var(--accent-dark); }
.primary-button:disabled { cursor: not-allowed; background: #aeb5b8; }

.preview-shell {
  position: relative;
  min-width: 0;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1264 / 1680;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid #aeb6b9;
  background: #d9dddc;
  box-shadow: 0 12px 28px rgba(24, 30, 33, 0.15);
}

#sleep-preview { display: block; width: 100%; min-width: 0; height: 100%; background: #fff; }
.empty-preview { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #5f686d; background: #e3e6e5; }
.empty-preview span { font-size: 13px; }
.image-mark { width: 48px; height: 38px; margin-bottom: 6px; border: 2px solid #788287; border-radius: 3px; position: relative; }
.image-mark::before { content: ""; position: absolute; width: 9px; height: 9px; top: 7px; left: 8px; border-radius: 50%; background: #788287; }
.image-mark::after { content: ""; position: absolute; left: 7px; right: 7px; bottom: 6px; height: 15px; background: #788287; clip-path: polygon(0 100%, 35% 25%, 53% 62%, 72% 0, 100% 100%); }

.position-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-top: 26px; }
.position-controls label { display: grid; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 650; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.checklist { list-style: none; margin: 27px 0; padding: 0; display: grid; gap: 19px; }
.checklist li { display: grid; grid-template-columns: 28px 1fr; gap: 11px; align-items: start; }
.checklist li > span { width: 27px; height: 27px; display: grid; place-items: center; border: 1px solid #a9b1b4; border-radius: 50%; color: var(--muted); font-size: 12px; font-weight: 750; }
.checklist li.done > span { color: #fff; border-color: var(--green); background: var(--green); }
.checklist strong, .checklist small { display: block; }
.checklist strong { margin: 1px 0 4px; font-size: 14px; }
.checklist small { color: var(--muted); font-size: 12px; line-height: 1.35; }

.webdav-fields { margin: 24px 0 0; padding: 16px; border: 1px solid #cbd1d3; border-radius: 4px; background: #fff; }
.webdav-fields legend { padding: 0 6px; font-size: 13px; font-weight: 750; }
.webdav-fields label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
.webdav-fields input { width: 100%; min-width: 0; height: 38px; padding: 7px 9px; border: 1px solid #adb6ba; border-radius: 3px; color: var(--ink); background: #fff; }
.webdav-fields input:focus { outline: 2px solid #8eb7d2; outline-offset: 1px; border-color: #5d8eaf; }
.credential-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 11px; }
#saved-webdav { display: block; margin-top: 10px; color: var(--green); font-size: 11px; }

.error-message { margin: 12px 0 0; color: #a12f23; font-size: 13px; line-height: 1.4; }
.run-status { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 18px; }
.status-line { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; font-size: 13px; }
.status-line span { color: var(--blue); }
#setup-log { height: 170px; margin: 0; padding: 12px; overflow: auto; border: 1px solid #c9ced0; border-radius: 3px; background: #202528; color: #d8e1e3; font: 11px/1.45 Consolas, monospace; white-space: pre-wrap; }

.kindle-step { display: grid; grid-template-columns: 32px 1fr; gap: 11px; margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.complete-mark { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--green); font-weight: 800; }
.kindle-step strong { font-size: 14px; }
.kindle-step p { margin: 7px 0 10px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.kindle-urls { display: grid; gap: 7px; }
.kindle-urls code { display: block; padding: 8px; overflow-wrap: anywhere; border: 1px solid #b9c8d2; border-radius: 3px; color: #24597d; background: #edf5fa; font-size: 12px; }

footer { height: 42px; display: flex; align-items: center; justify-content: center; padding: 0 20px; color: #727b80; background: #e5e8e7; font-size: 11px; }
footer a { color: #4b687a; }

@media (max-width: 850px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .image-workspace { border-right: 0; border-bottom: 1px solid var(--line); }
  .setup-panel { padding-bottom: 44px; }
}

@media (max-width: 520px) {
  .topbar { padding: 0 18px; }
  .image-workspace, .setup-panel { padding-inline: 18px; }
  .section-heading { align-items: start; flex-direction: column; }
  .secondary-button { width: 100%; }
  .position-controls { grid-template-columns: 1fr; }
  .credential-row { grid-template-columns: 1fr; }
  footer { height: auto; min-height: 42px; text-align: center; }
}
