/* ==========================================================================
   Classic Responsive Design System with Light / Dark Themes
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@500;600;700&display=swap');

/* --- Light Theme (Default) --- */
:root,
:root[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-subtle: #f1f5f9;
  --bg-board: #e2e8f0;
  
  --border-color: #e2e8f0;
  --border-subtle: #cbd5e1;
  --border-focus: #0284c7;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --brand-primary: #0284c7;
  --brand-primary-hover: #0369a1;
  --brand-text: #ffffff;

  --btn-secondary-bg: #ffffff;
  --btn-secondary-border: #cbd5e1;
  --btn-secondary-text: #334155;
  --btn-secondary-hover: #f1f5f9;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  
  --blank-tile-bg: #cbd5e1;
  --blank-tile-border: #94a3b8;
  --number-bg: rgba(15, 23, 42, 0.75);
  --number-color: #ffffff;
  
  --modal-backdrop: rgba(15, 23, 42, 0.6);
}

/* --- Dark Theme --- */
:root[data-theme="dark"] {
  --bg-body: #090d16;
  --bg-surface: #111827;
  --bg-surface-subtle: #1e293b;
  --bg-board: #1e293b;
  
  --border-color: #1f2937;
  --border-subtle: #374151;
  --border-focus: #38bdf8;

  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --brand-primary: #0284c7;
  --brand-primary-hover: #0369a1;
  --brand-text: #ffffff;

  --btn-secondary-bg: #1e293b;
  --btn-secondary-border: #374151;
  --btn-secondary-text: #e5e7eb;
  --btn-secondary-hover: #334155;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.5);

  --blank-tile-bg: #1e293b;
  --blank-tile-border: #374151;
  --number-bg: rgba(0, 0, 0, 0.75);
  --number-color: #ffffff;
  
  --modal-backdrop: rgba(0, 0, 0, 0.75);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100vh;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Header Navbar */
.app-header {
  width: 100%;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.85rem 2rem;
  position: sticky;
  top: 0;
  z-index: 40;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.header-container {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-name {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.brand-tag {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background-color: var(--bg-surface-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Fullscreen Wide Main Container */
.main-container {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 2rem 2rem 4rem;
}

/* Open Two-Column Layout */
.puzzle-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2.5rem;
  align-items: start;
}

@media (min-width: 1024px) {
  .puzzle-layout {
    grid-template-columns: 420px 1fr;
    gap: 3.5rem;
  }
}

@media (min-width: 1400px) {
  .puzzle-layout {
    grid-template-columns: 460px 1fr;
    gap: 4.5rem;
  }
}

/* Left Section: Information & Controls */
.info-section {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

.section-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Visual Hint Presentation */
.hint-display {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.hint-image-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1/1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface-subtle);
  box-shadow: var(--shadow-sm);
}

.hint-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hint-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hint-label {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}

.badge-tag {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

/* Open Stats Row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 0;
}

.stat-cell {
  display: flex;
  flex-direction: column;
}

.stat-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.stat-num {
  font-family: 'Outfit', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Left Actions */
.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Right Section: Puzzle Workspace */
.game-workspace {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
}

.board-wrapper {
  position: relative;
  width: 100%;
  max-width: 520px;
  aspect-ratio: 1/1;
  background-color: var(--bg-board);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px;
  box-shadow: var(--shadow-lg);
  user-select: none;
  touch-action: none;
}

@media (min-width: 1200px) {
  .board-wrapper {
    max-width: 560px;
  }
}

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
  height: 100%;
}

/* Classic Tile Styling */
.puzzle-tile {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background-repeat: no-repeat;
  background-size: 300% 300%;
  cursor: default;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.puzzle-tile.moveable {
  cursor: pointer;
}

.puzzle-tile.moveable:hover {
  transform: scale(0.985);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  outline: 2px solid var(--brand-primary);
}

.puzzle-tile.blank {
  background: var(--blank-tile-bg) !important;
  border: 1px dashed var(--blank-tile-border);
  box-shadow: none;
}

.tile-number {
  position: absolute;
  top: 6px;
  left: 6px;
  background-color: var(--number-bg);
  color: var(--number-color);
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 0.8rem;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.show-numbers .tile-number {
  opacity: 1;
}

.ghost-hint {
  position: absolute;
  inset: 8px;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10;
}

.ghost-hint.active {
  opacity: 0.6;
}

/* Controls Toolbar */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  max-width: 560px;
}

/* Classic Button System */
.btn {
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.15rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  user-select: none;
  line-height: 1.25;
}

.btn-primary {
  background-color: var(--brand-primary);
  color: var(--brand-text);
  border-color: var(--brand-primary);
}

.btn-primary:hover {
  background-color: var(--brand-primary-hover);
  border-color: var(--brand-primary-hover);
}

.btn-outline {
  background-color: var(--btn-secondary-bg);
  border-color: var(--btn-secondary-border);
  color: var(--btn-secondary-text);
}

.btn-outline:hover {
  background-color: var(--btn-secondary-hover);
}

.select-input {
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.55rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
}

/* Controls Hint Info */
.controls-help {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.kbd-badge {
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Clean Modal Window */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background-color: var(--modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

/* Clean Upload Dropzone */
.dropzone-area {
  border: 2px dashed var(--border-subtle);
  border-radius: 8px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  background-color: var(--bg-surface-subtle);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
  margin-bottom: 1.25rem;
}

.dropzone-area:hover, .dropzone-area.dragover {
  border-color: var(--brand-primary);
  background-color: var(--bg-surface);
}

.dropzone-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

.dropzone-subtext {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.preview-box {
  display: none;
  width: 120px;
  height: 120px;
  margin: 1rem auto 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.preview-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Clean Victory Modal */
.victory-content {
  text-align: center;
}

.victory-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.victory-sub {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

.victory-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  padding: 1.25rem 0;
  margin-bottom: 1.75rem;
}

/* Gallery Showcase Page */
.gallery-layout {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 2rem 2rem 5rem;
}

.gallery-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1.5rem;
}

.gallery-heading {
  font-family: 'Outfit', sans-serif;
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.gallery-subheading {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

.gallery-grid-wide {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.75rem;
}

.gallery-item {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.gallery-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.gallery-item.selected {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 2px var(--brand-primary);
}

.gallery-photo-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background-color: var(--bg-surface-subtle);
  overflow: hidden;
}

.gallery-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-item-body {
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.gallery-item-title {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

.gallery-item-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  flex: 1;
}

/* Toast */
.toast-bar {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast-msg {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.65rem 1.15rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow-md);
}

/* Confetti Canvas */
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 99;
}
