/* tools-ti-factions.css — TI4 Faction Designer */

.fd-app {
  display: grid;
  grid-template-columns: 1fr 380px;
  background: #0a0d2a;
}

/* Preview panel */
.fd-preview {
  padding: 32px;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.fd-preview__inner {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.fd-preview__tabs {
  display: flex;
  gap: 4px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.fd-preview__tab {
  font-family: var(--mg-font-body);
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.5);
  background: none;
  border: none;
  padding: 8px 14px;
  border-radius: 9999px;
  cursor: pointer;
  transition: background 150ms, color 150ms;
}
.fd-preview__tab:hover { color: rgba(255,255,255,0.8); background: rgba(255,255,255,0.05); }
.fd-preview__tab--active { color: #fff; background: rgba(255,255,255,0.1); }

/* Editor panel */
.fd-editor {
  background: #111428;
  border-left: 1px solid rgba(255,255,255,0.08);
  padding: 24px;
  overflow-y: auto;
  max-height: calc(100vh - 64px);
  position: sticky;
  top: 64px;
}
.fd-editor__tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding-bottom: 12px;
  flex-wrap: wrap;
}
.fd-editor__tab {
  font-family: var(--mg-font-body);
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.5);
  background: none;
  border: none;
  padding: 8px 14px;
  border-radius: 9999px;
  cursor: pointer;
  transition: background 150ms, color 150ms;
}
.fd-editor__tab:hover { color: rgba(255,255,255,0.8); background: rgba(255,255,255,0.05); }
.fd-editor__tab--active { color: #fff; background: rgba(255,255,255,0.1); }

.fd-editor__panel { display: none; }
.fd-editor__panel--active { display: block; }

/* Form elements */
.fd-field {
  margin-bottom: 14px;
}
.fd-field__label {
  display: block;
  font-family: var(--mg-font-mono);
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
}
.fd-field__input,
.fd-field__select {
  width: 100%;
  box-sizing: border-box;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: var(--mg-font-body);
  font-size: 13px;
  color: #fff;
  outline: none;
  transition: border-color 150ms;
}
.fd-field__input:focus,
.fd-field__select:focus {
  border-color: rgba(255,255,255,0.3);
}
.fd-field__input::placeholder {
  color: rgba(255,255,255,0.3);
}
.fd-field__select option {
  background: #111428;
  color: #fff;
}
.fd-field__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.fd-field__row--3 {
  grid-template-columns: 1fr 1fr 1fr;
}
.fd-field__row--4 {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}
.fd-field__file {
  width: 100%;
  box-sizing: border-box;
  background: rgba(255,255,255,0.04);
  border: 1px dashed rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--mg-font-body);
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
}
.fd-field__file::-webkit-file-upload-button {
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-family: var(--mg-font-body);
  font-size: 11px;
  color: #fff;
  cursor: pointer;
  margin-right: 8px;
}

/* Colour picker */
.fd-color-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.fd-color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 150ms, transform 150ms;
}
.fd-color-swatch:hover { transform: scale(1.15); }
.fd-color-swatch--active { border-color: #fff; transform: scale(1.15); }

/* Collapsible sections */
.fd-section {
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  padding-bottom: 12px;
}
.fd-section__head {
  font-family: var(--mg-font-display);
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.fd-section__head--toggle {
  cursor: pointer;
  padding: 8px 0;
  position: relative;
}
.fd-section__head--toggle::after {
  content: '▾';
  position: absolute;
  right: 0;
  top: 8px;
  font-size: 10px;
  color: rgba(255,255,255,0.4);
  transition: transform 150ms;
}
.fd-section--collapsed .fd-section__head--toggle::after {
  transform: rotate(-90deg);
}
.fd-section--collapsed .fd-section__body {
  display: none;
}

/* Shared card header: icon + name + type on one row */
.fc-card__header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  flex: 0 0 auto;
}
.fc-card__icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.7;
}
.fc-card__titles { flex: 1; min-width: 0; }
.fc-card__name {
  font-family: var(--mg-font-display);
  font-size: clamp(9px, 1.2vw, 13px);
  font-weight: 700;
  color: var(--fc-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fc-card__type {
  font-size: clamp(7px, 0.9vw, 9px);
  font-weight: 600;
  color: var(--fc-accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
/* Note card icon (bottom-right) */
.fc-note__icon {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 16px;
  height: 16px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.7;
}

/* Export bar */
.fd-export-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.fd-export-btn {
  padding: 10px 12px;
  border: none;
  border-radius: 9999px;
  font-family: var(--mg-font-body);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 150ms;
  background: #0c4f8d;
  color: #fff;
  white-space: nowrap;
}
.fd-export-btn:hover { opacity: 0.85; }
.fd-export-btn--outline {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7);
}
.fd-export-btn--outline:hover { border-color: rgba(255,255,255,0.5); color: #fff; }

/* Responsive */
@media (max-width: 1024px) {
  .fd-app {
    grid-template-columns: 1fr;
  }
  .fd-editor {
    position: static;
    max-height: none;
    border-left: none;
    border-top: 1px solid rgba(255,255,255,0.08);
  }
}
@media (max-width: 600px) {
  .fd-preview {
    padding: 16px;
  }
}

/* Print stylesheet */
@media print {
  @page { size: A4 landscape; margin: 0; }
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #0a0d2a !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  #nav-root,
  #footer-root,
  .fd-editor,
  .fd-preview__tabs { display: none !important; }
  .fd-app {
    display: block !important;
    background: #0a0d2a !important;
    height: auto !important;
  }
  .fd-preview {
    padding: 0 !important;
    background: #0a0d2a !important;
    overflow: visible !important;
    display: block !important;
  }
  .fd-preview__inner {
    max-width: none !important;
    padding: 3mm !important;
    gap: 0 !important;
  }
  .fc-sheet {
    width: 100% !important;
    height: calc(210mm - 6mm) !important;
    break-after: page;
    break-inside: avoid;
  }
  .fc-unit,
  .fc-flagship,
  .fc-commodities,
  .fc-sheet__system {
    aspect-ratio: unset !important;
  }
  .fc-cards-grid {
    width: 100% !important;
    padding-top: 3mm;
  }
}

/* =================================================================
   CODE-GENERATED CARDS — Pure CSS/HTML approach
   No PNG backgrounds. Full control over every element.
   ================================================================= */

/* Shared card tokens */
:root {
  --fc-bg: #0b1020;
  --fc-panel: #0a1a10;
  --fc-border: #2d8a4e;
  --fc-border-glow: #4dff91;
  --fc-accent: #00f6b1;
  --fc-text: #ffffff;
  --fc-text-dim: #aabbaa;
  --fc-text-muted: #667766;
  --fc-stat-bg: #0a1a10;
  --fc-card-w: 200px;
  --fc-card-h: calc(var(--fc-card-w) / 1.386);
}

/* --- FACTION SHEET --- */
/* A4 landscape full bleed: 297mm x 210mm (aspect 297:210 = 1.414:1)
   Contains: 4 unit cols + right abilities panel, 3 unit rows.
   Unit slots sized to fit landscape poker cards (88 x 63.5mm). */
.fc-sheet {
  background: linear-gradient(135deg, #050d1a 0%, #0a1a2a 40%, #061218 100%);
  border: 2px solid var(--fc-border);
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, auto);
  gap: 4px;
  padding: 4px;
  font-family: var(--mg-font-body);
}

.fc-sheet__name {
  grid-column: 3;
  grid-row: 1 / 3;
  align-self: start;
  justify-self: center;
  padding-top: 8px;
  font-family: var(--mg-font-display);
  font-size: clamp(14px, 2.2vw, 24px);
  font-weight: 700;
  color: var(--fc-text);
  z-index: 2;
  white-space: nowrap;
  text-align: center;
}

.fc-sheet__symbol {
  grid-column: 4;
  grid-row: 1;
  align-self: start;
  justify-self: end;
  margin: 6px 6px 0 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--fc-border);
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 3;
}

/* Flagship unit card — same aspect as a unit slot */
.fc-flagship {
  grid-column: 1;
  grid-row: 1;
  aspect-ratio: 88 / 63.5;
  border: 1px solid var(--fc-border);
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  background: var(--fc-panel);
}

.fc-flagship__label {
  font-size: 8px;
  font-weight: 600;
  color: var(--fc-accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.fc-flagship__name {
  font-family: var(--mg-font-display);
  font-size: clamp(12px, 1.6vw, 16px);
  font-weight: 700;
  color: var(--fc-text);
  margin-bottom: 4px;
}

.fc-flagship__ability-title {
  font-size: 9px;
  font-weight: 600;
  color: var(--fc-accent);
  margin-bottom: 2px;
}

.fc-flagship__ability {
  font-size: clamp(9px, 1.1vw, 11px);
  color: var(--fc-text-dim);
  line-height: 1.35;
  flex: 1;
  overflow: hidden;
}

.fc-flagship__stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 4px;
  margin-top: auto;
  padding-top: 4px;
  border-top: 1px solid rgba(45,138,78,0.3);
}

.fc-flagship__stat {
  text-align: center;
}

.fc-flagship__stat-val {
  font-family: var(--mg-font-display);
  font-size: clamp(14px, 2vw, 22px);
  font-weight: 700;
  color: #e6c020;
  line-height: 1;
}

.fc-flagship__stat-lbl {
  font-size: 6px;
  color: var(--fc-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Race image area — col 3, rows 1-2 */
.fc-sheet__race {
  grid-column: 3;
  grid-row: 1 / 3;
  background-size: 70% auto;
  background-position: center 75%;
  background-repeat: no-repeat;
  opacity: 0.4;
  border-radius: 8px;
}

/* Home system — col 2, row 1 (above cruiser) */
.fc-sheet__system {
  grid-column: 2;
  grid-row: 1;
  aspect-ratio: 88 / 63.5;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.fc-sheet__system-stats {
  display: flex;
  gap: 12px;
  padding: 4px 8px;
  background: rgba(0,0,0,0.6);
  border-radius: 4px;
}

.fc-sheet__system-stat {
  text-align: center;
}

.fc-sheet__system-stat-lbl {
  font-size: 6px;
  color: var(--fc-text-muted);
  text-transform: uppercase;
}

.fc-sheet__system-stat-val {
  font-family: var(--mg-font-display);
  font-size: clamp(12px, 1.6vw, 18px);
  font-weight: 700;
  color: var(--fc-text);
}

/* Right panel: quote + abilities — col 4, rows 1-2 */
.fc-sheet__right {
  grid-column: 4;
  grid-row: 1 / 3;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.fc-meta {
  padding: 10px 44px 8px 10px;
  border-bottom: 1px solid rgba(45,138,78,0.3);
  flex: 0 0 auto;
}

.fc-meta__quote {
  font-size: clamp(7px, 0.9vw, 9px);
  color: var(--fc-text-dim);
  font-style: italic;
  line-height: 1.3;
  margin-bottom: 4px;
}

.fc-meta__quoter {
  font-family: var(--mg-font-display);
  font-size: clamp(8px, 1vw, 11px);
  font-weight: 600;
  color: var(--fc-text);
}

.fc-abilities {
  padding: 10px 10px;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fc-ability {
  flex: 1;
  overflow: hidden;
}

.fc-ability__title {
  font-family: var(--mg-font-display);
  font-size: clamp(8px, 1vw, 11px);
  font-weight: 700;
  color: var(--fc-text);
  margin-bottom: 2px;
}

.fc-ability__text {
  font-size: clamp(7px, 0.85vw, 9px);
  color: var(--fc-text-dim);
  line-height: 1.3;
  overflow: hidden;
}

.fc-commodities {
  grid-column: 4;
  grid-row: 3;
  aspect-ratio: 88 / 63.5;
  border: 1px solid rgba(45,138,78,0.4);
  border-radius: 6px;
  background: var(--fc-panel);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.fc-commodities__label {
  font-size: 7px;
  color: var(--fc-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.fc-commodities__val {
  font-family: var(--mg-font-display);
  font-size: clamp(14px, 2vw, 22px);
  font-weight: 700;
  color: #e6c020;
}

/* Unit cards wrapper — no longer used, units placed individually */
.fc-sheet__units {
  display: contents;
}

.fc-unit {
  aspect-ratio: 88 / 63.5;
  border: 1px solid rgba(45,138,78,0.4);
  border-radius: 6px;
  background: var(--fc-panel);
  display: grid;
  grid-template-columns: 1fr 14px;
  overflow: hidden;
}
.fc-unit__body {
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.fc-unit__pips {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 4px 0;
  gap: 3px;
  border-left: 1px solid rgba(45,138,78,0.2);
}
.fc-unit__pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #333;
}
.fc-unit__pip--r { background: #d11a1a; }
.fc-unit__pip--g { background: #3a9928; }
.fc-unit__pip--y { background: #e6c020; }
.fc-unit__pip--b { background: #0c4f8d; }

/* Staircase unit placement via data attributes */
.fc-unit[data-pos="r2c1"] { grid-column: 1; grid-row: 2; }
.fc-unit[data-pos="r2c2"] { grid-column: 2; grid-row: 2; }
.fc-unit[data-pos="r3c1"] { grid-column: 1; grid-row: 3; }
.fc-unit[data-pos="r3c2"] { grid-column: 2; grid-row: 3; }
.fc-unit[data-pos="r3c3"] { grid-column: 3; grid-row: 3; }
.fc-unit[data-pos="r4c1"] { grid-column: 1; grid-row: 4; }
.fc-unit[data-pos="r4c2"] { grid-column: 2; grid-row: 4; }
.fc-unit[data-pos="r4c3"] { grid-column: 3; grid-row: 4; }
.fc-unit[data-pos="r4c4"] { grid-column: 4; grid-row: 4; }

.fc-unit__name {
  font-family: var(--mg-font-display);
  font-size: clamp(9px, 1.2vw, 12px);
  font-weight: 700;
  color: var(--fc-text);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 2px;
}

.fc-unit__keywords {
  font-size: clamp(7px, 0.9vw, 9px);
  color: var(--fc-accent);
  margin-top: 2px;
  letter-spacing: 0.2px;
}

.fc-unit__ability {
  font-size: clamp(7px, 0.9vw, 9px);
  color: var(--fc-text-dim);
  line-height: 1.3;
  margin-top: 3px;
  flex: 1;
  overflow: hidden;
}

.fc-unit__stats {
  display: flex;
  gap: 2px;
  margin-top: auto;
  padding-top: 4px;
  border-top: 1px solid rgba(45,138,78,0.3);
}

.fc-unit__stat {
  text-align: center;
  flex: 1;
}

.fc-unit__stat-val {
  font-family: var(--mg-font-display);
  font-size: clamp(14px, 2vw, 22px);
  font-weight: 700;
  color: #e6c020;
  line-height: 1;
}

.fc-unit__stat-lbl {
  font-size: 6px;
  color: var(--fc-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.fc-stat-mult {
  font-size: 0.5em;
  opacity: 0.5;
  font-weight: 400;
}

/* --- LEADER CARDS --- */
/* Cards grid — 4 columns matching faction sheet, 2 rows */
.fc-cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: auto auto;
  gap: 4px;
}
.fc-cards-grid__note {
  grid-column: 4;
  grid-row: 1 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fc-leader {
  aspect-ratio: 88 / 63.5;
  background: linear-gradient(160deg, #0a1a10 0%, #051510 100%);
  border: 2px solid var(--fc-border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fc-leader__content {
  display: grid;
  grid-template-columns: 35% 65%;
  flex: 1;
  min-height: 0;
}

.fc-leader__avatar {
  background-color: rgba(255,255,255,0.03);
  border-right: 1px solid rgba(45,138,78,0.3);
  background-size: 80% auto;
  background-position: center;
  background-repeat: no-repeat;
}

.fc-leader__ability {
  font-size: clamp(7px, 0.85vw, 9px);
  color: var(--fc-text-dim);
  line-height: 1.35;
  overflow: hidden;
  padding: 6px 8px;
}

/* --- NOTE CARD (portrait: 63.5mm x 88mm — same card rotated) --- */
.fc-note {
  aspect-ratio: 63.5 / 88;
  width: calc(100% * 63.5 / 88);
  background: linear-gradient(180deg, #f8f8f0 0%, #e8e8e0 100%);
  border: 2px solid var(--fc-border);
  border-radius: 10px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  position: relative;
}

.fc-note__name {
  font-family: var(--mg-font-display);
  font-size: clamp(9px, 1.2vw, 13px);
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 6px;
}

.fc-note__text {
  font-size: clamp(7px, 0.85vw, 9px);
  color: #444;
  line-height: 1.35;
  flex: 1;
  overflow: hidden;
}

/* --- TECH CARDS --- */

.fc-tech {
  aspect-ratio: 88 / 63.5;
  background: linear-gradient(160deg, #0a1a10 0%, #051510 100%);
  border: 2px solid var(--fc-border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fc-tech__content {
  display: grid;
  grid-template-columns: 14px 1fr;
  flex: 1;
  min-height: 0;
}

.fc-tech__pips {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 4px 0 8px;
  gap: 4px;
  border-right: 1px solid rgba(45,138,78,0.2);
}

.fc-tech__pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #333;
}

.fc-tech__pip--r { background: #d11a1a; }
.fc-tech__pip--g { background: #3a9928; }
.fc-tech__pip--y { background: #e6c020; }
.fc-tech__pip--b { background: #0c4f8d; }
.fc-tech__pip--none { display: none; }

.fc-tech__ability {
  font-size: clamp(7px, 0.85vw, 9px);
  color: var(--fc-text-dim);
  line-height: 1.35;
  overflow: hidden;
  padding: 6px 8px;
}

/* --- MECH CARD (same dimensions as tech/leader: landscape poker) --- */
.fc-mech {
  aspect-ratio: 88 / 63.5;
  background: linear-gradient(160deg, #0a1a10 0%, #051510 100%);
  border: 2px solid var(--fc-border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fc-mech__ability {
  font-size: clamp(7px, 0.85vw, 9px);
  color: var(--fc-text-dim);
  line-height: 1.35;
  overflow: hidden;
  flex: 1;
  padding: 0 8px;
}

.fc-mech__keywords {
  font-size: clamp(7px, 0.9vw, 9px);
  color: var(--fc-accent);
  padding: 4px 8px;
  margin-top: auto;
}

.fc-mech__stats {
  display: flex;
  gap: 2px;
  margin-top: auto;
  padding: 4px 8px 6px;
  border-top: 1px solid rgba(45,138,78,0.3);
}
