:root {
  --bg: #14161c;
  --panel: #1d2029;
  --line: #2f3340;
  --text: #e8eaf0;
  --muted: #8b90a0;
  --accent: #e8b53a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 16px;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2;
}
h1 { margin: 0; font-size: 20px; color: var(--accent); letter-spacing: .5px; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: 6px 14px; border-radius: 6px; cursor: pointer; font: inherit;
}
.tabs button.active { background: var(--accent); color: #1a1405; border-color: var(--accent); font-weight: 600; }
.actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
button, .btn {
  text-transform: none; letter-spacing: 0; font-size: 14px;
  font: inherit; border-radius: 6px; padding: 6px 12px; cursor: pointer;
  border: 1px solid var(--line); background: #2a2e3a; color: var(--text); display: inline-block;
}
.ghost:hover { border-color: var(--muted); }
.primary { background: var(--accent); color: #1a1405; border-color: var(--accent); font-weight: 600; }

main { display: grid; grid-template-columns: minmax(320px, 440px) 1fr; gap: 24px; padding: 20px; align-items: start; }
.editor { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.form[hidden] { display: none; }
.form { display: flex; flex-direction: column; gap: 12px; }
label:not(.btn) { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; flex: 1; min-width: 0; }
label .hint { text-transform: none; letter-spacing: 0; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
input, select, textarea {
  font: 14px inherit; font-family: inherit; text-transform: none; letter-spacing: 0;
  background: #12141a; color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 9px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
textarea { resize: vertical; }
.row { display: flex; gap: 10px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
legend { color: var(--accent); padding: 0 6px; font-size: 12px; }

.preview { position: sticky; top: 76px; display: flex; justify-content: center; }
canvas {
  width: 100%; max-width: 500px; height: auto; aspect-ratio: 750 / 1050;
  border-radius: 4.5%; box-shadow: 0 12px 40px rgba(0,0,0,.6);
}

@media (max-width: 860px) {
  main { grid-template-columns: 1fr; }
  .preview { position: static; order: -1; }
}

body:not([data-view="gallery"]) .view-gallery,
body:not([data-view="editor"]) .view-editor,
body:not([data-view="sheet"]) .view-sheet { display: none; }
.muted { color: var(--muted); }
.tabs button:disabled { opacity: .4; cursor: not-allowed; }

.gallery { padding: 24px 20px 40px; }
#gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; }
.g-create {
  aspect-ratio: 750 / 1050; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: 2px dashed var(--line); border-radius: 4.5%; background: transparent; color: var(--muted); font-size: 15px;
}
.g-create .plus { font-size: 56px; line-height: 1; color: var(--accent); }
.g-create:hover { border-color: var(--accent); color: var(--text); }
.g-item { position: relative; }
.g-open { display: flex; flex-direction: column; gap: 8px; width: 100%; padding: 0; background: none; border: 0; color: var(--text); text-align: center; }
.g-open img { width: 100%; aspect-ratio: 750 / 1050; border-radius: 4.5%; box-shadow: 0 6px 18px rgba(0,0,0,.5); transition: transform .12s; }
.g-open:hover img { transform: translateY(-3px); }
.g-open span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.g-actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; }
.g-actions button { padding: 0 8px; line-height: 24px; background: rgba(0,0,0,.7); border-color: transparent; }
.g-actions button:hover { background: rgba(0,0,0,.9); border-color: var(--muted); }
.g-item:hover .g-actions, .g-actions:focus-within { opacity: 1; }
@media (hover: none) { .g-actions { opacity: 1; } }

/* selecting cards */
#select-bar { display: none; align-items: center; gap: 8px; margin-bottom: 18px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; position: sticky; top: 58px; z-index: 1; }
body.selecting #select-bar { display: flex; }
#sel-info { margin-right: auto; color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
.g-check { position: absolute; top: 8px; left: 8px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.55); color: #1a1405; font-weight: 700; text-align: center; line-height: 20px; pointer-events: none; }
.g-item.selected .g-check { background: var(--accent); border-color: var(--accent); }
.g-item.selected .g-open img { outline: 3px solid var(--accent); outline-offset: 2px; }
.g-qty { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 6px; }
.g-qty button { padding: 0 9px; line-height: 22px; }
label.inline { flex-direction: row; align-items: center; gap: 6px; flex: none; text-transform: none; letter-spacing: 0; font-size: 14px; }
label.inline select { width: auto; padding: 4px 8px; }
label.inline input { width: auto; }

/* print sheet: 3 × 3 cards at 63.5 × 88.9 mm, centered on the page */
.sheet-wrap { padding: 24px 20px 40px; overflow-x: auto; }
#sheet { display: flex; flex-direction: column; align-items: center; gap: 24px; }
.sheet-page {
  --pw: 215.9mm; --ph: 279.4mm;
  width: var(--pw); height: var(--ph); flex: none; background: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.5);
  display: grid; grid-template-columns: repeat(3, 63.5mm); grid-auto-rows: 88.9mm; justify-content: center; align-content: start;
  padding-top: calc((var(--ph) - 266.7mm) / 2); /* same grid position on every page */
}
#sheet[data-size="A4"] .sheet-page { --pw: 210mm; --ph: 297mm; }
.sheet-page img { width: 63.5mm; height: 88.9mm; display: block; }
#sheet.marks .sheet-page img { outline: 0.2mm dashed #999; outline-offset: -0.1mm; }

@media print {
  html, body { background: #fff; }
  header, .gallery, main { display: none !important; }
  .sheet-wrap { padding: 0; overflow: visible; }
  #sheet { display: block; }
  .sheet-page { box-shadow: none; break-after: page; margin: 0; height: calc(var(--ph) - 1mm); overflow: hidden; }
  .sheet-page:last-child { break-after: auto; }
}
