:root {
  --bg: #f4f5fa;
  --card: #ffffff;
  --ink: #1b1d2a;
  --muted: #646a80;
  --line: #e1e4ee;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --warn: #b45309;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h2 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

/* ---------- Top bar ---------- */

.topbar { background: var(--card); border-bottom: 1px solid var(--line); }

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

.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }

.logo {
  position: relative;
  width: 18px;
  height: 24px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 5px -2px 0 -1px #c7d2fe;
}

.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--ink); text-decoration: underline; }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: calc(100vh - 57px);
}

.side {
  padding: 8px 20px 24px;
  background: var(--card);
  border-right: 1px solid var(--line);
}

.group { padding: 16px 0; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group h2 { display: flex; justify-content: space-between; margin-bottom: 10px; }
.group h2 output { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 14px; }

.seg {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: #eceef5;
}

.seg button {
  flex: 1;
  padding: 7px 6px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(20, 24, 60, 0.15); }

input[type="range"] { width: 100%; accent-color: var(--accent); }

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

.fit { margin: 10px 0 0; font-weight: 600; font-size: 14px; }
.fit.warn { color: var(--warn); }

.btn {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: #c4c9da; background: #fafbff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #4338ca; }

button:focus-visible, input:focus-visible, a:focus-visible, .dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.back-set { display: flex; align-items: center; gap: 12px; }
.back-thumb canvas { display: block; width: 56px; height: auto; border-radius: 3px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2); }
.back-actions { display: flex; flex-direction: column; gap: 6px; }

.export { display: grid; gap: 8px; }
.export .hint { margin-top: 4px; }
.summary { margin: 0 0 4px; font-weight: 600; }
.status { margin: 0; min-height: 1.2em; color: var(--accent); font-size: 13px; font-weight: 600; }
.private { padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); color: #3730a3; }

/* ---------- Work area ---------- */

.work { padding: 24px; min-width: 0; }

.dropzone {
  display: grid;
  place-items: center;
  padding: 28px 16px;
  border: 2px dashed #c3c8dc;
  border-radius: 16px;
  background: var(--card);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover, body.dropping .dropzone { border-color: var(--accent); background: var(--accent-soft); }
.dz-inner svg { width: 48px; height: 48px; color: var(--accent); }
.dz-title { margin: 6px 0 2px; font-size: 18px; font-weight: 700; }
.dz-sub { margin: 0; color: var(--muted); }

.linkish {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.empty { margin: 24px 0; color: var(--muted); text-align: center; }

.section-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 28px 0 12px;
}

.section-head h2 { font-size: 14px; color: var(--ink); }
.section-head .hint { margin: 0; flex: 1; }

.pill {
  display: inline-block;
  min-width: 22px;
  padding: 0 7px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  text-align: center;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  position: relative;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  cursor: grab;
}

.card.dragging { opacity: 0.4; }

.thumb canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}

.name {
  margin: 6px 0 4px;
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.qty { display: flex; align-items: center; justify-content: space-between; gap: 4px; }

.qty button {
  width: 30px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f6f7fb;
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.qty button:hover { border-color: #c4c9da; }
.qty span { font-weight: 700; font-variant-numeric: tabular-nums; }

.remove {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 1;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 22, 35, 0.75);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.card:hover .remove, .card:focus-within .remove { opacity: 1; }

.pages {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.sheet { margin: 0; }

.sheet canvas {
  display: block;
  width: 240px;
  height: auto;
  border-radius: 2px;
  box-shadow: 0 2px 10px rgba(20, 24, 60, 0.16);
}

.sheet figcaption { margin-top: 6px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- Dropping files ---------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(79, 70, 229, 0.12);
  border: 4px dashed var(--accent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 30;
}

.drop-overlay p {
  margin: 0;
  padding: 14px 22px;
  border-radius: 12px;
  background: var(--card);
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(20, 24, 60, 0.18);
}

body.dropping .drop-overlay { opacity: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 8px);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Narrow screens ---------- */

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .work { order: -1; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .work { padding: 18px 16px; }
  .topbar-row { padding-inline: 16px; }
  .sheet canvas { width: min(240px, calc(50vw - 28px)); }
  .remove { opacity: 1; }
}

@media (max-width: 480px) {
  .back .long { display: none; }
}
