:root {
  --bg: #15171c; --panel: #1e2128; --panel2: #262a33; --line: #343a46;
  --text: #e8eaee; --dim: #98a1b0; --accent: #3d8be0;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; cursor: pointer;
}
button:hover { border-color: #56607a; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: #ff8d85; }
button.small { padding: 2px 8px; font-size: 12px; }
input[type=text], input[type=number], select, textarea {
  width: 100%; background: #12141a; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
}
textarea { resize: vertical; min-height: 54px; }
input[type=color] { width: 40px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
input[type=range] { width: 100%; }
label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--dim); margin: 10px 0 3px; }
label.check { display: flex; align-items: center; gap: 8px; text-transform: none; font-size: 13px; color: var(--text); letter-spacing: 0; }

#app { display: grid; grid-template-rows: auto 1fr; height: 100%; }
header {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
header h1 { font-size: 16px; margin: 0 12px 0 0; }
header .spacer { flex: 1; }
header .hlink { color: var(--dim); font-size: 13px; text-decoration: none; }
header .hlink:hover { color: var(--text); }
header select { width: auto; }
header label { margin: 0; }

main { display: grid; grid-template-columns: 270px 1fr 480px; min-height: 0; }
main > section { min-height: 0; overflow: auto; padding: 14px; }
#start, #editor { background: var(--panel); }
#start { border-right: 1px solid var(--line); }
#start p { color: var(--dim); font-size: 13px; }
#editor { border-left: 1px solid var(--line); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); margin: 0 0 8px; }

.warn { margin-top: 8px; padding: 6px 8px; border-radius: 6px; background: #3a2f14; color: #f1cf7a; font-size: 12px; }
.pos {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center;
  padding: 8px; margin-top: 6px; background: var(--panel2); border-radius: 8px;
}
.pos .n { font-weight: 600; }
.pos .d { grid-column: 1 / -1; font-size: 12px; color: var(--dim); }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.row.tight > * { flex: none; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); margin: 18px 0 4px; padding-top: 12px; border-top: 1px solid var(--line); }
.checks { display: flex; flex-wrap: wrap; gap: 2px 12px; }
.checks label.check { font-size: 12px; margin: 2px 0; }

/* dial editor: type a value, then click a colour to give that slot a power */
.dial-grid { display: grid; gap: 2px; align-items: center; margin-top: 4px; }
.dial-grid + .dial-grid { margin-top: 10px; }
.dial-grid .lab { font-size: 10px; color: var(--dim); text-transform: uppercase; }
.dial-grid .num { font-size: 10px; color: var(--dim); text-align: center; }
.dial-grid input { width: 100%; padding: 5px 0; text-align: center; font-weight: 700; border-radius: 4px; }
.dial-grid input.special { box-shadow: inset 0 0 0 3px #111; }
.dial-grid input.cur { outline: 2px solid var(--accent); outline-offset: 1px; }
.swatches { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.swatches button { width: 26px; height: 26px; padding: 0; border-radius: 5px; border: 1px solid var(--line); font-size: 11px; font-weight: 700; }
.swatches button.special { background: #fff; box-shadow: inset 0 0 0 3px #111; color: #111; }
.swatches button.none { background: #fff; color: #111; }
#sw-name { min-height: 34px; margin-top: 6px; font-size: 12px; color: var(--dim); }
#sw-name b { color: var(--text); }
.pw { padding: 8px; margin-top: 6px; background: var(--panel2); border-radius: 8px; }
.pw .row { margin-bottom: 6px; }
.pw textarea { min-height: 46px; }

#cards { display: flex; flex-wrap: wrap; gap: 14px; align-content: flex-start; }
.thumb { position: relative; cursor: pointer; border-radius: 8px; outline: 3px solid transparent; outline-offset: 3px; }
.thumb.sel { outline-color: var(--accent); }
.thumb .hc { zoom: 0.62; }
.thumb .pair { display: flex; gap: 6px; }
.thumb .copies {
  position: absolute; right: -6px; top: -6px; background: var(--accent); color: #fff;
  border-radius: 10px; font-size: 11px; font-weight: 700; padding: 1px 7px;
}
.empty { color: var(--dim); padding: 40px; text-align: center; width: 100%; }

#preview { display: flex; justify-content: center; gap: 10px; padding: 4px 0 12px; background: var(--panel); }
@media (min-height: 860px) { #preview { position: sticky; top: -14px; z-index: 2; } }
#preview .hc { zoom: 0.9; }
#preview .h-art { cursor: grab; touch-action: none; }
#preview .h-art.drag { cursor: grabbing; }
#preview.over .hc { outline: 3px dashed var(--accent); }

/* ---------- sheets (screen preview + print) ---------- */
#sheets { display: none; background: #3b3f48; padding: 20px; overflow: auto; height: 100%; }
body.view-sheets main { display: none; }
body.view-sheets #sheets { display: block; }
.sheet {
  background: #fff; margin: 0 auto 20px; box-shadow: 0 4px 20px #0008;
  display: grid; grid-template-columns: repeat(3, 63.5mm); grid-auto-rows: 88.9mm;
  justify-content: center; align-content: start;
  overflow: hidden;
}
.sheet.fold { grid-template-columns: 127mm; }
.sheet .pair { display: flex; }
.sheet.backs { direction: rtl; }
.sheet.backs .hc { direction: ltr; }
.sheet.guides .hc { outline: 0.15mm dashed #777; }

@media print {
  html, body { height: auto; background: #fff; }
  #app { display: block; height: auto; }
  header, main { display: none !important; }
  #sheets { display: block !important; padding: 0; background: none; overflow: visible; height: auto; }
  .sheet { margin: 0; box-shadow: none; break-after: page; }
  .sheet:last-child { break-after: auto; }
}
