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

:root {
  color-scheme: only light;
  --bg: #e5e7eb;
  --card-bg: #ffffff;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --secondary: #6b7280;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --radius: 16px;

  --cat-dad: #f59e0b;
  --cat-pun: #10b981;
  --cat-knock: #3b82f6;
  --cat-math: #8b5cf6;
  --cat-tech: #06b6d4;
  --cat-work: #f97316;
  --cat-aging: #ec4899;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 16px 64px;
}

body.dark {
  color-scheme: dark;
  --bg: #111827;
  --card-bg: #1f2937;
  --text: #f9fafb;
  --text-muted: #9ca3af;
  --border: #374151;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body.dark .joke-punchline { color: #f98d40; }
body.dark .joke-card { background-image: linear-gradient(rgba(36,35,35,0.45), rgba(23, 23, 23, 0.41)), url('SmileyEdgedBackground.jpg'); }
body.dark footer a { color: #60a5fa; }


header {
  text-align: center;
  margin-bottom: 0;
  width: 100%;
  max-width: 640px;
}

.header-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  max-width: 640px;
}

.header-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  flex-shrink: 0;
  object-fit: cover;
}

header h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--primary);
}


.dark-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

body.dark select {
  background: #1f2937;
  color: #f9fafb;
  border-color: #374151;
}

.dark-toggle input { display: none; }

.dark-slider {
  width: 40px;
  height: 22px;
  background: #d1d5db;
  border-radius: 99px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.dark-slider::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}

.dark-toggle input:checked + .dark-slider { background: var(--primary); }
.dark-toggle input:checked + .dark-slider::after { transform: translateX(18px); }

.dark-label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 6px;
  width: 100%;
  max-width: 640px;
}

.controls-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 10px 20px;
  transition: background 0.15s, transform 0.1s;
}

.controls-row button {
  padding: 10px 14px;
}

button:active { transform: scale(0.97); }

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

.btn-secondary {
  background: #e0e7ff;
  color: var(--primary);
}
.btn-secondary:hover { background: #c7d2fe; }

.btn-ghost {
  background: #f3f4f6;
  color: var(--secondary);
}
.btn-ghost:hover { background: #ede9fe; color: var(--primary); }

.number-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.number-row label {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 500;
}

.number-row input[type="number"] {
  width: 80px;
  padding: 9px 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.92rem;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
}

.number-row input[type="number"]:focus {
  border-color: var(--primary);
}

select {
  padding: 9px 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.92rem;
  background: #fff;
  cursor: pointer;
  outline: none;
  color: var(--text);
}

select:focus { border-color: var(--primary); }

.joke-card {
  background: var(--card-bg);
  background-image: linear-gradient(rgba(231,229,229,0.75), rgba(217,214,214,0.75)), url('SmileyEdgedBackground.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 34px;
  max-width: 640px;
  width: 100%;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: opacity 0.2s;
}

.joke-card.fading { opacity: 0; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.joke-number {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

.category-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
}

.cat-dad    { background: var(--cat-dad); }
.cat-pun    { background: var(--cat-pun); }
.cat-knock-knock { background: var(--cat-knock); }
.cat-math   { background: var(--cat-math); }
.cat-tech   { background: var(--cat-tech); }
.cat-work   { background: var(--cat-work); }
.cat-aging  { background: var(--cat-aging); }

.joke-setup {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: pre-line;
}

.punchline-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.joke-punchline {
  font-size: 1.25rem;
  line-height: 1.5;
  color: var(--primary);
  font-weight: 500;
  white-space: pre-line;
  display: none;
}

.joke-punchline.visible { display: block; }

.btn-reveal {
  align-self: flex-start;
  background: #ede9fe;
  color: var(--primary);
  font-size: 0.85rem;
}
.btn-reveal:hover { background: #ddd6fe; }

.search-row {
  flex-basis: 100%;
  position: relative;
  display: none;
  align-items: center;
}

.search-row.visible {
  display: flex;
}

#searchInput {
  width: 100%;
  padding: 9px 34px 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.92rem;
  outline: none;
  background: var(--card-bg);
  color: var(--text);
  transition: border-color 0.15s;
}

#searchInput:focus { border-color: var(--primary); }

body.dark #searchInput {
  background: #1f2937;
  color: #f9fafb;
  border-color: #374151;
}

.search-clear {
  position: absolute;
  right: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 4px 7px;
  border-radius: 6px;
  display: none;
  line-height: 1;
}

.search-clear:hover { background: var(--border); color: var(--text); }

mark {
  background: #fef08a;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

body.dark mark { background: #854d0e; color: #fef3c7; }

.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  max-width: 640px;
  width: 100%;
}

.nav-center {
  display: flex;
  gap: 10px;
}

.nav-right {
  display: flex;
  justify-content: flex-end;
}

.keyboard-hint {
  margin-top: 8px;
  font-size: 0.78rem;
  color: #9ca3af;
  text-align: center;
}

@media (hover: none) {
  .keyboard-hint { display: none; }
}

.footer-banner-row {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
}

.footer-banner {
  width: 320px;
  max-width: 100%;
  border-radius: 10px;
  display: block;
}

.footer-webapp-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  background: var(--primary);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 700;
  border-radius: 10px;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s;
}

.footer-webapp-btn:hover { background: var(--primary-hover); text-decoration: none; }

@media (max-width: 400px) {
  .footer-banner { width: 240px; }
}

footer {
  margin-top: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

footer p {
  font-size: 0.88rem;
  color: var(--text-muted);
}

footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

footer a:hover {
  text-decoration: underline;
}

.footer-links-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.footer-pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 14px;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  transition: opacity 0.15s;
}

.footer-pill:hover { opacity: 0.85; text-decoration: none; }

.footer-pill-brand {
  background: var(--primary);
  color: #fff;
}

.footer-pill-fb {
  background: #1877f2;
  color: #fff;
}

body.dark .footer-pill-brand { background: var(--primary); }
body.dark .footer-pill-fb { background: #1877f2; }

.footer-actions-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.footer-pill-amazon {
  background: #FF9900;
  color: #131A22;
  font-size: 0.82rem;
  font-weight: 700;
}

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

.gallery-overlay.open { display: flex; }

.gallery-popup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 92vw;
  max-height: 92vh;
}

.gallery-popup img,
.gallery-popup video {
  max-width: 100%;
  max-height: calc(92vh - 80px);
  border-radius: 12px;
  display: block;
  object-fit: contain;
}

.gallery-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.gallery-controls .btn-ghost {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.gallery-controls .btn-ghost:hover {
  background: rgba(255,255,255,0.28);
  color: #fff;
}

.gallery-counter {
  font-size: 0.88rem;
  color: #d1d5db;
  min-width: 50px;
  text-align: center;
}

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

.image-overlay.open { display: flex; }

.image-popup {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-popup img,
.image-popup video {
  max-width: 100%;
  max-height: calc(90vh - 24px);
  border-radius: 10px;
  display: block;
}

.image-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--card-bg);
  cursor: pointer;
}

.image-close:hover { background: var(--primary-hover); }

@media (max-width: 500px) {
  .joke-card { padding: 24px 20px; }
  header h1 { font-size: 1.8rem; }
  .joke-setup { font-size: 1.1rem; }
}

@media (max-width: 430px) {
  header h1 { font-size: 1.4rem; }
}
