:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #2f2a24;
  --accent: #2f7f6d;
  --danger: #d94d3f;
  --line: #d8d2c8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Gill Sans", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 10%, #fffdf7 0%, var(--bg) 55%, #e6dfd1 100%);
}

.splash-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.splash-card {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
}

.splash-card h1 {
  margin: 0;
  font-size: 1.5rem;
}

.splash-card p {
  margin: 12px 0 0;
}

.splash-start-link {
  display: inline-block;
  margin-top: 18px;
  border: 1px solid #2f7f6d;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
  padding: 12px;
}

.game-column,
.maze-panel,
.sentence-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.game-column {
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.top-bar h1 {
  margin: 0;
  font-size: 1.1rem;
}

button {
  border: 1px solid #2f7f6d;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger {
  border-color: var(--danger);
  background: var(--danger);
}

.falling-field {
  position: relative;
  overflow: hidden;
  min-height: 320px;
  background: linear-gradient(180deg, #fbf8f1 0%, #f2ebdc 100%);
}

.word-card {
  position: absolute;
  top: -40px;
  min-width: 88px;
  text-align: center;
  background: #fff;
  border: 1px solid #bcb3a6;
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  user-select: none;
}

.word-card {
  cursor: pointer;
}

.word-card.flash-wrong {
  animation: wrongFlash 0.4s ease;
  border-color: var(--danger);
  background: #ffe8e5;
}

@keyframes wrongFlash {
  0% {
    transform: scale(1);
  }
  25% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

.word-card.flash-correct {
  background: #dff1ec;
  border-color: #2f7f6d;
  color: #1f6758;
  box-shadow: 0 0 0 3px rgba(47, 127, 109, 0.25);
  animation: correctFade 0.52s ease forwards;
}

@keyframes correctFade {
  0%   { opacity: 1; }
  40%  { opacity: 1; }
  100% { opacity: 0; }
}

.match-ripple {
  position: absolute;
  border: 2px solid #2f7f6d;
  border-radius: 10px;
  pointer-events: none;
  animation: rippleExpand 0.52s ease forwards;
}

@keyframes rippleExpand {
  0%   { transform: scale(1);   opacity: 0.7; }
  100% { transform: scale(3.2); opacity: 0;   }
}

.sentence-panel {
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  padding: 12px;
}

.sentence-panel h2 {
  margin: 0;
  font-size: 1rem;
}

.instruction,
.progress-text,
.maze-note {
  margin: 8px 0 0;
  font-size: 0.9rem;
}

.sentence-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.slot {
  border: 1px dashed #8c8377;
  min-width: 88px;
  padding: 8px;
  border-radius: 8px;
  text-align: left;
  background: #f6f3ea;
}

.slot-target {
  font-weight: 700;
  font-size: 0.98rem;
}

.slot-answer {
  margin-top: 4px;
  min-height: 1.1rem;
  font-size: 0.84rem;
  color: #6e6458;
}

.slot.ready,
.slot.slot-selected {
  border-color: #467f6f;
  background: #e8f3ef;
  cursor: pointer;
}

.slot {
  cursor: pointer;
}

.slot.complete {
  border-style: solid;
  border-color: #2f7f6d;
  background: #dff1ec;
}

.slot.complete .slot-answer {
  color: #1f6758;
  font-weight: 700;
}

.maze-column {
  display: flex;
}

.maze-panel {
  width: 100%;
  padding: 10px;
}

.maze-panel h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

#mazeCanvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .maze-column {
    min-height: 240px;
  }
}

/* ── Reward / completion screen ─────────────────────────────────────────── */

.reward-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px;
}

.reward-title {
  margin: 0;
  font-size: 1.8rem;
  color: var(--ink);
  text-align: center;
}

.reward-maze-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 2px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  width: min(560px, 100%);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.10);
}

.reward-maze-grid canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.reward-message {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.9s ease, transform 0.9s ease;
}

.reward-message.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Navigation bar ───────────────────────────────────────────────────────── */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 6px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

/* ── Navigate select ──────────────────────────────────────────────────────── */
.nav-select {
  padding: 4px 8px;
  font-size: 0.85rem;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  color: var(--ink);
  cursor: pointer;
}

.speed-select {
  width: 7rem;
}

/* ── Standalone nav bar actions (Reset Game, Log Out) ─────────────────────── */
.nav-action-form {
  margin: 0;
}

.nav-action-btn {
  display: inline-block;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 500;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.nav-action-btn:hover {
  background: var(--bg);
}

.nav-action-danger {
  color: var(--danger);
  border-color: var(--danger);
}

.nav-action-danger:hover {
  background: #fff0ee;
}

/* ── Story page ───────────────────────────────────────────────────────────── */
.story-page {
  padding: 24px 16px;
  max-width: 960px;
  margin: 0 auto;
}

.story-notes {
  margin-top: 12px;
}

.story-note {
  font-style: italic;
  color: var(--line);
  font-size: 0.85rem;
  margin: 4px 0;
}

.story-lang-hint {
  font-size: 0.8rem;
  color: var(--line);
  margin-top: 20px;
}

/* ── Lightbox ─────────────────────────────────────────────────────────────── */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.lightbox.open { display: flex; }

.lb-img {
  max-width: 90vw;
  max-height: 75vh;
  border-radius: 8px;
  object-fit: contain;
}

.lb-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
}

.lb-nav { display: flex; gap: 16px; }

.lb-btn {
  padding: 8px 20px;
  border: 1px solid #fff;
  border-radius: 6px;
  background: none;
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.lb-btn:hover { background: rgba(255, 255, 255, 0.15); }
.lb-btn:disabled { opacity: 0.3; cursor: default; }
.lb-btn:disabled:hover { background: none; }

/* ── Story image grid ─────────────────────────────────────────────────────── */
.story-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 3), 1fr);
  grid-auto-rows: min-content;
  gap: 8px;
  margin: 20px 0;
}

.story-grid-3col { grid-template-columns: repeat(3, 1fr); }
.story-grid-2col { grid-template-columns: repeat(2, 1fr); }
.story-grid-4col { grid-template-columns: repeat(4, 1fr); }

.story-grid img {
  width: 100%;
  height: auto;
  align-self: start;
  object-fit: contain;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.story-grid img:hover { opacity: 0.85; }

.story-grid-blank { /* empty cell — holds grid position */ }

/* ── Lightbox caption ─────────────────────────────────────────────────────── */
.lb-caption {
  text-align: center;
  color: #fff;
  max-width: 600px;
  padding: 0 16px;
}

.lb-caption h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.7;
}

.lb-caption p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
  opacity: 0.9;
}

/* ── Story page navigation ────────────────────────────────────────────────── */
.story-page-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.story-nav-btn {
  padding: 8px 22px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}

.story-nav-btn:hover { background: rgba(0, 0, 0, 0.06); }

.story-page-indicator {
  font-size: 0.85rem;
  color: var(--line);
  letter-spacing: 0.05em;
}

/* ── Drag-Match minigame ──────────────────────────────────────────────────── */
.dragmatch-outer {
  min-height: calc(100vh - 48px);
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: 24px;
  padding: 24px 16px;
}

.dragmatch-game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  flex: 1;
  min-width: 0;
}

.card-tray {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 420px;
}

.dm-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 90px;
  padding: 8px 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.09);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.dm-card img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  pointer-events: none;
}

.dm-card span {
  font-size: 0.78rem;
  font-weight: 600;
  pointer-events: none;
  text-align: center;
  word-break: break-word;
}

.dm-card.dm-dragging {
  cursor: grabbing;
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
}

.drop-zones {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 420px;
}

.dm-zone {
  width: 90px;
  min-height: 52px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  padding: 8px 6px;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}

/* ── DNA progress sidebar ─────────────────────────────────────────────────── */
.dna-sidebar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 160px;
  flex-shrink: 0;
  padding-top: 8px;
}

.dna-label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--line);
}

.dna-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: opacity 0.4s ease, filter 0.4s ease;
}

.dna-stage-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
}

.dna-img {
  width: 140px;
  height: 105px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--line);
}

.dna-gray .dna-img {
  filter: grayscale(100%) opacity(0.35);
  border-color: var(--line);
}

.dna-active .dna-img {
  filter: none;
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(var(--accent-rgb, 39,174,96), 0.35);
}

.dm-zone.dm-hover {
  border-style: solid;
  border-color: var(--accent);
  background: #e8f3ef;
}

.dm-zone.matched {
  border-style: solid;
  border-color: var(--accent);
  background: #dff1ec;
}

.dm-zone .zone-check {
  display: none;
  font-size: 1.3rem;
  color: var(--accent);
}

.dm-zone.matched .zone-check { display: block; }

@keyframes flashWrongZone {
  0%,66% { background: #ffe8e5; border-color: #c0392b; }
  33%,100% { background: var(--bg); border-color: var(--line); }
}

.dm-zone.flash-wrong {
  animation: flashWrongZone 400ms ease forwards;
}

/* Win overlay */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.win-overlay.hidden { display: none; }

.win-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.win-message {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}

@media (max-width: 760px) {
  .dragmatch-outer { flex-direction: column; align-items: center; }
  .dna-sidebar { flex-direction: row; flex-wrap: wrap; width: 100%; justify-content: center; }
  .dna-img { width: 80px; height: 60px; }
  .card-tray { grid-template-columns: repeat(4, 1fr); max-width: 360px; }
  .drop-zones { grid-template-columns: repeat(4, 1fr); max-width: 360px; }
  .dm-card { width: 76px; padding: 6px 4px; }
  .dm-card img { width: 52px; height: 52px; }
  .dm-zone { width: 76px; }
}

/* ── Word Victory page ────────────────────────────────────────────────────── */
.wv-page {
  min-height: calc(100vh - 48px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.wv-card {
  text-align: center;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.wv-icon {
  font-size: 5rem;
  line-height: 1;
}

.wv-title {
  margin: 0;
  font-size: 2rem;
  color: var(--accent);
}

.wv-subtitle {
  margin: 0;
  font-size: 1.1rem;
  opacity: 0.75;
}

.wv-message {
  margin: 0;
  font-size: 1rem;
  font-style: italic;
  opacity: 0;
  transition: opacity 1s ease;
}

.wv-message-visible {
  opacity: 0.8;
}

.wv-replay-link {
  font-size: 0.9rem;
  color: var(--line);
  text-decoration: underline;
  opacity: 0.7;
}

/* ── Falling Match & Chaos Match ─────────────────────────────────────────── */
.floating-arena {
  position: relative;
  width: 100%;
  height: calc(100vh - 90px);
  overflow: hidden;
  background: var(--bg);
}

.floating-hint {
  text-align: center;
  font-size: 0.82rem;
  color: #6b7280;
  padding: 0.4rem 1rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.floating-word {
  position: absolute;
  padding: 8px 18px;
  border-radius: 22px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  user-select: none;
  white-space: nowrap;
  transition: box-shadow 0.15s, transform 0.15s;
  touch-action: manipulation;
  will-change: left, top;
}

.word-en {
  background: #dbeafe;
  color: #1e40af;
  border: 2px solid #93c5fd;
}

.word-pt {
  background: #dcfce7;
  color: #166534;
  border: 2px solid #86efac;
}

.word-selected {
  box-shadow: 0 0 0 3px #f59e0b !important;
  transform: scale(1.1);
  z-index: 10;
}

.word-wrong {
  background: #fee2e2 !important;
  border-color: #f87171 !important;
}

.word-matched {
  opacity: 0;
  transform: scale(1.5);
  transition: opacity 0.5s ease, transform 0.5s ease;
  pointer-events: none;
}

.word-dragging {
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  transform: scale(1.08);
  cursor: grabbing;
}

.word-hover {
  box-shadow: 0 0 0 3px #f59e0b;
  transform: scale(1.06);
}

/* ── How-to-play popup ───────────────────────────────────────────────────── */
.how-to-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.how-to-overlay.hidden {
  display: none;
}

.how-to-box {
  background: #fff;
  border-radius: 14px;
  padding: 2rem 2.5rem;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.how-to-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: #1a1a2e;
  margin: 0;
}

.how-to-body {
  font-size: 1rem;
  color: #374151;
  line-height: 1.7;
  margin: 0;
}

.btn-okay {
  background: #4f46e5;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 2rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  align-self: center;
}

.btn-okay:hover {
  background: #4338ca;
}

/* ── Lightbox inner zoom wrapper ─────────────────────────────────────────── */
.lb-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  transform-origin: center center;
}

/* ── Lightbox v2 — card layout (overrides earlier rules) ────────────────── */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: hidden;
}

/* White card — scrollable, big */
.lb-inner {
  background: #fff;
  border-radius: 14px;
  width: min(820px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2rem 2.2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  transform-origin: center center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  position: relative;
}

/* Large image fills the card width */
.lb-img {
  width: 100%;
  max-width: 100%;
  max-height: 62vh;
  border-radius: 10px;
  object-fit: contain;
  display: block;
}

/* Text above the image */
.lb-above-text {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #1a1a2e;
  line-height: 1.5;
}

/* Text below the image — can be long */
.lb-below-text {
  margin: 0;
  font-size: 0.97rem;
  color: #374151;
  line-height: 1.75;
}

/* AnonoMouse internal thoughts — only the dialog text is styled */
.mouse-thought-text {
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  color: #4b5563;
}

/* Artist notes shown below image */
.lb-artist-notes {
  margin-top: 10px;
  padding: 8px 12px;
  background: #fefce8;
  border-left: 3px solid #ca8a04;
  font-size: 0.82rem;
  color: #78350f;
  font-style: italic;
  border-radius: 0 4px 4px 0;
}
.lb-artist-notes-label {
  font-weight: 700;
  font-style: normal;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  color: #92400e;
  display: block;
  margin-bottom: 2px;
}

/* Nav buttons — dark style on white background */
.lb-nav {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding-top: 0.5rem;
  border-top: 1px solid #e5e7eb;
  margin-top: 0.25rem;
}

.lb-btn {
  padding: 8px 22px;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  background: #f9fafb;
  color: #374151;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.lb-btn:hover       { background: #f3f4f6; border-color: #9ca3af; }
.lb-btn:disabled    { opacity: 0.35; cursor: default; }
.lb-btn:disabled:hover { background: #f9fafb; border-color: #d1d5db; }

/* Close button — floats over dark overlay */
.lb-close {
  position: fixed;
  top: 16px;
  right: 20px;
  background: rgba(0,0,0,0.45);
  border: none;
  color: #fff;
  font-size: 1.4rem;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1010;
  transition: background 0.15s;
}
.lb-close:hover { background: rgba(0,0,0,0.7); }

/* ── Lightbox card — no scroll, fixed layout ────────────────────────────── */
.lb-inner {
  overflow-y: visible;
  overflow-x: visible;
  max-height: none;
}

/* ── Story grid — clean layout ───────────────────────────────────────────── */
.story-grid {
  gap: 3px;
  padding: 12px;
}

/* ── Story column layout (flex-based, for pages with pinned columns) ──────── */
.story-col-layout {
  display: flex;
  gap: 3px;
  padding: 12px;
}

.story-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.story-col img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.story-col img:hover { opacity: 0.85; }

.story-grid img {
  border-radius: 4px;
  transition: opacity 0.15s;
}

.story-grid img:hover {
  opacity: 0.85;
}
