:root {
  --bg-0: #090d18;
  --bg-1: #111a31;
  --ambient-core: rgba(136, 162, 229, 0.17);
  --ambient-side: rgba(44, 67, 126, 0.16);
  --text-soft: #cdd6eb;
  --text-muted: #8894b1;
  --line: rgba(214, 225, 255, 0.18);
  --panel-fill: rgba(10, 17, 35, 0.45);
  --input-fill: rgba(5, 10, 20, 0.62);
  --history-fill: rgba(8, 16, 34, 0.62);
  --history-line: rgba(216, 227, 255, 0.2);
  --theme-accent: rgba(248, 244, 236, 0.92);
  --theme-accent-ink: #0f1f45;
  --hint: rgba(216, 226, 251, 0.72);
  --stamp-fill: rgba(8, 16, 34, 0.54);
  --stamp-line: rgba(216, 227, 255, 0.18);
  --stamp-code: #f2f6ff;
  --stamp-city: #a6b4d8;
  --board-shadow: rgba(0, 0, 0, 0.45);
}

body[data-theme="BA"] {
  --bg-0: #071022;
  --bg-1: #10204a;
  --ambient-core: rgba(120, 157, 235, 0.22);
  --ambient-side: rgba(22, 52, 129, 0.22);
  --text-soft: #d5dff7;
  --text-muted: #8ea0d2;
  --line: rgba(188, 208, 255, 0.18);
  --panel-fill: rgba(8, 18, 41, 0.55);
  --input-fill: rgba(4, 11, 24, 0.7);
  --history-fill: rgba(8, 16, 34, 0.68);
  --history-line: rgba(216, 227, 255, 0.24);
  --theme-accent: rgba(240, 246, 255, 0.95);
  --theme-accent-ink: #10234c;
  --hint: rgba(215, 226, 255, 0.76);
  --stamp-fill: rgba(11, 22, 45, 0.62);
  --stamp-line: rgba(193, 211, 255, 0.18);
  --stamp-code: #f2f6ff;
  --stamp-city: #a8b7df;
  --board-shadow: rgba(3, 10, 26, 0.62);
}

body[data-theme="AF"] {
  --bg-0: #090d18;
  --bg-1: #111a31;
  --ambient-core: rgba(248, 244, 236, 0.12);
  --ambient-side: rgba(122, 147, 206, 0.16);
  --text-soft: #ede4d6;
  --text-muted: #bcae9d;
  --line: rgba(232, 221, 204, 0.18);
  --panel-fill: rgba(13, 19, 38, 0.56);
  --input-fill: rgba(8, 13, 24, 0.72);
  --history-fill: rgba(12, 18, 34, 0.7);
  --history-line: rgba(242, 229, 209, 0.16);
  --theme-accent: rgba(248, 244, 236, 0.95);
  --theme-accent-ink: #10234c;
  --hint: rgba(243, 230, 214, 0.76);
  --stamp-fill: rgba(16, 22, 40, 0.66);
  --stamp-line: rgba(243, 230, 214, 0.14);
  --stamp-code: #fff7eb;
  --stamp-city: #ceb9a1;
  --board-shadow: rgba(9, 13, 24, 0.56);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background-color: #090d18;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: "Space Grotesk", "Avenir Next", sans-serif;
  background-color: var(--bg-0);
  background-image:
    radial-gradient(1100px 700px at 50% -12%, var(--ambient-core), transparent 65%),
    radial-gradient(920px 620px at 84% 8%, var(--ambient-side), transparent 62%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  background-repeat: no-repeat, no-repeat, no-repeat;
  color: var(--text-soft);
  transition: background 1100ms ease, color 320ms ease;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  border-radius: 999px;
  pointer-events: none;
  z-index: -1;
  opacity: 0.92;
  transition: transform 1100ms ease, opacity 1100ms ease, background 1100ms ease;
}

body::before {
  top: 9vh;
  left: -12vw;
  width: 42vw;
  height: 42vw;
  background: radial-gradient(circle at 45% 45%, var(--ambient-core), transparent 68%);
  transform: rotate(-12deg);
}

body::after {
  right: -10vw;
  bottom: -8vw;
  width: 34vw;
  height: 34vw;
  background: radial-gradient(circle at 55% 55%, var(--ambient-side), transparent 70%);
  transform: rotate(16deg);
}

.shell {
  width: min(1160px, 100% - 40px);
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  align-content: center;
  gap: 26px;
  padding: 48px 0 56px;
}

.panel {
  max-width: 680px;
  margin: 0 auto;
  text-align: center;
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--text-muted);
}

h1 {
  margin: 12px 0 8px;
  font-family: "Fraunces", "Cormorant Garamond", serif;
  font-size: clamp(36px, 6vw, 54px);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
}

.input-area {
  margin-top: 24px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-fill);
  backdrop-filter: blur(5px);
  transition: border-color 420ms ease, background-color 420ms ease;
}

textarea {
  width: 100%;
  border: 1px solid rgba(183, 197, 232, 0.28);
  border-radius: 10px;
  background: var(--input-fill);
  color: #e9efff;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 20px;
  line-height: 1.35;
  padding: 12px 14px;
  resize: none;
  min-height: 76px;
  transition: border-color 260ms ease, box-shadow 260ms ease, background-color 260ms ease;
}

body[data-theme="AF"] textarea {
  color: #f7efe2;
}

textarea:focus {
  outline: none;
  border-color: rgba(227, 236, 255, 0.74);
  box-shadow: 0 0 0 1px rgba(227, 236, 255, 0.33);
}

textarea::placeholder {
  color: rgba(226, 233, 250, 0.54);
}

.actions {
  margin-top: 12px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

button {
  border: 1px solid rgba(200, 214, 250, 0.4);
  background: transparent;
  color: #d6e0fa;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: "Space Grotesk", sans-serif;
  cursor: pointer;
  transition: transform 260ms ease, background-color 260ms ease, border-color 260ms ease, opacity 260ms ease, color 260ms ease;
}

button:hover:enabled {
  transform: translateY(-1px);
  border-color: rgba(234, 242, 255, 0.86);
  background: rgba(234, 242, 255, 0.08);
}

#generateBtn {
  background: var(--theme-accent);
  border-color: var(--theme-accent);
  color: var(--theme-accent-ink);
}

#generateBtn:hover:enabled {
  background: #fff9ef;
  border-color: #fff9ef;
}

#rerollBtn {
  border-color: rgba(248, 244, 236, 0.52);
}

.lang-toggle {
  display: inline-flex;
  gap: 22px;
  align-items: center;
  width: auto;
  min-width: 0;
  padding: 0;
  margin-right: 6px;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  cursor: pointer;
  overflow: visible;
  transition: opacity 180ms ease;
}

.lang-toggle::before,
.lang-toggle::after {
  content: none;
}

.lang-toggle.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.lang-rail {
  display: none;
}

.lang-option {
  min-width: auto;
  min-height: auto;
  padding: 0 0 5px;
  appearance: none;
  border: 0;
  border-radius: 0;
  border-bottom: 1px solid transparent;
  background: none;
  color: #5e7087;
  font-family: "Space Grotesk", sans-serif;
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  line-height: 1;
  text-shadow: none;
  transition: color 0.2s, border-color 0.2s;
}

.lang-option-en {
  grid-column: auto;
}

.lang-option-fr {
  grid-column: auto;
}

.lang-option:hover:enabled {
  transform: none;
  background: none;
  border-color: transparent;
}

.lang-option:not(.is-active):hover:enabled {
  color: #8ca1b8;
}

.lang-option:focus-visible {
  outline: none;
  color: #ede1c7;
  border-bottom-color: rgba(201, 169, 97, 0.72);
}

.lang-option.is-active {
  color: #ede1c7;
  border-bottom-color: #c9a961;
}

.lang-option:disabled {
  opacity: 1;
}

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

.loading-line,
.error-line {
  min-height: 20px;
  margin: 12px 0 0;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.loading-line {
  color: var(--text-muted);
  opacity: 0;
}

.loading-line.is-visible {
  opacity: 1;
  animation: loadingFade 1.5s ease forwards;
}

.error-line {
  color: #ffd7d4;
}

.turnstile-mount {
  position: fixed;
  width: 0;
  height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.board-stage {
  min-height: 0;
  display: grid;
  gap: 12px;
}

.board-wrap {
  width: min(100%, 980px);
  margin: 0 auto;
  perspective: 2200px;
  opacity: 0;
  max-height: 0;
  transform: translateY(18px) scale(0.985);
  transition: opacity 1.1s ease, transform 1.1s ease, max-height 0.9s ease;
}

.board-wrap.is-visible {
  opacity: 1;
  max-height: 980px;
  transform: translateY(0) scale(1);
}

.board-card {
  position: relative;
  width: 100%;
  aspect-ratio: 1500 / 860;
  transform-style: preserve-3d;
  transition: transform 1.18s cubic-bezier(0.2, 0.74, 0.16, 1);
  border-radius: 28px;
  cursor: pointer;
  box-shadow: 0 24px 72px var(--board-shadow);
}

.board-card.is-instant {
  transition: none;
}

.board-face {
  position: absolute;
  inset: 0;
  border-radius: 28px;
  overflow: hidden;
  backface-visibility: hidden;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.board-face-back {
  transform: rotateY(180deg);
}

.board-wrap[data-face="back"] .board-card {
  transform: rotateY(180deg);
}

.board-card:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.36),
    0 24px 72px var(--board-shadow);
}

#boardingCanvas,
#boardingBackCanvas {
  width: 100%;
  height: auto;
  display: block;
}

.board-hint {
  margin: 0 auto;
  min-height: 16px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--hint);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 320ms ease, transform 320ms ease;
}

.board-stage.has-board .board-hint {
  opacity: 1;
  transform: translateY(0);
}

.memory-section,
.history-section {
  width: min(100%, 980px);
  margin: 0 auto;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px);
  transition: max-height 260ms ease, opacity 260ms ease, transform 260ms ease;
  pointer-events: none;
}

.memory-section.has-items,
.history-section.has-items {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.memory-section.has-items {
  max-height: 250px;
}

.history-section.has-items {
  max-height: 280px;
}

.memory-title,
.history-title {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.memory-strip,
.history-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.memory-strip::-webkit-scrollbar,
.history-strip::-webkit-scrollbar {
  height: 8px;
}

.memory-strip::-webkit-scrollbar-thumb,
.history-strip::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

.memory-item {
  width: 220px;
  min-width: 220px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--stamp-line);
  background: var(--stamp-fill);
  cursor: pointer;
  transition: transform 220ms ease, border-color 220ms ease, background-color 220ms ease;
}

.memory-item:hover,
.history-item:hover {
  transform: translateY(-2px);
}

.memory-item:focus-visible,
.history-item:focus-visible {
  outline: none;
  border-color: rgba(244, 250, 255, 0.92);
  box-shadow: 0 0 0 1px rgba(244, 250, 255, 0.24);
}

.memory-item[data-theme="BA"] {
  background: rgba(9, 18, 39, 0.68);
}

.memory-item[data-theme="AF"] {
  background: rgba(34, 27, 36, 0.7);
}

.memory-route,
.memory-city,
.memory-foot,
.memory-code {
  margin: 0;
}

.memory-route,
.memory-foot {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.memory-route,
.memory-foot,
.memory-city {
  color: var(--stamp-city);
}

.memory-code {
  margin-top: 6px;
  color: var(--stamp-code);
  font-family: "Fraunces", "Cormorant Garamond", serif;
  font-size: 40px;
  letter-spacing: 0.02em;
}

.memory-city {
  margin-top: 4px;
  font-size: 14px;
  letter-spacing: 0.04em;
}

.memory-foot {
  margin-top: 12px;
}

.history-item {
  border: 1px solid var(--history-line);
  border-radius: 12px;
  background: var(--history-fill);
  width: 152px;
  min-width: 152px;
  padding: 7px;
  cursor: pointer;
  transition: border-color 220ms ease, transform 220ms ease, background-color 220ms ease;
}

.history-item img {
  width: 100%;
  height: 86px;
  border-radius: 8px;
  object-fit: cover;
  display: block;
}

.history-meta {
  margin-top: 6px;
  color: #d8e3ff;
  font-size: 11px;
  letter-spacing: 0.04em;
  line-height: 1.35;
}

@keyframes loadingFade {
  0% {
    opacity: 0;
    letter-spacing: 0.22em;
  }
  100% {
    opacity: 1;
    letter-spacing: 0.14em;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(1160px, 100% - 24px);
    padding: 28px 0 40px;
    gap: 18px;
  }

  .input-area {
    padding: 14px;
    border-radius: 14px;
  }

  textarea {
    font-size: 19px;
    min-height: 72px;
  }

  button:not(.lang-option) {
    width: 100%;
  }

  .lang-toggle {
    width: auto;
    min-width: 0;
  }

  .board-card,
  .board-face {
    border-radius: 22px;
  }

  .memory-item {
    width: 184px;
    min-width: 184px;
    padding: 14px 16px;
  }

  .memory-code {
    font-size: 34px;
  }

  .history-item {
    width: 138px;
    min-width: 138px;
  }
}
