/* Page shells. The editor and preview live on separate HTML pages; this
   file owns the shared editor chrome plus the two page-level wrappers. */

/* Preview page: the stage is a fixed 1920×1080 canvas. On smaller
   viewports we scale it down with CSS transform so the whole dashboard
   fits without horizontal scrolling. See the @media block at the
   bottom of this file for the scale math. */
main.preview-page {
  display: block;
  grid-template-columns: none;
  max-width: none;
  margin: 0;
  padding: 18px;
  width: max-content;
}

/* Stage auto-scale wrapper — only applied on narrow viewports.
   Defined as a CSS var so the @media block below can override it
   without rewriting the transform. Default `1` means "don't scale". */
.superevent-stage {
  --stage-scale: 1;
}
.superevent-stage:not(.is-debug) {
  transform: scale(var(--stage-scale));
  transform-origin: top left;
}

/* Preview page background is pure black — overrides main.css's radial
   gradient so the area outside the stage doesn't read as lighter blue-
   gray. */
body.preview-body {
  background: #000 !important;
}

/* Editor page: full-width editor, no sticky sidebar. */
main.editor-page {
  display: block;
  grid-template-columns: none;
  padding: 18px;
  max-width: 1200px;
  margin: 0 auto;
}

.header-link {
  color: var(--text-dim); font-size: 11px; letter-spacing: 1.5px;
  text-transform: uppercase; text-decoration: none;
  padding: 4px 10px; border: 1px solid transparent;
  border-radius: 2px; transition: border-color 0.12s, color 0.12s;
}
.header-link:hover { color: var(--accent); border-color: var(--panel-border); }

/* ── Editor panel: full-width on its own page ─────────────────────── */
.editor-panel {
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.015) 0%, rgba(0,0,0,0.12) 100%),
    var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.03);
}

.editor-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 8px 8px 0;
  background: linear-gradient(180deg, #24272b 0%, #16181b 100%);
  border-bottom: 1px solid var(--panel-border-strong);
}
.editor-tabs button {
  position: relative;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--text-dim);
  padding: 9px 13px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 3px 3px 0 0;
  margin-right: 2px;
  margin-bottom: -1px;
  transition: color 0.15s ease, background 0.15s ease;
}
.editor-tabs button::after {
  /* Underline accent that animates in when active. */
  content: '';
  position: absolute;
  left: 50%;
  bottom: -1px;
  width: 0;
  height: 2px;
  background: var(--accent);
  transform: translateX(-50%);
  transition: width 0.18s ease;
}
.editor-tabs button:hover {
  color: var(--text);
  background: rgba(255,255,255,0.04);
}
.editor-tabs button.is-active {
  color: var(--accent);
  background: var(--panel);
  border-color: var(--panel-border-strong);
  border-bottom: 1px solid var(--panel);
  text-shadow: 0 1px 0 rgba(0,0,0,0.6);
}
.editor-tabs button.is-active::after { width: 70%; }

.editor-panels { padding: 20px 28px 26px; }

.tab-panel { display: none; flex-direction: column; gap: 10px; }
.tab-panel.is-active { display: flex; }

.sub-heading {
  margin: 8px 0 2px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
  font-weight: 700;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(212,210,202,0.2);
}
.sub-heading:first-child { margin-top: 0; }

.hint {
  margin: 0 0 4px;
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
}

.ghost-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px dashed #2f3236;
  padding: 7px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  cursor: pointer;
  border-radius: 2px;
}
.ghost-btn:hover { color: var(--accent); border-color: var(--accent); background: rgba(212,210,202,0.05); }

.editor-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* Background-strip control row in the Leaders tab. */
.bg-strip-row {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
}
.bg-select {
  flex: 1; min-width: 140px;
  background: #0c0d10;
  border: 1px solid #2f3236;
  color: var(--text);
  font: inherit; font-size: 12.5px;
  padding: 5px 8px;
  border-radius: 2px;
}
.bg-strip-row .ghost-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: #2a2d31;
  color: #5a5d61;
}
.bg-strip-status {
  font: 10.5px ui-monospace, Consolas, monospace;
  color: #7cc97b;
  width: 100%;
  min-height: 14px;
}
.bg-strip-status.is-err { color: #c44a3a; }

.bg-toneify-check {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  cursor: pointer;
}
.bg-toneify-check input { cursor: pointer; }

.bg-srctype {
  flex: 0 0 auto; min-width: 110px;
  font-size: 11px;
}

/* ──────────── Modernised Leaders tab layout ──────────── */
.leader-card {
  background: linear-gradient(180deg, #1a1c1f 0%, #131517 100%);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  margin-bottom: 20px;
  overflow: hidden;
}
.leader-card-head {
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.015);
  border-bottom: 1px solid var(--panel-border);
}
.leader-card-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px 18px 18px;
}
@media (min-width: 720px) {
  .leader-card-body { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
}

.leader-fields {
  display: flex; flex-direction: column; gap: 10px;
}
.leader-upload {
  background: #0f1114;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.leader-upload-head {
  font-size: 10.5px;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.leader-drop {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px;
  padding: 20px;
  border: 2px dashed #2f3236;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  text-align: center;
}
.leader-drop:hover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.02);
}
/* Drag-over state: bigger glow + tinted bg, makes the drop target obvious. */
.leader-drop.is-drag-over {
  border-color: var(--accent);
  border-style: solid;
  background: rgba(212, 210, 202, 0.08);
  box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(212, 210, 202, 0.25);
  transform: scale(1.01);
}
.leader-drop.is-drag-over .leader-drop-icon {
  transform: scale(1.15);
  transition: transform 0.15s ease;
}
.leader-drop-input { position: absolute; opacity: 0; width: 0; height: 0; }
.leader-drop-cta {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
  letter-spacing: 0.5px;
}
.leader-drop-icon {
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}
.leader-drop-hint {
  font-size: 10.5px;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.leader-process-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.leader-process-row .primary {
  background: linear-gradient(180deg, #ff9c2e 0%, #e8801a 100%);
  color: #15171a;
  border: 1px solid #ff9c2e;
  padding: 7px 16px;
  font-size: 11.5px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-weight: 700;
  border-radius: 2px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 2px 6px rgba(0, 0, 0, 0.4);
}
.leader-process-row .primary:hover { filter: brightness(1.08); }
.leader-process-row .primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #2a2d31;
  color: #5a5d61;
  border-color: #2a2d31;
  box-shadow: none;
  filter: none;
}

/* ── Field row ────────────────────────────────────────────────────── */
.field {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 10px;
  align-items: center;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  font-weight: 600;
}
.field > input,
.field > textarea,
.field > select {
  font-size: 13px;
  font-family: var(--font-ui);
  padding: 6px 10px;
  background: #0c0d10;
  border: 1px solid #2f3236;
  color: var(--text);
  border-radius: 2px;
  text-transform: none;
  letter-spacing: normal;
}
.field > textarea {
  min-height: 60px;
  resize: vertical;
  line-height: 1.4;
}
.field > .code-area {
  font-family: ui-monospace, 'Consolas', monospace;
  font-size: 11.5px;
  line-height: 1.4;
}
.field--full { grid-template-columns: 1fr; gap: 4px; align-items: start; }
.field > .field-label { grid-column: 1 / 2; }

/* ── Slot list (national spirits editor rows) ─────────────────────── */
.slot-list { display: flex; flex-direction: column; gap: 8px; }
.slot-row {
  display: grid;
  /* picker · upload · label · delete */
  grid-template-columns: 1fr 32px 1fr 28px;
  gap: 6px;
  align-items: center;
}
.slot-row .slot-upload {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: #0c0d10;
  border: 1px solid #2f3236;
  border-radius: 3px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.slot-row .slot-upload:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: #181a1d;
}
.slot-row .slot-upload:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.slot-row input[type=text] {
  padding: 6px 10px;
  background: #0c0d10;
  border: 1px solid #2f3236;
  color: var(--text);
  border-radius: 2px;
  font: inherit;
  font-size: 12.5px;
}
.slot-row .slot-del {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
}
.slot-row .slot-del:hover { color: var(--danger); border-color: var(--danger); }

/* ── Loading veil ─────────────────────────────────────────────────── */
#loading-veil {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at center, #16181b 0%, #0b0c0e 80%);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  transition: opacity 0.4s;
}
#loading-veil.is-hidden { opacity: 0; pointer-events: none; }
.lv-inner { text-align: center; }
.lv-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--panel-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: lv-spin 0.8s linear infinite;
}
@keyframes lv-spin { to { transform: rotate(360deg); } }
.lv-text {
  color: var(--accent);
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 600;
}
.lv-sub {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: 1px;
  min-height: 14px;
}

/* Pie frame inside the preview — mimics the in-game Soziale Trends box */
.pie-frame {
  padding: 16px 14px 18px !important;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background:
    radial-gradient(ellipse at center, #14171a 0%, #060503 80%) !important;
  border: 1px solid #3c3f43 !important;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.04),
    inset 0 -1px 0 rgba(0,0,0,0.6),
    inset 0 0 40px rgba(0,0,0,0.7) !important;
}
.pie-frame-title {
  font-family: var(--font-title);
  font-size: 13px; color: var(--accent);
  letter-spacing: 3px; text-transform: uppercase;
  font-weight: 700;
  text-shadow: 0 1px 0 rgba(0,0,0,0.7);
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(212,210,202,0.2);
  width: 80%; text-align: center;
}

/* ───────────────────────────────────────────────────────────────────────
   Mobile / phone-portrait layout.
   The TNO superevent stage is a fixed 1280×720 layout — it can't
   actually shrink below ~720px wide without becoming unreadable. So
   on phones we let it horizontally scroll inside its container, but
   make the chrome (header, tabs, modals, footer) phone-friendly.
   ─────────────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  /* Header — collapse padding + smaller title. */
  header.app-header {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }
  header.app-header h1 { font-size: 14px; letter-spacing: 2px; }
  header.app-header .subtitle { display: none; }

  /* Nav links — wrap onto a second row, full-width when there's room. */
  .app-nav {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }
  .app-nav .header-link {
    padding: 6px 8px;
    font-size: 10.5px;
    letter-spacing: 1px;
    flex: 1;
    text-align: center;
  }

  /* Editor panel chrome. */
  main.editor-page { padding: 8px; }
  .editor-panels { padding: 14px 14px 18px; }
  .editor-tabs {
    overflow-x: auto;
    padding: 6px 6px 0;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;       /* hide scrollbar on Firefox */
  }
  .editor-tabs::-webkit-scrollbar { display: none; }

  /* Preview page — let the stage scroll horizontally on phones; the
     1280px-wide superevent layout can't actually reflow narrower. */
  main { display: block; padding: 8px; }
  .left-column { gap: 12px; }
  #se-stage {
    transform-origin: top left;
  }

  /* Asset picker drawer — taller on phones since the screen is
     vertical-oriented. */
  .ap-popup {
    height: 70vh;
    padding: 16px 14px 18px;
  }

  /* Disclaimer / help modal — full-width with margins. */
  .disclaimer-panel {
    margin: 12px;
    padding: 22px 20px 18px;
    max-height: 86vh;
    font-size: 13px;
  }

  /* Footer — stack on its own line. */
  .site-footer {
    padding: 14px 12px 18px;
    font-size: 11.5px;
  }
}

/* Very narrow phones (≤ 380px). */
@media (max-width: 380px) {
  header.app-header h1 { font-size: 12px; letter-spacing: 1.5px; }
  .app-nav .header-link { font-size: 10px; padding: 5px 4px; }
}

/* ───────────────────────────────────────────────────────────────────────
   Stage auto-scale for non-1920 viewports.

   The 1920×1080 stage is a fixed design surface — components sit at
   hardcoded pixel coordinates. Rather than rewriting the layout for
   every breakpoint, we scale the whole stage with a CSS transform so
   the entire dashboard fits in whatever viewport the user has.

   • viewport ≥ 1920: scale = 1, stage is 1:1.
   • viewport 720–1919: scale fits width with modest side margins.
   • viewport < 720:   scale fits width edge-to-edge on phones.
   • `.is-debug` active: no scale (layout editor needs unscaled coords
     for drag handles to line up with `getBoundingClientRect`).

   Transform doesn't affect layout size, so we also shrink the preview
   page's reserved width/height to match the SCALED stage — otherwise
   the page would leave a huge empty scroll region below the visible
   stage on phones.
   ─────────────────────────────────────────────────────────────────────── */
@media (max-width: 1919px) {
  .superevent-stage:not(.is-debug) {
    --stage-scale: calc(100vw / 1920);
  }
  main.preview-page {
    /* Shrink the page to the scaled stage size. Clamped to 100vw so a
       thin extra pixel at the right edge doesn't trigger horizontal
       scroll. */
    width: 100vw;
    min-width: 0;
    max-width: 100vw;
    height: calc(1080px * (100vw / 1920));
    padding: 0;
    overflow: hidden;
  }
  /* When layout-editor IS active the stage stays 1:1. Give the page
     back room to scroll in both axes so the user can still drag-edit
     a full-size stage on a narrow display. */
  main.preview-page:has(.superevent-stage.is-debug) {
    width: max-content;
    height: auto;
    overflow: visible;
    padding: 18px;
  }
}

/* On tight phone viewports give the stage a hairline of vertical space
   underneath so the page footer never crashes into its bottom edge. */
@media (max-width: 720px) {
  main.preview-page {
    padding-bottom: 12px;
    height: calc(1080px * (100vw / 1920) + 12px);
  }
}
