:root {
  --max-width: 1140px; /* Use a slightly wider max for desktops */
  --accent: #3d6aff;
  --muted: #666;
  --bg: #ffffff;
}

/* ==========================================================================
   Base & Mobile First Styles
   ========================================================================== */

/* --- Basic Reset --- */
* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Patrick Hand", sans-serif;
  background: var(--bg);
  color: #222;
}
.container {
  width: 100%; /* Take up full width on mobile */
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px;
}

/* --- Header --- */
.site-header {
  background: linear-gradient(90deg, #fff 0%, #fff 60%, rgba(61, 90, 255, 0.06) 100%);
  border-bottom: 1px solid #eee;
}
.header-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.header-link {
  text-decoration: none;
  color: inherit;
}
.logo-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.site-logo {
  height: 42px; /* Slightly smaller for mobile */
}
.site-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2rem;
  color: var(--accent);
  margin: 0;
}
.sub-header-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.site-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

/* --- Main Layout --- */
.main {
  display: flex;
  flex-direction: column; /* Stack note and options on top of each other by default */
  align-items: center;
  gap: 20px;
  padding: 20px;
}
.note-area {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  width: 100%; /* Take full width on mobile */
  max-width: 500px; /* But don't let it get too wide on mid-size screens */
}

/* --- Sticky Note --- */
.sticky {
  width: 100%; /* CRITICAL: Make the note take 100% of its container width on mobile */
  height: 360px; /* Keep a fixed height */
  border-radius: 12px;
  padding: 18px;
  transition: background 200ms ease, box-shadow 200ms ease;
  background: #FFF9A6;
  box-shadow: 0 8px 20px rgba(0,0,0,0.12), inset 0 0 6px rgba(0,0,0,0.05);
  position: relative;
}
.sticky::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0) 100%);
  border-bottom-right-radius: 12px;
  box-shadow: -3px 3px 5px rgba(0,0,0,0.12);
  pointer-events: none;
}
.sticky textarea {
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  font-family: 'Patrick Hand', cursive;
  font-size: 18px;
  line-height: 1.4;
  color: #222;
  padding: 6px;
}

/* --- Options Panel --- */
.options {
  width: 100%; /* CRITICAL: Make options take 100% width on mobile */
  background: #fff;
  padding: 18px;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.06);
}
.option-row { margin-bottom: 16px; }
.label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
}
.color-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.preset {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.06);
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0,0,0,0.06);
}
.preset.custom-swatch {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  position: relative;
  z-index: 1;
  border-radius: 10px;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.06);
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(0,0,0,0.04);
  transition: transform .12s ease, box-shadow .12s ease;
  min-width: 140px;
  justify-content: flex-start;
}
#swatch {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.06);
  box-shadow: 0 3px 8px rgba(0,0,0,0.06) inset;
  flex: 0 0 30px;
}
.swatch-label {
  font-size: 0.95rem;
  color: #333;
  font-weight: 600;
}
#customColor {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; margin: 0; z-index: 2;
}

/* --- Destroy Options --- */
.destroy-options {
  display: flex;
  flex-direction: column; /* Stack options vertically on mobile for clarity */
  gap: 12px;
  align-items: flex-start;
}
.destroy-options label {
  font-weight: 500;
  color: #444;
  display: flex;
  gap: 6px;
  align-items: center;
}
.destroy-options select, .destroy-options input[type="number"] {
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #ddd;
  width: 100%; /* Make dropdowns full width on mobile */
}

/* --- Buttons and Link Box --- */
.actions { display: flex; gap: 10px; }
.btn { padding: 10px 14px; border-radius: 10px; border: 0; cursor: pointer; font-weight: 600; box-shadow: 0 6px 14px rgba(0,0,0,0.06); background: #fff; }
.btn.small { padding: 6px 10px; font-size: 0.9rem; border-radius: 8px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { transform: translateY(-2px); }
.btn.outline { background: #fff; border: 1px solid #eee; }
.link-box { display: flex; gap: 8px; margin-top: 8px; }
.link-box input { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid #eee; }

/* --- Modal --- */
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 999; }
.modal[hidden] { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
.modal-content { position: relative; background: transparent; z-index: 10; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.display-note { width: 90vw; max-width: 400px; }
.note-inner { background: #fff; padding: 18px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.12); }
.note-body { min-height: 180px; font-family: 'Patrick Hand', cursive; font-size: 18px; white-space: pre-wrap; color: #222; }

/* --- Drop Animation --- */
.note-dropping {
  transform-origin: top center;
  animation: drop-and-fade 1.2s forwards ease-in;
}
@keyframes drop-and-fade {
  0% { transform: translateY(0) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translateY(200px) scale(0.6) rotate(10deg); opacity: 0; }
}

/* --- Help Tooltip Styles --- */
.help-tooltip {
  position: relative;
  display: inline-block;
}
.help-button {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #ccc;
  background-color: #f0f0f0;
  color: #666;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.help-button:hover {
  background-color: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.help-tooltip .tooltip-text {
  visibility: hidden;
  opacity: 0;
  width: 280px;
  background-color: #333;
  color: #fff;
  text-align: left;
  border-radius: 8px;
  padding: 12px 15px;
  position: absolute;
  z-index: 10;
  top: 140%;
  left: 50%;
  margin-left: -140px;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  line-height: 1.5;
}
.help-tooltip .tooltip-text::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent transparent #333 transparent;
}
.help-tooltip:hover .tooltip-text {
  visibility: visible;
  opacity: 1;
}
.tooltip-text strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1.1em;
  color: #fff;
}
.tooltip-text ol {
  margin: 0;
  padding-left: 20px;
}
.tooltip-text li {
  margin-bottom: 5px;
}

/* ==========================================================================
   Responsive Design - Media Queries (Refined Version)
   ========================================================================== */

/* For very small devices (e.g., iPhone SE in portrait)
   This is our new, more granular breakpoint.
   -------------------------------------------------------------------------- */
@media (max-width: 380px) {
  .site-title {
    font-size: 1.8rem; /* Make the main title a bit smaller */
  }
  .site-logo {
    height: 38px; /* Shrink the logo slightly */
  }
  .main {
    padding: 15px; /* Reduce main padding */
  }
  .note-area {
    gap: 15px; /* Reduce gap between note and options */
  }
  .sticky {
    height: 320px; /* Make the note area a bit shorter */
    padding: 15px;
  }
  .sticky textarea {
    font-size: 17px;
  }
  .options {
    padding: 15px;
  }
  .btn {
    padding: 10px 12px; /* Make buttons slightly less wide */
    font-size: 0.95rem;
  }
  .color-presets {
      gap: 6px; /* Tighten up the color presets */
  }
  .preset {
      width: 32px;
      height: 32px;
  }
  .help-tooltip .tooltip-text {
    width: 250px; /* Make tooltip narrower to prevent overflow */
    margin-left: -125px; /* Re-center it */
  }
}

/* For Tablets and up (e.g., iPads)
   This breakpoint remains largely the same but builds on our solid mobile base.
   -------------------------------------------------------------------------- */
@media (min-width: 768px) {
  .site-logo {
    height: 48px; /* Restore logo size */
  }
  .site-title {
    font-size: 2.5rem;
  }
  .main {
    padding: 30px;
    gap: 30px;
  }
  .note-area {
    gap: 30px;
    max-width: 600px;
  }
  .sticky {
    height: 420px;
  }
  .options {
    padding: 22px;
  }
  .destroy-options {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .destroy-options select, .destroy-options input[type="number"] {
      width: auto;
  }
  .sticky textarea {
    font-size: 20px;
  }
  .content-page {
    font-size: 1.1rem;
  }
}

/* For Desktops and up
   This switches to the two-column layout.
   -------------------------------------------------------------------------- */
@media (min-width: 992px) {
  .main {
    flex-direction: row; 
    align-items: flex-start;
    justify-content: center;
    gap: 40px;
  }
  .note-area {
    flex-direction: row;
    max-width: none;
    gap: 40px;
  }
  .sticky {
    width: 480px;
    height: 450px;
    margin: 0;
  }
  .options {
    width: 420px;
    margin-top: 0;
  }
  .site-title {
    font-size: 2.8rem;
  }
}