/* ============================================
   MAGIC TREE — DECISION PICKER
   Design tokens + layout + UI styling
   ============================================ */

:root {
  --bg-sky-top: #87CEEB;
  --bg-sky-bottom: #C8E6C9;
  --grass: #4CAF50;
  --grass-dark: #2E7D32;
  --trunk: #5D4037;
  --branch: #6D4C41;
  --paper-white: #FFFDE7;
  --paper-shadow: #F9A825;
  --string-color: #8D6E63;
  --stone-color: #78909C;
  --accent-gold: #FFD700;
  --ui-surface: rgba(255, 255, 255, 0.92);
  --ui-border: rgba(0, 0, 0, 0.08);
  --ui-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  --text-primary: #1A1A2E;
  --text-secondary: #546E7A;
  --btn-primary: #2E7D32;
  --btn-hover: #1B5E20;
  --chip-bg: #E8F5E9;
  --chip-text: #1B5E20;
  --chip-border: #A5D6A7;
  --result-bg: linear-gradient(135deg, #FFFDE7, #FFF9C4);
  --result-border: #FFD54F;
}

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

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-primary);
  background: #f4f1ea;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input {
  font-family: inherit;
}

/* ----- ANIMATED BACKGROUND ----- */
.bg-gradient {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(
    135deg,
    #fef6e4 0%,
    #f3e9d2 25%,
    #e8f5e9 50%,
    #d7eef0 75%,
    #fef6e4 100%
  );
  background-size: 400% 400%;
  animation: bgShift 30s ease-in-out infinite;
}

@keyframes bgShift {
  0%,
  100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

/* ----- ACCESSIBILITY UTILITY ----- */
/* Visually hidden but available to screen readers and search engines.
   Used for SR-only headings and SEO content blocks. */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ----- LAYOUT ----- */
.app {
  min-height: 100vh;
  width: 100vw;
  display: grid;
  grid-template-columns: minmax(360px, 35%) 1fr;
  padding: 24px;
  gap: 24px;
}

.panel {
  position: relative;
  background: var(--ui-surface);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--ui-border);
  border-radius: 24px;
  box-shadow: var(--ui-shadow);
  padding: 28px 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.18) transparent;
}

.panel::-webkit-scrollbar {
  width: 6px;
}
.panel::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 3px;
}

.canvas-wrap {
  position: relative;
  background: linear-gradient(to bottom, var(--bg-sky-top), var(--bg-sky-bottom));
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--ui-shadow);
  border: 1px solid var(--ui-border);
}

#treeCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ----- MUTE BUTTON ----- */
.mute-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.04);
  display: grid;
  place-items: center;
  font-size: 16px;
  transition: all 0.2s ease;
  z-index: 2;
}
.mute-btn:hover {
  background: rgba(0, 0, 0, 0.09);
  transform: scale(1.06);
}

/* ----- HEADER ----- */
.panel-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.title {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 900;
  font-size: 32px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  line-height: 1.1;
}

.subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
}

.divider {
  margin-top: 12px;
  height: 2px;
  width: 60px;
  background: linear-gradient(90deg, var(--accent-gold), transparent);
  border-radius: 2px;
}

/* ----- SECTIONS ----- */
.section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

/* ----- INPUT ROW ----- */
.input-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.name-input {
  flex: 1;
  height: 42px;
  padding: 0 16px;
  border-radius: 50px;
  border: 1px solid var(--ui-border);
  background: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: all 0.18s ease;
}

.name-input::placeholder {
  color: #B0BEC5;
}

.name-input:focus {
  border-color: var(--btn-primary);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.12);
  background: #fff;
}

.add-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--btn-primary);
  color: #fff;
  font-size: 22px;
  font-weight: 600;
  display: grid;
  place-items: center;
  transition: all 0.18s ease;
  box-shadow: 0 4px 12px rgba(46, 125, 50, 0.28);
}

.add-btn:hover {
  background: var(--btn-hover);
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 6px 16px rgba(46, 125, 50, 0.36);
}

.add-btn:active {
  transform: translateY(0) scale(1);
}

/* ----- CHIPS ----- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 12px;
  background: var(--chip-bg);
  color: var(--chip-text);
  border: 1px solid var(--chip-border);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  transform-origin: center;
  animation: chipIn 0.25s cubic-bezier(0.4, 0, 0.2, 1.4);
}

.chip.removing {
  animation: chipOut 0.18s ease forwards;
}

@keyframes chipIn {
  from {
    transform: scale(0.5);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes chipOut {
  to {
    transform: scale(0);
    opacity: 0;
  }
}

.chip-remove {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(27, 94, 32, 0.12);
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--chip-text);
  transition: all 0.15s ease;
}

.chip-remove:hover {
  background: rgba(27, 94, 32, 0.25);
  transform: scale(1.1);
}

.count-line {
  font-size: 11px;
  color: #90A4AE;
  font-weight: 500;
}

/* ----- STEPPER ----- */
.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  padding: 4px;
  width: fit-content;
}

.step-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  color: var(--btn-primary);
  font-size: 18px;
  font-weight: 600;
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}

.step-btn:hover:not(:disabled) {
  background: rgba(46, 125, 50, 0.12);
}

.step-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.step-value {
  min-width: 38px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  transition: transform 0.18s ease;
}

.step-value.pulse {
  animation: numPulse 0.3s ease;
}

@keyframes numPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.25);
    color: var(--btn-primary);
  }
  100% {
    transform: scale(1);
  }
}

/* ----- CTA ----- */
.cta {
  width: 100%;
  height: 52px;
  border-radius: 14px;
  background: var(--btn-primary);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s ease;
  box-shadow: 0 6px 18px rgba(46, 125, 50, 0.3);
}

.cta:hover:not(:disabled) {
  background: var(--btn-hover);
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(46, 125, 50, 0.4);
}

.cta:active:not(:disabled) {
  transform: translateY(0);
}

.cta:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.cta-icon {
  font-size: 20px;
}

/* ----- SECONDARY BUTTONS ----- */
.secondary-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.secondary {
  height: 40px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  border: 1.5px solid;
  transition: all 0.18s ease;
}

.outlined-green {
  border-color: var(--btn-primary);
  color: var(--btn-primary);
}
.outlined-green:hover {
  background: rgba(46, 125, 50, 0.08);
}

.outlined-red {
  border-color: #B0BEC5;
  color: #607D8B;
}
.outlined-red:hover {
  border-color: #E57373;
  color: #C62828;
  background: rgba(229, 115, 115, 0.06);
}

/* ----- RESULT AREA ----- */
.result-area {
  min-height: 4px;
}

.result-card {
  position: relative;
  padding: 18px 18px 16px;
  background: var(--result-bg);
  border: 1.5px solid var(--result-border);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(255, 213, 79, 0.25);
  animation: resultIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

@keyframes resultIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-title {
  font-size: 14px;
  font-weight: 600;
  color: #B26500;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.result-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.result-pill {
  position: relative;
  padding: 8px 16px;
  background: #fff;
  border: 1.5px solid var(--accent-gold);
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(255, 215, 0, 0.25);
}

.history {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed rgba(178, 101, 0, 0.2);
}

.history-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #B26500;
  margin-bottom: 6px;
  font-weight: 500;
}

.history-item {
  font-size: 12px;
  color: #8D6E63;
  margin-bottom: 3px;
}

/* ----- CONFETTI ----- */
/* ----- BULK ADD PANEL ----- */
.bulk-add {
  border-radius: 14px;
  background: rgba(46, 125, 50, 0.04);
  border: 1px dashed rgba(46, 125, 50, 0.25);
  overflow: hidden;
  transition: background 0.2s;
}

.bulk-add[open] {
  background: rgba(46, 125, 50, 0.06);
}

.bulk-add-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #2E7D32;
  user-select: none;
  list-style: none;
}

.bulk-add-toggle::-webkit-details-marker { display: none; }

.bulk-add-toggle::after {
  content: "▾";
  margin-left: auto;
  font-size: 11px;
  transition: transform 0.2s;
}

.bulk-add[open] .bulk-add-toggle::after {
  transform: rotate(180deg);
}

.bulk-add-toggle:hover {
  color: #1B5E20;
}

.bulk-add-body {
  padding: 4px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bulk-textarea {
  width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
  color: #263238;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border-color 0.15s;
}

.bulk-textarea:focus {
  border-color: #2E7D32;
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.12);
}

.bulk-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.bulk-file-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid rgba(46, 125, 50, 0.4);
  color: #2E7D32;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.bulk-file-btn:hover {
  background: rgba(46, 125, 50, 0.08);
}

.bulk-file-btn:active {
  transform: scale(0.97);
}

.bulk-add-btn {
  margin-left: auto;
  padding: 8px 18px;
  border-radius: 999px;
  background: #2E7D32;
  color: #fff;
  border: 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.bulk-add-btn:hover { background: #1B5E20; }
.bulk-add-btn:active { transform: scale(0.97); }
.bulk-add-btn:disabled {
  background: #B0BEC5;
  cursor: not-allowed;
}

.bulk-hint {
  font-size: 11px;
  color: #607D8B;
}

.bulk-hint.error { color: #C62828; }
.bulk-hint.success { color: #2E7D32; }

/* ----- FAQ SECTION ----- */
.faq {
  max-width: 820px;
  margin: 32px auto 48px;
  padding: 28px 28px 12px;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 8px 32px rgba(46, 125, 50, 0.08);
  position: relative;
  z-index: 2;
}

.faq-heading {
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  font-size: 26px;
  color: #1B5E20;
  margin: 0 0 18px;
  text-align: center;
}

.faq-item {
  border-bottom: 1px solid rgba(46, 125, 50, 0.12);
  padding: 14px 4px;
  transition: background 0.15s;
}

.faq-item:last-child { border-bottom: 0; }

.faq-item summary {
  font-weight: 600;
  font-size: 15px;
  color: #263238;
  cursor: pointer;
  padding: 4px 36px 4px 4px;
  position: relative;
  list-style: none;
  outline: none;
  border-radius: 8px;
  transition: color 0.15s;
}

.faq-item summary::-webkit-details-marker { display: none; }

.faq-item summary::after {
  content: "+";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 22px;
  font-weight: 400;
  color: #2E7D32;
  transition: transform 0.2s;
  line-height: 1;
}

.faq-item[open] summary::after {
  content: "−";
}

.faq-item summary:hover { color: #2E7D32; }
.faq-item summary:focus-visible {
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.2);
}

.faq-item p {
  margin: 10px 4px 4px;
  color: #455A64;
  font-size: 14px;
  line-height: 1.65;
}

@media (max-width: 720px) {
  .faq {
    margin: 20px 12px 32px;
    padding: 22px 18px 8px;
    border-radius: 20px;
  }
  .faq-heading { font-size: 22px; }
  .faq-item summary { font-size: 14px; }
  .faq-item p { font-size: 13.5px; }
}

/* ----- WINNER PARTY OVERLAY ----- */
.party-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  overflow: hidden;
  z-index: 9999;
}

.party-piece {
  position: absolute;
  display: block;
  will-change: transform, opacity;
  transform: translate(0, 0) rotate(var(--rot-start, 0deg));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

@keyframes party-fall {
  0% {
    transform: translate(0, 0) rotate(var(--rot-start));
    opacity: 1;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translate(var(--end-x), var(--end-y)) rotate(var(--rot-end));
    opacity: 0;
  }
}

/* Bounce-in pop for the winner card */
.winner-pop {
  animation: winner-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes winner-pop {
  0%   { transform: scale(0.6); opacity: 0; }
  60%  { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  pointer-events: none;
  border-radius: 1px;
  opacity: 0;
  top: 50%;
  left: 50%;
  animation: confetti 1.2s ease-out forwards;
}

@keyframes confetti {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(var(--tx), var(--ty)) rotate(var(--rot));
  }
}

/* ----- FOOTER ----- */
.footer-links {
  margin-top: 6px;
  font-size: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}
.footer-sep { color: #B0BEC5; }
.footer-links a {
  color: #2E7D32;
  text-decoration: none;
  font-weight: 600;
  transition: color 0.15s;
}
.footer-links a:hover {
  color: #1B5E20;
  text-decoration: underline;
}

.panel-footer {
  margin-top: auto;
  padding-top: 12px;
  font-size: 11px;
  color: #90A4AE;
  text-align: center;
  border-top: 1px dashed rgba(0, 0, 0, 0.06);
}

/* ----- RESPONSIVE ----- */
@media (max-width: 900px) {
  /* Allow the whole page to scroll on mobile so users can reach the
     results panel and previous-picks history below the canvas. */
  html,
  body {
    height: auto;
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    padding: 12px;
    gap: 12px;
  }

  .canvas-wrap {
    order: -1;
    /* Fixed canvas height on mobile so it doesn't eat the whole viewport */
    height: 55vh;
    min-height: 320px;
  }

  .panel {
    /* Let the panel grow to its content; page scrolls instead of panel */
    overflow-y: visible;
    padding: 20px 18px 16px;
    gap: 14px;
  }

  .title {
    font-size: 26px;
  }
}

/* ============================================
   SITE NAVIGATION (top of page, all pages)
   ============================================ */
.site-nav {
  max-width: 1100px;
  margin: 18px auto 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px 10px 18px;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  box-shadow: 0 4px 18px rgba(46, 125, 50, 0.08);
  position: relative;
  z-index: 5;
}

.site-nav-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 18px;
  color: #1B5E20;
  text-decoration: none;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.site-nav-links {
  list-style: none;
  display: flex;
  gap: 4px;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
  white-space: nowrap;
}

.site-nav-links a {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: #455A64;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.site-nav-links a:hover {
  background: rgba(46, 125, 50, 0.08);
  color: #2E7D32;
}

.site-nav-links a[aria-current="page"] {
  background: #2E7D32;
  color: #ffffff;
}

@media (max-width: 720px) {
  .site-nav {
    margin: 12px 12px 8px;
    padding: 8px 10px 8px 14px;
    border-radius: 22px;
  }
  .site-nav-brand { font-size: 16px; }
  .site-nav-links a { padding: 6px 12px; font-size: 13px; }
}

/* On the home page (.app follows nav), pull the app a little closer to the
   nav and shave its min-height so the whole page still fits ~one viewport. */
.site-nav + .app {
  min-height: calc(100vh - 88px);
  padding-top: 8px;
}

/* ============================================
   OVERFLOW HANDLING WHEN MANY NAMES ARE ADDED
   ============================================
   Prior to this rule the chips list grew unbounded, stretching the whole
   panel taller than the viewport. body has overflow:hidden (intentional
   app-like layout) so the bottom controls + Throw Stone button became
   invisible with no way to scroll. Fix:
   1) Cap the chips list with its own internal scroll (max-height ~26vh)
      so input, bulk-add, throw button and footer always stay visible.
   2) Lock the .app grid row height to viewport-minus-nav and let
      min-height:0 on the panel allow internal scroll as a safety net. */
.chips {
  max-height: clamp(140px, 26vh, 280px);
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.18) transparent;
}
.chips::-webkit-scrollbar { width: 6px; }
.chips::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 3px;
}

/* Allow the panel (a grid item) to shrink below its intrinsic content height
   so its existing overflow-y:auto actually triggers scrolling. */
.panel { min-height: 0; }
.site-nav + .app { height: calc(100vh - 88px); }

/* On mobile the page scrolls naturally — don't double-scroll the chips. */
@media (max-width: 900px) {
  .chips {
    max-height: none;
    overflow-y: visible;
    padding-right: 0;
  }
  .site-nav + .app {
    height: auto;
    min-height: auto;
  }
}
