:root {
  --cream: #fff8ec;
  --paper: #fffdf8;
  --dough: #f4d9a8;
  --crust: #c98a45;
  --cocoa: #5a3417;
  --cocoa-soft: #7a5233;
  --berry: #e2556b;
  --mint: #2f9e7e;
  --line: #ecd9bd;
  --shadow: 0 6px 20px rgba(90, 52, 23, .12);
  --radius: 16px;
  --font: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0; font-family: var(--font); color: var(--cocoa);
  background: var(--cream) radial-gradient(circle at 20% 0%, #ffe9c7 0, transparent 45%) no-repeat;
  line-height: 1.6;
}
a { color: #b3541e; }
img, svg { max-width: 100%; }

/* ---------- Header / footer ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  max-width: 1200px; margin: 0 auto; padding: .75rem 1rem;
}
.logo { display: flex; align-items: center; gap: .5rem; font-weight: 900; font-size: 1.35rem; color: var(--cocoa); text-decoration: none; white-space: nowrap; }
.logo svg { width: 34px; height: 34px; }
.topbar nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.topbar nav a { color: var(--cocoa-soft); text-decoration: none; font-weight: 700; }
.topbar nav a:hover { color: var(--cocoa); text-decoration: underline; }
.site-footer { border-top: 1px solid var(--line); margin-top: 3rem; padding: 2rem 1rem; text-align: center; font-size: .9rem; color: var(--cocoa-soft); }
.site-footer nav { display: flex; justify-content: center; gap: 1.25rem; flex-wrap: wrap; margin-bottom: .5rem; }

/* ---------- Game layout ---------- */
.game {
  display: grid; grid-template-columns: minmax(300px, 5fr) 6fr; gap: 1rem;
  max-width: 1200px; margin: 0 auto; padding: 0 1rem;
}
.bake-area {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, #fff3df, #ffe6c2);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 1.25rem 1rem 1.5rem; min-height: 540px; text-align: center;
}
.bakery-name {
  background: none; border: 1px dashed transparent; border-radius: 8px; cursor: pointer;
  font: inherit; font-weight: 800; font-size: 1.1rem; color: var(--cocoa-soft); padding: .1rem .5rem;
}
.bakery-name:hover { border-color: var(--crust); }
.count { font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 900; line-height: 1.15; margin: .25rem 0 0; font-variant-numeric: tabular-nums; }
.count small { display: block; font-size: 1rem; font-weight: 700; color: var(--cocoa-soft); }
.per-sec { font-weight: 700; color: var(--cocoa-soft); margin-bottom: .5rem; font-variant-numeric: tabular-nums; }
.big-cookie {
  margin: 1rem auto; width: min(300px, 70vw); aspect-ratio: 1; padding: 0; border: 0; background: none;
  cursor: pointer; border-radius: 50%; -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 12px 18px rgba(90, 52, 23, .3)); transition: transform .1s ease;
  touch-action: manipulation; user-select: none;
}
.big-cookie:hover { transform: scale(1.03); }
.big-cookie:active { transform: scale(.95); }
.big-cookie.bump { animation: bump .15s ease; }
.big-cookie:focus-visible { outline: 4px solid var(--berry); outline-offset: 6px; }
.big-cookie svg { width: 100%; height: 100%; display: block; animation: spin 60s linear infinite; }
@keyframes bump { 50% { transform: scale(.93); } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .big-cookie svg { animation: none; } }

.buffs { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; min-height: 1.8rem; }
.buff { background: var(--berry); color: #fff; padding: .15rem .6rem; border-radius: 999px; font-weight: 800; font-size: .85rem; }
.rebake { margin-top: auto; }

.lucky-star {
  position: absolute; z-index: 5; width: 64px; height: 64px; border: 0; padding: 0; background: none; cursor: pointer;
  font-size: 52px; line-height: 64px; animation: twinkle 1.2s ease-in-out infinite; filter: drop-shadow(0 0 10px #ffd34d);
}
@keyframes twinkle { 50% { transform: scale(1.18) rotate(12deg); } }

/* ---------- Shop ---------- */
.shop { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 540px; max-height: 80vh; }
.tabs { display: flex; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
  flex: 1; background: none; border: 0; border-bottom: 3px solid transparent; padding: .8rem .6rem; font: inherit; font-weight: 800;
  color: var(--cocoa-soft); cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--cocoa); border-bottom-color: var(--crust); }
.badge { display: inline-block; min-width: 1.3em; background: var(--berry); color: #fff; border-radius: 999px; font-size: .75rem; padding: 0 .35em; margin-left: .25rem; }
.badge:empty { display: none; }
.tab-panel { overflow-y: auto; padding: .75rem; flex: 1; }
.buy-amount { display: flex; gap: .35rem; align-items: center; margin-bottom: .6rem; font-weight: 700; font-size: .9rem; }
.buy-amount button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: .2rem .6rem; font: inherit; font-weight: 800; cursor: pointer; color: var(--cocoa); }
.buy-amount button.active { background: var(--cocoa); color: #fff; border-color: var(--cocoa); }

.building, .upgrade {
  display: flex; align-items: center; gap: .75rem; width: 100%; text-align: left; font: inherit; color: inherit;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .6rem .75rem; margin-bottom: .5rem;
  cursor: pointer; opacity: .55; transition: transform .08s, opacity .2s, border-color .2s;
}
.building.affordable, .upgrade.affordable { opacity: 1; border-color: var(--crust); }
.building.affordable:hover, .upgrade.affordable:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(90,52,23,.12); }
.building.mystery { cursor: default; opacity: .4; }
.b-icon, .u-icon { font-size: 2rem; width: 2.6rem; height: 2.6rem; line-height: 2.6rem; text-align: center; flex-shrink: 0; overflow: hidden; white-space: nowrap; }
.b-main, .u-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.b-name, .u-name { font-weight: 800; }
.b-desc, .u-desc { font-size: .8rem; color: var(--cocoa-soft); line-height: 1.35; }
.b-cost { font-weight: 800; font-size: .9rem; color: var(--mint); }
.u-cost { font-weight: 800; font-size: .9rem; color: var(--mint); white-space: nowrap; }
.building:not(.affordable) .b-cost, .upgrade:not(.affordable) .u-cost { color: var(--berry); }
.b-owned { font-size: 1.8rem; font-weight: 900; color: var(--dough); -webkit-text-stroke: 1px var(--crust); min-width: 2ch; text-align: right; }
.empty { color: var(--cocoa-soft); text-align: center; padding: 2rem 1rem; }

.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .5rem; }
.ach { display: flex; gap: .6rem; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .5rem .6rem; opacity: .5; }
.ach.got { opacity: 1; border-color: #e7b75f; background: #fffaf0; }
.ach strong { display: block; font-size: .9rem; }
.ach small { display: block; font-size: .75rem; color: var(--cocoa-soft); line-height: 1.3; }
.a-icon { font-size: 1.5rem; }

.stats-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.stats-table th, .stats-table td { padding: .4rem .3rem; border-bottom: 1px solid var(--line); text-align: left; }
.stats-table td { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.options { margin-top: 1rem; display: grid; gap: .6rem; }
.options label { display: flex; gap: .5rem; align-items: center; font-weight: 700; }
.options textarea { width: 100%; min-height: 70px; font-family: monospace; font-size: .75rem; border: 1px solid var(--line); border-radius: 8px; padding: .5rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 10px; padding: .55rem 1rem; font: inherit; font-weight: 800; cursor: pointer;
  background: var(--dough); color: var(--cocoa);
}
.btn.primary { background: var(--cocoa); color: #fff; }
.btn.danger { background: #fde2e2; color: #a12b2b; }
.btn:disabled { opacity: .6; cursor: default; }

/* ---------- Effects ---------- */
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.float-num { position: fixed; transform: translate(-50%, -50%); font-weight: 900; font-size: 1.3rem; color: var(--cocoa); text-shadow: 0 1px 0 #fff, 0 0 6px #fff; animation: floatUp .9s ease-out forwards; }
@keyframes floatUp { to { transform: translate(-50%, -150%); opacity: 0; } }
.crumb { position: fixed; width: 7px; height: 7px; border-radius: 40%; background: var(--crust); animation: crumbFly .7s ease-out forwards; }
@keyframes crumbFly { to { transform: translate(var(--dx), var(--dy)) rotate(200deg); opacity: 0; } }
.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: .4rem; align-items: center; width: min(92vw, 420px); }
.toast { background: var(--cocoa); color: #fff; padding: .55rem 1rem; border-radius: 12px; font-weight: 700; box-shadow: var(--shadow); transition: opacity .4s, transform .4s; text-align: center; }
.toast.out { opacity: 0; transform: translateY(8px); }

dialog { border: 0; border-radius: var(--radius); padding: 1.5rem; max-width: min(92vw, 420px); text-align: center; color: var(--cocoa); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(60, 35, 15, .45); }
dialog h2 { margin-top: 0; }
.big-gain { font-size: 1.8rem; font-weight: 900; margin: .25rem 0; }
.muted { color: var(--cocoa-soft); font-size: .85rem; }
#modal-actions { display: flex; gap: .5rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }

/* ---------- Ad slots (reserve space to avoid layout shift) ---------- */
.ad-slot { max-width: 1200px; margin: 1.25rem auto; padding: 0 1rem; min-height: 0; }
.ad-slot:empty { display: none; }

/* ---------- Content pages ---------- */
.content { max-width: 820px; margin: 2.5rem auto 0; padding: 0 1rem; }
.content h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); line-height: 1.2; }
.content h2 { margin-top: 2.2rem; font-size: 1.5rem; border-bottom: 2px solid var(--line); padding-bottom: .3rem; }
.content h3 { margin-top: 1.5rem; }
.content table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: .95rem; background: #fff; border-radius: 12px; overflow: hidden; }
.content th, .content td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); text-align: left; }
.content thead th { background: var(--dough); }
.content .tip { background: #fff; border-left: 4px solid var(--crust); padding: .75rem 1rem; border-radius: 0 12px 12px 0; }
.content details { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .75rem 1rem; margin: .5rem 0; }
.content summary { font-weight: 800; cursor: pointer; }
.table-wrap { overflow-x: auto; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  .game { grid-template-columns: minmax(0, 1fr); }
  .tabs button { padding: .7rem .45rem; font-size: .9rem; }
  .bake-area { min-height: 0; }
  .shop { max-height: none; min-height: 0; }
  .tab-panel { max-height: 70vh; }
  .topbar nav { gap: .6rem; font-size: .9rem; }
}
@media (max-width: 480px) {
  .topbar nav a:not(:first-child) { display: none; }
}
