/* ── Reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #222;
  background: #1a1a2e;
}

/* ── App layout ───────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────── */
#sidebar {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #f5f5f5;
  border-right: 1px solid #ccc;
  overflow-y: auto;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #ddd;
}

#sidebar-header h1 {
  font-size: 18px;
  margin: 0;
}

.btn-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #bbb;
  background: #e5e7eb;
  font-size: 14px;
  font-weight: 700;
  color: #555;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-icon:hover {
  background: #d1d5db;
}

#decklist-section {
  padding: 12px 16px;
  border-bottom: 1px solid #ddd;
}

#decklist-section label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
}

#decklist-input {
  width: 100%;
  font-family: "Consolas", "Monaco", monospace;
  font-size: 12px;
  padding: 8px;
  border: 1px solid #bbb;
  border-radius: 4px;
  resize: vertical;
  margin-bottom: 8px;
}

#resolve-status {
  font-size: 12px;
  color: #555;
  margin-top: 4px;
  min-height: 18px;
}

#resolve-status.error {
  color: #c00;
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn-primary, .btn-secondary {
  display: block;
  width: 100%;
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  background: #2563eb;
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
}
.btn-primary:disabled {
  background: #93b4f5;
  cursor: not-allowed;
}

.btn-secondary {
  background: #e5e7eb;
  color: #333;
}
.btn-secondary:hover:not(:disabled) {
  background: #d1d5db;
}
.btn-secondary:disabled {
  color: #999;
  cursor: not-allowed;
}

/* ── Config panel ─────────────────────────────────────────────────── */
#config-section {
  flex: 1;
  padding: 0 16px 12px;
  overflow-y: auto;
}

#config-section details {
  border-bottom: 1px solid #ddd;
}

#config-section summary {
  font-weight: 600;
  font-size: 13px;
  padding: 10px 0;
  cursor: pointer;
  user-select: none;
}

.config-group {
  padding: 0 0 12px;
}

.config-group label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 6px;
}

.config-group label.checkbox-label {
  justify-content: flex-start;
}

.config-group input[type="number"],
.config-group select {
  width: 90px;
  padding: 3px 6px;
  border: 1px solid #bbb;
  border-radius: 3px;
  font-size: 13px;
}

.config-group input[type="color"] {
  width: 40px;
  height: 26px;
  padding: 1px;
  border: 1px solid #bbb;
  border-radius: 3px;
  cursor: pointer;
}

.config-group input[type="checkbox"] {
  margin-right: 6px;
}

/* ── Sidebar footer ───────────────────────────────────────────────── */
#sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid #ddd;
  background: #eee;
}

.print-hint {
  font-size: 11px;
  color: #777;
  margin-bottom: 8px;
  line-height: 1.3;
}

/* ── Preview area ─────────────────────────────────────────────────── */
#preview-area {
  flex: 1;
  overflow: auto;
  background: #2a2a3e;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#pages-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
}

#empty-state {
  color: #999;
  font-size: 16px;
  text-align: center;
  margin-top: 80px;
}
#empty-state strong {
  color: #bbb;
}

/* ── Page rendering ───────────────────────────────────────────────── */
.page-wrapper {
  transform-origin: top center;
}

.sheet-page {
  background: white;
  position: relative;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  overflow: hidden;
}

.card-grid {
  position: absolute;
  display: grid;
}

.card-cell {
  position: relative;
  overflow: hidden;
}

.card-cell img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
  background: #ddd;
}

/* ── Ink-saver template ───────────────────────────────────────────── */
.ink-saver-card {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 2mm 2mm 1.5mm;
  border: 0.3mm solid #444;
  border-radius: 2mm;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 8px;
  line-height: 1.25;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.is-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1mm;
  flex-shrink: 0;
}

.is-name {
  font-weight: 700;
  font-size: 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.is-mana {
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  gap: 0.5mm;
}

.mana-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.2mm;
  height: 3.2mm;
  border-radius: 50%;
  font-size: 6px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

.mana-W       { background: #f0d654; color: #333; }
.mana-U       { background: #0e68ab; color: #fff; }
.mana-B       { background: #2b2b2b; color: #ccc; }
.mana-R       { background: #d3202a; color: #fff; }
.mana-G       { background: #00733e; color: #fff; }
.mana-C       { background: #bbb;    color: #333; }
.mana-generic { background: #bbb;    color: #333; }

.is-divider {
  border-top: 0.2mm solid #aaa;
  margin: 0.8mm 0;
  flex-shrink: 0;
}

.is-type {
  font-size: 7px;
  font-style: italic;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.is-text {
  flex: 1;
  font-size: 7px;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 0;
}

.is-pt {
  text-align: right;
  font-weight: 700;
  font-size: 8px;
  flex-shrink: 0;
  margin-top: auto;
  padding-top: 0.5mm;
}

/* ── Text-only template ──────────────────────────────────────────── */
.text-only-card {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 1.5mm;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 7px;
  line-height: 1.2;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.to-header {
  font-weight: 700;
  font-size: 8px;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.to-type {
  font-size: 6.5px;
  color: #555;
  flex-shrink: 0;
}

.to-text {
  flex: 1;
  font-size: 6.5px;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 0.5mm;
  min-height: 0;
}

.to-pt {
  text-align: right;
  font-weight: 700;
  font-size: 7px;
  flex-shrink: 0;
  margin-top: auto;
}

/* Drag sorting visual feedback */
.card-cell[draggable="true"] {
  cursor: grab;
}
.card-cell[draggable="true"]:active {
  cursor: grabbing;
}
.card-cell.drag-over {
  outline: 3px solid #2563eb;
  outline-offset: -3px;
}
.card-cell.dragging {
  opacity: 0.4;
}

/* ── SVG overlays ─────────────────────────────────────────────────── */
.crop-marks-layer,
.registration-marks-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* ── Decklist page ────────────────────────────────────────────────── */
.decklist-content {
  position: absolute;
  top: 20mm;
  left: 20mm;
  right: 20mm;
  bottom: 20mm;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.decklist-content h2 {
  font-size: 18pt;
  margin-bottom: 10mm;
}

.decklist-columns {
  column-count: 2;
  column-gap: 10mm;
  font-size: 9pt;
  line-height: 1.5;
}

.decklist-type-group {
  break-inside: avoid;
  margin-bottom: 4mm;
}

.decklist-type-header {
  font-weight: bold;
  font-size: 11pt;
  margin-bottom: 1mm;
}

.decklist-entry {
  padding-left: 3mm;
}

.decklist-total {
  font-weight: bold;
  font-size: 11pt;
  margin-top: 4mm;
  break-inside: avoid;
}

/* ── Loading overlay ──────────────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#loading-overlay.hidden {
  display: none;
}

#loading-content {
  background: #fff;
  border-radius: 12px;
  padding: 32px 48px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

#loading-message {
  margin-top: 16px;
  font-size: 14px;
  color: #555;
}

.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto;
  border: 4px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Toast notifications ──────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 400px;
}

.toast {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  animation: toast-in 0.25s ease-out;
  cursor: pointer;
  position: relative;
}

.toast.toast-success {
  background: #065f46;
  color: #d1fae5;
}

.toast.toast-error {
  background: #991b1b;
  color: #fecaca;
}

.toast.toast-warning {
  background: #78350f;
  color: #fef3c7;
}

.toast.toast-info {
  background: #1e3a5f;
  color: #dbeafe;
}

.toast.toast-fade-out {
  animation: toast-out 0.3s ease-in forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

/* ── Tooltip triggers ─────────────────────────────────────────────── */
.tip {
  cursor: help;
  outline: none;
}
span.tip {
  text-decoration: underline dashed rgba(0,0,0,0.3) 1px;
  text-underline-offset: 2px;
}
span.tip:hover,
span.tip:focus-visible {
  text-decoration: none;
}
.tip:focus-visible {
  border-radius: 2px;
  box-shadow: 0 0 0 2px rgba(184,134,11,0.4);
}

/* ── Tooltip popup (positioned by JS) ─────────────────────────────── */
.tooltip {
  position: fixed;
  width: 230px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2000;
}
.tooltip.is-visible {
  opacity: 1;
}
.tooltip-body {
  padding: 8px 10px;
  border-radius: 6px;
  background: #1f2937;
  color: #f3f4f6;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.4;
  white-space: normal;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.tooltip-arrow {
  position: absolute;
  width: 0;
  height: 0;
}

/* arrow directions */
.tooltip[data-placement="above"] .tooltip-arrow {
  bottom: -6px;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #1f2937;
}
.tooltip[data-placement="below"] .tooltip-arrow {
  top: -6px;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid #1f2937;
}
.tooltip[data-placement="right"] .tooltip-arrow {
  left: -6px;
  transform: translateY(-50%);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 6px solid #1f2937;
}
.tooltip[data-placement="left"] .tooltip-arrow {
  right: -6px;
  transform: translateY(-50%);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 6px solid #1f2937;
}

/* ── About modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1500;
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  max-width: 560px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 24px;
  color: #888;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover {
  color: #333;
}

.modal-content h2 {
  font-size: 22px;
  margin-bottom: 4px;
}

.about-tagline {
  color: #666;
  font-size: 14px;
  margin-bottom: 16px;
}

.modal-content p {
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 12px;
}

.modal-content ul {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}

.modal-content li {
  font-size: 13px;
  line-height: 1.5;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
}

.modal-content li:last-child {
  border-bottom: none;
}

.modal-content li strong {
  color: #1e3a5f;
}

.about-footer {
  font-size: 12px;
  color: #888;
  margin-top: 16px;
  margin-bottom: 0;
}

.about-footer a {
  color: #2563eb;
  text-decoration: none;
}
.about-footer a:hover {
  text-decoration: underline;
}

/* ── Page label (e.g., "Page 1 Front") ────────────────────────────── */
.page-label {
  text-align: center;
  color: #999;
  font-size: 12px;
  margin-bottom: 4px;
}
