:root {
  --bg-dark: #0f172a;
  --card-bg: #1e293b;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --success: #10b981;
  --success-hover: #059669;
  --radius: 12px;
}

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

body {
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 16px 12px 100px 12px;
}

.app-container {
  width: 100%;
  max-width: 1280px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header - Ultra Modern Mobile Responsive */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.4rem;
  font-weight: 800;
}

.logo-text strong {
  color: var(--primary);
}

.badge {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

/* Tool Suite Navigation Navbar - Sleek Touch-Friendly Responsive Tabs */
.tool-navbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  background-color: var(--card-bg);
  padding: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.nav-tab {
  padding: 12px 10px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  background-color: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  word-break: break-word;
}

.nav-tab:hover {
  color: var(--text-main);
  background-color: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
  color: var(--text-main);
  background-color: var(--primary);
  box-shadow: 0 4px 15px -2px rgba(59, 130, 246, 0.4);
}

/* Mobile Adjustments for Navigation */
@media (max-width: 600px) {
  .tool-navbar {
    grid-template-columns: 1fr 1fr;
  }
  .nav-tab {
    padding: 10px 8px;
    font-size: 0.8rem;
  }
}

/* Content Layout (Grid: Main Tools + Sidebar Ad) */
.content-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 1024px) {
  .content-layout {
    grid-template-columns: 1fr 300px;
  }
}

.sidebar-ad-area {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.main-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.tool-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Cards - Responsive Mobile Padding */
.card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (max-width: 600px) {
  .card {
    padding: 16px;
    border-radius: 10px;
  }
}

.title {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: -6px;
  line-height: 1.4;
}

/* Form Controls */
.puzzle-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.image-input-action-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.col-grow {
  flex: 1;
  min-width: 200px;
}

.btn-danger-sm {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.btn-danger-sm:hover {
  background-color: var(--danger);
  color: white;
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.form-row .col {
  flex: 1;
  min-width: 100%;
}

@media (min-width: 640px) {
  .form-row .col {
    min-width: 200px;
  }
}

.form-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.styled-input, .styled-textarea, .styled-select {
  background-color: #0f172a;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  width: 100%;
  transition: border-color 0.2s;
}

.styled-input:focus, .styled-textarea:focus, .styled-select:focus {
  border-color: var(--primary);
}

/* Quiz Controls & Count Badge */
.quiz-controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background-color: rgba(15, 23, 42, 0.4);
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.question-count-badge {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  background-color: rgba(59, 130, 246, 0.15);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.quiz-btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Scrollable Form & On-Screen Preview Containers */
.scrollable-form-container {
  max-height: 440px;
  overflow-y: auto;
  padding-right: 6px;
}

.scrollable-preview-window {
  max-height: 520px;
  overflow-y: auto;
  padding-right: 8px;
  scroll-behavior: smooth;
}

.scrollable-form-container::-webkit-scrollbar,
.scrollable-preview-window::-webkit-scrollbar {
  width: 6px;
}

.scrollable-form-container::-webkit-scrollbar-thumb,
.scrollable-preview-window::-webkit-scrollbar-thumb {
  background-color: #cbd5e1;
  border-radius: 4px;
}

.scrollable-form-container::-webkit-scrollbar-track,
.scrollable-preview-window::-webkit-scrollbar-track {
  background-color: #f1f5f9;
  border-radius: 4px;
}

/* Quiz Questions Card */
.quiz-questions-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.quiz-question-card {
  background-color: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  padding: 14px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  position: relative;
}

.quiz-question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-remove-q {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  font-weight: 600;
}

.btn-remove-q:hover {
  background-color: var(--danger);
  color: white;
}

.quiz-text-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}

.quiz-text-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  background-color: #f8fafc;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  color: #0f172a;
  page-break-inside: avoid;
}

.quiz-prompt-heading {
  font-size: 0.95rem;
  font-weight: 700;
}

.quiz-answer-space {
  font-family: monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: #475569;
  word-break: break-all;
}

/* Centered Large Square Puzzle Frame - Fluid Mobile Responsive */
.puzzle-cut-sheet-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.puzzle-square-frame {
  position: relative;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1 / 1;
  height: auto;
  margin: 0 auto;
  border: 3px solid #0f172a;
  border-radius: 8px;
  overflow: hidden;
  background-color: #f8fafc;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.draggable-puzzle-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transform-origin: center center;
}

.draggable-puzzle-img:active {
  cursor: grabbing;
}

.puzzle-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #f1f5f9;
  z-index: 2;
  padding: 16px;
}

.jigsaw-overlay-svg-thin {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* 🔤 WORD SCRAMBLE STYLING */
.scramble-render-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}

.scramble-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  background-color: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  color: #0f172a;
}

.scramble-boxes {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.scramble-box {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Roboto Mono', monospace;
  font-weight: 800;
  font-size: 0.95rem;
  background-color: #ffffff;
  border: 2px solid #0f172a;
  border-radius: 4px;
  color: #0f172a;
}

/* Template Pills */
.templates-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.template-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.template-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill-btn {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.pill-btn:hover {
  background-color: var(--primary);
  border-color: var(--primary);
}

/* Action Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.2s;
  width: 100%;
}

@media (min-width: 640px) {
  .btn {
    width: auto;
  }
}

.btn-hero {
  padding: 14px 28px;
  font-size: 1.05rem;
  border-radius: 10px;
}

.btn-hero-success {
  background-color: var(--success);
  color: white;
  padding: 12px 24px;
  font-size: 1rem;
  box-shadow: 0 4px 15px -2px rgba(16, 185, 129, 0.4);
}
.btn-hero-success:hover {
  background-color: var(--success-hover);
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--border-color);
  color: var(--text-main);
}
.btn-secondary:hover {
  background-color: #475569;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

/* Worksheet Display Output - Mobile Responsive */
.worksheet-card {
  background-color: #ffffff;
  color: #0f172a;
  border: 2px solid #cbd5e1;
  border-radius: 12px;
  padding: 24px;
}

@media (max-width: 600px) {
  .worksheet-card {
    padding: 16px;
  }
}

.worksheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 2px solid #0f172a;
  padding-bottom: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.puzzle-headline {
  font-size: 1.4rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.2;
}

.student-info-line {
  font-family: monospace;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  gap: 12px;
  color: #334155;
  flex-wrap: wrap;
}

.puzzle-render-area {
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: center;
  width: 100%;
}

/* Interactive Word Search Grid - Ultra Fluid Mobile Scaling */
.wordsearch-grid {
  display: grid;
  gap: 3px;
  user-select: none;
  background-color: #f1f5f9;
  padding: 8px;
  border-radius: 8px;
  border: 2px solid #94a3b8;
  max-width: 100%;
  overflow-x: auto;
}

.grid-cell {
  width: clamp(20px, 5.5vw, 36px);
  height: clamp(20px, 5.5vw, 36px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Roboto Mono', monospace;
  font-size: clamp(0.75rem, 3.2vw, 1.2rem);
  font-weight: 700;
  color: #0f172a;
  background-color: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.grid-cell:hover {
  background-color: #e2e8f0;
}

.grid-cell.found-word {
  background-color: #bbf7d0;
  color: #166534;
  font-weight: 800;
  border-color: #86efac;
}

.grid-cell.solution-highlight {
  background-color: #fef08a;
  color: #854d0e;
  font-weight: 800;
  border-color: #fde047;
}

/* Word Finder List */
.words-finder-panel {
  width: 100%;
  background-color: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 14px;
  text-align: left;
}

.word-list-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: #0f172a;
}

.word-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px;
  list-style: none;
}

.word-item {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: #334155;
  padding: 3px 6px;
  border-radius: 4px;
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
}

.word-item.completed {
  text-decoration: line-through;
  opacity: 0.5;
  background-color: #e2e8f0;
}

.worksheet-toolbar {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  border-top: 1px solid #cbd5e1;
  padding-top: 16px;
  flex-wrap: wrap;
}

/* Ad Slot Styling - Responsive Ad Slots */
.ad-slot {
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.ad-placeholder-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px;
}

.ad-badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  background-color: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
}

.ad-size {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.ad-leaderboard { min-height: 70px; width: 100%; }
.ad-infeed { min-height: 70px; width: 100%; }
.ad-sidebar { min-height: 500px; width: 100%; height: 100%; }

.ad-sticky-anchor {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  background-color: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border-color);
  z-index: 999;
}

/* Features Grid */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.feature-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
}

.feature-icon { font-size: 1.5rem; margin-bottom: 6px; }
.feature-card h3 { font-size: 0.95rem; margin-bottom: 4px; }
.feature-card p { color: var(--text-muted); font-size: 0.8rem; line-height: 1.3; }

/* Cookie Modal */
.cookie-banner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 400px;
  background-color: rgba(30, 41, 59, 0.98);
  backdrop-filter: blur(16px);
  border: 2px solid var(--primary);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  z-index: 9999;
  text-align: center;
}

.cookie-content { display: flex; flex-direction: column; gap: 12px; }
.cookie-title { font-size: 1.1rem; font-weight: 700; }
.cookie-content p { font-size: 0.85rem; color: var(--text-muted); }
.cookie-buttons { display: flex; gap: 10px; justify-content: center; }

.footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}
.footer-links a { color: var(--text-muted); text-decoration: none; }
.footer-links a:hover { color: var(--primary); }

.hidden { display: none !important; }

/* 🖨️ PERFECT A4 PAGE PRINT MEDIA QUERY */
@page {
  size: A4 portrait;
  margin: 12mm 15mm;
}

@media print {
  .no-print, body > *:not(.app-container), .app-container > *:not(.content-layout) {
    display: none !important;
  }
  body {
    background-color: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .app-container {
    max-width: 100% !important;
    padding: 0 !important;
  }
  .content-layout {
    display: block !important;
  }
  .worksheet-card {
    border: none !important;
    padding: 0 !important;
    background-color: transparent !important;
    box-shadow: none !important;
  }
  .scrollable-preview-window {
    max-height: none !important;
    overflow: visible !important;
  }
  .puzzle-square-frame {
    border: 3px solid #000000 !important;
    box-shadow: none !important;
  }
}
