:root {
  --bg-top: #f7c98e;
  --bg-mid: #f2a65a;
  --bg-low: #d9744b;
  --ink: #3b2418;
  --ink-soft: #7a5440;
  --sheet: #fff7ec;
  --accent: #e8564a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  position: fixed;
  inset: 0;
  font-family: "Baloo 2", ui-rounded, system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 8%, rgba(255, 244, 214, 0.75), transparent 40%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 55%, var(--bg-low) 100%);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}
button { font: inherit; color: inherit; }
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(var(--sg-corner-top) - 10px) 16px calc(var(--safe-bottom) + 8px); /* the top row (64px) centers the corner's menu button */
  max-width: 560px;
  margin: 0 auto;
}
.top {
  display: grid;
  grid-template-columns: 48px 1fr 88px;
  align-items: center;
  min-height: 64px;
  gap: 6px;
}
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.3);
  cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; }
.score-box { text-align: center; line-height: 1; }
.score {
  font-size: clamp(36px, 10vw, 46px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 3px 0 rgba(94, 40, 20, 0.28);
  font-variant-numeric: tabular-nums;
  transition: transform 0.12s;
}
.score.pop { transform: scale(1.14); }
.best { font-size: 15px; font-weight: 700; color: rgba(255, 255, 255, 0.92); text-shadow: 0 1px 0 rgba(94, 40, 20, 0.25); margin-top: 2px; }
.next-box {
  display: flex; align-items: center; justify-content: flex-end; gap: 4px;
  font-size: 13px; font-weight: 700; color: #fff; text-shadow: 0 1px 0 rgba(94, 40, 20, 0.25);
}
.next-box canvas { width: 44px; height: 44px; background: rgba(255, 255, 255, 0.28); border-radius: 50%; }

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
}
#jar {
  display: block;
  width: min(100%, calc((100dvh - 190px - var(--safe-top) - var(--safe-bottom)) * 408 / 586));
  aspect-ratio: 408 / 586;
  touch-action: none;
}
.banner {
  position: absolute; left: 50%; top: 12%;
  transform: translate(-50%, 0); pointer-events: none;
  font-size: 30px; font-weight: 800; color: #fff; white-space: nowrap;
  text-shadow: 0 3px 0 rgba(94, 40, 20, 0.35);
  opacity: 0;
}
.banner.show { animation: banner 1.3s ease-out; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, 14px) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  30% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -18px) scale(1); }
}

.evo {
  display: flex; justify-content: space-between; align-items: center;
  height: 48px; padding: 0 6px; margin-top: 6px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 24px;
  cursor: pointer;
}
.evo canvas { width: 30px; height: 30px; flex: none; }
.evo canvas.cur { filter: drop-shadow(0 0 4px #fff) drop-shadow(0 0 2px #fff); }

.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 70px);
  transform: translate(-50%, -12px); width: max-content; max-width: calc(100vw - 40px);
  padding: 10px 16px; border-radius: 14px; background: rgba(59, 36, 24, 0.94); color: #fff;
  font-size: 16px; font-weight: 600; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.sheet {
  width: min(340px, calc(100vw - 40px));
  max-height: calc(100dvh - 40px);
  border: 0; border-radius: 26px; padding: 24px 22px 22px;
  background: var(--sheet); color: var(--ink);
  box-shadow: 0 24px 60px -20px rgba(59, 36, 24, 0.6);
  text-align: center; overflow-y: auto; touch-action: pan-y;
}
.sheet.wide { width: min(380px, calc(100vw - 32px)); }
.sheet::backdrop { background: rgba(59, 36, 24, 0.42); }
.sheet[open] { animation: sheet-in 0.28s cubic-bezier(0.3, 1.3, 0.5, 1); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(16px) scale(0.96); } to { opacity: 1; transform: none; } }
.sheet h2 { margin: 0; font-size: 30px; font-weight: 800; line-height: 1.1; }
.sheet p { margin: 6px 0 14px; font-size: 17px; color: var(--ink-soft); }
.primary, .secondary {
  width: 100%; min-height: 52px; border-radius: 16px; font-size: 18px; font-weight: 700;
  text-decoration: none; display: grid; place-items: center; cursor: pointer; margin-top: 10px;
}
.primary { border: 0; background: var(--ink); color: #fff; }
.secondary { border: 2px solid rgba(59, 36, 24, 0.2); background: transparent; color: var(--ink); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.sheet-actions .primary, .sheet-actions .secondary { margin-top: 0; }
.sg-actions .primary, .sg-actions .secondary { margin-top: 0; }
/* Title screen: the shared layout (shared/mainmenu.js); these are only Neko Game's colors. */
#mm {
  --sg-bg: linear-gradient(180deg, var(--bg-top), var(--bg-mid) 55%, var(--bg-low));
  --sg-ink: var(--ink); --sg-ink-soft: var(--ink-soft);
  --sg-title: #fff7ec; --sg-title-shadow: 0 3px 0 #b5502f, 0 8px 14px rgba(90, 40, 15, 0.35);
  --sg-accent: var(--accent); --sg-accent-ink: #fff;
  --sg-card: var(--sheet); --sg-card-ink: var(--ink); --sg-line: rgba(59, 36, 24, 0.2);
}
.sg-sheet { --sg-sheet-bg: var(--sheet); --sg-sheet-ink: var(--ink); --sg-accent: var(--accent); --sg-accent-ink: #fff; --sg-ink-soft: var(--ink-soft); }

.over-new { color: var(--accent) !important; font-weight: 800; font-size: 20px !important; margin: 4px 0 0 !important; }
.over-cat { display: grid; justify-items: center; margin: 8px 0 4px; font-weight: 800; font-size: 20px; }
.over-cat canvas { width: 88px; height: 88px; }
.over-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0; }
.over-stats div { background: rgba(59, 36, 24, 0.06); border-radius: 14px; padding: 8px 4px; }
.over-stats small { display: block; font-size: 14px; color: var(--ink-soft); font-weight: 600; }
.over-stats b { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.over-line { font-size: 15px !important; min-height: 1.3em; margin: 6px 0 4px !important; }

.col-sub { font-size: 15px !important; margin: 2px 0 10px !important; }
.col-cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
.col-cat { display: grid; justify-items: center; gap: 0; font-size: 12px; font-weight: 700; line-height: 1.1; color: var(--ink-soft); }
.col-cat canvas { width: 54px; height: 54px; }
.col-cat.locked { color: #a8968a; }
.ach-title { font-size: 24px !important; margin-top: 4px !important; }
.ach-list { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 6px; text-align: left; }
.ach-list li {
  display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 14px; background: rgba(59, 36, 24, 0.05);
}
.ach-list li.got { background: rgba(60, 154, 108, 0.16); }
.ach-list .dot {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: #d8cabd; color: #fff; font-weight: 800; font-size: 16px;
}
.ach-list li.got .dot { background: #3c9a6c; }
.ach-list b { display: block; font-size: 16px; line-height: 1.1; }
.ach-list span { display: block; font-size: 14px; color: var(--ink-soft); line-height: 1.2; }
.ach-list li:not(.got) b { color: var(--ink-soft); }

/* The jar's end: what it opened, and what's next */
.over-unlock { margin: 4px 0 6px !important; padding: 8px 12px; border-radius: 14px; background: #fff0c8; color: var(--ink) !important; font-size: 15px !important; font-weight: 700; }
.over-next { margin: 2px 0 10px !important; font-size: 15px !important; font-weight: 700; }
.over-next:empty { display: none; }

/* The title screen's picture: the three biggest cats you know, in their outfits */
.title-cats { display: flex; align-items: flex-end; justify-content: center; width: 100%; height: 150px; }
.title-cats .tc { display: block; width: 112px; margin: 0 -10px; filter: drop-shadow(0 6px 8px rgba(90, 40, 15, 0.3)); }
.title-cats .tc svg { display: block; width: 100%; height: auto; }
.title-cats .tc0, .title-cats .tc2 { width: 100px; }
.title-cats .tc1 { width: 128px; z-index: 1; }
.title-cats .tc.solo { width: 128px; }

/* The Cat Closet sheet */
.closet { text-align: left; }
.closet-next { padding: 10px 12px; border-radius: 16px; background: #fff0c8; }
.closet-next small { display: block; font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-soft); }
.closet-next p { margin: 4px 0 0 !important; font-size: 15px !important; font-weight: 700; color: var(--ink) !important; }
.closet-note { margin: 8px 2px 4px !important; font-size: 14px !important; line-height: 1.35; }
.closet-cat { margin-top: 12px; padding: 8px; border-radius: 16px; background: rgba(242, 166, 90, 0.14); }
.closet-cat.locked { opacity: 0.7; }
.closet-head { display: flex; align-items: center; gap: 10px; }
.closet-face { flex: none; width: 52px; height: 60px; }
.closet-face svg { width: 52px; height: 60px; display: block; }
.closet-head b { display: block; font-size: 18px; line-height: 1.1; }
.closet-head small { display: block; font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.closet-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
.closet-tile, .jar-tile {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 84px; padding: 4px 2px 6px;
  border: 2px solid rgba(59, 36, 24, 0.12); border-radius: 12px; background: #fffaf2; color: var(--ink); cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(59, 36, 24, 0.07);
}
.closet-tile:active:not(:disabled), .jar-tile:active:not(:disabled) { transform: scale(0.96); }
.closet-tile[aria-pressed="true"], .jar-tile[aria-pressed="true"] { border-color: #3c9a6c; background: #eef8f2; }
.closet-tile:disabled, .jar-tile:disabled { background: rgba(255, 250, 242, 0.5); cursor: default; box-shadow: none; }
.closet-tile .tile-pic { width: 46px; height: 53px; }
.closet-tile .tile-pic svg { width: 46px; height: 53px; display: block; }
.closet-tile .tile-pic.dim { opacity: 0.35; filter: grayscale(1); }
.tile-name { font-size: 13px; font-weight: 700; line-height: 1.1; text-align: center; }
.closet-tile:disabled .tile-name, .jar-tile:disabled .tile-name { color: var(--ink-soft); }
.closet h3 { margin: 16px 0 8px; font-size: 17px; font-weight: 800; }
.jar-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.jar-tile { min-height: 76px; padding: 6px 4px; }
.jar-tile .sw { width: 100%; height: 38px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(59, 36, 24, 0.12); }
.jar-tile:disabled .sw { opacity: 0.4; filter: grayscale(0.7); }
.jar-swatch-kitchen .sw { background: radial-gradient(circle at 15% 8%, rgba(255, 244, 214, 0.75), transparent 40%), linear-gradient(#f7c98e, #f2a65a 55%, #d9744b); }
.jar-swatch-window .sw { background: linear-gradient(90deg, transparent 47%, #fff 47% 53%, transparent 53%), linear-gradient(transparent 45%, #fff 45% 52%, transparent 52%), linear-gradient(#8fd0f5, #cdeefc 70%, #f6e7c8 70%); }
.jar-swatch-attic .sw { background: repeating-linear-gradient(90deg, transparent 0 22px, rgba(60, 30, 20, 0.25) 22px 25px), linear-gradient(#8f6a8f, #c79a86 60%, #e2b98f); }
.jar-swatch-cafe .sw { background: repeating-linear-gradient(90deg, #f6efe2 0 10px, #9fd3c0 10px 20px); }
.jar-swatch-garden .sw { background: radial-gradient(circle at 25% 70%, #ff9bb0 0 4px, transparent 5px), radial-gradient(circle at 70% 60%, #ffe14a 0 4px, transparent 5px), linear-gradient(#a8e0ff, #d9f4c8 60%, #7cc35a 60%); }
.jar-swatch-night .sw { background: radial-gradient(circle at 75% 30%, #fff7d6 0 5px, transparent 6px), radial-gradient(circle, #fff 0 0.8px, transparent 1.2px) 3px 4px / 11px 9px, linear-gradient(#1a2350, #3b3474 60%, #6a4a7a); }

/* Jar themes: the room around the jar (the page behind it) */
body.jar-window { --bg-top: #8fd0f5; --bg-mid: #cdeefc; --bg-low: #f2d9a8; }
body.jar-window::before {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, transparent calc(50% - 5px), rgba(255, 255, 255, 0.85) calc(50% - 5px) calc(50% + 5px), transparent calc(50% + 5px)) 0 0 / 100% 46%,
    linear-gradient(transparent calc(23% - 5px), rgba(255, 255, 255, 0.85) calc(23% - 5px) calc(23% + 5px), transparent calc(23% + 5px)) 0 0 / 100% 46% no-repeat,
    radial-gradient(ellipse 30% 8% at 25% 18%, rgba(255, 255, 255, 0.9) 98%, transparent 100%),
    radial-gradient(ellipse 22% 6% at 75% 10%, rgba(255, 255, 255, 0.8) 98%, transparent 100%);
}
body.jar-attic { --bg-top: #7c5a80; --bg-mid: #b98c86; --bg-low: #d9a77a; }
body.jar-attic::before {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background:
    linear-gradient(135deg, transparent 49.4%, rgba(70, 38, 26, 0.35) 49.5% 51%, transparent 51.1%) 0 0 / 100% 40% no-repeat,
    linear-gradient(-135deg, transparent 49.4%, rgba(70, 38, 26, 0.35) 49.5% 51%, transparent 51.1%) 0 0 / 100% 40% no-repeat,
    repeating-linear-gradient(90deg, transparent 0 70px, rgba(70, 38, 26, 0.12) 70px 74px);
}
body.jar-cafe { --bg-top: #f3e6cf; --bg-mid: #e9cfa8; --bg-low: #c9946a; }
body.jar-cafe::before {
  content: ""; position: fixed; inset: 0 0 auto; height: 70px; pointer-events: none;
  background: repeating-linear-gradient(90deg, #f7f1e6 0 26px, #7fc2aa 26px 52px);
  -webkit-mask: radial-gradient(circle 14px at 13px 56px, #000 98%, transparent) 0 0 / 26px 70px, linear-gradient(#000 0 56px, transparent 56px);
  mask: radial-gradient(circle 14px at 13px 56px, #000 98%, transparent) 0 0 / 26px 70px, linear-gradient(#000 0 56px, transparent 56px);
}
body.jar-garden { --bg-top: #9fdcfb; --bg-mid: #d4f1d0; --bg-low: #7cc35a; }
body.jar-garden::before {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle, #ff9bb0 0 4px, transparent 5px) 12px 20px / 90px 70px,
    radial-gradient(circle, #ffe14a 0 3.5px, transparent 4.5px) 55px 50px / 110px 90px,
    radial-gradient(circle, #ffffff 0 3px, transparent 4px) 30px 5px / 130px 80px;
  -webkit-mask: linear-gradient(transparent 62%, #000 70%);
  mask: linear-gradient(transparent 62%, #000 70%);
}
body.jar-night { --bg-top: #141b3a; --bg-mid: #2f2d66; --bg-low: #5b3f7a; }
body.jar-night::before {
  content: ""; position: fixed; inset: -50%; transform: rotate(17deg); pointer-events: none;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.9) 0 1.1px, transparent 1.6px) 13px 17px / 71px 67px,
    radial-gradient(circle, rgba(255, 255, 255, 0.6) 0 0.9px, transparent 1.4px) 41px 5px / 103px 89px,
    radial-gradient(circle, rgba(255, 240, 200, 0.85) 0 1.4px, transparent 2px) 97px 31px / 173px 157px;
}
body.jar-night .app, body.jar-window .app, body.jar-attic .app, body.jar-cafe .app, body.jar-garden .app { position: relative; z-index: 1; }

@media (prefers-reduced-motion: reduce) {
  .sheet[open], .banner.show { animation: none; }
  .banner.show { opacity: 1; transform: translate(-50%, 0); }
  .score { transition: none; }
}

/* iPhone: no double-tap zoom anywhere. touch-action isn't inherited, so it goes on every element
   (anything with its own touch-action keeps it). Text fields stay selectable. */
* { touch-action: manipulation; }
input, textarea { -webkit-user-select: text; user-select: text; }
body.jar-night #mm { --sg-ink: #fff4e6; --sg-ink-soft: #e6dcff; }
