.guide-page-wrapper {
  animation: fadeIn 0.4s ease-out;
}

:root {
  --card-grad-1: #cdd9e5;
  --card-grad-2: #adbac7;
  --card-text: #1e293b;
  --sudoku-grid-line: #000;
  --sudoku-inner-line: #bbb;
}

body.dark-mode {
  --card-grad-1: #64748b;
  --card-grad-2: #475569;
  --card-text: #ffffff;
  --sudoku-grid-line: #fff;
  --sudoku-inner-line: #444;
}

.guide-card {
  padding: 25px;
  min-height: 500px;
  display: flex;
  flex-direction: column;
}

.guide-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 15px;
  margin-bottom: 20px;
}

.guide-header-top h2 {
  margin: 0;
  font-size: 1.8rem;
  color: #fff;
}

.close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition:
    color 0.2s,
    transform 0.2s;
}

.close-btn:hover {
  color: white;
  transform: scale(1.1);
}

/* (Segmented Control styles removed) */

.jigsaw-slot.locked {
  cursor: not-allowed !important;
  position: relative;
}

.jigsaw-slot.locked::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.05); /* Light Mode Overlay */
  pointer-events: none;
  z-index: 10;
  border-radius: 10px;
}

body.dark-mode .jigsaw-slot.locked::after {
  background: rgba(0, 0, 0, 0.3); /* Dark Mode Overlay */
}

body.dark-mode .guide-selector {
  background: rgba(0, 0, 0, 0.4);
}

/* Content Area */
.guide-content-area {
  flex: 1;
}

.guide-tab-content {
  animation: slideUp 0.3s ease-out;
}

.guide-tab-content.hidden {
  display: none;
}

.guide-list {
  list-style: none;
  padding: 0;
}

.guide-list li {
  margin-bottom: 12px;
  padding-left: 25px;
  position: relative;
}

.guide-list li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--primary-color, #fbbf24);
}

/* Mechanics Grid */
.mechanic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.mechanic-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 15px;
  border-radius: 12px;
  transition: transform 0.3s;
}

.mechanic-item:hover {
  transform: translateY(-5px);
  background: rgba(255, 255, 255, 0.05);
}

/* Info Cards */
.info-card {
  padding: 24px;
  margin-bottom: 24px;
  width: 100%;
  box-sizing: border-box;
}

.info-card h3 {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 1.3rem;
  color: var(--primary-color, #fbbf24);
}

.info-card ul {
  padding-left: 20px;
  margin: 0;
}

.info-card li {
  margin-bottom: 10px;
  line-height: 1.5;
}

.info-card p {
  line-height: 1.6;
  margin-bottom: 15px;
}

.mechanic-item h4 {
  margin: 0 0 10px 0;
  color: var(--primary-color, #fbbf24);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Tutorial Styles */
.tutorial-step-info {
  margin-bottom: 20px;
  padding: 20px;
  border-left: 4px solid var(--primary-color, #fbbf24);
}

.tutorial-header {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 25px;
  background: rgba(255, 255, 255, 0.03);
  padding: 15px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.tutorial-header-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
}

.sudoku-tutorial-wrapper {
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-start !important;
  justify-content: center !important;
  gap: 30px !important;
  width: 100% !important;
  max-width: 900px !important;
  margin: 0 auto !important;
}

.tutorial-sudoku-board {
  flex: 0 0 auto !important;
  width: min(400px, 50vw) !important; /* Slightly smaller board */
  height: auto !important;
  aspect-ratio: 1/1 !important;
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;

  /* Use Variables for Dark Mode Parity */
  background: var(--sudoku-grid-line) !important;
  border: 4px solid var(--bg-secondary) !important;
  gap: 2px !important;

  border-radius: 8px;
  overflow: hidden;
}

/* Remove hardcoded overrides */

.mini-sudoku-grid {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  width: 100% !important;
  height: 100% !important;
}

.tutorial-sudoku-controls {
  flex: 0 0 160px !important; /* Narrower keypad */
  display: flex !important;
  flex-direction: column !important;
  gap: 10px !important;
  padding-top: 5px !important;
}

/* Keypad Grid for Side Layout */
.tutorial-sudoku-controls .control-row.primary.numbers {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 6px !important;
}

.tutorial-sudoku-controls .sudoku-num {
  width: 100% !important;
  aspect-ratio: 1/1 !important;
  height: auto !important;
  font-size: 1.2rem !important; /* Smaller text */
  border-radius: 10px !important;
}

.tutorial-sudoku-controls .control-row.secondary {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 6px !important;
}

.tutorial-sudoku-controls .btn-sudoku-action {
  aspect-ratio: 1/1 !important;
  height: auto !important;
  width: 100% !important;
}

.tutorial-sudoku-board .mini-cell.user-filled {
  color: var(--accent-color) !important;
  font-weight: 900 !important;
}

/* Responsive: Stack on mobile */
@media (max-width: 768px) {
  .sudoku-tutorial-wrapper {
    flex-direction: column !important;
    align-items: center !important;
    gap: 20px !important;
  }
  .tutorial-sudoku-board {
    width: 90vw !important;
  }
  .tutorial-sudoku-controls {
    flex: 1 1 auto !important;
    width: 100% !important;
    max-width: 320px !important;
  }
}

.tutorial-title-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.tutorial-nav-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.2rem;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.tutorial-nav-btn:hover:not(:disabled) {
  background: var(--primary-color, #fbbf24);
  color: #1e293b;
  transform: scale(1.1);
}

.tutorial-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  filter: grayscale(1);
}

#tutorial-stage-name {
  font-weight: bold;
  font-size: 1.1rem;
  color: var(--primary-color, #fbbf24);
  text-align: center;
}

.tutorial-stage-description {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
  border-radius: 8px;
  border-left: 3px solid var(--primary-color, #fbbf24);
}

.tutorial-stage-description strong {
  color: var(--primary-color, #fbbf24);
  font-weight: 600;
}

#tutorial-progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

#tutorial-progress-fill {
  height: 100%;
  background: var(--primary-color, #fbbf24);
  transition: width 0.5s ease;
}

.tutorial-board-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 400px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 15px;
  padding: 20px;
  position: relative;
}

/* Tutorial specific layout adjustments */
.tutorial-board-container .memory-grid {
  display: grid;
  grid-template-columns: repeat(
    4,
    1fr
  ) !important; /* Forces 8 cards in 4x2 for tutorial */
  gap: 15px; /* Explicit gap instead of relying on fractions stretching */
  width: max-content; /* Only take as much space as the 4 cards need */
  margin: 0 auto; /* Center the compact grid block within the container */
  perspective: 1000px; /* Perspective belongs on the container for uniform 3D feel */
}

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

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 600px) {
  .guide-page-wrapper {
    padding: 10px;
  }
  .guide-card {
    padding: 15px;
  }
  .guide-tab {
    padding: 8px 12px;
    font-size: 0.9rem;
  }
}

/* Tutorial Mini-Games Styles */
/* Variables now handled at root/global */

.mini-sudoku-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  width: 100%;
  height: 100%;
  gap: 0;
  container-type: size;
  contain: layout paint style;
  border-radius: 0; /* Standardized to Sudoku style */
  overflow: hidden;
}

.mini-cell {
  background: white;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18cqw;
  font-weight: 700;
  font-family: "Outfit", sans-serif;
  color: #333;
  line-height: 1;
  border-right: 1px solid var(--sudoku-inner-line);
  border-bottom: 1px solid var(--sudoku-inner-line);
  box-sizing: border-box;
}

body.dark-mode .mini-cell {
  background: #2a2a2a;
  color: #eee;
}

/* Cleanup for outer edges of mini-grids */
.mini-cell:nth-child(3n) {
  border-right: none;
}
.mini-cell:nth-child(n + 7) {
  border-bottom: none;
}

body.dark-mode .mini-cell {
  background: #2a2a2a;
  color: #eee;
}

.mini-cell:nth-child(3n) {
  border-right: none;
}
.mini-cell:nth-child(n + 7) {
  border-bottom: none;
}

/* Card Overrides for Guide */
.tutorial-board-container .memory-card {
  width: 80px;
  height: 80px;
  position: relative;
  cursor: pointer;
  transform-style: preserve-3d;
  transition:
    transform 0.2s ease-out,
    box-shadow 0.2s ease;
}

.tutorial-board-container .memory-card.flipped {
  transform: rotateY(180deg);
  cursor: default;
}

.tutorial-board-container .memory-card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
}

.tutorial-board-container .memory-card.flipped .memory-card-inner {
  /* Rotation moved back to the card itself to match daily game */
  transform: none;
}

.tutorial-board-container .memory-card-front,
.tutorial-board-container .memory-card-back {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.tutorial-board-container .memory-card-front {
  background: linear-gradient(135deg, var(--card-grad-1), var(--card-grad-2));
  color: var(--card-text);
  font-size: 1.5rem;
  font-weight: bold;
}

body.dark-mode .tutorial-board-container .memory-card-front {
  background: linear-gradient(135deg, var(--card-grad-1), var(--card-grad-2));
  color: var(--card-text);
}

.tutorial-board-container .memory-card-back {
  background: var(--bg-secondary);
  transform: rotateY(180deg);
  border: 2px solid #1e293b;
  border-radius: 6px;
  overflow: hidden;
  /* Daily Game Strategy: Hide content when not flipped to prevent bleaching */
  visibility: hidden;
  transition: visibility 0s linear 0.1s;
}

body.dark-mode .tutorial-board-container .memory-card-back {
  border-color: var(--primary-color, #fbbf24);
  background: #1a1c1e;
}

.tutorial-board-container .memory-card.flipped .memory-card-back {
  visibility: visible;
  transition-delay: 0s;
}

/* Jigsaw Tutorial */
.tutorial-jigsaw-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: min(300px, 80vw); /* Reduced to leave more space on sides */
  aspect-ratio: 1/1;
  gap: 4px;
  background: var(--bg-secondary);
  padding: 4px;
  border-radius: 8px;
  border: none;
  margin: 0 auto 20px auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  box-sizing: border-box;
}

.tutorial-jigsaw-panel {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  min-height: 100px; /* Ensure it's a generous drop target */
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  width: 100%;
}

/* Jigsaw Interaction & Drag-Drop */
.jigsaw-piece.dragging-source {
  opacity: 0.2;
}

.dragging-clone {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.9;
  transform: scale(1.1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  display: block;
  overflow: hidden;
  transition:
    width 0.3s ease,
    height 0.3s ease,
    transform 0.3s ease;
}

.dragging-clone .mini-sudoku-grid {
  width: 100% !important;
  height: 100% !important;
  container-type: size !important; /* Fix: Numbers resolve cqw correctly inside wrapper */
}

.jigsaw-slot.drop-hover,
.jigsaw-panel-slot.drop-hover {
  background: rgba(255, 255, 255, 0.15) !important;
  border: 2px solid var(--primary-color, #fbbf24) !important;
  box-shadow: 0 0 15px var(--primary-color, #fbbf24);
}

.jigsaw-panel-slot {
  width: 74px; /* slightly larger than piece (70px + 2px borders) */
  height: 74px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-sizing: border-box;
}

.jigsaw-panel-slot.empty {
  border: 1px dashed rgba(255, 255, 255, 0.1);
}

.jigsaw-piece {
  width: 70px;
  height: 70px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid #1e293b; /* Daily Light Mode Border */
  background: var(--bg-secondary);
  cursor: pointer;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0; /* Changed from default margin to fit in slot */
}

body.dark-mode .jigsaw-piece {
  border-color: var(--primary-color, #fbbf24); /* Daily Dark Mode Border */
}

.jigsaw-piece:hover {
  transform: translateY(-5px) scale(1.05);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.jigsaw-piece.selected {
  border-color: #fff;
  box-shadow: 0 0 15px var(--primary-color, #fbbf24);
  transform: scale(1.1);
}

/* Slots and filled pieces should be flush */
.jigsaw-slot.filled {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.jigsaw-slot.filled .mini-sudoku-grid {
  border: 1px solid #1e293b;
  border-radius: 10px;
  background: white; /* Hides fractional rendering gaps */
}

body.dark-mode .jigsaw-slot.filled .mini-sudoku-grid {
  border-color: var(--primary-color, #fbbf24);
  background: #2a2a2a; /* Matches dark cell color perfectly */
}

/* Error feedback */
.jigsaw-slot.error-blink {
  animation: jigsawError 0.5s ease;
}

@keyframes jigsawError {
  0%,
  100% {
    border-color: transparent;
  }
  50% {
    border-color: #ff5555;
    background: rgba(255, 85, 85, 0.2);
  }
}

/* Sudoku Tutorial */
/* Peaks & Valleys Tutorial Styles */

.peak-found {
  background-color: rgba(251, 191, 36, 0.3) !important; /* Amber-400 alpha */
  box-shadow: inset 0 0 10px #fbbf24 !important;
  color: var(--card-text) !important;
  font-weight: 900 !important;
  transition: all 0.3s ease;
}

.valley-found {
  background-color: rgba(33, 150, 243, 0.3) !important; /* Blue-500 alpha */
  box-shadow: inset 0 0 10px #2196f3 !important;
  color: var(--card-text) !important;
  font-weight: 900 !important;
  transition: all 0.3s ease;
}

.error-shake {
  animation: errorShake 0.4s ease-in-out;
  color: #ef4444 !important; /* Red-500 */
}

@keyframes errorShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* Interaction Feedback */
.error-blink {
  animation: errorBlink 0.5s;
}

@keyframes errorBlink {
  0%,
  100% {
    transform: translateX(0);
    box-shadow: none;
  }
  25% {
    transform: translateX(-5px);
    box-shadow: 0 0 15px red;
  }
  75% {
    transform: translateX(5px);
    box-shadow: 0 0 15px red;
  }
}

.tutorial-finish {
  text-align: center;
  padding: 40px;
  animation: slideUp 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
/* Peaks & Valleys Tutorial Styles */

/* Override user-filled color for Peaks to be neutral (matches daily game) */
.tutorial-sudoku-board .mini-cell.user-filled {
  color: var(--card-text) !important;
  font-weight: 700 !important; /* Reset to normal weight vs 900 */
}

.peak-found {
  background-color: rgba(251, 191, 36, 0.3) !important; /* Amber-400 alpha */
  box-shadow: inset 0 0 10px #fbbf24 !important;
  font-weight: 900 !important;
  transition: all 0.3s ease;
}

.peak-found .curr-number {
  color: var(--card-text) !important; /* Ensure visibility */
}

.valley-found {
  background-color: rgba(33, 150, 243, 0.3) !important; /* Blue-500 alpha */
  box-shadow: inset 0 0 10px #2196f3 !important;
  font-weight: 900 !important;
  transition: all 0.3s ease;
}

.valley-found .curr-number {
  color: var(--card-text) !important;
}

.error-shake {
  animation: errorShake 0.4s ease-in-out;
  color: #ef4444 !important; /* Red-500 */
  display: inline-block; /* Required for transform */
}

@keyframes errorShake {
  0%,
  100% {
    transform: translateX(0);
    color: var(--card-text);
  }
  25% {
    transform: translateX(-5px);
    color: #ef4444;
  }
  75% {
    transform: translateX(5px);
    color: #ef4444;
  }
}
/* Fix for "Thick Lines" in Sudoku Tutorial */
/* The daily game uses borders, but the tutorial uses gaps. */
/* We must disable the inherited borders for the tutorial to avoid double thickness */

.tutorial-sudoku-board .sudoku-chunk-slot {
  border: none !important; /* Disable inherited daily game borders */
  margin: 0 !important;
  padding: 0 !important;
}

/* Ensure mini-grids fill the slot completely and have no rounding to avoid clipping internal colored cells */
.tutorial-sudoku-board .sudoku-chunk-slot,
.tutorial-sudoku-board .mini-sudoku-grid {
  width: 100% !important;
  height: 100% !important;
  border: none !important;
  border-radius: 0 !important;
}

.tutorial-sudoku-board.sudoku-mode .mini-cell.user-filled,
.tutorial-sudoku-board.sudoku-mode .mini-sudoku-grid .note-slot {
  color: var(--accent-color) !important;
}

/* --- INFO / RANKS STYLES (Merged) --- */
.ranks-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 5px 0;
}

.rank-row {
  display: grid;
  grid-template-columns: 40px 1fr auto; /* Slightly narrower icon col */
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: transform 0.2s, background 0.2s;
}

.rank-row:hover {
  transform: translateX(5px);
  background: rgba(255, 255, 255, 1);
  /* In light mode, hover becomes white */
}

body.dark-mode .rank-row:hover {
  background: rgba(255, 255, 255, 0.1);
}

.rank-icon {
  font-size: 1.5rem;
  text-align: center;
}

.rank-details {
  display: flex;
  flex-direction: column;
}

.rank-name {
  font-weight: bold;
  font-size: 1rem;
  color: var(--text-primary);
}

.rank-level {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.rank-req {
  font-weight: bold;
  color: var(--accent-color);
  font-size: 0.95rem;
  background: rgba(251, 191, 36, 0.1);
  padding: 4px 8px;
  border-radius: 6px;
}

/* App Version Footer */
.app-version-container {
  text-align: center;
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  .ranks-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .rank-row {
    padding: 8px;
    grid-template-columns: 1fr auto; /* Removed icon column */
  }
  .rank-icon {
    display: none; /* Hide icons on mobile */
  }
  .rank-name {
    font-size: 0.9rem;
  }
  .rank-level {
    font-size: 0.75rem;
  }
  .rank-req {
    font-size: 0.85rem;
    padding: 2px 6px;
  }
}
