/* Wrapped Summary Card Stylesheet - Unified WYSIWYG Architecture */
:root {
  --preview-card-scale: clamp(0.72, calc((100svh - 120px) / 640), 0.95);
}

@media (max-width: 799px) {
  :root {
    --preview-card-scale: min(1, calc((100vw - 32px) / 360));
  }
}

.data-source-toggle {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: -4px -4px 0;
  border: 1px solid oklch(80% 0.02 250 / 0.12);
  border-radius: 14px;
  background: oklch(20% 0.03 250 / 0.5);
}

.toggle-option {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  user-select: none;
}

.toggle-option input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.toggle-option span {
  color: oklch(75% 0.02 250);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
}

.toggle-option:has(input:checked) {
  background: linear-gradient(135deg, oklch(65% 0.2 30), oklch(55% 0.22 260));
  box-shadow: 0 4px 12px oklch(60% 0.2 145 / 0.25);
}

.toggle-option:has(input:checked) span,
.toggle-option:focus-within span {
  color: #fff;
}

.toggle-option:hover:not(:has(input:checked)) {
  background: oklch(90% 0.02 250 / 0.06);
}

.wrapped-search {
  margin-bottom: 24px;
}
.wrapped-search.card:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--card-border, oklch(80% 0.02 250 / 0.15));
}

.wrapped-save-fallback {
  margin-top: 12px;
  color: oklch(78% 0.02 250);
  font-size: 0.85rem;
  line-height: 1.4;
}

.wrapped-save-fallback p {
  margin: 0 0 10px;
}

.wrapped-save-image {
  display: block;
  width: min(100%, 360px);
  height: auto;
  margin: 0 auto 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  touch-action: manipulation;
  -webkit-touch-callout: default;
}

.wrapped-save-fallback a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid oklch(72% 0.16 145 / 0.65);
  border-radius: 10px;
  background: oklch(35% 0.08 145 / 0.35);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
}

.wrapped-save-fallback a:hover,
.wrapped-save-fallback a:focus-visible {
  background: oklch(40% 0.1 145 / 0.5);
}

/* Page Header & Lede display */
.page-header {
  width: 100%;
  max-width: none;
}

@media (min-width: 860px) {
  .page-header .lede {
    white-space: nowrap;
  }
}

/* Right Column & Card Scaling Container */
@media (min-width: 800px) {
  .content-right {
    max-height: none !important;
    overflow: visible !important;
    padding-right: 0 !important;
    margin-top: clamp(-110px, -12vh, -75px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
  }
}

.story-card-wrapper {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  height: calc(640px * var(--preview-card-scale));
  flex-shrink: 0;
}

/* Base 9:16 Story Card (Single Source of Truth: 360x640) */
.story-card {
  width: 360px;
  height: 640px;
  aspect-ratio: 9 / 16;
  background: radial-gradient(circle at 85% 15%, rgba(224, 80, 64, 0.22), transparent 55%),
              linear-gradient(160deg, #25122e 0%, #141829 52%, #070a11 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 28px;
  padding: 24px 20px;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.2), 0 24px 60px rgba(0, 0, 0, 0.8);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  overflow: hidden;
  box-sizing: border-box;
  backdrop-filter: blur(20px);
  transform: scale(var(--preview-card-scale));
  transform-origin: top center;
  flex-shrink: 0;
}

.story-card[data-role="judge"] {
  background: radial-gradient(circle at 85% 15%, rgba(105, 94, 255, 0.22), transparent 55%),
              linear-gradient(160deg, #201735 0%, #141829 52%, #070a11 100%);
}

/* 9:16 Ghost Skeleton Preview Card */
.placeholder-wrapper {
  animation: fadeIn 350ms cubic-bezier(0.16, 1, 0.3, 1);
}

.story-card.ghost-card {
  background: radial-gradient(circle at 85% 15%, oklch(65% 0.15 20 / 0.14), transparent 60%),
              radial-gradient(circle at 20% 85%, oklch(55% 0.2 260 / 0.1), transparent 60%),
              linear-gradient(160deg, #1d152a 0%, #131726 52%, #090c15 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.12), 0 20px 50px rgba(0, 0, 0, 0.6);
  justify-content: space-between;
  user-select: none;
}

.ghost-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  width: 100%;
}

.ghost-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: oklch(65% 0.15 20 / 0.15);
  border: 1px solid oklch(65% 0.15 20 / 0.35);
  color: oklch(92% 0.08 20);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 9999px;
}

.ghost-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: auto 0;
  width: 100%;
  text-align: center;
}

.ghost-callout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.ghost-callout-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, oklch(65% 0.18 20 / 0.25), oklch(55% 0.2 260 / 0.2));
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  color: oklch(94% 0.08 20);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.ghost-callout h3 {
  font-size: 1.18rem;
  font-weight: 800;
  color: oklch(98% 0 0);
  letter-spacing: -0.01em;
  margin: 2px 0 0;
  text-wrap: balance;
}

.ghost-callout p {
  font-size: 0.84rem;
  line-height: 1.45;
  color: oklch(78% 0.02 250);
  max-width: 30ch;
  margin: 0 auto;
  text-wrap: pretty;
}

.ghost-skeleton-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0.32;
  margin-top: 4px;
  pointer-events: none;
}

.ghost-bar {
  display: inline-block;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.22);
}

.ghost-bar-xs { width: 32px; height: 6px; }
.ghost-bar-sm { width: 52px; height: 6px; }
.ghost-bar-md { width: 76px; height: 7px; }
.ghost-bar-lg { width: 100%; max-width: 140px; height: 7px; }

.ghost-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.ghost-stat-box {
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ghost-titles-mock {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ghost-title-item {
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ghost-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  width: 100%;
}

.ghost-watermark {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  color: oklch(62% 0.02 250);
  letter-spacing: 0.04em;
}

/* Off-screen Export Stage & Export Card (Identical 360x640 proportions) */
.wrapped-export-stage {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 360px;
  height: 640px;
  pointer-events: none;
}

.story-card.export-card {
  width: 360px !important;
  max-width: none !important;
  height: 640px !important;
  aspect-ratio: auto !important;
  border-radius: 28px !important;
  padding: 24px 20px !important;
  transform: none !important;
}

/* Card Internal Typography & Components - Exact 1:1 Sync */
.story-header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  margin-bottom: 12px;
  width: 100%;
  box-sizing: border-box;
}

.header-logo-img {
  height: 22px;
  width: 22px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  display: block;
}

.header-tourn-title {
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #ffffff;
  text-transform: uppercase;
  overflow-wrap: anywhere;
  line-height: 1.25;
  margin: 0;
}

.summary-content {
  display: flex;
  flex-direction: column;
  /* Keep four-title preview footprint aligned with the fixed canvas renderer. */
  gap: 10px;
  min-height: 0;
}

.summary-identity,
.summary-title-section,
.assignment-section {
  min-width: 0;
}

.summary-name {
  font-size: 1.55rem;
  font-weight: 800;
  color: white;
  line-height: 1.1;
  margin: 0 0 3px;
  overflow-wrap: anywhere;
}

.summary-subtitle {
  overflow-wrap: anywhere;
  color: oklch(82% 0.02 250);
  font-size: 0.86rem;
  font-weight: 500;
  margin: 0;
}

.summary-peak {
  background: linear-gradient(135deg, rgba(224, 80, 64, 0.12) 0%, rgba(255, 255, 255, 0.04) 100%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-top: 2px solid rgba(224, 80, 64, 0.5);
  backdrop-filter: blur(16px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.story-card[data-role="judge"] .summary-peak {
  background: linear-gradient(135deg, rgba(105, 94, 255, 0.14) 0%, rgba(255, 255, 255, 0.04) 100%);
  border-top-color: rgba(105, 94, 255, 0.55);
}

.summary-peak .hl-label {
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  color: oklch(82% 0.03 250);
  font-weight: 700;
  text-transform: none;
}

.summary-peak .hl-value {
  font-size: 1.02rem;
  font-weight: 800;
  color: oklch(98% 0 0);
  line-height: 1.15;
}

.summary-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.summary-stats-grid .stat-item {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.03) 100%);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-top: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 11px;
  padding: 8px 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.summary-stats-grid .stat-val {
  font-size: 1.25rem;
  line-height: 1.1;
  font-weight: 800;
  color: #ffffff;
}

.summary-stats-grid .stat-val.stat-val-long {
  font-size: 0.95rem;
  line-height: 1.1;
  white-space: nowrap;
  overflow-wrap: normal;
}

.summary-stats-grid .stat-lbl {
  font-size: 0.52rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: oklch(82% 0.02 250);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: visible;
}

.hl-label {
  font-size: 0.72rem;
  color: oklch(80% 0.02 250);
  font-weight: 700;
  text-transform: uppercase;
}

.hl-values {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.hl-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: oklch(98% 0 0);
  overflow-wrap: anywhere;
}

.hl-value-secondary {
  font-size: 0.95rem;
  color: oklch(82% 0.02 250);
}

.summary-peak .hl-value-secondary {
  font-size: 0.82rem;
}

.stat-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-top: 2px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-val {
  font-size: 1.25rem;
  font-weight: 800;
  color: oklch(98% 0 0);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.stat-lbl {
  font-size: 0.68rem;
  color: oklch(75% 0.02 250);
  font-weight: 600;
}

.pos-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.title-card-list {
  display: grid;
  gap: 7px;
  margin-bottom: 0;
}

.title-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 6px;
  padding: 8px 11px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 11px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.03) 100%);
  backdrop-filter: blur(12px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  min-width: 0;
}

.summary-title-cards .title-card {
  padding-top: 7px;
  padding-bottom: 7px;
}

.title-card-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.title-card-name,
.title-card-tagline,
.title-card-evidence {
  overflow-wrap: anywhere;
  display: block;
}

.title-card-name {
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
}

.title-card-tagline {
  color: oklch(82% 0.02 250);
  font-size: 0.58rem;
  font-style: italic;
  font-weight: 500;
  line-height: 1.25;
  display: block;
}

.title-card-evidence {
  color: #f6c76b;
  font-size: 0.54rem;
  font-weight: 600;
  line-height: 1.25;
  display: block;
}

.title-card-rarity {
  color: #f6c76b;
  font-size: 0.56rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 0 8px rgba(246, 199, 107, 0.3);
}

.section-label {
  color: oklch(80% 0.02 250);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 5px;
  text-transform: uppercase;
}

.assignment-section {
  margin-top: 6px;
}

.assignment-section .pos-chips {
  margin-bottom: 0;
}

.summary-title-section .section-label,
.summary-assignment-section .section-label {
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  color: oklch(82% 0.02 250);
  font-weight: 800;
  margin-bottom: 4px;
}

.summary-assignment-section {
  margin-top: 0;
}

.summary-assignment-section .pos-chips {
  gap: 4px;
}

.summary-assignment-section .chip {
  padding: 4px 7px;
  border-radius: 8px;
  font-size: 0.64rem;
}

.chip {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 700;
  color: white;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.story-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: auto;
  padding-top: 6px;
}

.story-footer-note {
  font-size: 0.65rem;
  font-weight: 700;
  color: oklch(65% 0.02 250);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.story-watermark {
  display: flex;
  align-items: center;
  margin-left: auto;
  gap: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  color: oklch(78% 0.02 250);
  letter-spacing: 0.04em;
}

.watermark-logo-img {
  height: 15px;
  width: 15px;
  border-radius: 3px;
  object-fit: cover;
  opacity: 0.9;
  flex-shrink: 0;
}

#btnExportImage:focus-visible {
  outline: 3px solid oklch(82% 0.16 80);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .placeholder-wrapper {
    animation: none;
  }
}
