*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #071013;
  --bg2: #0c1416;
  --surface: #131b1e;
  --text: #fff;
  --text2: #8b949e;
  --accent: #d70913;
  --accent2: #b5070f;
  --accent-glow: rgba(215, 9, 19, 0.25);
  --success: #2ecc71;
  --success-glow: rgba(46, 204, 113, 0.25);
  --warn: #f39c12;
  --border: #1d2529;
  --overlay-bg: rgba(7, 16, 19, 0.9);
  --radius: 8px;
  --font: "Ubuntu", sans-serif;
}

html.light {
  --bg: #f5f0eb;
  --bg2: #ede7df;
  --surface: #faf6f1;
  --text: #171717;
  --text2: #5a5a5a;
  --accent: #d70913;
  --accent2: #b5070f;
  --accent-glow: rgba(215, 9, 19, 0.2);
  --success: #27ae60;
  --success-glow: rgba(39, 174, 96, 0.2);
  --border: #d8d0c8;
  --overlay-bg: rgba(245, 240, 235, 0.92);
}

html {
  height: 100%;
}
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  transition:
    background 0.3s,
    color 0.3s;
}

/* ── Theme toggle ── */
#themeToggle {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
#themeToggle:hover {
  background: var(--border);
}

/* ── Screens ── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  animation: fadeIn 0.35s ease;
}
.hidden {
  display: none !important;
}
.screen.hidden {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ══════════════════════════════════════
   WELCOME LANDING PAGE
   ══════════════════════════════════════ */
.welcome-landing {
  justify-content: flex-start !important;
  padding: 0 !important;
  overflow-y: auto !important;
  position: relative;
}

/* ── Background mosaic ── */
.mosaic {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  grid-template-columns: 30% 28% 42%;
  grid-template-rows: 1fr auto;
  gap: 2px;
  pointer-events: none;
}
.m-cell {
  transition: background 0.3s;
}
.m1 {
  background: #15191a;
  grid-row: 1;
}
.m2 {
  background: #1e1a16;
  grid-row: 1;
}
.m3 {
  background: #1a1610;
  grid-row: 1;
}
.m4 {
  background: #1c1f1e;
  grid-row: 2;
}
.m5 {
  background: #201c18;
  grid-row: 2;
}
.m6 {
  background: #191614;
  grid-row: 2;
}
html.light .m1 {
  background: #e8e0d5;
}
html.light .m2 {
  background: #ddd5c8;
}
html.light .m3 {
  background: #e2dcd4;
}
html.light .m4 {
  background: #d8d0c5;
}
html.light .m5 {
  background: #e0d8cd;
}
html.light .m6 {
  background: #dbd3c8;
}

/* ── Navbar ── */
.er-nav {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 20px 40px;
}
.er-nav-brand {
  font-family: "Playfair Display", Georgia, serif;
  font-style: italic;
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--accent);
}
.er-nav-links {
  display: flex;
  gap: 32px;
}
.er-nav-links a {
  text-decoration: none;
  color: var(--text2);
  font-size: 0.85rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  transition: color 0.2s;
}
.er-nav-links a:hover {
  color: var(--text);
}

/* ── Hero ── */
.er-hero {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 42% 1fr;
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: 0 40px 0 0;
  align-items: center;
}
.er-hero-img {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 0 24px 40px;
}
.er-hero-img img {
  width: 100%;
  max-width: 380px;
  border-radius: 8px;
  display: block;
  box-shadow: 0 12px 60px rgba(0, 0, 0, 0.4);
}
html.light .er-hero-img img {
  box-shadow: 0 12px 60px rgba(0, 0, 0, 0.12);
}
.er-hero-content {
  padding: 40px 0 40px 48px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Label */
.er-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}
.er-label span {
  display: block;
  width: 32px;
  height: 2px;
  background: var(--accent);
}

/* Title */
.er-title {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  margin: 0 0 8px;
}
html.light .er-title {
  color: var(--text);
}

/* Subtitle */
.er-subtitle {
  font-family: "Playfair Display", Georgia, serif;
  font-style: italic;
  font-size: 1.8rem;
  color: var(--accent);
  margin: 0 0 16px;
  line-height: 1.2;
}

/* Description */
.er-desc {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text2);
  max-width: 440px;
  margin: 0 0 28px;
}

/* Hero buttons */
.er-hero-btns {
  display: flex;
  gap: 16px;
  margin-bottom: 32px;
}
.btn-hero-er {
  max-width: none;
  width: auto;
  padding: 18px 32px;
  background: var(--accent);
  color: #fff;
  border: 2px solid var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.4;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 6px;
}
.btn-hero-er:hover {
  background: #fff;
  color: var(--accent);
}
.er-arrow {
  font-size: 1.3rem;
}
.btn-outline-er {
  max-width: none;
  width: auto;
  padding: 18px 32px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.4;
  text-align: left;
  border-radius: 6px;
}
.btn-outline-er:hover {
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
  background: transparent;
}
html.light .btn-outline-er:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Stats */
.er-stats {
  display: flex;
  align-items: center;
  gap: 20px;
}
.er-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.er-stat-num {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}
.er-stat-lbl {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text2);
}
.er-stat-div {
  width: 1px;
  height: 36px;
  background: var(--border);
}

/* ── Color swatches ── */
.er-swatches {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  width: 100%;
  padding: 0 0 0 0;
}
.sw {
  height: 80px;
  transition: background 0.3s;
}
.sw-1 {
  background: #2a2520;
}
.sw-2 {
  background: #3a3530;
}
.sw-3 {
  background: #252220;
}
.sw-4 {
  background: #1e1c1a;
}
.sw-5 {
  background: #302a25;
}
html.light .sw-1 {
  background: #d4c9b8;
}
html.light .sw-2 {
  background: #c8bca8;
}
html.light .sw-3 {
  background: #ded6c8;
}
html.light .sw-4 {
  background: #e5ddd0;
}
html.light .sw-5 {
  background: #ccc2b0;
}

/* ── Footer ── */
.er-footer {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  width: 100%;
  padding: 32px 40px;
  background: #0a0c0e;
  transition: background 0.3s;
}
html.light .er-footer {
  background: #e8e0d5;
}
.er-footer-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.er-footer-brand {
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}
.er-footer-copy {
  font-size: 0.6rem;
  color: var(--text2);
  letter-spacing: 0.06em;
}
.er-footer-right {
  display: flex;
  gap: 28px;
}
.er-footer-right a {
  text-decoration: none;
  color: var(--text2);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 0.2s;
}
.er-footer-right a:hover {
  color: var(--text);
}

/* ── Buttons ── */
.btn {
  display: block;
  width: 100%;
  max-width: 340px;
  padding: 14px 24px;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
}
.btn:hover {
  background: #fff;
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--accent-glow);
}
.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn:disabled:hover {
  background: var(--accent);
  color: #fff;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover {
  background: var(--surface);
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.btn-back {
  background: transparent;
  border-color: transparent;
  color: var(--text2);
  font-size: 0.9rem;
  margin-top: 4px;
}
.btn-back:hover {
  color: var(--text);
  background: transparent;
  transform: none;
  box-shadow: none;
}
.btn-add {
  background: var(--surface);
  border: 2px dashed var(--border);
  color: var(--accent);
  font-weight: 500;
}
.btn-add:hover {
  border-color: var(--accent);
  background: var(--surface);
  color: var(--accent);
  transform: none;
  box-shadow: none;
}
.btn-copy {
  width: auto;
  padding: 10px 20px;
  flex-shrink: 0;
}
.btn-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
  max-width: 200px;
  margin: 8px auto 0;
}
.btn-copy:hover,
.btn-sm:hover {
  background: var(--accent2);
  color: #fff;
  transform: none;
  box-shadow: none;
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
}
.btn-success:hover {
  background: #27ae60;
  color: #fff;
  transform: none;
  box-shadow: none;
}

/* ── Back to Games ── */
.back-to-games {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text2);
  text-decoration: none;
  letter-spacing: 0.04em;
  transition: color 0.2s;
  align-self: flex-start;
}
.back-to-games:hover {
  color: var(--text);
}

/* ── Forms ── */
.form-container {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.form-container .input-group,
.form-container .timer-options,
.form-container .rooms-list,
.form-container .edit-buttons,
.form-container .code-display,
.form-container .code-box,
.form-container .share-actions,
.form-container .payment-features,
.form-container .payment-price-box,
.form-container .restore-section {
  width: 100%;
}
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.input-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text2);
  text-align: center;
}
.input-group label:has(input[type="checkbox"]) {
  flex-direction: row;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 400;
}
.input-group input[type="text"],
.input-group input[type="number"],
.input-group textarea,
.input-group select {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
.input-group input:focus,
.input-group textarea:focus,
.input-group select:focus {
  border-color: var(--accent);
}
.input-group textarea {
  min-height: 90px;
  resize: vertical;
}
.input-group select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238a8797' d='M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}
.input-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.timer-options {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 0 26px;
}
.timer-options input {
  width: 80px;
}
.timer-options label {
  margin: 0;
}

.helper {
  font-size: 0.75rem;
  color: var(--text2);
}
.hint {
  color: var(--text2);
  font-size: 0.9rem;
  text-align: center;
}

h2 {
  text-align: center;
  font-size: 1.5rem;
  color: var(--accent);
}
h3 {
  font-size: 1.2rem;
  color: var(--accent);
}

/* ── Rooms list ── */
.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.room-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}
.room-info {
  flex: 1;
  overflow: hidden;
}
.room-info-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-info-type {
  font-size: 0.75rem;
  color: var(--text2);
}
.room-actions {
  display: flex;
  gap: 6px;
}
.room-action-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
  transition: color 0.15s;
}
.room-action-btn:hover {
  color: var(--text);
}
.room-action-btn.delete:hover {
  color: var(--accent);
}

/* ── Edit buttons ── */
.edit-buttons {
  display: flex;
  gap: 12px;
}
.edit-buttons .btn {
  flex: 1;
}

/* ── Puzzle fields ── */
.puzzle-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.puzzle-field-group label {
  font-size: 0.85rem;
  color: var(--text2);
  font-weight: 500;
}
.puzzle-field-group input,
.puzzle-field-group textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
}
.puzzle-field-group input:focus,
.puzzle-field-group textarea:focus {
  border-color: var(--accent);
}
.puzzle-field-group textarea {
  min-height: 60px;
  resize: vertical;
}
.puzzle-field-group .helper {
  font-size: 0.7rem;
}

/* ── Share ── */
.share-container {
  align-items: center;
}
.code-display {
  display: flex;
  gap: 8px;
  width: 100%;
}
.code-display input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: monospace;
  font-size: 0.75rem;
  outline: none;
}
.code-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.code-box textarea {
  width: 100%;
  height: 80px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: monospace;
  font-size: 0.65rem;
  resize: none;
  outline: none;
}
.copy-feedback {
  color: var(--success);
  font-size: 0.85rem;
  text-align: center;
}
.share-actions {
  display: flex;
  gap: 12px;
  width: 100%;
}
.share-actions .btn {
  flex: 1;
}

/* ── Play: Room Intro ── */
.room-intro-container {
  max-width: 400px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}
.room-header {
  width: 100%;
  max-width: 400px;
}
.room-progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}
.room-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}
.room-progress-text {
  font-size: 0.8rem;
  color: var(--text2);
  text-align: center;
  margin-top: 4px;
}
.room-number {
  font-size: 3rem;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  box-shadow: 0 0 30px var(--accent-glow);
}
.room-name {
  color: var(--accent);
  font-size: 1.4rem;
}
.room-story {
  color: var(--text);
  line-height: 1.7;
  font-size: 0.95rem;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  white-space: pre-wrap;
}

/* ── Timer ── */
.timer {
  font-family: "Ubuntu", monospace;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  letter-spacing: 0.05em;
}
.timer.warning {
  color: var(--warn);
  animation: timerPulse 1s infinite;
}
.timer.critical {
  color: var(--accent);
  animation: timerPulse 0.5s infinite;
}

@keyframes timerPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* ── Play: Puzzle ── */
.puzzle-container {
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.puzzle-room-name {
  color: var(--text2);
  font-size: 1rem;
  font-weight: 400;
}
.puzzle-area {
  width: 100%;
  padding: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.puzzle-prompt {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  text-align: center;
  font-style: italic;
}
.puzzle-input-row {
  display: flex;
  gap: 8px;
  width: 100%;
}
.puzzle-input-row input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  outline: none;
  text-align: center;
}
.puzzle-input-row input:focus {
  border-color: var(--accent);
}
.puzzle-input-row .btn {
  width: auto;
  padding: 12px 20px;
}

.puzzle-wrong {
  color: var(--accent);
  font-size: 0.85rem;
  text-align: center;
  animation: shake 0.4s ease;
}

/* Cipher display */
.cipher-display {
  font-family: monospace;
  font-size: 1.3rem;
  letter-spacing: 0.2em;
  text-align: center;
  padding: 16px;
  background: var(--bg);
  border-radius: 8px;
  color: var(--accent);
  word-break: break-all;
}
.cipher-key {
  font-size: 0.85rem;
  color: var(--text2);
  text-align: center;
}

/* Unscramble tiles */
.scramble-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.scramble-tile {
  padding: 10px 16px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.scramble-tile:hover {
  border-color: var(--accent);
}
.scramble-tile.selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.scramble-answer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  min-height: 44px;
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
  border: 2px dashed var(--border);
}
.scramble-placed {
  padding: 8px 14px;
  background: var(--accent-glow);
  border-radius: 6px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

/* Sequence / ordering — drag & drop */
.seq-hint {
  font-size: 0.8rem;
  color: var(--text2);
  text-align: center;
  margin-bottom: 4px;
}
.sequence-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}
.seq-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  user-select: none;
  transition:
    transform 0.15s,
    box-shadow 0.15s,
    opacity 0.15s;
}
.seq-item .seq-grip {
  cursor: grab;
  color: var(--text2);
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px 2px;
  flex-shrink: 0;
  touch-action: none;
  transition: color 0.15s;
}
.seq-item .seq-grip:active {
  cursor: grabbing;
}
.seq-item .seq-grip:hover {
  color: var(--accent);
}
.seq-item .seq-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.seq-item .seq-text {
  flex: 1;
  font-size: 0.9rem;
}
.seq-item.seq-dragging {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  transform: scale(1.03);
  border-color: var(--accent);
  opacity: 0.95;
}
.seq-placeholder {
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: var(--accent-glow, rgba(200, 50, 50, 0.08));
  transition: height 0.15s;
}

.puzzle-hint {
  font-size: 0.85rem;
  color: var(--warn);
  text-align: center;
  padding: 10px;
  background: rgba(243, 156, 18, 0.1);
  border-radius: 8px;
  animation: fadeIn 0.3s;
}

/* ── Overlay ── */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
  animation: fadeIn 0.25s ease;
}
.overlay.hidden {
  display: none;
}
.overlay-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 380px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-8px);
  }
  40% {
    transform: translateX(8px);
  }
  60% {
    transform: translateX(-6px);
  }
  80% {
    transform: translateX(6px);
  }
}
.shake {
  animation: shake 0.4s ease;
}

.solved-card {
  gap: 20px;
}
.solved-icon {
  font-size: 2.5rem;
}
.solved-message {
  color: var(--text);
  line-height: 1.7;
  font-size: 1rem;
  white-space: pre-wrap;
}

/* ── Final ── */
#finalEscapeScreen {
  overflow-y: auto;
}
.final-container {
  text-align: center;
  max-width: 400px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px 0;
}
.final-icon {
  font-size: 3rem;
}
.final-stats {
  font-size: 0.9rem;
  color: var(--text2);
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100%;
}
.final-from {
  color: var(--text2);
  font-size: 0.95rem;
}
.final-message {
  color: var(--text);
  line-height: 1.8;
  font-size: 1.05rem;
  padding: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  width: 100%;
}
.final-actions {
  display: flex;
  gap: 12px;
}

/* ── Keepsake CTA ── */
.pdf-cta {
  margin-top: 20px;
  padding: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  text-align: center;
  width: 100%;
}
.pdf-cta-heading {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
}
.pdf-cta-sub {
  font-size: 0.85rem;
  color: var(--text2);
  margin-bottom: 14px;
  line-height: 1.5;
}
.pdf-cta-btn {
  display: inline-block;
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 500;
  font-family: var(--font);
  transition: background 0.2s;
}
.pdf-cta-btn:hover {
  background: var(--accent2);
}

/* ── Confetti ── */
#confettiCanvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
}

/* ── Example button ── */
.btn-example {
  background: var(--surface);
  border: 1.5px solid var(--accent);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 10px 18px;
  width: 100%;
  max-width: 340px;
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    background 0.2s,
    color 0.2s;
  letter-spacing: 0.02em;
  font-family: var(--font);
}
.btn-example:hover {
  background: var(--accent);
  color: #fff;
  transform: none;
  box-shadow: none;
}

/* ── Review Screen ── */
.review-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.review-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.review-item-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.review-item-header:hover {
  background: var(--bg);
}
.review-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
}
.review-name {
  flex: 1;
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.review-type {
  font-size: 0.72rem;
  color: var(--text2);
  flex-shrink: 0;
}
.review-chevron {
  font-size: 1.2rem;
  color: var(--text2);
  flex-shrink: 0;
  transition: transform 0.2s;
}
.review-item.open .review-chevron {
  transform: rotate(90deg);
}

.review-item-body {
  display: none;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--border);
  display: none;
  flex-direction: column;
  gap: 6px;
}
.review-item.open .review-item-body {
  display: flex;
}

.review-field {
  font-size: 0.82rem;
  color: var(--text2);
  line-height: 1.5;
}
.review-field span {
  font-weight: 600;
  color: var(--text);
}

/* ── Lifeline button ── */
.btn-lifeline {
  background: transparent;
  border: 2px solid #e67e22;
  color: #e67e22;
  font-size: 0.9rem;
  margin-top: 8px;
  max-width: 340px;
  width: 100%;
}
.btn-lifeline:hover {
  background: #e67e22;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(230, 126, 34, 0.3);
}

/* ── Unscramble: Word Grid (Wheel of Fortune style) ── */
.scramble-words-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: flex-end;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  border: 2px dashed var(--border);
  min-height: 56px;
}
.scramble-word {
  display: flex;
  gap: 4px;
  align-items: center;
}
.scramble-word-gap {
  width: 16px; /* visual gap between words */
}
.scramble-blank {
  width: 34px;
  height: 40px;
  border-bottom: 2px solid var(--text2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  cursor: default;
  transition:
    border-color 0.15s,
    background 0.15s;
  border-radius: 4px 4px 0 0;
}
.scramble-blank-filled {
  border-bottom-color: var(--accent);
  background: var(--accent-glow);
  cursor: pointer;
}
.scramble-blank-filled:hover {
  background: rgba(215, 9, 19, 0.18);
}

/* ── Final stats grid ── */
.final-stats {
  padding: 0;
  background: none;
  border: none;
}
.final-stats-grid {
  display: flex;
  gap: 0;
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.fsg-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 8px;
  gap: 4px;
  border-right: 1px solid var(--border);
}
.fsg-item:last-child {
  border-right: none;
}
.fsg-num {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}
.fsg-lbl {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text2);
  text-align: center;
}

/* Per-room breakdown */
.final-room-breakdown {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}
.breakdown-name {
  color: var(--text2);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  flex-shrink: 0;
  margin-left: 8px;
}
.room-badge.perfect {
  background: rgba(46, 204, 113, 0.15);
  color: var(--success);
}
.room-badge.tries {
  background: var(--surface);
  color: var(--text2);
  border: 1px solid var(--border);
}
.room-badge.lifeline {
  background: rgba(230, 126, 34, 0.15);
  color: #e67e22;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .er-hero {
    grid-template-columns: 1fr;
    padding: 0;
  }
  .er-hero-img {
    padding: 20px 24px 0;
    justify-content: center;
  }
  .er-hero-img img {
    max-width: 300px;
  }
  .er-hero-content {
    padding: 24px 24px 32px;
    align-items: center;
    text-align: center;
  }
  .er-label {
    justify-content: center;
  }
  .er-title {
    font-size: 3.5rem;
  }
  .er-subtitle {
    font-size: 1.4rem;
  }
  .er-desc {
    text-align: center;
  }
  .er-hero-btns {
    flex-direction: column;
    width: 100%;
    max-width: 320px;
  }
  .btn-hero-er,
  .btn-outline-er {
    width: 100%;
    display: flex;
    text-align: center;
    justify-content: center;
  }
  .er-stats {
    justify-content: center;
  }
  .mosaic {
    display: none;
  }
  .er-swatches {
    display: none;
  }
  .welcome-landing {
    background: var(--bg) !important;
  }
}

@media (max-width: 600px) {
  .er-nav {
    padding: 16px 20px;
  }
  .er-nav-links {
    gap: 20px;
  }
  .er-title {
    font-size: 2.8rem;
  }
  .er-subtitle {
    font-size: 1.2rem;
  }
  .sw {
    height: 50px;
  }
  .er-footer {
    flex-direction: column;
    gap: 20px;
    padding: 24px 20px;
    align-items: flex-start;
  }
  .er-footer-right {
    flex-wrap: wrap;
    gap: 16px;
  }
}

@media (max-width: 480px) {
  .overlay-card {
    padding: 22px 18px;
  }
  .puzzle-area {
    padding: 14px;
  }
  .cipher-display {
    font-size: 1.1rem;
  }

  /* Scramble letter tiles — smaller on mobile */
  .scramble-tile {
    padding: 8px 11px;
    font-size: 1rem;
  }

  /* Word-grid blanks — narrower so long answers don't overflow */
  .scramble-blank {
    width: 28px;
    height: 36px;
    font-size: 0.9rem;
  }
  .scramble-word-gap {
    width: 10px;
  }

  /* Sequence drag items — tighter on small screens */
  .seq-item {
    padding: 10px 10px;
    gap: 8px;
  }
  .seq-item .seq-text {
    font-size: 0.85rem;
  }
}

/* ── iPhone 12 Pro / small phones (≤430px) ──
   Total layout was hitting ~844px exactly on a 390×844 screen,
   pushing CTAs to the edge. Tighten everything to bring buttons
   clearly into view without scrolling.                          */
@media (max-width: 430px) {
  .er-hero-img {
    padding: 10px 24px 0;
  }
  .er-hero-img img {
    max-width: 180px;
  }
  .er-hero-content {
    padding: 12px 20px 16px;
    gap: 2px;
  }
  .er-title {
    font-size: 2.2rem;
  }
  .er-subtitle {
    font-size: 1rem;
    margin-bottom: 10px;
  }
  .er-desc {
    font-size: 0.88rem;
    margin-bottom: 14px;
  }
  .er-label {
    margin-bottom: 6px;
  }
  .er-hero-btns {
    gap: 10px;
    margin-bottom: 16px;
    max-width: 100%;
    align-items: center;
  }
  .btn-hero-er,
  .btn-outline-er {
    padding: 13px 20px;
    font-size: 0.78rem;
    text-align: center;
    justify-content: center;
  }
  .er-stats {
    gap: 14px;
  }
}
