:root {
  --bg: #16171b;
  --card: #212328;
  --raised: #2a2d33;
  --ink: #ece6d6;
  --muted: #9a9686;
  --line: #34373e;
  --accent: #c9a441;
  --accent-ink: #1b1a15;
  --accent-soft: rgba(201, 164, 65, 0.12);
  --danger: #d4554c;
}

* { 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-family: "Barlow Condensed", "Inter", sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.1em;
  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-family: "Barlow Condensed", "Inter", sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.logo {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle, #2a2d33 0 58%, #b3261e 60%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.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 h2 { margin-bottom: 10px; }

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

.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(--raised); color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); }

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

.hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.hint.center { text-align: center; }
.fine { margin: 16px 0 0; color: #6f6c62; font-size: 12px; }

.row-btns { display: flex; flex-wrap: wrap; gap: 6px; }

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

.btn:hover:not(:disabled) { border-color: #4a4e57; background: #31343b; }
.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: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: #d8b552; }
.btn.danger { color: var(--danger); }

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

.export { display: grid; gap: 8px; border-bottom: 0; }
.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: #dcc27a; }

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

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

.section-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin: 20px 0 12px;
}

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

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

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

.token {
  padding: 10px 10px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  transition: border-color 0.15s, background 0.15s;
}

.token.zero .thumb { opacity: 0.4; }
.token.over { border-color: var(--accent); background: #2b2a24; }

.thumb {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.thumb canvas { display: block; width: 100%; height: auto; }

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

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

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

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

.empty { margin: 12px 0; color: var(--muted); }

.group-sec { margin-bottom: 26px; }
.group-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.group-head h3 {
  margin: 0 6px 0 0;
  font-family: "Barlow Condensed", "Inter", sans-serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.group-sec > .hint { margin: 4px 0 12px; max-width: 760px; }
.note { margin: -4px 0 6px; color: var(--muted); font-size: 11.5px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field textarea { resize: vertical; }

.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 12px rgba(0, 0, 0, 0.5);
}

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

/* ---------- Editor ---------- */

.editor {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
}

.editor::backdrop { background: rgba(0, 0, 0, 0.6); }

.ed-head, .ed-foot { display: flex; align-items: center; gap: 8px; padding: 14px 18px; }
.ed-head { justify-content: space-between; border-bottom: 1px solid var(--line); }
.ed-head h2 { font-size: 18px; color: var(--ink); }
.ed-foot { justify-content: flex-end; border-top: 1px solid var(--line); }
.ed-foot .danger { margin-right: auto; }

.x {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.x:hover { background: var(--raised); color: var(--ink); }

.ed-body { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; padding: 18px; }

.ed-preview canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  background: #f3f1ea;
  cursor: grab;
  touch-action: none;
}

.ed-preview canvas.dragging { cursor: grabbing; }

.ed-controls { display: grid; align-content: start; gap: 14px; }

.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.opt { font-weight: 400; }

.field input[type="text"], .field textarea {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #17181c;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }

.swatch {
  width: 28px;
  height: 28px;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.swatch.on { border-color: var(--ink); }

.pic-row { display: flex; flex-wrap: wrap; gap: 6px; }

#edPicOpts { display: grid; gap: 14px; }

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

.drop-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: end center;
  padding-bottom: 32px;
  border: 4px dashed var(--accent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 30;
}

.drop-overlay p {
  margin: 0;
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--raised);
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

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: var(--bg);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 40;
}

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

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

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .work { order: -1; padding: 4px 16px 18px; }
  .side { border-right: 0; border-top: 1px solid var(--line); }
  .topbar-row { padding-inline: 16px; }
  .tokens { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .sheet canvas { width: min(240px, calc(50vw - 28px)); }
  .ed-body { grid-template-columns: minmax(0, 1fr); }
  .ed-preview canvas { max-width: 300px; margin: 0 auto; }
}

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