:root {
  --paper: #f3efe6;
  --ink: #1c1b19;
  --card: #fffdf8;
  --line: #ddd5c8;
  --line-strong: #c4b9a8;
  --muted: #6e685e;
  --accent: #6b4a2b;
  --accent-soft: #efe4d6;
  --bad: #9b2c2c;
  --bad-soft: #f8e3e0;
  --good: #2f6b3a;
  --good-soft: #e2f0e3;
  --radius: 14px;
  --dock: 96px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-padding-bottom: var(--dock); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 "Avenir Next", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

/* Header */

.top {
  max-width: 960px;
  margin: 0 auto;
  padding: 22px 16px 6px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand img { flex: none; }

h1 { margin: 0; font-size: 22px; letter-spacing: 0.01em; }

.sub { margin: 0; color: var(--muted); font-size: 14px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 7px 12px;
  font-size: 14px;
}

.chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
}

.chip.set .dot { background: var(--accent); }
.chip.live .dot { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 16px calc(var(--dock) + 32px);
}

/* Steps */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 14px;
}

.step-head, summary {
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-title { margin: 0; font-size: 17px; font-weight: 650; white-space: nowrap; }

.num {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--card);
  font-size: 13px;
  font-weight: 700;
}

summary {
  cursor: pointer;
  list-style: none;
  border-radius: 8px;
}

summary::-webkit-details-marker { display: none; }

summary::after {
  content: "";
  margin-left: auto;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-3px);
  transition: transform 0.15s;
}

details[open] > summary::after { transform: rotate(-135deg) translateY(-1px); }

.summary-note {
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

details[open] .summary-note { display: none; }

.setup-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
  margin-top: 14px;
}

.setup-body .hint, #scan { grid-column: 1 / -1; }

.step > textarea { margin-top: 12px; }

.labels-step { margin-top: 26px; }
.labels-step .step-head { padding: 0 2px; }

.count-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  vertical-align: 2px;
}

/* Fields */

.field span, .fields > label > span, .order legend {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 5px;
}

.printer-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 10px 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  min-height: 44px;
}

.printer-box.ready { border-color: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }

.printer-state { flex: 1 1 160px; min-width: 0; display: grid; }
.printer-state strong { font-size: 15px; }
.printer-state small { color: var(--muted); font-size: 13px; }
.printer-box.ready .printer-state strong::before { content: "● "; color: var(--good); }
.printer-box .link { margin-left: 0; }

.field em { font-style: normal; font-weight: 400; color: var(--muted); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  color: var(--ink);
  font: inherit;
  padding: 10px 12px;
  min-height: 44px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236e685e' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 12px center;
  text-overflow: ellipsis;
  cursor: pointer;
}

.fields select { min-height: 40px; padding-top: 8px; padding-bottom: 8px; }

input::placeholder, textarea::placeholder { color: #a39b8e; }

textarea {
  min-height: 150px;
  resize: vertical;
  font: 15px/1.5 ui-monospace, "SF Mono", Menlo, monospace;
}

.with-btn { display: flex; gap: 8px; }
.with-btn input { flex: 1; min-width: 0; }

.hint { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

/* Buttons */

button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: white;
  border-radius: 999px;
  padding: 10px 18px;
  min-height: 44px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}

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

button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line-strong);
}

button.ghost:hover:not(:disabled) { background: var(--accent-soft); }

button.ghost.light { color: white; border-color: rgba(255, 255, 255, 0.5); }

button.link {
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 6px 8px;
  min-height: 0;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}

button.primary { padding: 12px 24px; font-size: 17px; }

button:disabled { opacity: 0.4; cursor: not-allowed; }
button.busy { opacity: 0.75; cursor: progress; }

kbd {
  font: 12px ui-monospace, monospace;
  opacity: 0.6;
  margin-left: 6px;
}

@media (pointer: coarse) { kbd { display: none; } }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 12px;
}

/* Labels */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px 14px;
  margin-top: 16px;
}

#list:empty { display: none; }

.order {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.order.printing { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.order.printed { border-color: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }

.order .badge {
  position: absolute;
  top: -10px;
  left: 14px;
  z-index: 1;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--ink);
  color: white;
}

.order.printed .badge { background: var(--good); }

.preview {
  background: #e9e3d8;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  place-items: center;
}

.order canvas {
  width: 100%;
  max-width: 240px;
  aspect-ratio: 4 / 3;
  height: auto;
  background: white;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(28, 27, 25, 0.18);
  image-rendering: pixelated;
}

.remove {
  position: absolute;
  top: -12px;
  right: -12px;
  z-index: 1;
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  background: var(--card);
  color: var(--muted);
  box-shadow: 0 1px 3px rgba(28, 27, 25, 0.15);
  border: 1px solid var(--line);
  font-size: 18px;
  line-height: 1;
}

.remove:hover { color: var(--bad); border-color: var(--bad); }

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

.fields .wide { grid-column: 1 / -1; }

.fields input { min-height: 40px; padding: 8px 10px; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

.sizes { display: flex; gap: 4px; }

.sizes label { flex: 1; position: relative; }

.sizes input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.sizes span {
  display: grid;
  place-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.sizes input:checked + span { background: var(--ink); color: white; border-color: var(--ink); }
.sizes input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.add-tile {
  min-height: 64px;
  border: 2px dashed var(--line-strong);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
}

.add-tile:hover { color: var(--ink); border-color: var(--ink); background: var(--card); }
.add-tile span { font-size: 20px; margin-right: 4px; }

/* Scanner */

#scan {
  display: none;
  background: black;
  border-radius: var(--radius);
  overflow: hidden;
}

#scan video { width: 100%; max-height: 300px; display: block; object-fit: cover; }
#scan .bar { padding: 10px; margin: 0; }

/* Save menu */

.save-menu { position: relative; }

.split-btn { display: flex; }
.split-btn > button:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split-btn > .more {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: 0;
  padding-left: 12px;
  padding-right: 14px;
}

.pop {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 20;
  width: 260px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(28, 27, 25, 0.18);
  display: grid;
  gap: 2px;
}

.pop button {
  display: grid;
  text-align: left;
  gap: 2px;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 600;
}

.pop button:hover, .pop button:focus-visible { background: var(--accent-soft); }
.pop small { color: var(--muted); font-weight: 400; font-size: 13px; }

@media (max-width: 640px) {
  .pop { right: auto; left: 50%; transform: translateX(-50%); }
}

/* Dock */

.dock {
  position: fixed;
  z-index: 10;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(243, 239, 230, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}

.dock-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.dock .bar { margin: 0; flex: none; }

.dock-status { flex: 1; min-width: 0; }

.status {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  padding-left: 18px;
  position: relative;
}

.status::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.45em;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line-strong);
}

.status.ok { color: var(--good); }
.status.ok::before { background: var(--good); }
.status.err { color: var(--bad); }
.status.err::before { background: var(--bad); }
.status.busy { color: var(--ink); }
.status.busy::before { background: var(--accent); animation: pulse 1s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.3; } }

.progress {
  margin-top: 6px;
  height: 4px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.3s;
}

@media (max-width: 640px) {
  .top { padding-top: 16px; }
  .sub { display: none; }
  .setup-body { grid-template-columns: 1fr; }
  .dock-inner { flex-direction: column; align-items: stretch; gap: 10px; }
  .dock .bar { display: grid; grid-template-columns: auto auto 1fr; }
  .dock .bar button { padding: 10px 12px; font-size: 15px; white-space: nowrap; }
  .dock .bar .more { padding: 10px 10px; }
  :root { --dock: 140px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
