/* ChiliClicker -- warm dark theme.
   Layout is three columns: the chili, the upgrades, the store. */

:root {
  --bg: #14090b;
  --bg-2: #1e1013;
  --panel: #241417;
  --panel-2: #2c191d;
  --line: #3a2226;
  --text: #f6e6e2;
  --muted: #b08d87;
  --dim: #7a5c58;
  --red: #e0231c;
  --red-2: #ff6b4a;
  --orange: #ff8a3d;
  --gold: #ffc93c;
  --green: #57ad57;
  --bad: #c2417a;
  --radius: 10px;
  --shadow: 0 6px 22px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(1100px 700px at 18% -10%, #3a1618 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 0%, #2a1220 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- top bar ---------- */

/* env() is 0 wherever there is no notch, so max() leaves desktop untouched
   and only pushes content clear on the phones that need it. */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: max(10px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
           10px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(20, 9, 11, .7);
  backdrop-filter: blur(8px);
  flex: none;
}

.topbar h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -.3px;
  color: var(--red-2);
}
.topbar h1 span { color: var(--text); font-weight: 500; }

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

.pill {
  display: flex;
  gap: 6px;
  align-items: baseline;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--panel);
  font-size: 12px;
}
.pill label { color: var(--dim); text-transform: uppercase; letter-spacing: .06em; font-size: 10px; }
.pill b { font-variant-numeric: tabular-nums; }

.topbar nav { margin-left: auto; display: flex; gap: 8px; }

.ghost {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  transition: background .12s, border-color .12s, transform .08s;
}
.ghost:hover { background: var(--panel-2); border-color: #55323a; }
.ghost:active { transform: translateY(1px); }
.ghost b { color: var(--gold); font-variant-numeric: tabular-nums; }

/* ---------- main grid ---------- */

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(320px, 1.15fr) minmax(300px, .95fr);
  gap: 14px;
  padding: 14px max(18px, env(safe-area-inset-right))
           max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.panel h2 em { color: var(--dim); font-style: normal; font-size: 11px; }

/* ---------- clicker column ---------- */

.clicker {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 0;
}

.counter { text-align: center; }

.count {
  font-size: clamp(28px, 3.4vw, 44px);
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.count small { font-size: .42em; font-weight: 500; color: var(--muted); }
.rate { color: var(--orange); font-variant-numeric: tabular-nums; font-size: 15px; }

.chili-stage { position: relative; display: grid; place-items: center; margin: 4px 0; }

.chili {
  background: none;
  border: 0;
  padding: 0;
  width: clamp(180px, 22vw, 280px);
  aspect-ratio: 200 / 240;
  filter: drop-shadow(0 14px 26px rgba(224, 35, 28, .3));
  transition: transform .09s cubic-bezier(.34, 1.8, .64, 1);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.chili svg { width: 100%; height: 100%; display: block; }
.chili:hover { transform: scale(1.03); }
.chili.hit { transform: scale(.92); }
.chili:focus-visible { outline: 2px solid var(--gold); outline-offset: 10px; border-radius: 20px; }
.chili .glow { animation: breathe 4s ease-in-out infinite; transform-origin: center; }

@keyframes breathe {
  0%, 100% { opacity: .55; transform: scale(1); }
  50%      { opacity: .9;  transform: scale(1.07); }
}

.particles { position: absolute; inset: 0; pointer-events: none; }

.particle {
  position: absolute;
  font-weight: 700;
  font-size: 17px;
  color: var(--gold);
  text-shadow: 0 2px 8px rgba(0, 0, 0, .7);
  animation: float-up .9s ease-out forwards;
  white-space: nowrap;
}

@keyframes float-up {
  0%   { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -85px) scale(1.25); }
}

/* ---------- pepper weevils ---------- */

.weevils { position: absolute; inset: 0; pointer-events: none; }

/* The button is the hit box and nothing else: 44px, and its transform is the
   centring translate, never an animation. Everything that moves lives on the
   glyph inside.

   It used to animate directly, and `:active` shrank it to 70% -- so pressing
   slightly off-centre shrank the button out from under the cursor before
   mouseup, no click event fired, and popping one took several attempts. */
.weevil {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  background: none;
  border: 0;
  padding: 0;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
}

.weevil .bug {
  display: block;
  font-size: 22px;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .6));
  /* `rotate` is its own property, so the gnaw and these scales compose
     instead of overwriting one another. */
  animation: weevil-gnaw 1.6s ease-in-out infinite;
  transition: transform .1s;
}
.weevil:hover .bug { transform: scale(1.35); }
.weevil:active .bug { transform: scale(.8); }

/* A pop should look like a pop even though the node vanishes a frame later. */
.weevil.popping { pointer-events: none; }
.weevil.popping .bug { animation: none; transform: scale(2.2); opacity: 0;
                       transition: transform .25s ease-out, opacity .25s ease-out; }
.weevil::after {
  content: attr(data-eaten);
  position: absolute;
  left: 50%;
  top: -14px;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  color: var(--bad);
  white-space: nowrap;
  opacity: 0;
  transition: opacity .12s;
}
.weevil:hover::after { opacity: 1; }

@keyframes weevil-gnaw {
  0%, 100% { rotate: -8deg; }
  50%      { rotate: 8deg; }
}

.weevil-note {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.weevil-note b { color: var(--bad); }

.perclick { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.perclick b { color: var(--text); }

.buffs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: 30px; }

.buff {
  position: relative;
  overflow: hidden;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--gold);
  color: var(--gold);
  background: rgba(255, 201, 60, .1);
}
.buff.bad { border-color: var(--bad); color: var(--bad); background: rgba(194, 65, 122, .12); }
.buff .bar {
  position: absolute;
  left: 0; bottom: 0; height: 2px;
  background: currentColor;
  transition: width .2s linear;
}

/* ---------- upgrades ---------- */

/* A scrolling list rather than a grid of glyphs: an upgrade is a decision,
   and a decision needs a name, a price and a consequence side by side. */
.upg-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  padding-right: 4px;
  max-height: 58%;
  min-height: 0;
}

.upg {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 7px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  opacity: .62;
  transition: transform .1s, opacity .12s, border-color .12s, background .12s;
}
.upg .icon { font-size: 20px; text-align: center; line-height: 1; }
.upg .body { min-width: 0; }
.upg .row1 { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.upg .name {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upg .price { color: var(--gold); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.upg .row2 {
  font-size: 11.5px;
  color: var(--green);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upg.can { opacity: 1; border-color: var(--green); box-shadow: 0 0 0 1px rgba(87, 173, 87, .22); }
.upg.can:hover { transform: translateX(2px); background: #24301f; }

/* Locked rows stay legible -- they are the goal, not noise. */
.upg.locked { opacity: .42; cursor: default; filter: grayscale(.55); }
.upg.locked .price { color: var(--dim); }
.upg.locked .row2 { color: var(--muted); }
.upg:hover { border-color: var(--gold); }

/* A refused click has to look refused, or it reads as a dead control. */
@keyframes denied-shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}
.denied { animation: denied-shake .22s ease-in-out; }

.empty { color: var(--dim); font-size: 13px; margin: 8px 2px; }

.log-title { margin-top: 14px !important; }
.log {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  font-size: 12.5px;
  color: var(--muted);
}
.log li { padding: 3px 0; border-bottom: 1px solid rgba(58, 34, 38, .5); }
.log li:first-child { color: var(--text); }

/* ---------- store ---------- */

.modes { display: flex; gap: 8px; margin-bottom: 10px; }

.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
}
.seg button {
  background: none;
  border: 0;
  padding: 5px 11px;
  font-size: 12px;
  color: var(--muted);
  transition: background .12s, color .12s;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--red); color: #fff; }
#buy-mode button.on[data-mode="sell"] { background: var(--bad); }

.gens { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; flex: 1; min-height: 0; padding-right: 4px; }

.gen {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 11px;
  text-align: left;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  opacity: .5;
  filter: grayscale(.6);
  transition: transform .1s, opacity .12s, border-color .12s, filter .12s, background .12s;
}
.gen.can { opacity: 1; filter: none; }
.gen.can:hover { transform: translateX(2px); border-color: var(--red-2); background: #33191e; }
.gen .icon { font-size: 26px; text-align: center; line-height: 1; }
.gen .name { font-weight: 600; font-size: 14px; }
.gen .cost { font-size: 12.5px; color: var(--gold); font-variant-numeric: tabular-nums; }
.gen.can .cost::before { content: "🌶️ "; font-size: 10px; }
.gen .yield {
  font-size: 11.5px;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}
.gen:not(.can) .yield { color: var(--dim); }
.milestone-note {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.milestone-note b { color: var(--green); }
.milestone-note.close b { color: var(--gold); }

/* Ascending is what gives the late game its rhythm; say so. */
.ghost.ready {
  background: var(--red);
  border-color: var(--red-2);
  color: #fff;
  animation: ascend-ready 2.2s ease-in-out infinite;
}
@keyframes ascend-ready {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224, 35, 28, .55); }
  50%      { box-shadow: 0 0 0 7px rgba(224, 35, 28, 0); }
}
.gen .owned {
  font-size: 21px;
  font-weight: 700;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.gen.owns .owned { color: var(--text); }
.sell-mode .gen { border-style: dashed; }

/* ---------- golden chili ---------- */

.golden { position: fixed; z-index: 40; }
.golden button {
  background: none;
  border: 0;
  font-size: 46px;
  padding: 8px;
  filter: drop-shadow(0 0 16px var(--gold)) saturate(.35) brightness(1.7) sepia(.7) hue-rotate(-12deg);
  animation: golden-pulse 1.1s ease-in-out infinite;
}
@keyframes golden-pulse {
  0%, 100% { transform: scale(1) rotate(-6deg); }
  50%      { transform: scale(1.18) rotate(6deg); }
}

/* A chain in progress announces itself: each link is worth more. */
.golden.chained::after {
  content: attr(data-label);
  position: absolute;
  left: 50%;
  top: -6px;
  transform: translateX(-50%);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(0, 0, 0, .9);
  white-space: nowrap;
  pointer-events: none;
}
.golden.chained button { animation-duration: .55s; }

/* ---------- tooltip ---------- */

.tooltip {
  position: fixed;
  z-index: 60;
  max-width: 290px;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #180c0f;
  box-shadow: var(--shadow);
  font-size: 13px;
  pointer-events: none;
}
.tooltip h3 { margin: 0 0 3px; font-size: 14px; }
.tooltip .price { color: var(--gold); font-variant-numeric: tabular-nums; margin-bottom: 6px; }
.tooltip .effect { color: var(--green); }
.tooltip .gain {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.tooltip .locked-note { color: var(--muted); margin-top: 4px; }
.tooltip .flavor { color: var(--dim); font-style: italic; margin-top: 6px; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  /* On desktop this corner is empty space. Stacked on a phone it is the
     upgrade list, and a fixed overlay sitting there ate taps meant for the
     row underneath for as long as the toast lived. Toasts are read, not
     operated, so pointers pass through them -- and only the sticky one,
     which has to be dismissible, takes them back. */
  pointer-events: none;
}

.toast {
  border: 1px solid var(--gold);
  background: #241a06;
  color: var(--gold);
  border-radius: 10px;
  padding: 9px 14px;
  box-shadow: var(--shadow);
  animation: toast-in .28s ease-out, toast-out .4s ease-in 5.2s forwards;
  max-width: 320px;
}
.toast b { display: block; font-size: 13.5px; }
.toast span { font-size: 12px; opacity: .85; }

/* "While you were away" is the one message a returning player must not miss,
   and it is the only one whose number is otherwise unrecoverable. A phone
   spends the seconds after unlocking waking, repainting and reconnecting --
   the client alone waits up to a second before retrying the socket -- which
   eats most of the 5.2s the transient toasts get. So this one waits to be
   dismissed rather than expiring on a timer. */
.toast.sticky {
  animation: toast-in .28s ease-out;
  pointer-events: auto;
  cursor: pointer;
}
.toast.sticky::after {
  content: 'Tap to dismiss';
  display: block;
  margin-top: 6px;
  font-size: 11px;
  opacity: .55;
}
.toast.bad { border-color: var(--bad); background: #260c18; color: #ff9ec4; }
.toast.ascend { border-color: var(--red-2); background: #2a1008; color: var(--red-2); }
.toast.info { border-color: var(--line); background: var(--panel); color: var(--muted); }

@keyframes toast-in  { from { opacity: 0; transform: translateX(20px); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(20px); } }

/* ---------- dialogs ---------- */

.dlg {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-2);
  color: var(--text);
  padding: 22px;
  width: min(560px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.dlg.wide { width: min(880px, 94vw); }
.dlg::backdrop { background: rgba(8, 4, 5, .72); backdrop-filter: blur(3px); }
.dlg h2 { margin: 0 0 6px; font-size: 19px; }
.dlg h2 em { font-style: normal; font-size: 13px; color: var(--muted); }
.lede { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }
.dlg footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.danger {
  background: var(--red);
  border: 1px solid var(--red-2);
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
}
.danger:disabled { opacity: .4; cursor: not-allowed; }
.danger.confirm { background: var(--bad); border-color: var(--bad); }

.asc-stats { display: flex; gap: 22px; margin-bottom: 16px; flex-wrap: wrap; }
.asc-stats label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--dim); }
.asc-stats b { font-size: 20px; color: var(--gold); font-variant-numeric: tabular-nums; }

.asc-upgrades { display: flex; flex-direction: column; gap: 8px; max-height: 42vh; overflow-y: auto; }

.asc-tabs { display: flex; gap: 6px; margin: 0 0 12px; }
.asc-tabs button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--muted);
}
.asc-tabs button.on { background: var(--red); border-color: var(--red-2); color: #fff; }

.asc-vault { display: flex; flex-direction: column; gap: 5px; max-height: 42vh; overflow-y: auto; }

.vault-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: center;
  text-align: left;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  transition: border-color .12s, background .12s, opacity .12s;
}
.vault-row .mark { font-size: 13px; text-align: center; }
.vault-row .body { min-width: 0; display: block; }
.vault-row .n { display: block; font-weight: 600; font-size: 13px; }
.vault-row .e {
  display: block;
  font-size: 11.5px;
  color: var(--green);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vault-row:hover:not(:disabled) { border-color: var(--gold); background: var(--panel-2); }
.vault-row.kept { border-color: var(--gold); background: #241a06; }
.vault-row:disabled { opacity: .35; cursor: not-allowed; }

.asc {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  text-align: left;
  width: 100%;
}
.asc:disabled { opacity: .45; cursor: not-allowed; }
.asc.owned { border-color: var(--green); opacity: 1; }
.asc .n { font-weight: 600; }
.asc .e { font-size: 12px; color: var(--green); }
.asc .f { font-size: 12px; color: var(--dim); font-style: italic; }
.asc .c { color: var(--gold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.asc.owned .c { color: var(--green); }

.ach-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 8px;
  max-height: 62vh;
  overflow-y: auto;
}
.ach {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  opacity: .42;
}
.ach.got { opacity: 1; border-color: var(--gold); }
.ach b { display: block; font-size: 13px; }
.ach span { font-size: 12px; color: var(--muted); }

/* ---------- misc ---------- */

.disconnected {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--bad);
  color: #fff;
  padding: 8px 18px;
  border-radius: 99px;
  font-size: 13px;
}

.version-skew {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 90;
  background: var(--gold);
  color: #241a06;
  padding: 8px 18px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}

::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #43262c; border-radius: 9px; }
::-webkit-scrollbar-thumb:hover { background: #5a3239; }

@media (max-width: 1080px) {
  main { grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; overflow-y: auto; }
  .clicker { grid-column: 1 / -1; }
  body { overflow: auto; }
}

@media (max-width: 1080px) and (min-width: 721px) {
  /* Two columns still share a 1fr row, so the same squeeze applies here in
     miniature: give the list a floor rather than letting it round to zero. */
  .upg-list { min-height: 180px; }
}

@media (max-width: 720px) {
  main { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }

  /* On a phone the *page* scrolls, not the layout box. Desktop sizes `main`
     to the viewport (`flex: 1`) and lets panels compress (`min-height: 0`)
     so three columns always fit on one screen; stacked, that same rule
     squeezed three rows into one screenful and every panel then overflowed
     its row -- the chili drew across the upgrades, the upgrades across the
     store, and the 1fr row left for upgrades was 30px, which collapsed
     .upg-list to zero while it held 50 rendered rows.
     Undo the viewport fit and let each row be as tall as its content. */
  main {
    grid-template-rows: none;
    flex: none;
    min-height: auto;
    overflow: visible;
  }
  .panel, .clicker { min-height: auto; }

  /* Centring overflows in both directions when content outgrows the box,
     and the half that goes up vanishes under the top bar -- taking the
     chili count with it. Stack from the top instead. */
  .clicker { justify-content: flex-start; }

  /* Content-height now, so the list needs its own cap or it runs to fifty
     screens; the floor keeps it a usable list on a short phone. */
  .upg-list { max-height: 60vh; min-height: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
