/* ===== 11W Labs – Base Theme ===== */
:root {
  --bg: #0f0f10;
  --panel: #17181a;
  --subtext: #A7B1B7;
  --muted: #8b8f98;
  --fg: #eaeaf0;
  --line: #26282c;
  --brand: #BA0C2F;
  --error-bg: #EFF1F2;
  --error-text: var(--brand);
  --canvas-max: 720px;
  --card-pad: 16px;
  --canvas-pad: 32px;
  --panel-pad: 16px;
  --grid-gap: 16px;
  --left-rail: 240px;
  --right-rail: 250px;
  --layout-max: calc(var(--canvas-max) + var(--canvas-pad) + var(--left-rail) + var(--right-rail) + (var(--grid-gap) * 2) + (var(--panel-pad) * 2));
}

* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial
}

a {
  color: var(--brand);
}

/* ===== Shell ===== */
header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #121316d9;
  backdrop-filter: blur(8px);
  /* remove separator line under header */
  border-bottom: none;
}

h1 {
  font-size: 18px;
  margin: 0;
  padding: 12px 16px
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, var(--layout-max));
  /* single column (no sidebar) */
  gap: 12px;
  justify-content: center;
  width: 100%;
  padding: 0 var(--panel-pad) var(--panel-pad);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-top: 15px;
  padding: var(--panel-pad);
}

h2 {
  margin: 4px 0 12px;
  font-size: 24px
}

.footer {
  margin-top: 32px;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: #121316;
}

.footer__content {
  width: min(100%, var(--layout-max));
  margin: 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.tables-input-wrap .if-input.tables-input {
  width: 100%;
  min-height: 224px;
}

.tables-input-wrap {
  display: block;
  width: 100%;
}

.subtext {
  color: var(--subtext);
  font-size: 14px;
}

/* Info Box */
.info-box {
  background: #15171a;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 20px 0 30px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 16px;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--fg);
}

.tables-options-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  margin: 8px 0 16px;
}

.info-box--with-icon {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.info-icon {
  display: inline-flex;
  width: 26px;
  min-width: 26px;
  height: 26px;
  color: currentColor;
  /* inherits var(--muted) */
}

.info-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
  /* OR replace with #b90b2f for permanent red */
}

/* Text block (right column) */
.info-text {
  padding-top: 3px;
}

.info-text p {
  margin: 0 0 8px;
}

.info-text p:last-child {
  margin-bottom: 0;
}

/* left-align under brand */
.muted {
  color: var(--muted);
  font-size: 12px
}

/* Inline code token / keyword / variable pill */
.code-token {
  display: inline-block;
  padding: 3px 5px 2px;
  margin: 0 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.3;
  color: #b2bbc0;

  background: #1d1f23;
  border-radius: 6px;
  /* pill shape */

  white-space: nowrap;
  user-select: text;
}

/* ===== Header bar + horizontal nav ===== */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(100%, var(--layout-max));
  margin: 0 auto;
  padding: 8px 16px;
}

.brand {
  font-weight: 800;
  letter-spacing: .2px
}

.topnav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.nav-item {
  position: relative;
}

.nav-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: #1a1c20;
  color: var(--fg);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}

.nav-item.is-open .nav-trigger,
.nav-trigger:hover,
.nav-item.is-active .nav-trigger {
  border-color: #2a2e34;
}

.nav-item.is-active .nav-trigger {
  color: var(--brand);
  border-color: var(--brand);
}

.nav-trigger:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.nav-trigger-caret {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  margin-left: 4px;
  transition: transform .2s ease;
}

.nav-item.is-open .nav-trigger-caret {
  transform: rotate(-135deg);
}

.nav-flyout {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 220px;
  padding: 10px 8px 8px;
  border-radius: 10px;
  background: #1b1e23;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 18px 30px rgba(5, 7, 11, 0.45);
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity .18s ease, transform .18s ease;
  z-index: 20;
}

.nav-item.is-open .nav-flyout {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.nav-flyout::before {
  content: '';
  position: absolute;
  top: -5px;
  left: 12px;
  width: 9px;
  height: 9px;
  background: #1b1e23;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom: none;
  border-right: none;
  transform: rotate(45deg);
  pointer-events: none;
  z-index: 0;
}

.nav-flyout-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  transition: background .15s ease, color .15s ease;
  position: relative;
  z-index: 1;
}

.nav-flyout-link:hover,
.nav-flyout-link:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav-flyout-link.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: transparent;
}

.nav-flyout-link.active {
  background: rgba(186, 12, 47, 0.16);
  color: var(--brand);
}

/* ===== Image Factory view ===== */

/* Working grid variants */
.if-grid {
  display: grid;
  gap: var(--grid-gap);
  margin-top: var(--grid-gap);
}

.if-grid--three {
  grid-template-columns: var(--left-rail) calc(var(--canvas-max) + var(--canvas-pad)) var(--right-rail);
}

/* thumbs • canvas • options */

.if-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: var(--card-pad);
}

/* Thumbnails */
.if-thumbs {
  max-height: 52vh;
  overflow: auto
}

.if-thumb {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  cursor: pointer
}

.if-thumb img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #2a2d33
}

.if-thumb.active {
  background: #1d2025
}

/* Drop zone */
.if-drop {
  border: 2px dashed #2a2d33;
  border-radius: 12px;
  padding: 48px 16px;
  text-align: center;
  margin-bottom: 10px;
  background: #16181d;
  transition: background .2s, border-color .2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px
}

.if-drop:hover {
  border-color: #BA0C2F;
  background: #1a1d23
}

.if-browse span {
  background: #e5e7eb;
  color: #111;
  padding: 5px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: background .15s;
  font-size: 12px;
}

.if-browse span:hover {
  background: #d1d5db
}

/* Toolbar (above canvas) */
.if-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px
}

.if-toolbar-left,
.if-toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px
}

.if-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted)
}

.if-card input[type="range"] {
  accent-color: var(--brand);
}

.if-tip {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.if-tip-label {
  color: var(--fg);
  font-weight: 600;
}

.if-keyrow {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.if-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #202227;
  border: 1px solid rgba(255, 255, 255, 0.07);
  color: #eef1f6;
  font-size: 12px;
  line-height: 1.2;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.4);
}

.if-key-divider {
  color: var(--muted);
  font-size: 12px;
}

.if-input {
  background: #22252a;
  border: 1px solid var(--line);
  color: var(--fg);
  border-radius: 10px;
  padding: 8px 10px
}

.if-input--sm {
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 13px
}

.if-size-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.if-toolbar .if-size-label {
  color: var(--muted);
}

.if-field--sliders input[type="range"] {
  width: 100%;
}

.if-input:disabled {
  background: #1b1d21;
  border-color: rgba(255, 255, 255, 0.05);
  color: #5f646e;
  opacity: 0.65;
}

.if-card input[type="range"]:disabled {
  opacity: 0.35;
  filter: grayscale(0.4);
}

.btn:disabled,
.btn.secondary:disabled {
  background: #2a2d33;
  color: #6b7079;
  opacity: 0.5;
  box-shadow: none;
}

/* Buttons */
.if-actions {
  display: flex;
  gap: 8px
}

.btn {
  background: #e5e7eb;
  color: #111;
  padding: 8px 12px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  font-weight: 700
}

.btn.secondary {
  background: #2a2d33;
  color: var(--fg)
}

.btn--success {
  color: #4ade80 !important;
}

.is-hidden {
  display: none !important;
}

/* Canvas block — true 904×490 with responsive downscale */
.if-canvas-wrap {
  position: relative;
  background: #0b0c0e;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  width: 100%;
  max-width: var(--canvas-max);
  height: auto;
}

.if-canvas-wrap canvas {
  width: 100%;
  max-width: var(--canvas-max);
  height: 100%;
  display: block;
}

/* Gridlines overlay */
.if-gridlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to right, transparent 32%, rgba(255, 255, 255, .12) 33%, transparent 34%),
    linear-gradient(to right, transparent 65%, rgba(255, 255, 255, .12) 66%, transparent 67%),
    linear-gradient(to bottom, transparent 32%, rgba(255, 255, 255, .12) 33%, transparent 34%),
    linear-gradient(to bottom, transparent 65%, rgba(255, 255, 255, .12) 66%, transparent 67%)
}

/* Right options rail */
.if-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px
}

#if-wm-pos-field {
  display: none;
}

.if-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px
}

/* Rankings generator */
.rankings-controls,
.table-builder-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  margin-top: 16px;
}

.rankings-controls-card,
.table-builder-controls-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111215;
  padding: 16px;
}

.table-builder-controls-card {
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}

.table-builder-controls-card .rankings-actions {
  margin-top: 4px;
  justify-content: flex-start;
  width: 100%;
}

.table-builder-controls-card .tables-options-row {
  width: 100%;
  margin: 0 0 8px;
  justify-content: flex-start;
}

.rankings-select-wrap {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}

.rankings-select-wrap select {
  width: auto;
  min-width: 200px;
}

.rankings-controls-card .rankings-select-wrap {
  margin-bottom: 0;
  align-items: flex-start;
}

.bsd-url-field {
  flex: 2 1 400px;
}

.bsd-url-input {
  width: 100%;
}

.rankings-controls .if-field {
  margin-bottom: 0;
}

.rankings-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-end;
}

.rankings-align-row,
.output-controls-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.output-controls-card,
.rankings-align-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111215;
  padding: 12px 14px;
  display: flex;
  width: 100%;
  margin-top: 10px;
}

.rankings-output,
.output-block {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.output-block h3 {
  margin: 0 0 6px;
}

.output-block textarea,
.output-textarea {
  min-height: 200px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  resize: vertical;
}

.status-message {
  margin-top: 12px;
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  padding: 6px 10px 6px 0;
  display: inline-block;
  border-radius: 4px;
}

.status-message.error {
  background-color: var(--error-bg);
  color: var(--error-text);
  padding: 6px 10px;
}

.rankings-results {
  display: flex;
  gap: 24px;
  margin-top: 20px;
  align-items: flex-start;
}

.rankings-preview {
  flex: 1 1 60%;
  max-width: 60%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  background: #111215;
  overflow-x: auto;
}

.rankings-output {
  flex: 1 1 40%;
}

.rankings-results .rankings-output.is-hidden {
  display: none;
}

@media (max-width: 1024px) {
  .rankings-results {
    flex-direction: column;
  }

  .rankings-preview,
  .rankings-output {
    max-width: 100%;
  }
}

.rankings-preview:empty {
  display: none;
}

/* Make the right rail stick beside the canvas on wide screens */
@media (min-width:1201px) {
  .if-grid--three>.if-card:last-child {
    position: sticky;
    top: 72px
  }
}

/* ===== Responsive ===== */
@media (max-width:1200px) {
  .if-canvas-wrap {
    width: 100%;
    height: auto;
    aspect-ratio: 904/490
  }

  .if-canvas-wrap canvas {
    width: 100%;
    height: auto
  }

  .if-grid--three {
    grid-template-columns: 1fr
  }

  /* stack columns */
  .if-card+.if-card {
    margin-top: 12px
  }

  .topnav {
    justify-content: flex-end
  }
}
