:root {
  --bg: #060814;
  --panel: rgba(255, 255, 255, 0.04);
  --ink: #EDEFF6;
  --ink-soft: #9AA1B5;
  --accent: #8FA8FF;
  --accent-soft: rgba(143, 168, 255, 0.16);
  --line: rgba(255, 255, 255, 0.12);
  --grid-line: rgba(255, 255, 255, 0.05);
  --radius: 10px;
  --shadow: 0 1px 8px rgba(0, 0, 0, 0.35);
  --shadow-hover: 0 4px 18px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(143, 168, 255, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  #bgCanvas { display: none; }
  .intro-overlay { display: none !important; }
  .reveal { opacity: 1 !important; transform: none !important; }
}

/* ---------- Intro Big Bang overlay ---------- */
.intro-overlay {
  position: fixed;
  inset: 0;
  background: #000000;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  animation: introOverlaySequence 3.4s ease forwards;
  cursor: pointer;
}

.intro-overlay.intro-waiting,
.intro-overlay.intro-waiting * {
  animation-play-state: paused !important;
}

.intro-click-prompt {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  animation: tapPromptPulse 1.8s ease-in-out infinite;
  white-space: nowrap;
}

.intro-overlay.intro-waiting .intro-click-prompt {
  display: block;
}

@keyframes tapPromptPulse {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 1; }
}

.intro-overlay.intro-done {
  display: none;
}

.intro-ball {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #FFFFFF;
  animation: introBall 1.85s cubic-bezier(0.3, 0, 0.4, 1) forwards;
}

.intro-rainbow {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    #FF5C5C, #FFAE5C, #FFEC5C, #8CFF7A, #5CD0FF, #8A7BFF, #FF7AD6, #FF5C5C
  );
  filter: blur(9px);
  mix-blend-mode: screen;
  animation: introRainbow 1.85s cubic-bezier(0.3, 0, 0.4, 1) forwards;
}

.intro-rays {
  position: absolute;
  width: 2px;
  height: 2px;
  background: transparent;
  box-shadow:
    0 -60px 18px 0 rgba(255,255,255,0.0),
    60px 0 18px 0 rgba(255,255,255,0.0),
    0 60px 18px 0 rgba(255,255,255,0.0),
    -60px 0 18px 0 rgba(255,255,255,0.0);
  animation: introRays 1.85s ease forwards;
}

.intro-shock {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.9);
  opacity: 0;
  animation: introShock 0.45s ease-out forwards;
  animation-delay: 1.35s;
}

@keyframes introBall {
  0%   { transform: scale(0.3); opacity: 0; box-shadow: 0 0 0 0 rgba(255,255,255,0); }
  38%  { transform: scale(1); opacity: 1; box-shadow: 0 0 22px 6px rgba(255,255,255,0.7), 0 0 50px 16px rgba(190,205,255,0.35); }
  62%  { transform: scale(1.3); opacity: 1; box-shadow: 0 0 40px 12px rgba(255,255,255,0.9), 0 0 90px 36px rgba(190,205,255,0.5); }
  78%  { transform: scale(1.6); opacity: 1; box-shadow: 0 0 60px 20px rgba(255,255,255,1), 0 0 130px 55px rgba(190,205,255,0.6); }
  85%  { transform: scale(2.1); opacity: 1; }
  100% { transform: scale(9); opacity: 1; box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

@keyframes introRainbow {
  0%   { transform: scale(0.5); opacity: 0; }
  38%  { transform: scale(1.8); opacity: 0.45; }
  62%  { transform: scale(2.4); opacity: 0.55; }
  78%  { transform: scale(3); opacity: 0.6; }
  85%  { transform: scale(3.6); opacity: 0.45; }
  100% { transform: scale(9.5); opacity: 0; }
}

@keyframes introRays {
  0%   { box-shadow:
    0 -60px 18px 0 rgba(255,255,255,0),
    60px 0 18px 0 rgba(255,255,255,0),
    0 60px 18px 0 rgba(255,255,255,0),
    -60px 0 18px 0 rgba(255,255,255,0);
    transform: scale(0.4) rotate(0deg); }
  62%  { box-shadow:
    0 -40px 22px 0 rgba(255,255,255,0.55),
    40px 0 22px 0 rgba(255,255,255,0.55),
    0 40px 22px 0 rgba(255,255,255,0.55),
    -40px 0 22px 0 rgba(255,255,255,0.55);
    transform: scale(1) rotate(35deg); }
  85%  { box-shadow:
    0 -30px 26px 0 rgba(255,255,255,0.85),
    30px 0 26px 0 rgba(255,255,255,0.85),
    0 30px 26px 0 rgba(255,255,255,0.85),
    -30px 0 26px 0 rgba(255,255,255,0.85);
    transform: scale(1.3) rotate(55deg); }
  100% { box-shadow:
    0 -10px 10px 0 rgba(255,255,255,0),
    10px 0 10px 0 rgba(255,255,255,0),
    0 10px 10px 0 rgba(255,255,255,0),
    -10px 0 10px 0 rgba(255,255,255,0);
    transform: scale(3.5) rotate(70deg); }
}

@keyframes introShock {
  0%   { width: 10px; height: 10px; opacity: 0.9; border-width: 2px; }
  100% { width: 1100px; height: 1100px; opacity: 0; border-width: 0.5px; }
}

.intro-text {
  position: absolute;
  color: #000000;
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: clamp(1.82rem, 5.2vw, 3.12rem);
  letter-spacing: -0.01em;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  animation: introTextFadeIn 0.3s ease forwards;
  animation-delay: 1.6s;
}

@keyframes introTextFadeIn {
  0%   { opacity: 0; }
  100% { opacity: 1; }
}

/* black -> brief white flash -> hold white -> fade out to reveal page */
@keyframes introOverlaySequence {
  0%   { background-color: #000000; opacity: 1; }
  41%  { background-color: #000000; opacity: 1; }
  46%  { background-color: #FFFFFF; opacity: 1; }
  85%  { background-color: #FFFFFF; opacity: 1; }
  100% { background-color: #FFFFFF; opacity: 0; }
}

/* ---------- Cosmic nebula clouds ---------- */
#cosmicClouds {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.55;
  filter: blur(70px);
  background:
    radial-gradient(circle at 18% 28%, rgba(255, 110, 170, 0.28), transparent 58%),
    radial-gradient(circle at 82% 18%, rgba(255, 160, 90, 0.22), transparent 55%),
    radial-gradient(circle at 55% 82%, rgba(100, 140, 255, 0.28), transparent 60%),
    radial-gradient(circle at 30% 75%, rgba(180, 110, 255, 0.16), transparent 55%);
  animation: cloudDrift 50s ease-in-out infinite alternate;
}

@keyframes cloudDrift {
  0%   { transform: scale(1) translate(0%, 0%); }
  100% { transform: scale(1.15) translate(-3%, 4%); }
}

/* ---------- Floating background canvas ---------- */
#bgCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}

.site-header, .board {
  position: relative;
  z-index: 1;
}

/* ---------- Contradiction screen flash ---------- */
#contradictionFlash {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: #FF1F1F;
  opacity: 0;
  pointer-events: none;
}

#contradictionFlash.flash {
  animation: contradictionFlash 1s ease-out;
}

@keyframes contradictionFlash {
  0%   { opacity: 0; }
  10%  { opacity: 0.4; }
  100% { opacity: 0; }
}

/* ---------- Opening reveal ---------- */
@keyframes revealUp {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.reveal {
  opacity: 0;
  animation: revealUp 0.5s ease forwards;
}

#mainTitle,
#subtitle,
.structural-label.reveal {
  animation-delay: 2.89s;
  animation-duration: 0.51s;
}

.category-block.reveal {
  animation-duration: 0.51s;
}

/* ---------- Header ---------- */
.site-header {
  text-align: center;
  padding: 32px 24px 8px;
  transform: translateY(-14px);
}

.site-header h1 {
  font-weight: 700;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  margin: 0 0 6px;
  letter-spacing: -0.01em;
  cursor: pointer;
  display: inline-block;
}

.site-header h1:hover { color: var(--accent); }

.title-input-bar {
  display: none;
  -webkit-appearance: none;
  appearance: none;
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  letter-spacing: -0.01em;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--accent);
  text-align: center;
  outline: none;
  width: min(90vw, 560px);
  margin: 0 0 6px;
  padding: 0 4px 4px;
}

.title-input-bar::placeholder { color: var(--ink-soft); }

.title-input-bar.active { display: inline-block; }

.title-menu-btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-block;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 1.1rem;
  line-height: 1;
  margin-left: 6px;
  padding: 4px;
  cursor: pointer;
  vertical-align: middle;
}

.title-menu-btn:hover { color: var(--ink); }

.title-wrap {
  display: block;
  text-align: center;
}

.title-dropdown {
  display: none;
  background: rgba(10, 12, 22, 0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-hover);
  padding: 8px;
  width: 300px;
  margin: 10px auto 0;
  text-align: left;
}

.title-dropdown.open {
  display: block;
}

#titleOptionsList {
  display: block;
  width: 100%;
}

.title-option {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  box-sizing: border-box;
  background: none;
  border: none;
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 0.88rem;
  text-align: left;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  line-height: 1.4;
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: 8px;
  cursor: pointer;
  pointer-events: auto;
}

.title-option:last-child { margin-bottom: 0; }

.title-option:hover { background: rgba(255, 255, 255, 0.08); }

#titleCustomBtn { margin-top: 2px; }

.subtitle {
  font-size: 0.92rem;
  color: var(--ink-soft);
  margin: 0;
}

/* ---------- Layout ---------- */
.board {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 18px;
  min-height: 78vh;
  position: relative;
  padding: 0 24px;
}

.col-label {
  font-size: clamp(1.326rem, 3.315vw, 2.21rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  text-transform: none;
  color: #FFFFFF;
  margin: 0 0 14px;
  line-height: 1;
}

/* ---------- Structural If / Then labels ---------- */
.structural-label {
  font-size: clamp(1.326rem, 3.315vw, 2.21rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 14px;
  color: #FFFFFF;
  line-height: 1;
}

.label-if { color: #FFFFFF; }
.label-then { color: #FFFFFF; }

/* ---------- Assumptions column ---------- */
.col-assumptions {
  padding: 28px 22px 28px 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
}

.tile-categories {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
}

/* ---------- Create your own ---------- */
.create-own {
  padding-top: 14px;
  margin-top: 10px;
}

.create-own-title {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0 0 6px;
}

.create-own-hint {
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin: 0 0 10px;
  line-height: 1.4;
}

.create-own-row {
  display: flex;
  gap: 8px;
}

.create-own-input {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
  color: var(--ink);
}

.create-own-input::placeholder { color: var(--ink-soft); }

.create-own-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.1);
}

.btn-small {
  padding: 8px 14px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.custom-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.custom-tile {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 7px 8px 7px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
  cursor: grab;
  user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.2s ease;
}

.custom-tile:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.custom-tile.used { opacity: 0.3; pointer-events: none; }

.custom-tile-remove {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 5px;
}

.custom-tile-remove:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
}

.category-block { margin-bottom: 10px; }

.category-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 0 8px;
  margin: 0 0 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.category-title {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--accent);
}

.category-chevron {
  font-size: 0.7rem;
  color: var(--ink-soft);
  transition: transform 0.2s ease;
}

.category-block.open .category-chevron { transform: rotate(90deg); }

.tile-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.28s ease, opacity 0.2s ease;
}

.category-block.open .tile-list {
  max-height: 600px;
  opacity: 1;
  margin-bottom: 6px;
}

.tile {
  position: relative;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
  cursor: grab;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.2s ease;
}

.tile-emoji {
  font-size: 1rem;
  line-height: 1;
}

.tile:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.tile:active { cursor: grabbing; transform: scale(0.96); }

.tile.dragging { opacity: 0.4; }

.tile.used { opacity: 0.3; pointer-events: none; }

/* tooltip */
.shared-tooltip {
  position: fixed;
  background: #0B0D18;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.3;
  padding: 6px 9px;
  border-radius: 6px;
  max-width: 200px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 5000;
}

.shared-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Void column ("If") ---------- */
.col-void {
  display: flex;
  flex-direction: column;
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background-color: rgba(255, 255, 255, 0.2);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 30px 30px;
}

.void-area {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 10px;
  min-height: 420px;
  margin-bottom: 14px;
  position: relative;
  transition: box-shadow 0.15s ease;
}

.void-area.drag-over {
  box-shadow: inset 0 0 0 2px var(--accent);
  border-radius: var(--radius);
}

.void-empty {
  font-size: 0.98rem;
  color: rgba(255, 255, 255, 0.35);
  margin: auto;
  text-align: center;
  width: 100%;
  pointer-events: none;
}

.void-tile {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  animation: popIn 0.22s ease;
}

.void-tile:hover {
  box-shadow: var(--shadow-hover);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}
.void-tile:active { transform: scale(0.96); }

.void-tile.removing { animation: popOut 0.18s ease forwards; }

.void-tile.contradicted {
  background: rgba(255, 90, 90, 0.14);
  border-color: rgba(255, 130, 130, 0.5);
  color: #FF9B9B;
}

@keyframes popIn {
  0%   { transform: scale(0.75); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes popOut {
  to { transform: scale(0.7); opacity: 0; }
}

/* ---------- Then column ---------- */
.col-then {
  padding: 28px 28px 28px 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
}

.then-box {
  flex: 1;
}

#definitionText {
  font-size: 1.1rem;
  line-height: 1.55;
  color: var(--ink);
  margin: 0;
  transition: color 0.2s ease;
}

#definitionText.definition-placeholder {
  color: rgba(255, 255, 255, 0.35);
  font-size: 0.98rem;
}

#definitionText.contradiction {
  color: #FF8E8E;
  font-weight: 500;
}

.def-actions {
  display: flex;
  align-items: center;
  margin-top: 14px;
}

/* ---------- Then column: type-to-generate row ---------- */
.then-type-title {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--accent);
  margin: 14px 0 8px;
}

.then-type-row {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
  margin-top: 8px;
}

.then-type-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--ink);
  font-size: 0.9rem;
  font-family: 'Inter', sans-serif;
}

.then-type-input::placeholder { color: var(--ink-soft); }

.then-type-hint {
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin: 6px 0 0;
  line-height: 1.4;
}

/* ---------- Buttons ---------- */
.btn {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.98); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  align-self: flex-start;
}

.btn-ghost:hover { border-color: var(--ink-soft); color: var(--ink); }

.btn-primary { background: var(--accent); color: #0A0D18; }
.btn-primary:hover:not(:disabled) { background: #A9BCFF; }
.btn-primary:disabled { background: rgba(255, 255, 255, 0.08); color: var(--ink-soft); cursor: not-allowed; }

.copy-confirm {
  margin-left: 10px;
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.copy-confirm.show { opacity: 1; }

/* ---------- Credit tag ---------- */
.credit-tag {
  position: fixed;
  bottom: 14px;
  right: 16px;
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.3);
  letter-spacing: 0.02em;
  z-index: 5;
  pointer-events: none;
  user-select: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .board { grid-template-columns: 1fr; min-height: unset; padding: 0 16px; }
  .col-assumptions { max-height: 320px; }
  .void-area { min-height: 220px; }
  .structural-label { font-size: 2.2rem; }
}
