:root {
  --bg: #ead8bd;
  --wash: #f8efe2;
  --paper: #fffaf1;
  --paper-soft: #fdf2df;
  --ink: #2c2118;
  --muted: #7a6654;
  --line: rgba(96, 66, 42, 0.2);
  --line-strong: rgba(96, 66, 42, 0.34);
  --accent: #9a5a33;
  --accent-dark: #5d321c;
  --olive: #566244;
  --blue-back: #587b9d;
  --gray-back: #85817a;
  --shadow-soft: 0 16px 36px rgba(75, 48, 27, 0.14);
  --shadow-card: 0 10px 22px rgba(68, 43, 24, 0.18);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, rgba(86, 98, 68, 0.07) 1px, transparent 1px),
    linear-gradient(180deg, rgba(86, 98, 68, 0.05) 1px, transparent 1px),
    radial-gradient(circle at 12% 0%, rgba(255, 250, 241, 0.85), transparent 34%),
    linear-gradient(145deg, #f6ead9 0%, #ead7bb 45%, #dfc7a7 100%);
  background-size: 38px 38px, 38px 38px, auto, auto;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      100deg,
      rgba(84, 59, 36, 0.035) 0,
      rgba(84, 59, 36, 0.035) 1px,
      transparent 1px,
      transparent 9px
    );
  mix-blend-mode: multiply;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.page-shell {
  width: min(1320px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 72px;
}

.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 28px;
  min-height: 230px;
  padding: 34px 34px 30px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(120deg, rgba(255, 250, 241, 0.96), rgba(250, 234, 209, 0.82)),
    var(--paper);
  box-shadow: var(--shadow-soft);
}

.hero::before,
.hero::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.hero::before {
  inset: 18px;
  border: 1px solid rgba(96, 66, 42, 0.16);
  border-radius: var(--radius);
}

.hero::after {
  right: 34px;
  top: 24px;
  width: min(32vw, 350px);
  height: 160px;
  background:
    linear-gradient(90deg, rgba(253, 242, 223, 0), rgba(253, 242, 223, 0.88) 34%, rgba(253, 242, 223, 0)),
    repeating-linear-gradient(90deg, rgba(96, 66, 42, 0.16) 0 1px, transparent 1px 20px);
  opacity: 0.48;
  transform: rotate(-2deg);
}

.hero-copy,
.hero-actions,
.section-head,
.admin-grid,
.selected-rows,
.card-grid {
  position: relative;
  z-index: 1;
}

.hero-copy {
  max-width: 760px;
}

.hero h1 {
  margin: 8px 0 0;
  font-size: clamp(2.45rem, 5.8vw, 5.8rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.hero h1 span {
  display: block;
  color: var(--accent-dark);
}

.deck-marks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.deck-marks span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid rgba(96, 66, 42, 0.18);
  border-radius: 999px;
  padding: 0 12px;
  background: rgba(255, 250, 241, 0.62);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 760;
}

.hero-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  width: min(260px, 100%);
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h2 {
  margin: 4px 0 0;
  font-size: clamp(1.18rem, 1.8vw, 1.64rem);
  line-height: 1.12;
  letter-spacing: 0;
}

.primary-btn,
.secondary-btn {
  min-height: 42px;
  border-radius: 999px;
  padding: 0 18px;
  white-space: nowrap;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.primary-btn {
  background: var(--accent);
  color: #fffaf1;
  box-shadow: 0 12px 22px rgba(154, 90, 51, 0.22);
}

.secondary-btn {
  border: 1px solid rgba(96, 66, 42, 0.25);
  background: rgba(255, 250, 241, 0.68);
  color: var(--accent-dark);
}

.primary-btn:hover,
.secondary-btn:hover {
  transform: translateY(-1px);
}

.secondary-btn:hover {
  border-color: rgba(96, 66, 42, 0.42);
  background: rgba(255, 250, 241, 0.92);
}

.admin-panel,
.selected-panel,
.deck-section {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 241, 0.74);
  box-shadow: var(--shadow-soft);
}

.admin-panel {
  display: none;
  padding: 20px;
}

.admin-panel.is-open {
  display: block;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.upload-box {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 168px;
  padding: 16px;
  border: 1px dashed rgba(96, 66, 42, 0.28);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 250, 241, 0.72), rgba(250, 234, 209, 0.52)),
    var(--paper-soft);
}

.upload-box span {
  color: var(--ink);
  font-weight: 760;
}

.upload-box input {
  width: 100%;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-line {
  min-height: 24px;
  margin: 14px 0 0;
  color: var(--accent-dark);
  font-weight: 760;
}

.selected-panel {
  position: sticky;
  top: 10px;
  z-index: 8;
  padding: 18px;
  background:
    linear-gradient(120deg, rgba(255, 250, 241, 0.94), rgba(247, 231, 205, 0.9)),
    var(--paper);
}

.selected-rows {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.selected-row {
  display: grid;
  grid-template-columns: 72px repeat(3, minmax(96px, 148px));
  align-items: center;
  gap: 14px;
}

.row-label {
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 850;
}

.slot {
  position: relative;
  aspect-ratio: 733 / 1027;
  overflow: hidden;
  border: 1px dashed rgba(96, 66, 42, 0.36);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 250, 241, 0.54), rgba(230, 205, 171, 0.42)),
    var(--paper-soft);
}

.slot::before {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(96, 66, 42, 0.1);
  border-radius: 6px;
}

.selected-card {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  padding: 0;
  border-radius: var(--radius);
  background: transparent;
}

.selected-card img,
.card-face img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.selected-card[draggable="true"] {
  cursor: grab;
}

.selected-card.dragging {
  opacity: 0.42;
}

.deck-section {
  padding: 18px;
}

.sticky-head {
  position: sticky;
  top: 215px;
  z-index: 4;
  margin: -18px -18px 0;
  padding: 16px 18px 12px;
  border-bottom: 1px solid rgba(96, 66, 42, 0.12);
  border-radius: var(--radius) var(--radius) 0 0;
  background: rgba(242, 226, 201, 0.9);
  backdrop-filter: blur(12px);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(9px, 1.35vw, 16px);
  margin-top: 18px;
}

.card {
  position: relative;
  aspect-ratio: 733 / 1027;
  padding: 0;
  border-radius: var(--radius);
  perspective: 1000px;
  background: transparent;
}

.card::after {
  content: "";
  position: absolute;
  inset: 7px 8px -7px;
  z-index: -1;
  border-radius: var(--radius);
  background: rgba(67, 43, 24, 0.16);
  filter: blur(6px);
  opacity: 0.72;
  transition: opacity 180ms ease, transform 180ms ease;
}

.card:hover::after {
  opacity: 0.94;
  transform: translateY(2px);
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 520ms cubic-bezier(0.2, 0.74, 0.18, 1);
}

.card.is-flipped .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid rgba(76, 49, 28, 0.18);
  border-radius: var(--radius);
  backface-visibility: hidden;
  background: var(--paper);
  box-shadow: inset 0 0 0 1px rgba(255, 250, 241, 0.32);
}

.card-front {
  transform: rotateY(180deg);
  background: #fff;
}

.fallback-back {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: rgba(255, 255, 255, 0.82);
  font-size: clamp(0.82rem, 1.7vw, 1.05rem);
  font-weight: 850;
}

.fallback-back.image {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0)),
    var(--blue-back);
}

.fallback-back.text {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0)),
    var(--gray-back);
}

.divider {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 34px 0 14px;
  color: var(--accent);
}

.divider::before,
.divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, transparent, rgba(154, 90, 51, 0.5), transparent);
}

.divider span {
  width: 104px;
  height: 12px;
  border-top: 1px solid rgba(154, 90, 51, 0.46);
  border-bottom: 1px solid rgba(154, 90, 51, 0.46);
}

.preview-dialog {
  width: min(86vw, 560px);
  max-height: 92dvh;
  border: 1px solid rgba(96, 66, 42, 0.22);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--paper);
  box-shadow: 0 24px 80px rgba(40, 25, 13, 0.34);
}

.preview-dialog::backdrop {
  background: rgba(44, 33, 24, 0.5);
  backdrop-filter: blur(2px);
}

.preview-dialog img {
  display: block;
  width: 100%;
  max-height: 76dvh;
  object-fit: contain;
  border-radius: var(--radius);
}

.icon-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(96, 66, 42, 0.2);
  border-radius: 999px;
  background: rgba(255, 250, 241, 0.92);
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
}

#flipBackFromPreview {
  width: 100%;
  margin-top: 12px;
}

@media (max-width: 980px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .hero-actions {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .selected-panel {
    position: relative;
    top: auto;
  }

  .sticky-head {
    top: 0;
  }

  .selected-row {
    grid-template-columns: 1fr repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .page-shell {
    width: min(100% - 18px, 1320px);
    padding-top: 10px;
  }

  .hero,
  .deck-section,
  .selected-panel,
  .admin-panel {
    padding: 12px;
  }

  .hero {
    min-height: 0;
  }

  .hero::before,
  .hero::after {
    display: none;
  }

  .hero h1 {
    font-size: 2.08rem;
    line-height: 1.02;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .selected-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
  }

  .row-label {
    grid-column: 1 / -1;
  }

  .sticky-head {
    margin: -12px -12px 0;
    padding: 12px;
  }

  .card-grid {
    gap: 7px;
  }

  .primary-btn,
  .secondary-btn {
    min-height: 40px;
    padding: 0 14px;
    font-size: 0.92rem;
  }
}
