/* Cat Yard — warm, cozy, rounded. */
:root {
  --cream: #fff7ec;
  --paper: #fffaf3;
  --ink: #4a2e1f;
  --ink-soft: #7a5a45;
  --terracotta: #d9774a;
  --terracotta-dk: #b85a31;
  --honey: #f2b84b;
  --sage: #8fae8b;
  --shadow: 0 10px 30px rgba(74, 46, 31, 0.18), 0 2px 6px rgba(74, 46, 31, 0.12);
  --radius: 18px;
  --font-display: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  /* sky behind the transparent WebGL canvas; bottom matches the scene fog */
  background: linear-gradient(180deg, #8ecdf0 0%, #bfe2f2 32%, #f2e6d2 55%, #f6dcc0 70%, #f6dcc0 100%);
  -webkit-font-smoothing: antialiased;
}

#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; outline: none; touch-action: none; }

.card {
  background: rgba(255, 250, 243, 0.9);
  border: 2px solid rgba(217, 119, 74, 0.18);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.05em 0.45em;
  margin-right: 0.2em;
  font: 700 0.78rem/1.5 var(--font-body);
  text-align: center;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid #e2cdb4;
  border-bottom-width: 3px;
  border-radius: 7px;
}

/* ================= Join screen ================= */
#join {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(255, 240, 220, 0.35), rgba(74, 46, 31, 0.35));
  backdrop-filter: blur(3px);
  transition: opacity 0.45s ease, visibility 0.45s;
}
#join.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.join-card {
  width: min(430px, 100%);
  padding: 0 30px 24px;
  text-align: center;
  background: var(--paper);
  border-radius: 28px;
  overflow: hidden;
  animation: pop-in 0.55s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes pop-in { from { transform: translateY(18px) scale(0.96); opacity: 0; } }

.join-art { position: relative; height: 112px; margin: 0 -30px 6px; background: linear-gradient(#bfe2f2, #e9f3e2); }
.fence-strip {
  position: absolute; left: 0; right: 0; bottom: 0; height: 34px; z-index: 2;
  background:
    linear-gradient(#b5793f, #b5793f) 0 9px / 100% 5px no-repeat,
    repeating-linear-gradient(90deg, #d29b63 0 18px, #c48a55 18px 20px, transparent 20px 24px);
  border-bottom: 6px solid #79b351;
}
.peek-cat { position: absolute; left: 50%; bottom: 8px; width: 132px; transform: translateX(-50%); z-index: 1; overflow: visible; }
.peek-body, .peek-head { fill: #e8893a; }
.peek-tail { fill: none; stroke: #e8893a; stroke-width: 9; stroke-linecap: round; transform-origin: 96px 78px; animation: tail 2.6s ease-in-out infinite; }
.peek-eye { fill: var(--ink); animation: blink 4.5s infinite; transform-box: fill-box; transform-origin: center; }
.peek-nose { fill: #e0727a; }
.peek-whisk { stroke: #fff7ec; stroke-width: 1.6; stroke-linecap: round; }
@keyframes tail { 50% { transform: rotate(-14deg); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }

.join-card h1 {
  margin: 8px 0 2px;
  font: 700 2.6rem/1 var(--font-display);
  letter-spacing: 0.01em;
  color: var(--terracotta-dk);
}
.tagline { margin: 6px 0 20px; color: var(--ink-soft); font-weight: 600; line-height: 1.45; }

.field { display: block; text-align: left; margin-bottom: 16px; }
.field-label { display: block; font: 600 0.9rem var(--font-display); margin-bottom: 6px; color: var(--ink); }
.field-label em { font-style: normal; color: var(--terracotta); margin-left: 6px; }
#cat-name {
  width: 100%;
  padding: 12px 16px;
  font: 700 1.1rem var(--font-body);
  color: var(--ink);
  background: #fff;
  border: 2px solid #ecd9c2;
  border-radius: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#cat-name::placeholder { color: #c4a88e; }
#cat-name:focus { border-color: var(--terracotta); box-shadow: 0 0 0 4px rgba(217, 119, 74, 0.18); }

#swatches { display: flex; gap: 10px; justify-content: space-between; }
.swatch {
  width: 42px; height: 42px; flex: 0 0 auto;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px #ecd9c2, 0 3px 6px rgba(74, 46, 31, 0.2);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.swatch:hover { transform: translateY(-2px) rotate(-6deg); }
.swatch[aria-checked='true'] { box-shadow: 0 0 0 3px var(--terracotta), 0 6px 12px rgba(217, 119, 74, 0.35); transform: scale(1.1); }
.swatch:focus-visible { outline: 3px dashed var(--honey); outline-offset: 4px; }
.coat-orange { background: repeating-linear-gradient(115deg, #e8893a 0 7px, #c4682a 7px 11px); }
.coat-black { background: radial-gradient(circle at 35% 30%, #4a464e, #2b282e 60%); }
.coat-white { background: radial-gradient(circle at 35% 30%, #fff, #ebe6dd 70%); }
.coat-gray { background: repeating-linear-gradient(115deg, #8c919a 0 7px, #61656e 7px 11px); }
.coat-calico {
  background:
    radial-gradient(circle at 28% 30%, #e08a3a 0 9px, transparent 10px),
    radial-gradient(circle at 70% 64%, #2e2926 0 10px, transparent 11px),
    radial-gradient(circle at 74% 22%, #e08a3a 0 5px, transparent 6px),
    #f6efe4;
}
.coat-siamese { background: radial-gradient(circle at 50% 45%, #efe1c8 0 35%, #b89a7c 58%, #4a342a 85%); }
.coat-tuxedo { background: radial-gradient(ellipse at 50% 100%, #f7f4ee 0 38%, transparent 40%), #232026; }

.enter-btn {
  width: 100%;
  margin-top: 6px;
  padding: 14px 18px;
  font: 600 1.2rem var(--font-display);
  color: #fff;
  background: linear-gradient(180deg, #e5895c, var(--terracotta));
  border: none;
  border-radius: 16px;
  box-shadow: 0 5px 0 var(--terracotta-dk), 0 10px 20px rgba(217, 119, 74, 0.35);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, filter 0.15s;
}
.enter-btn:hover { filter: brightness(1.05); }
.enter-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--terracotta-dk), 0 4px 10px rgba(217, 119, 74, 0.3); }
.enter-btn:focus-visible { outline: 3px dashed var(--honey); outline-offset: 3px; }
.fine { margin: 14px 0 0; font-size: 0.8rem; color: #a88a72; font-weight: 600; }

/* ================= HUD ================= */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; opacity: 0; transition: opacity 0.5s 0.2s; }
body.playing #hud { opacity: 1; }
#hud > * { pointer-events: auto; }
#hud #toasts, #hud #hint, #hud .chat-area { pointer-events: none; }

.top-left { position: absolute; top: 14px; left: 16px; display: flex; align-items: center; gap: 10px; }
.brand {
  font: 700 1.35rem var(--font-display);
  color: #fff;
  text-shadow: 0 2px 0 var(--terracotta-dk), 0 4px 12px rgba(74, 46, 31, 0.35);
}
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px;
  font: 700 0.8rem var(--font-body);
  background: rgba(255, 250, 243, 0.88);
  border-radius: 99px;
  box-shadow: var(--shadow);
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--honey); box-shadow: 0 0 0 3px rgba(242, 184, 75, 0.25); }
#status[data-state='open'] .status-dot { background: #5fb35a; box-shadow: 0 0 0 3px rgba(95, 179, 90, 0.25); }
#status[data-state='closed'] .status-dot { background: #d9534f; box-shadow: 0 0 0 3px rgba(217, 83, 79, 0.25); animation: pulse 1.2s infinite; }
#status[data-state='connecting'] .status-dot { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.top-right { position: absolute; top: 14px; right: 16px; display: flex; align-items: flex-start; gap: 8px; }
.scoreboard { min-width: 300px; max-width: min(460px, calc(100vw - 90px)); padding: 10px 12px 8px; }
.score-head { display: flex; justify-content: space-between; align-items: center; font: 600 0.9rem var(--font-display); margin-bottom: 6px; }
.count { min-width: 24px; padding: 0 8px; border-radius: 99px; background: var(--terracotta); color: #fff; font-size: 0.78rem; text-align: center; line-height: 1.6; }
#score-list { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; }
#score-list li {
  display: grid; grid-template-columns: 12px minmax(64px, 1fr) auto; gap: 7px; align-items: center;
  padding: 5px 6px; border-radius: 10px;
  font-weight: 700; font-size: 0.88rem;
}
#score-list li + li { border-top: 1px dashed #ecd9c2; }
#score-list li.me { background: rgba(242, 184, 75, 0.3); box-shadow: inset 3px 0 0 var(--terracotta); }
bdi, #score-list .name { unicode-bidi: isolate; }
#score-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#score-list .stats { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
#score-list .stat { font: 800 0.9rem/1.25 var(--font-body); font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
#score-list .stat.zero { opacity: 0.4; font-weight: 700; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 0 2px #fff, 0 0 0 3px #e2cdb4; flex: none; }

.icon-btn {
  width: 40px; height: 40px;
  font-size: 1.1rem;
  border: none; border-radius: 12px;
  background: rgba(255, 250, 243, 0.9);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.icon-btn:focus-visible { outline: 3px dashed var(--honey); }

/* ================= High scores ================= */
.icon-stack { display: flex; flex-direction: column; gap: 8px; }
#scores-btn[aria-expanded='true'] { background: #ffefcc; box-shadow: 0 0 0 2px var(--honey), var(--shadow); }
.scores-panel {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(620px, calc(100vw - 32px)); max-height: min(720px, calc(100vh - 40px));
  display: flex; flex-direction: column;
  padding: 18px 22px 12px;
  background: var(--paper);
  border-radius: 24px;
  z-index: 15;
  /* dim the yard behind the panel */
  box-shadow: 0 0 0 100vmax rgba(60, 38, 24, 0.35), var(--shadow);
  animation: panel-in 0.35s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes panel-in { from { transform: translate(-50%, calc(-50% + 18px)) scale(0.96); opacity: 0; } }
.scores-panel[hidden] { display: none; }
.scores-head { display: flex; justify-content: space-between; align-items: center; }
.scores-head h2 { margin: 0; font: 700 1.45rem var(--font-display); color: var(--terracotta-dk); }
.close-btn {
  width: 34px; height: 34px; border: none; border-radius: 50%;
  background: #f6e8d6; color: var(--ink); font-weight: 800; cursor: pointer;
}
.close-btn:hover { background: #f0dcc2; }
.scores-tabs { display: flex; gap: 6px; margin: 12px 0 4px; flex-wrap: wrap; }
.scores-tab {
  flex: 1 1 auto; min-width: 44px; padding: 7px 10px;
  font: 600 0.95rem var(--font-display); color: var(--ink);
  background: #fbefe0; border: 2px solid transparent; border-radius: 12px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.scores-tab:hover { background: #f6e3cc; }
.scores-tab[aria-selected='true'] { background: #fff; border-color: var(--terracotta); color: var(--terracotta-dk); }
.scores-tab:focus-visible, .close-btn:focus-visible { outline: 3px dashed var(--honey); outline-offset: 2px; }
.scores-caption { margin: 6px 2px 6px; font-size: 0.8rem; font-weight: 700; color: var(--ink-soft); }
.scores-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.scores-list li {
  display: grid; grid-template-columns: 34px 14px minmax(0, 1fr) auto 90px; gap: 10px; align-items: center;
  padding: 9px 10px; border-radius: 12px; font-weight: 700; font-size: 1rem;
}
.scores-list li:nth-child(odd) { background: rgba(242, 184, 75, 0.08); }
.scores-list li.mine { background: rgba(242, 184, 75, 0.32); box-shadow: inset 0 0 0 2px rgba(217, 119, 74, 0.35); }
.scores-list .rank { text-align: center; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.scores-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: isolate; }
.scores-list .you { font-style: normal; color: var(--terracotta); font-size: 0.8rem; }
.scores-list .score { font: 700 1.05rem var(--font-display); font-variant-numeric: tabular-nums; color: var(--terracotta-dk); }
.scores-list .when { text-align: right; font-size: 0.75rem; color: #a88a72; white-space: nowrap; }
.scores-empty { margin: 18px 0; text-align: center; color: var(--ink-soft); font-weight: 700; }
.scores-foot { margin: 8px 0 0; text-align: center; font-size: 0.75rem; color: #a88a72; font-weight: 700; }

/* toasts */
#toasts { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px 10px 12px;
  background: var(--paper);
  border: 2px solid var(--honey);
  border-radius: 99px;
  box-shadow: var(--shadow);
  animation: toast-in 0.5s cubic-bezier(.2, 1.5, .4, 1) both;
  transition: opacity 0.5s, transform 0.5s;
}
.toast.out { opacity: 0; transform: translateY(-10px); }
.toast.bump { animation: toast-bump 0.35s ease; }
@keyframes toast-bump { 40% { transform: scale(1.06); } }
.toast-body small[hidden] { display: none; }
.toast-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: #ffefcc; font-size: 1.3rem; }
.toast-body strong { display: block; font: 600 1.02rem var(--font-display); }
.toast-body small { display: block; font-weight: 700; color: var(--ink-soft); font-size: 0.78rem; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.9); } }

/* context hint, positioned under the local cat from JS */
#hint {
  position: absolute; left: 0; top: 0;
  padding: 5px 12px 5px 6px;
  font: 700 0.85rem var(--font-body);
  white-space: nowrap;
  color: var(--ink);
  background: rgba(255, 250, 243, 0.92);
  border-radius: 99px;
  box-shadow: 0 4px 12px rgba(74, 46, 31, 0.2);
  opacity: 0;
  transition: opacity 0.15s;
  will-change: transform;
}
#hint.show { opacity: 1; }
#hint kbd { background: var(--terracotta); color: #fff; border-color: var(--terracotta-dk); }
/* pounce charge bar shown while crouching */
#hint .hint-charge { display: inline-block; width: 46px; height: 7px; margin-left: 8px; vertical-align: middle; border-radius: 99px; background: #f1e2cf; overflow: hidden; }
#hint .hint-charge[hidden] { display: none; }
#hint .hint-charge-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--honey), var(--terracotta)); transform-origin: left center; border-radius: inherit; }
#hint.charged .hint-charge-fill { animation: pulse 0.5s infinite; }
#hint .hint-part + .hint-part { margin-left: 10px; padding-left: 10px; border-left: 1.5px solid #ecd9c2; }
/* season packs can tint the sky: a translucent layer between the CSS sky and the canvas */
#sky-tint { position: fixed; inset: 0; pointer-events: none; opacity: 0.7; transition: background 1.2s; }

/* controls cheat-sheet */
.help { position: absolute; left: 16px; bottom: 16px; width: 260px; padding: 4px 6px 6px; max-height: calc(100vh - 90px); overflow-y: auto; }
#help-toggle {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  padding: 7px 8px; border: none; background: none; cursor: pointer;
  font: 600 0.95rem var(--font-display); color: var(--ink);
}
.chev { transition: transform 0.2s; }
.help.collapsed .chev { transform: rotate(-90deg); }
.help.collapsed dl { display: none; }
.help.collapsed { width: auto; }
.help dl { margin: 0; padding: 0 8px 4px; }
.help dl div { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 2px 0; font-size: 0.8rem; font-weight: 700; }
.help dt { white-space: nowrap; color: var(--ink-soft); }
.help dd { margin: 0; text-align: right; }
.help .key-main { padding: 5px 6px; margin: 2px -6px; border-radius: 10px; background: rgba(242, 184, 75, 0.18); }
.help .key-main dd small { display: block; font-weight: 600; font-size: 0.7rem; color: var(--ink-soft); }
.touch-btns .act-btn { background: var(--terracotta); color: #fff; font-size: 1.4rem; }

/* chat */
/* sits to the right of the controls sheet so the log never overlaps it */
.chat-area { position: absolute; left: 292px; right: 16px; bottom: 18px; max-width: 560px; display: flex; flex-direction: column; gap: 6px; }
.help.collapsed ~ .chat-area { left: 16px; }
#chat-log { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.chat-line {
  max-width: 100%;
  padding: 4px 12px;
  font-size: 0.86rem; font-weight: 700;
  background: rgba(74, 46, 31, 0.62);
  color: #fff7ec;
  border-radius: 12px;
  overflow-wrap: anywhere;
  transition: opacity 1s;
  animation: toast-in 0.3s ease both;
}
.chat-line .dot { width: 9px; height: 9px; margin-right: 6px; vertical-align: 1px; box-shadow: 0 0 0 1.5px #fff7ec; }
.chat-line b { margin-right: 2px; color: #ffd8a8; }
.chat-line.system { background: rgba(255, 250, 243, 0.8); color: var(--ink-soft); font-style: italic; }
.chat-line.fade { opacity: 0; }
#chat { display: none; pointer-events: auto; }
#chat.open { display: block; }
#chat-input {
  width: 100%;
  padding: 11px 16px;
  font: 700 0.95rem var(--font-body);
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--terracotta);
  border-radius: 14px;
  box-shadow: var(--shadow);
  outline: none;
}

/* touch controls */
#touch { display: none; }
body.touch.playing #touch { display: block; }
#joy {
  position: absolute; left: 24px; bottom: 28px;
  width: 130px; height: 130px; border-radius: 50%;
  background: rgba(255, 250, 243, 0.35);
  border: 2px solid rgba(255, 250, 243, 0.7);
  touch-action: none;
}
#joy-knob { position: absolute; left: 40px; top: 40px; width: 50px; height: 50px; border-radius: 50%; background: rgba(217, 119, 74, 0.85); box-shadow: var(--shadow); }
.touch-btns { position: absolute; right: 18px; bottom: 24px; display: grid; grid-template-columns: repeat(3, 58px); gap: 10px; }
.touch-btns button {
  height: 58px; border: none; border-radius: 50%;
  font: 700 0.85rem var(--font-display);
  background: rgba(255, 250, 243, 0.85); color: var(--ink);
  box-shadow: var(--shadow);
  touch-action: none;
}
body.touch .help { display: none; }
body.touch .chat-area { bottom: 180px; }

.noscript { position: fixed; inset: auto 0 40% 0; text-align: center; font-weight: 800; }

@media (max-width: 760px) {
  .chat-area { left: 16px; bottom: 70px; }
  .scoreboard { min-width: 0; max-width: 200px; }
  .brand { display: none; }
  .join-card { padding: 0 20px 20px; }
  .join-art { margin: 0 -20px 6px; }
  #swatches { gap: 6px; }
  .swatch { width: 36px; height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
