:root {
  --bg: #070b14;
  --panel: #0f172a;
  --panel2: #141d33;
  --line: #1f2a44;
  --text: #e2e8f0;
  --muted: #8b9ab3;
  --accent: #2dd4bf;
  --accent-ink: #042f2e;
  --gold: #fde047;
  --danger: #fb7185;
  --radius: 10px;
  --app-h: 100vh;
}
@supports (height: 100dvh) { :root { --app-h: 100dvh; } }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

#app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top" "scene shop";
  height: var(--app-h);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* ---- header ---- */
.top {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 800; color: var(--text); text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.top nav { display: flex; align-items: center; gap: 8px; }
.play-td {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  padding: 6px 10px;
  border: 1px solid rgba(45, 212, 191, 0.4);
  border-radius: 8px;
}
.play-td:hover { background: rgba(45, 212, 191, 0.1); }
#btnStats {
  display: grid; place-items: center;
  width: 36px; height: 34px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
#btnMute {
  display: grid; place-items: center;
  width: 36px; height: 34px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
#btnMute svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#btnMute .spk { fill: var(--text); }
#btnMute .off, #btnMute.muted .on { display: none; }
#btnMute.muted .off { display: inline; }
#btnMute.muted svg { stroke: var(--muted); }
#btnMute.muted .spk { fill: var(--muted); }
@media (max-width: 400px) { .play-td .wide { display: none; } }
#btnStats svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 2.2; stroke-linecap: round; }

/* ---- the owl's field ---- */
#scene { grid-area: scene; position: relative; min-height: 0; overflow: hidden; }
#field {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: manipulation;
  cursor: pointer;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
}
.ticker {
  position: absolute; left: 0; right: 0; top: 0; z-index: 1;
  height: 24px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  background: rgba(2, 6, 15, 0.55);
  border-bottom: 1px solid rgba(31, 42, 68, 0.8);
  font-size: 12.5px; color: #cbd5e1;
  cursor: pointer;
}
.ticker:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ticker .caret { flex: none; color: var(--muted); font-size: 11px; transition: transform 0.2s, color 0.2s; }
.ticker:hover .caret, .ticker[aria-expanded="true"] .caret { color: var(--text); }
.ticker[aria-expanded="true"] .caret { transform: rotate(180deg); }
.tick-bell { flex: none; position: relative; display: grid; place-items: center; margin-right: -4px; }
.tick-bell svg { width: 15px; height: 15px; fill: none; stroke: var(--gold); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.lately-count {
  position: absolute; left: 9px; top: -6px;
  min-width: 14px; height: 14px; padding: 0 3px; border-radius: 7px;
  background: var(--danger); color: #fff; font-size: 9.5px; font-weight: 800; line-height: 14px; text-align: center;
}
.lately {
  position: absolute; left: 8px; right: 8px; top: 28px; z-index: 3;
  max-width: 520px; max-height: calc(100% - 36px); margin: 0 auto;
  display: flex; flex-direction: column;
  background: rgba(15, 23, 42, 0.97);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 13px; line-height: 1.35;
}
.lately-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 6px 14px; border-bottom: 1px solid var(--line); }
.lately-head h3 { margin: 0; font-size: 15px; }
.lately-head .close-x { width: 32px; height: 32px; }
.lately-body { overflow-y: auto; padding: 2px 14px 8px; overscroll-behavior: contain; }
.lately h4 { margin: 10px 0 0; color: var(--gold); font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.lately ol { list-style: none; margin: 0; padding: 0; }
.lately li { padding: 6px 0; border-top: 1px solid var(--line); color: #cbd5e1; }
.lately li:first-child { border-top: 0; }
.lately li b { color: var(--text); }
.lately li .story { display: block; color: var(--muted); font-style: italic; }
.lately li small { display: block; color: var(--muted); font-size: 11px; }
.lately li.empty { color: var(--muted); }
body.ending .lately { display: none; }
.ticker .tag { flex: none; color: var(--gold); font-weight: 800; font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; }
.tick-win { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; }
#tickText { display: inline-block; }
.end-skip {
  position: absolute; right: 12px; top: 34px; z-index: 2;
  padding: 5px 14px; border-radius: 8px; cursor: pointer;
  background: rgba(15, 23, 42, 0.85); border: 1px solid var(--line); color: var(--text); font-weight: 600;
}
body.ending #shop, body.ending .top nav { opacity: 0.25; pointer-events: none; transition: opacity 1s; }
body.ending .counter, body.ending .ticker { opacity: 0; transition: opacity 1s; }
body.ending .ticker { pointer-events: none; }
.counter {
  position: absolute; left: 0; right: 0; top: 34px;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}
.hoots { font-size: 15px; color: var(--muted); }
.hoots b {
  display: inline-block;
  font-size: clamp(30px, 5vw, 46px);
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}
.hps { color: var(--text); font-variant-numeric: tabular-nums; }
#hps { display: inline-block; font-weight: 700; }
#hps.up { animation: rate-up 1s ease-out; }
@keyframes rate-up { 0% { color: #86efac; transform: scale(1.3); } 60% { color: #86efac; } 100% { transform: scale(1); } }
.tap-rate { margin-left: 8px; color: #fbbf24; font-weight: 700; }
@media (max-width: 520px) { .tap-rate { display: block; margin: 0; font-size: 12.5px; } }
.buffs { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 6px; }
.buffs:empty { display: none; }
.buff.feast { background: rgba(244, 114, 182, 0.16); border-color: rgba(244, 114, 182, 0.6); color: #fbcfe8; }
.toast .story { display: block; margin-top: 3px; color: var(--muted); font-style: italic; font-size: 13px; }
.ach-pop {
  position: absolute; left: 50%; bottom: 12px;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  max-width: calc(100% - 32px);
  padding: 7px 14px 7px 10px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(250, 204, 21, 0.6);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5), 0 0 18px rgba(250, 204, 21, 0.2);
  pointer-events: none;
  animation: ach-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.ach-pop b { display: block; color: var(--gold); }
.ach-pop small { display: block; color: var(--muted); font-size: 12px; }
.ach-star { font-size: 22px; color: var(--gold); }
@keyframes ach-in { from { opacity: 0; transform: translate(-50%, 16px) scale(0.9); } }
.buff {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  background: rgba(250, 204, 21, 0.16);
  border: 1px solid rgba(250, 204, 21, 0.6);
  color: #fde68a;
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.toast {
  position: absolute; left: 50%; top: 124px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  text-align: center;
  pointer-events: none;
  animation: toast-in 0.25s ease-out;
}
.toast b { color: var(--gold); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---- shop ---- */
#shop {
  grid-area: shop;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 10px 12px calc(16px + env(safe-area-inset-bottom));
}
#shop h2 { margin: 6px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.flock-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  background: transparent; border: 0; padding: 4px 9px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 12.5px;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: rgba(45, 212, 191, 0.16); color: var(--accent); }

.flock { display: flex; flex-direction: column; gap: 6px; }
.item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 10px 6px 6px;
  text-align: left;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s, background 0.15s;
}
.item:hover:not(.off) { border-color: rgba(45, 212, 191, 0.6); }
.item:active:not(.off) { background: #1a2541; }
.item.off { cursor: default; }
.item.off .cost { color: var(--danger); }
.item.off canvas, .item.off .name { opacity: 0.55; }
.item .right { display: flex; flex-direction: column; align-items: flex-end; }
.item canvas { width: 44px; height: 44px; display: block; }
.item .name { font-weight: 700; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .desc { display: block; color: var(--muted); font-size: 12px; line-height: 1.3; }
.item .cost { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item .owned {
  font-size: 22px; font-weight: 800; color: rgba(226, 232, 240, 0.35);
  font-variant-numeric: tabular-nums; text-align: right; min-width: 2ch;
}
.item.mystery { opacity: 0.5; }
.item.mystery .name { letter-spacing: 0.15em; }

.upgrades { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.upgrade {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 5px 10px 5px 5px;
  text-align: left;
  background: linear-gradient(90deg, rgba(250, 204, 21, 0.08), transparent 60%), var(--panel2);
  border: 1px solid rgba(250, 204, 21, 0.35);
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
}
.upgrade:hover:not(.off) { border-color: rgba(250, 204, 21, 0.8); }
.upgrade.off { cursor: default; border-color: var(--line); background: var(--panel2); }
.upgrade.off .cost { color: var(--danger); }

/* each shop row: the row itself buys; (i) or a long press shows the info card */
.row-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 30px; align-items: center; gap: 6px; }
.item, .upgrade { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.info-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--muted);
  font: italic 700 15px Georgia, "Times New Roman", serif;
  cursor: pointer;
  touch-action: manipulation;
}
.info-btn:hover { color: var(--text); border-color: rgba(45, 212, 191, 0.6); }

/* info card */
.info-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.info-head canvas { width: 56px; height: 56px; flex: none; }
.info-head h2 { margin: 2px 0 4px; font-size: 18px; }
.info-head p { margin: 0; font-size: 13px; }
.info-card .row button:disabled { opacity: 0.45; cursor: default; }
.upgrade canvas { width: 36px; height: 36px; display: block; }
.upgrade .name { font-weight: 700; display: block; }
.upgrade .desc { display: block; color: var(--muted); font-size: 12px; line-height: 1.3; }
.upgrade .cost { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- wager ---- */
.wager {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 10px;
  padding: 10px;
  margin-bottom: 10px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.wager p { grid-column: 1 / -1; margin: 0; }
.wager-btn {
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid #ca8a04;
  background: linear-gradient(180deg, #fde047, #eab308);
  color: #1c1917;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  touch-action: manipulation;
}
.wager-btn:hover:not(:disabled) { filter: brightness(1.08); }
.wager-btn:disabled { cursor: default; background: var(--panel); border-color: var(--line); color: var(--muted); }

.wager-stats { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 8px; font-size: 12.5px; }
.wager-stats dl { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 3px 10px; margin: 0 0 6px; }
.wager-stats dt { color: var(--muted); }
.wager-stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.wager-stats .win { color: #86efac; }
.wager-stats .lose { color: #fda4af; }
.wager-stats .last { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.wager-stats .dots { display: flex; flex-wrap: wrap; gap: 3px; }
.wager-stats .dots i { width: 9px; height: 9px; border-radius: 50%; }
.wager-stats .dots i.w { background: #facc15; box-shadow: 0 0 4px rgba(250, 204, 21, 0.6); }
.wager-stats .dots i.l { background: #a16207; opacity: 0.55; }

/* ---- buy all, hunting, a new farm ---- */
.mini {
  padding: 3px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(250, 204, 21, 0.6); background: rgba(250, 204, 21, 0.12);
  color: var(--gold); font-weight: 700; font-size: 12.5px; touch-action: manipulation;
}
.mini:hover { background: rgba(250, 204, 21, 0.22); }
.mice-count { color: var(--muted); font-size: 12.5px; }
.mice-count b { color: #f9a8d4; font-size: 15px; font-variant-numeric: tabular-nums; }
.hunt {
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px 10px;
  padding: 10px; margin-bottom: 6px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius);
}
.hunt .seg { justify-self: start; }
.hunt p { grid-column: 1 / -1; margin: 0; }
.upgrade.mouse {
  border-color: rgba(244, 114, 182, 0.4);
  background: linear-gradient(90deg, rgba(244, 114, 182, 0.09), transparent 60%), var(--panel2);
}
.upgrade.mouse:hover:not(.off) { border-color: rgba(244, 114, 182, 0.85); }
.upgrade.mouse .cost { color: #f9a8d4; }
.upgrade.mouse.off { border-color: var(--line); background: var(--panel2); }
.upgrade.mouse.off .cost { color: var(--danger); }
.newfarm {
  padding: 10px; margin-bottom: 10px;
  background: linear-gradient(180deg, rgba(250, 204, 21, 0.07), transparent), var(--panel2);
  border: 1px solid rgba(250, 204, 21, 0.35); border-radius: var(--radius);
}
.newfarm p { margin: 0 0 8px; }
.newfarm dl { margin-bottom: 10px; }
.newfarm .wager-btn { width: 100%; }
.newfarm .farm-hint { margin: 0 0 10px; color: var(--muted); }
.newfarm .farm-hint.go { color: #86efac; font-weight: 600; }

.great {
  padding: 10px; margin-bottom: 10px;
  background: radial-gradient(circle at 85% 10%, rgba(254, 249, 195, 0.16), transparent 60%), var(--panel2);
  border: 1px solid rgba(254, 249, 195, 0.5); border-radius: var(--radius);
}
.great p { margin: 0 0 10px; }
.great .wager-btn { width: 100%; }
.link-btn { background: none; border: 0; padding: 6px 0 0; color: var(--muted); font-size: 12px; text-decoration: underline; cursor: pointer; }
.great .link-btn { display: block; margin: 0 auto; }
.buff.scared { background: rgba(148, 163, 184, 0.16); border-color: rgba(148, 163, 184, 0.6); color: #e2e8f0; }
.credits-card { text-align: left; }
.credits-card > p:first-of-type { font-size: 15px; }

/* ---- stats ---- */
.modal {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(2, 6, 15, 0.72);
}
.card {
  width: min(440px, 100%);
  max-height: calc(var(--app-h) - 32px);
  overflow-y: auto;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.card h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 20px; }
.card h2 img { width: 30px; height: 30px; }
/* the menu's title row stays put while the rest scrolls, with an X to close */
.card-head {
  position: sticky; top: -16px; z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: -16px -18px 10px; padding: 12px 12px 10px 18px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.card-head h2 { margin: 0; }
.close-x {
  flex: none; display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--panel2); border: 1px solid var(--line); cursor: pointer;
}
.close-x:hover { border-color: rgba(45, 212, 191, 0.6); }
.close-x svg { width: 18px; height: 18px; fill: none; stroke: var(--text); stroke-width: 2.4; stroke-linecap: round; }
.card h3 { margin: 14px 0 2px; font-size: 14px; }
.stat-list { display: grid; grid-template-columns: auto auto; gap: 4px 16px; margin: 0; }
.stat-list dt { color: var(--muted); }
.stat-list dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.ach-grid { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.ach-grid span {
  padding: 2px 8px; border-radius: 10px; font-size: 11.5px;
  border: 1px solid var(--line); color: var(--muted); opacity: 0.55;
}
.ach-grid span.got { opacity: 1; color: var(--gold); border-color: rgba(250, 204, 21, 0.45); background: rgba(250, 204, 21, 0.08); }
.journal { margin: 4px 0 0; padding-left: 20px; font-size: 12.5px; color: var(--muted); max-height: 200px; overflow-y: auto; }
.journal li { margin: 3px 0; }
.journal li:first-child { color: var(--text); }
.row { display: flex; gap: 8px; margin-top: 10px; }
.row button {
  flex: 1;
  padding: 9px 10px;
  border-radius: 9px;
  background: var(--panel2);
  border: 1px solid var(--line);
  cursor: pointer;
  font-weight: 600;
}
.row button:hover { border-color: rgba(45, 212, 191, 0.6); }
.row button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.row button.danger { color: #fca5a5; border-color: rgba(251, 113, 133, 0.5); }

/* ---- phones held upright: owl on top, shop below ---- */
@media (max-width: 760px) and (orientation: portrait) {
  #app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 46% minmax(0, 1fr);
    grid-template-areas: "top" "scene" "shop";
  }
  #shop { border-left: 0; border-top: 1px solid var(--line); }
  .play-td { padding: 5px 8px; font-size: 13px; }
  /* keep the flock in view: just the three cheapest upgrades, names only */
  .upgrades > :nth-child(n+4) { display: none; }
  .upgrade .desc { display: none; }
}
/* ---- phones held sideways and small windows: narrower shop ---- */
@media (max-width: 900px) and (orientation: landscape) {
  #app { grid-template-columns: minmax(0, 1fr) minmax(260px, 42%); }
  .upgrades > :nth-child(n+4) { display: none; }
  .upgrade .desc { display: none; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .top { padding: 4px 12px; }
  .brand { font-size: 16px; }
  .brand img { width: 22px; height: 22px; }
  .counter { top: 28px; }
  .ach-pop { bottom: 6px; padding: 4px 10px; }
  .toast { top: 92px; }
  .hoots b { font-size: 28px; }
}
