/* ===========================
   Cookie Chaos — Base Styles
   =========================== */

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

:root {
  --bg: #1a0a00;
  --surface: #2b1500;
  --accent: #ff8c00;
  --accent-soft: #ffb347;
  --text: #ffe8c0;
  --text-muted: #a07040;
  --border: #3d2200;
  --cookie-size: 180px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ── Layout ── */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#header {
  text-align: center;
  padding: 1rem;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
}

#header h1 {
  font-size: 2rem;
  color: var(--accent);
  letter-spacing: 0.05em;
}

#header #tagline {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

#game {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr auto 260px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "score  clicker  shop"
    "score  clicker  shop";
  gap: 0;
}

/* ── Score Panel ── */

#score-panel {
  grid-area: score;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  border-right: 1px solid var(--border);
}

#cookie-count {
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--accent);
}

#cookie-label {
  font-size: 1.2rem;
  color: var(--text-muted);
}

#rate-display {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

#click-rate-display {
  margin-top: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

#ascension-display {
  display: none;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--accent-soft);
  text-align: center;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
}

#ascension-bonus {
  font-weight: 700;
  color: var(--accent);
}

/* Ascend button — hidden by default, shown when eligible */
#ascend-btn {
  display: none;
  flex-direction: column;
  align-items: center;
  margin-top: 1rem;
  padding: 0.75rem 1.25rem;
  border: 2px solid gold;
  border-radius: 8px;
  background: linear-gradient(135deg, #1a0f00, #2e1d00);
  color: gold;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.04em;
  box-shadow: 0 0 16px #ffd70044;
  transition: box-shadow 0.2s, transform 0.15s;
  width: 100%;
}
#ascend-btn:hover {
  box-shadow: 0 0 32px #ffd70088;
  transform: scale(1.03);
}
#ascend-btn:active {
  transform: scale(0.97);
}
.ascend-sub {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.7;
  margin-top: 0.2rem;
  letter-spacing: 0;
}

#cps, #cpc {
  color: var(--accent-soft);
  font-weight: 600;
}

/* ── Clicker Area ── */

#clicker-area {
  grid-area: clicker;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

#big-cookie {
  width: var(--cookie-size);
  height: var(--cookie-size);
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 35% 35%, #f4a830, #c06800);
  cursor: pointer;
  font-size: 5rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 30px #ff8c0055, 0 4px 20px #0008;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  user-select: none;
}

#big-cookie:hover {
  transform: scale(1.05);
  box-shadow: 0 0 50px #ff8c0088, 0 4px 24px #0008;
}

/* :active kept subtle — the real feel comes from the JS .clicking animation */
#big-cookie:active {
  transform: scale(0.95);
}

#big-cookie.clicking {
  animation: cookie-bounce 0.38s cubic-bezier(0.36, 0.07, 0.19, 0.97) forwards;
}

@keyframes cookie-bounce {
  0%   { transform: scale(1); }
  20%  { transform: scale(0.88); }
  55%  { transform: scale(1.10); }
  75%  { transform: scale(0.97); }
  100% { transform: scale(1); }
}

#click-feedback {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 1.2em;
  text-align: center;
}

/* ── Shop / Upgrades ── */

#shop {
  grid-area: shop;
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  padding: 1.25rem 1rem;
}

#shop h2 {
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

#shop-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 2rem;
}

#upgrade-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.upgrade-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.upgrade-item.affordable {
  cursor: pointer;
  border-color: var(--accent);
  box-shadow: 0 0 8px #ff8c0033;
}

.upgrade-item.affordable:hover {
  background: #2f1800;
  box-shadow: 0 0 16px #ff8c0066;
}

.upgrade-item.locked {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: var(--border);
}

.upgrade-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-soft);
}

.upgrade-cost {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.upgrade-flavour {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  font-style: italic;
}

/* ── Chaos Ticker ── */

#chaos-ticker {
  text-align: center;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

.floater {
  position: fixed;
  pointer-events: none;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  transform: translate(-50%, -50%);
  animation: floatArc 1s ease-out forwards;
  z-index: 999;
}

@keyframes floatArc {
  0%   { opacity: 1;   transform: translate(calc(-50% + 0px),              -50%)  scale(1.2); }
  40%  { opacity: 1;   transform: translate(calc(-50% + var(--drift, 0px)), -200%) scale(1); }
  100% { opacity: 0;   transform: translate(calc(-50% + calc(var(--drift, 0px) * 1.6)), -320%) scale(0.75); }
}

/* ── Responsive (narrow screens) ── */

@media (max-width: 700px) {
  #game {
    grid-template-columns: 1fr;
    grid-template-areas:
      "score"
      "clicker"
      "shop";
  }

  #score-panel, #shop {
    border: none;
    border-bottom: 1px solid var(--border);
  }
}

/* ── Save toast ── */

#save-toast {
  position: fixed;
  bottom: 2.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent-soft);
  font-size: 0.82rem;
  padding: 0.45rem 1rem;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 1001;
  white-space: nowrap;
}
#save-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Chaos level themes ─────────────────────────────────────────────────────
   Body classes chaos-0 through chaos-5 override CSS variables.
   CSS custom properties don't animate, so level change is instant —
   the milestone popup and chaos-transitioning flash provide the moment. */

body.chaos-0 {
  --bg: #1a0a00; --surface: #2b1500; --accent: #ff8c00;
  --accent-soft: #ffb347; --border: #3d2200; --text-muted: #a07040;
}
body.chaos-1 {
  --bg: #1d0800; --surface: #2f1200; --accent: #ff7000;
  --accent-soft: #ffaa33; --border: #421c00; --text-muted: #9a6838;
}
body.chaos-2 {
  --bg: #220500; --surface: #340900; --accent: #ff3d00;
  --accent-soft: #ff7033; --border: #4a1000; --text-muted: #a05030;
}
body.chaos-3 {
  --bg: #200010; --surface: #2d0018; --accent: #ff1155;
  --accent-soft: #ff5577; --border: #45001f; --text-muted: #994466;
}
body.chaos-4 {
  --bg: #0d0018; --surface: #160025; --accent: #bb00ff;
  --accent-soft: #dd55ff; --border: #310055; --text-muted: #7a44aa;
}
body.chaos-5 {
  --bg: #04000f; --surface: #0c001e; --accent: #5500ff;
  --accent-soft: #9944ff; --border: #1e0044; --text-muted: #5533aa;
}

/* Eldritch pulse at max chaos */
body.chaos-5 #big-cookie {
  animation: eldritch-pulse 2.5s ease-in-out infinite !important;
}
@keyframes eldritch-pulse {
  0%, 100% {
    box-shadow: 0 0 30px var(--accent), 0 4px 20px #0008;
    filter: hue-rotate(0deg) saturate(1);
  }
  50% {
    box-shadow: 0 0 90px var(--accent), 0 0 60px var(--accent-soft), 0 4px 40px #000c;
    filter: hue-rotate(40deg) saturate(1.5);
  }
}

/* Flash overlay for chaos level transitions */
body.chaos-transitioning::after {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--accent);
  pointer-events: none;
  z-index: 998;
  animation: chaos-flash 0.9s ease-out forwards;
}
@keyframes chaos-flash {
  0%   { opacity: 0.35; }
  100% { opacity: 0; }
}

/* ── Milestone overlay ── */

#milestone-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
#milestone-overlay.visible {
  opacity: 1;
}
#milestone-content {
  text-align: center;
  padding: 2rem 3rem;
  max-width: 600px;
}
#milestone-title {
  font-size: clamp(1.8rem, 6vw, 3.2rem);
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 0 40px var(--accent), 0 0 80px var(--accent-soft);
  animation: milestone-pop 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
#milestone-sub {
  margin-top: 1.2rem;
  font-size: clamp(0.9rem, 2.5vw, 1.15rem);
  color: var(--text);
  font-style: italic;
  opacity: 0.85;
  line-height: 1.5;
}
@keyframes milestone-pop {
  0%   { transform: scale(0.6); opacity: 0; }
  70%  { transform: scale(1.06); }
  100% { transform: scale(1);   opacity: 1; }
}
