/* ==== Base ==== */
* {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  width: 100vw;
  overflow-x: hidden;
  font-family: 'Karla', sans-serif;
  background: #f9f9f9;
  color: #333;
  scroll-behavior: smooth;
}
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 100vw;
  overflow-x: hidden;
  background: inherit;
}
.app.dark {
  background: #181824;
  color: #f1f1f1;
}

/* ==== Header ==== */
.header {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(90deg, #672280, #A626D3);
  color: white;
  padding: 1rem 1.5rem;
  gap: 1rem;
  box-shadow: 0 2px 12px rgba(103,34,128,0.08);
  border-radius: 0 0 16px 16px;
  min-height: 64px;
  position: relative;
}
.header img {
  height: 44px;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.12));
}
.header h1 {
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: 1.5px;
  font-weight: 800;
}
.app.dark .header {
  background: linear-gradient(90deg, #232336, #672280 80%);
  color: #fff;
}

/* ==== Toggle ==== */
.dark-toggle {
  position: absolute;
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255,255,255,0.10);
  border-radius: 8px;
  padding: 0.4rem 0.9rem;
  transition: background 0.3s;
  font-size: 1rem;
}
.app.dark .dark-toggle {
  background: rgba(51,51,51,0.7);
  color: #fff;
}
.dark-toggle input[type="checkbox"] {
  accent-color: #A626D3;
  width: 1.2rem;
  height: 1.2rem;
}

/* ==== Modern Toggle Switch ==== */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
  vertical-align: middle;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #ccc;
  border-radius: 28px;
  transition: background 0.3s;
}
.switch input:checked + .slider {
  background: linear-gradient(90deg, #711F8D, #A818DA);
}
.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: 0 2px 6px #0002;
}
.switch input:checked + .slider:before {
  transform: translateX(20px);
  background: #fff;
}

/* ==== Redesigned Form Section ==== */
.form {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  max-width: 500px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 24px rgba(103,34,128,0.10);
  padding: 2rem 2.2rem 2rem 2.2rem;
  margin: 0 auto 2.5rem auto;
  transition: background 0.3s;
  gap: 1.2rem;
}
.app.dark .form {
  background: #232336;
  box-shadow: 0 2px 24px #181824cc;
}
.form-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}
.form-row {
  display: flex;
  gap: 1rem;
  width: 100%;
}
.form label {
  font-size: 1.08rem;
  font-weight: 600;
  color: #672280;
  margin-bottom: 0.2rem;
}
.app.dark .form label {
  color: #A626D3;
}
.form input[type="text"] {
  width: 100%;
  font-size: 1.15rem;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  border: 1.5px solid #ccc;
  background: #f5f5f5;
  transition: border 0.2s;
  font-family: inherit;
  font-weight: 500;
}
.app.dark .form input[type="text"] {
  background: #181824;
  color: #fff;
  border: 1.5px solid #444;
}
.form input[type="text"]:focus {
  outline: none;
  border: 2px solid #A626D3;
}
.form select, .form input[type="color"], .form input[type="number"] {
  font-size: 1.05rem;
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  border: 1.5px solid #ccc;
  background: #f5f5f5;
  transition: border 0.2s;
}
.app.dark .form select, .app.dark .form input[type="color"], .app.dark .form input[type="number"] {
  background: #181824;
  color: #fff;
  border: 1.5px solid #444;
}
.form input[type="color"] {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  background: none;
}
.form input[type="number"] {
  width: 4.5rem;
  text-align: center;
}
.form .form-row > * {
  flex: 1 1 0;
}
.form .form-row > label {
  margin-bottom: 0;
}
.form .button-row {
  display: flex;
  gap: 1rem;
  width: 100%;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}
.form button {
  flex: 1 1 0;
  min-width: 0;
  padding: 0.8rem 0;
  font-size: 1.08rem;
  border-radius: 8px;
  margin: 0;
  display: inline-block;
}

/* ==== Meme ==== */
.meme {
  position: relative;
  width: 100%;
  max-width: 600px;
  aspect-ratio: 1/1;
  margin: 0 auto 2rem auto;
  background: #eaeaea;
  border-radius: 16px;
  box-shadow: 0 2px 16px rgba(103,34,128,0.10);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.app.dark .meme {
  background: #232336;
}
.meme img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 16px;
  display: block;
}
.meme span {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  padding: 0.4rem 0.8rem;
  font-family: Impact, sans-serif;
  font-size: 2.2rem;
  text-transform: uppercase;
  color: white;
  text-shadow: 2px 2px 8px black, 0 0 2px #A626D3;
  letter-spacing: 1.5px;
  user-select: none;
  pointer-events: none;
}
.meme .top {
  top: 18px;
}
.meme .bottom {
  bottom: 18px;
}

/* ==== Gallery ==== */
.gallery {
  width: 100%;
  max-width: 900px;
  margin: 0 auto 2rem auto;
  padding: 2rem 1rem;
}
.gallery h3 {
  margin-bottom: 1.5rem;
  font-size: 1.4rem;
  font-weight: 700;
  color: #672280;
}
.app.dark .gallery h3 {
  color: #A626D3;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
}
.gallery-item {
  position: relative;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(103,34,128,0.08);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}
.app.dark .gallery-item {
  background: #232336;
}
.gallery-item:hover {
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 6px 24px rgba(103,34,128,0.16);
}
.gallery-item img {
  width: 100%;
  display: block;
  border-radius: 10px;
}
.overlay {
  position: absolute;
  width: 100%;
  left: 0;
  text-align: center;
  font-size: 1.1rem;
  font-family: Impact, sans-serif;
  color: white;
  text-shadow: 2px 2px 6px black;
  pointer-events: none;
  user-select: none;
  padding: 0.2rem 0.5rem;
}
.overlay.top {
  top: 10px;
}
.overlay.bottom {
  bottom: 10px;
}

/* ==== Sticker Bar ==== */
.sticker-bar {
  display: flex;
  gap: 1.2rem;
  justify-content: center;
  margin: 1.5rem 0 2.5rem 0;
  background: #fff6;
  border-radius: 10px;
  padding: 0.7rem 1.2rem;
  box-shadow: 0 2px 8px rgba(103,34,128,0.06);
  transition: background 0.3s;
}
.app.dark .sticker-bar {
  background: #232336cc;
}
.sticker-bar span[draggable] {
  font-size: 2.2rem;
  cursor: grab;
  user-select: none;
  transition: transform 0.15s, filter 0.15s;
  filter: drop-shadow(1px 1px 2px #0004);
}
.sticker-bar span[draggable]:active {
  transform: scale(1.2) rotate(-8deg);
  filter: drop-shadow(2px 2px 6px #A626D3);
}

/* ==== Template Gallery ==== */
.template-gallery-bar {
  width: 100%;
  max-width: 700px;
  margin: 0 auto 1.2rem auto;
  padding: 0.5rem 0.5rem 0.2rem 0.5rem;
  background: #fff8;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(103,34,128,0.04);
  overflow-x: auto;
  transition: background 0.3s;
}
.app.dark .template-gallery-bar {
  background: #232336cc;
}
.template-gallery-scroll {
  display: flex;
  flex-direction: row;
  overflow-x: auto;
  gap: 0.5rem;
  padding-bottom: 0.3rem;
  scrollbar-width: thin;
  scrollbar-color: #A626D3 #eee;
}
.template-gallery-scroll::-webkit-scrollbar {
  height: 8px;
}
.template-gallery-scroll::-webkit-scrollbar-thumb {
  background: #A626D3;
  border-radius: 4px;
}
.template-gallery-scroll::-webkit-scrollbar-track {
  background: #eee;
  border-radius: 4px;
}
.template-selected {
  border: 3px solid #A626D3 !important;
  box-shadow: 0 2px 12px #A626D3aa !important;
}

/* ==== Share Bar ==== */
.share-bar {
  display: flex;
  justify-content: center;
  gap: 1.2rem;
  margin: 1.2rem 0 0.5rem 0;
}
.share-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 1.08rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  background: #eee;
  color: #333;
  box-shadow: 0 1px 4px #0001;
  transition: background 0.2s, color 0.2s, transform 0.15s;
}
.share-btn.twitter {
  background: #1da1f2;
  color: #fff;
}
.share-btn.facebook {
  background: #1877f3;
  color: #fff;
}
.share-btn.reddit {
  background: #ff4500;
  color: #fff;
}
.share-btn:hover {
  filter: brightness(1.08) drop-shadow(0 2px 8px #A626D344);
  transform: translateY(-2px) scale(1.04);
}

/* ==== Responsive ==== */
@media (max-width: 900px) {
  .form {
    max-width: 99vw;
    padding: 1.5rem 0.5rem;
    gap: 1.2rem 1rem;
    row-gap: 1.2rem;
  }
  .gallery {
    padding: 1rem 0.5rem;
  }
  .template-gallery-bar {
    max-width: 98vw;
    padding: 0.3rem 0.1rem 0.1rem 0.1rem;
  }
}
@media (max-width: 600px) {
  .header {
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.7rem 0.3rem;
    border-radius: 0 0 10px 10px;
    min-height: 48px;
  }
  .form {
    max-width: 99vw;
    padding: 0.7rem 0.2rem;
    gap: 0.7rem;
  }
  .form-group {
    gap: 0.3rem;
    margin-bottom: 0.4rem;
  }
  .form-row {
    flex-direction: column;
    gap: 0.5rem;
  }
  .form label {
    font-size: 1rem;
  }
  .form input[type="text"] {
    font-size: 1rem;
    padding: 0.6rem 0.6rem;
  }
  .form select, .form input[type="color"], .form input[type="number"] {
    font-size: 0.98rem;
    padding: 0.3rem 0.4rem;
  }
  .form input[type="number"] {
    width: 3.2rem;
  }
  .form button {
    font-size: 0.98rem;
    padding: 0.6rem 0;
  }
  .meme {
    max-width: 98vw;
    aspect-ratio: 1/1.1;
  }
  .gallery-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .meme span {
    font-size: 1.1rem;
  }
  .share-bar {
    flex-direction: column;
    gap: 0.7rem;
    align-items: center;
  }
  .share-btn {
    width: 100%;
    justify-content: center;
  }
}
button:focus, .form input:focus, .form select:focus, .gallery-item:focus, .template-gallery-scroll img:focus, .sticker-bar span[draggable]:focus {
  outline: 2.5px solid #A626D3;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px #A626D344;
  z-index: 2;
}

/* ==== Add more vertical spacing between sections ==== */
.template-gallery-bar, .sticker-bar, .share-bar {
  margin-top: 2.2rem;
}

/* ==== Polish dark mode backgrounds and borders ==== */
.app.dark .template-gallery-bar, .app.dark .sticker-bar, .app.dark .share-bar {
  background: #232336ee;
  border: 1.5px solid #333;
}

/* ==== Subtle background and border effects for premium look ==== */
.form, .template-gallery-bar, .sticker-bar, .share-bar {
  border: 1.5px solid #eee;
}
.app.dark .form, .app.dark .template-gallery-bar, .app.dark .sticker-bar, .app.dark .share-bar {
  border: 1.5px solid #232336;
}
