: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;
}
#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;
}
.counter {
  position: absolute; left: 0; right: 0; top: 14px;
  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; }
.buff {
  display: inline-block;
  margin-top: 6px;
  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: 104px;
  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; }

/* ---- 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; }
.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; }
.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%); }
  .item .desc { display: none; }
  .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: 6px; }
  .toast { top: 70px; }
  .hoots b { font-size: 28px; }
}
