/**
 * The Puzzle Architect - Daily Puzzle Styles
 * Designed to fit on one screen without scrolling
 * All classes prefixed with puzzle-
 */

/* ============================================================================
   MAIN LAYOUT - Single Screen Focus
   ============================================================================ */

.puzzle-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px 20px 20px;
  background: linear-gradient(180deg, #f8f9ff 0%, #fff 100%);
  min-height: calc(100vh - 140px); /* Account for nav + footer */
}

/* ============================================================================
   HEADER
   ============================================================================ */

.puzzle-header {
  text-align: center;
  margin-bottom: 10px;
  flex-shrink: 0;
  width: 100%;
}

.puzzle-date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-bottom: 8px;
}

.puzzle-nav-btn {
  background: none;
  border: 1px solid #ddd;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
}

.puzzle-nav-btn:hover {
  background: #f0f7ff;
  border-color: #0052CC;
  color: #0052CC;
}

.puzzle-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.puzzle-nav-btn-hidden {
  display: none;
}

.puzzle-nav-btn-hidden.show {
  display: inline-flex;
}

.puzzle-date {
  font-size: 1.15rem;
  font-weight: 700;
  color: #1a1a2e;
  margin: 0;
}

.puzzle-countdown {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  font-size: 0.8rem;
}

.puzzle-countdown-label {
  color: #888;
}

.puzzle-countdown-time {
  font-weight: 700;
  color: #0052CC;
}

/* Difficulty Tabs */
.puzzle-difficulty-tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.puzzle-tab {
  padding: 6px 16px;
  border: 2px solid #e0e0e0;
  background: #fff;
  border-radius: 25px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
}

.puzzle-tab:hover {
  border-color: #0052CC;
  color: #0052CC;
}

.puzzle-tab.active {
  background: #0052CC;
  border-color: #0052CC;
  color: #fff;
}

.puzzle-tab.completed {
  position: relative;
}

.puzzle-tab.completed::after {
  content: '✓';
  position: absolute;
  top: -5px;
  right: -5px;
  background: #4CAF50;
  color: #fff;
  font-size: 0.6rem;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================================
   PUZZLE CONTAINER
   ============================================================================ */

.puzzle-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.puzzle-grid-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  position: relative;
  width: 100%;
}

/* ============================================================================
   SUDOKU GRID
   ============================================================================ */

.puzzle-grid-wrapper {
  position: relative;
}

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: 1px;
  background: #1a1a2e;
  padding: 2px;
  border-radius: 8px;
  width: 360px;
  height: 360px;
  box-sizing: border-box;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  border: 2px solid #1a1a2e;
  overflow: hidden;
}

.puzzle-cell {
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  user-select: none;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* 3x3 box borders */
.puzzle-cell:nth-child(3n) {
  border-right: 2px solid #1a1a2e;
}

.puzzle-cell:nth-child(9n) {
  border-right: none;
}

.puzzle-cell:nth-child(n+19):nth-child(-n+27),
.puzzle-cell:nth-child(n+46):nth-child(-n+54) {
  border-bottom: 2px solid #1a1a2e;
}

/* Cell states */
.puzzle-cell.given {
  background: #f0f4f8;
  color: #1a1a2e;
  cursor: default;
}

.puzzle-cell.selected {
  background: #e3f2fd;
  box-shadow: inset 0 0 0 2px #0052CC;
}

.puzzle-cell.highlighted {
  background: #f0f7ff;
}

.puzzle-cell.user-input {
  color: #0052CC;
}

.puzzle-cell.error {
  background: #ffebee;
  color: #d32f2f;
}

.puzzle-cell.hint {
  color: #4CAF50;
  animation: hintPulse 0.5s ease;
}

@keyframes hintPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Pencil marks */
.puzzle-cell .pencil-marks {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: clamp(0.4rem, 1.5vw, 0.65rem);
  color: #888;
  font-weight: 400;
}

.puzzle-cell .pencil-marks span {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================================
   COMPLETION OVERLAY
   ============================================================================ */

.puzzle-complete-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.95);
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  z-index: 10;
}

.puzzle-complete-overlay.show {
  display: flex;
}

.puzzle-complete-content {
  text-align: center;
  padding: 20px;
}

.puzzle-complete-icon {
  font-size: 3rem;
  margin-bottom: 10px;
}

.puzzle-complete-content h2 {
  font-size: 1.5rem;
  color: #1a1a2e;
  margin-bottom: 10px;
}

.puzzle-complete-time {
  font-size: 1.2rem;
  color: #0052CC;
  font-weight: 700;
  margin-bottom: 5px;
}

.puzzle-complete-message {
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 15px;
}

.puzzle-complete-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ============================================================================
   STATS PANEL
   ============================================================================ */

.puzzle-stats {
  position: absolute;
  left: calc(50% + 200px);
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 80px;
}

.puzzle-stat {
  background: #fff;
  padding: 10px 12px;
  border-radius: 8px;
  text-align: center;
  border: 1px solid #e8f0ff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.puzzle-stat-label {
  display: block;
  font-size: 0.7rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.puzzle-stat-value {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a1a2e;
}

.puzzle-stat-best .puzzle-stat-value {
  color: #4CAF50;
}

.puzzle-stat-streak .puzzle-stat-value {
  color: #ff6b35;
}

/* ============================================================================
   NUMBER PAD
   ============================================================================ */

.puzzle-numpad {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.puzzle-num {
  width: 38px;
  height: 38px;
  border: 2px solid #e0e0e0;
  background: #fff;
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: 700;
  color: #1a1a2e;
  cursor: pointer;
  transition: all 0.15s;
}

.puzzle-num:hover {
  background: #f0f7ff;
  border-color: #0052CC;
  color: #0052CC;
}

.puzzle-num:active {
  transform: scale(0.95);
}

.puzzle-num.complete {
  opacity: 0.4;
  cursor: default;
}

/* ============================================================================
   ACTION BUTTONS
   ============================================================================ */

.puzzle-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.puzzle-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border: 1px solid #e0e0e0;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 58px;
}

.puzzle-action:hover {
  background: #f0f7ff;
  border-color: #0052CC;
}

.puzzle-action[aria-pressed="true"] {
  background: #0052CC;
  border-color: #0052CC;
  color: #fff;
}

.puzzle-action-icon {
  font-size: 1rem;
}

.puzzle-action-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
}

.puzzle-action-danger:hover {
  background: #ffebee;
  border-color: #d32f2f;
  color: #d32f2f;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.puzzle-btn-primary {
  display: inline-block;
  padding: 10px 20px;
  background: #0052CC;
  color: #fff;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.2s;
}

.puzzle-btn-primary:hover {
  background: #003d99;
}

.puzzle-btn-secondary {
  display: inline-block;
  padding: 10px 20px;
  background: #fff;
  color: #0052CC;
  font-weight: 600;
  border: 1px solid #0052CC;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.puzzle-btn-secondary:hover {
  background: #f0f7ff;
}

/* ============================================================================
   MODAL
   ============================================================================ */

.puzzle-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.puzzle-modal.show {
  display: flex;
}

.puzzle-modal-content {
  background: #fff;
  padding: 25px 30px;
  border-radius: 12px;
  text-align: center;
  max-width: 400px;
  margin: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.puzzle-modal-content p {
  font-size: 1.1rem;
  color: #333;
  margin-bottom: 20px;
  line-height: 1.5;
}

.puzzle-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ============================================================================
   TOAST
   ============================================================================ */

.puzzle-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1a1a2e;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  max-width: 90%;
  text-align: center;
}

.puzzle-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.puzzle-toast p {
  margin: 0;
  font-size: 0.95rem;
}

/* ============================================================================
   RESPONSIVE - Tablets & Smaller Laptops
   ============================================================================ */

@media (max-width: 1024px) {
  .puzzle-grid {
    width: min(340px, 45vw, 42vh);
  }

  .puzzle-stats {
    gap: 8px;
  }

  .puzzle-stat {
    padding: 10px 12px;
    min-width: 80px;
  }
}

/* ============================================================================
   RESPONSIVE - Mobile
   ============================================================================ */

@media (max-width: 900px) {
  .puzzle-stats {
    position: static;
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 10px;
  }

  .puzzle-grid-row {
    flex-direction: column-reverse;
    align-items: center;
  }

  .puzzle-stat {
    padding: 8px 12px;
    min-width: 70px;
  }
}

@media (max-width: 768px) {
  .puzzle-grid {
    width: min(340px, 85vw);
    height: min(340px, 85vw);
  }
}

@media (max-width: 600px) {
  .puzzle-main {
    padding: 10px 15px;
  }

  .puzzle-grid {
    width: min(300px, 90vw);
    height: min(300px, 90vw);
  }

  .puzzle-date-nav {
    flex-wrap: wrap;
    gap: 8px;
  }

  .puzzle-date {
    font-size: 1rem;
    order: -1;
    width: 100%;
  }

  .puzzle-countdown {
    flex-direction: row;
    gap: 5px;
  }

  .puzzle-difficulty-tabs {
    gap: 4px;
  }

  .puzzle-tab {
    padding: 5px 10px;
    font-size: 0.75rem;
  }

  .puzzle-stat-value {
    font-size: 1rem;
  }

  .puzzle-num {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }

  .puzzle-action {
    padding: 5px 10px;
    min-width: 50px;
  }

  .puzzle-action-icon {
    font-size: 0.9rem;
  }

  .puzzle-action-label {
    font-size: 0.55rem;
  }
}

/* Very small screens */
@media (max-width: 380px) {
  .puzzle-numpad {
    gap: 4px;
  }

  .puzzle-num {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }

  .puzzle-actions {
    gap: 6px;
  }

  .puzzle-action {
    padding: 5px 8px;
    min-width: 48px;
  }
}

/* Landscape mobile */
@media (max-height: 600px) and (orientation: landscape) {
  .puzzle-main {
    padding: 5px 15px;
  }

  .puzzle-header {
    margin-bottom: 8px;
  }

  .puzzle-date {
    font-size: 1rem;
  }

  .puzzle-tab {
    padding: 5px 15px;
  }

  .puzzle-container {
    gap: 8px;
  }

  .puzzle-stats {
    flex-direction: column;
    gap: 8px;
  }

  .puzzle-stat {
    padding: 6px 10px;
  }

  .puzzle-stat-label {
    font-size: 0.65rem;
  }

  .puzzle-stat-value {
    font-size: 1rem;
  }

  .puzzle-num {
    width: 34px;
    height: 34px;
  }

  .puzzle-footer {
    padding: 8px;
  }
}

/* ============================================================================
   REDUCED MOTION
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  .puzzle-cell,
  .puzzle-num,
  .puzzle-action,
  .puzzle-tab,
  .puzzle-toast {
    transition: none;
  }

  @keyframes hintPulse {
    0%, 100% { transform: none; }
  }
}
