/* cozy.css — a cozy library at golden hour, poured into stylesheets. */

:root {
  --cream:  #FFF6E9;
  --butter: #FFE3A9;
  --peach:  #FFC6A5;
  --sage:   #BFD8B8;
  --rose:   #E8A0A0;
  --ink:    #4A3F35;
  --gold:   #C98A2D;
  --card-bg: rgba(255, 246, 233, 0.82);
  --card-border: 1px solid #00000010;
  --card-shadow: 0 10px 30px rgba(74, 63, 53, 0.14), 0 2px 6px rgba(74, 63, 53, 0.08);
  --radius: 15px;
  --font: ui-rounded, "SF Pro Rounded", "Comic Neue", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font);
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
  cursor: grab;
}
#stage:active { cursor: grabbing; }

/* the ui layer floats above the world; only its cards catch the pointer */
#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  text-transform: lowercase;
}
#ui > * { pointer-events: auto; }

/* ---------- shared card look ---------- */

.card {
  background: var(--card-bg);
  border: var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* ---------- hud (top-left) ---------- */

.hud {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  min-width: 178px;
  animation: drift-in-left 0.25s ease-out;
}
.hud-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}
.hud-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
  line-height: 1.65;
}
.hud-key { opacity: 0.62; }
.hud-val { font-variant-numeric: tabular-nums; font-weight: 600; }

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

.topbar {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.btn {
  font: inherit;
  font-weight: 700;
  font-size: 12px;
  color: var(--ink);
  background: var(--butter);
  border: var(--card-border);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  text-transform: lowercase;
  transition: transform 0.15s ease, background 0.15s ease;
}
.btn:hover { background: var(--peach); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.98); }
.hint {
  font-size: 10.5px;
  color: var(--ink);
  opacity: 0.6;
  background: var(--card-bg);
  border: var(--card-border);
  border-radius: 999px;
  padding: 5px 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ---------- monkey detail panel (right) ---------- */

.panel {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: auto;
  max-height: calc(100vh - 24px);
  width: min(308px, calc(100vw - 24px));
  padding: 14px 14px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.panel.entering { animation: rise 0.2s ease-out; }
.panel.leaving  { animation: rise 0.2s ease-out reverse forwards; }
.hidden { display: none !important; }

.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: var(--card-border);
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.close-btn:hover { background: var(--rose); color: #fff; transform: rotate(90deg); }

.mp-name {
  margin: 0 30px 2px 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.mp-sub {
  font-size: 10.5px;
  opacity: 0.65;
  margin-bottom: 16px;
  line-height: 1.5;
}
.mp-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0.5;
  margin: 14px 0 6px;
}

/* live typing feed — fresh keystrokes, straight from the desk */
.feed {
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre;
  overflow-x: auto;
  background: #ffffffaa;
  border: var(--card-border);
  border-radius: 12px;
  padding: 9px 11px;
  letter-spacing: 0.05em;
}
.feed-gold {
  color: var(--gold);
  font-weight: 700;
  background: var(--butter);
  border-radius: 4px;
}
.feed-caret {
  color: var(--rose);
  animation: blink 1s steps(1) infinite;
}

/* target quote */
.quote-box {
  background: #ffffff88;
  border: var(--card-border);
  border-radius: 12px;
  padding: 9px 11px;
}
.quote-text {
  font-size: 12px;
  line-height: 1.55;
  font-style: italic;
}
.quote-hit {
  background: var(--butter);
  color: var(--gold);
  font-weight: 700;
  font-style: normal;
  border-radius: 4px;
  padding: 0 1px;
}
.quote-meta {
  margin-top: 8px;
  font-size: 11.5px;
  opacity: 0.6;
}

/* closeness bar — soft pastel fill */
.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  margin: 11px 0 4px;
}
.bar {
  height: 10px;
  border-radius: 999px;
  background: #00000012;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  min-width: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--peach), var(--rose));
  box-shadow: inset 0 1px 0 #ffffff66;
  transition: width 0.3s ease;
}

/* stat chips */
.chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 11px;
}
.chip {
  background: #ffffff99;
  border: var(--card-border);
  border-radius: 11px;
  padding: 7px 5px;
  text-align: center;
}
.chip-v {
  font-size: 11.5px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.chip-k {
  font-size: 9px;
  opacity: 0.55;
  margin-top: 3px;
  letter-spacing: 0.04em;
}

.bestrun {
  margin-top: 10px;
  font-size: 11px;
  line-height: 1.55;
  background: var(--sage);
  border: var(--card-border);
  border-radius: 14px;
  padding: 10px 14px;
}
.bestrun q {
  font-family: var(--mono);
  font-weight: 700;
  quotes: "“" "”";
}

/* ---------- leaderboard overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(74, 63, 53, 0.28);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade 0.2s ease-out;
}
.lb-card {
  position: relative;
  width: min(560px, 100%);
  max-height: min(78vh, 640px);
  display: flex;
  flex-direction: column;
  padding: 20px 20px 14px;
}
.lb-card.entering { animation: pop 0.2s ease-out; }
.lb-head { display: flex; align-items: flex-start; justify-content: space-between; }
.lb-title { margin: 0; font-size: 19px; font-weight: 800; }
.lb-sub { font-size: 12px; opacity: 0.6; margin: 4px 0 12px; }
.lb-list {
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  text-transform: lowercase;
  background: #ffffff88;
  border: var(--card-border);
  border-radius: 14px;
  padding: 9px 12px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.lb-row:hover { background: var(--butter); transform: translateX(3px); }
.lb-rank {
  flex: 0 0 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--peach);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12.5px;
}
.lb-row:nth-child(1) .lb-rank { background: var(--butter); box-shadow: 0 0 0 2px var(--gold) inset; }
.lb-mid { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.lb-name { font-weight: 700; font-size: 13.5px; }
.lb-quote {
  font-size: 11.5px;
  opacity: 0.65;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-right { display: flex; flex-direction: column; align-items: flex-end; flex: 0 0 auto; }
.lb-len { font-weight: 800; font-size: 13px; font-variant-numeric: tabular-nums; }
.lb-close { font-size: 11px; opacity: 0.6; font-variant-numeric: tabular-nums; }

/* ---------- micro-animations ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: none; }
}
@keyframes drift-in-left {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: none; }
}
@keyframes pop {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes blink {
  50% { opacity: 0; }
}

/* ---------- vignette: the world in a warm hug ---------- */

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background:
    radial-gradient(ellipse at 50% 42%, transparent 58%, rgba(120, 78, 45, 0.16) 100%);
}

/* ---------- pastel polish ---------- */

.card {
  background:
    linear-gradient(160deg, rgba(255, 252, 244, 0.9), rgba(255, 236, 205, 0.82));
  outline: 1.5px dashed rgba(74, 63, 53, 0.14);
  outline-offset: -5px;
}

*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--peach); border-radius: 999px; }
*::-webkit-scrollbar-track { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--peach) transparent; }

.btn-row { display: flex; gap: 8px; }

/* star pupil hud row */
.hud-star-row { margin-top: 4px; }
.hud-star {
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-transform: lowercase;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  max-width: 190px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-star:hover { color: var(--ink); }

/* ---------- gossip ticker (bottom-center) ---------- */

.ticker {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: min(620px, calc(100vw - 200px));
  padding: 7px 14px;
  font: inherit;
  font-size: 11.5px;
  color: var(--ink);
  cursor: pointer;
  text-transform: lowercase;
  border-radius: 999px;
  transition: transform 0.15s ease;
}
.ticker:hover { transform: translateX(-50%) translateY(-2px); }
.ticker.tick-in .tick-text { animation: tick-fade 0.35s ease-out; }
.tick-emoji { font-size: 16px; flex: none; }
.tick-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}
@keyframes tick-fade {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- streak toasts (top-center) ---------- */

.toasts {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  text-transform: lowercase;
  border-radius: 999px;
  animation: toast-in 0.25s cubic-bezier(0.34, 1.4, 0.64, 1);
}
.toast:hover { background: var(--butter); }
.toast-out { opacity: 0; transform: translateY(-8px); transition: all 0.25s ease; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px) scale(0.94); }
  to   { opacity: 1; transform: none; }
}

/* ---------- watch dock (bottom-right) ---------- */

.watchdock {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 208px;
}
.watch-card {
  padding: 9px 12px;
  animation: pop 0.2s ease-out;
}
.watch-card.watch-hot { box-shadow: 0 0 0 2px var(--gold), var(--card-shadow); }
.watch-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.watch-name {
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-transform: lowercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.watch-name:hover { color: var(--gold); }
.watch-off {
  font: inherit;
  font-size: 14px;
  line-height: 1;
  border: none;
  background: none;
  color: var(--ink);
  opacity: 0.4;
  cursor: pointer;
  flex: none;
}
.watch-off:hover { opacity: 1; color: #c96a6a; }
.watch-tail {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  opacity: 0.75;
}

/* ---------- the typing directory (bottom-left) ---------- */

.dir {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: min(356px, calc(100vw - 24px));
  max-height: min(44vh, 390px);
  display: flex;
  flex-direction: column;
  padding: 14px 14px 10px;
  animation: pop 0.2s ease-out;
}
.dir-head { display: flex; align-items: center; justify-content: space-between; }
.dir-title { margin: 0; font-size: 13px; font-weight: 800; }
.close-sm { position: static; width: 26px; height: 26px; font-size: 15px; }

.dir-search { display: flex; gap: 6px; margin: 10px 0 2px; }
.dir-input {
  flex: 1;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  background: #ffffffaa;
  border: var(--card-border);
  border-radius: 999px;
  padding: 7px 14px;
  outline: none;
}
.dir-input:focus { border-color: var(--peach); box-shadow: 0 0 0 3px #ffc6a544; }
.dir-input::placeholder { color: var(--ink); opacity: 0.4; }
.btn-go { padding: 7px 16px; font-size: 12.5px; }

.dir-msg {
  font-size: 11.5px;
  color: #c96a6a;
  padding: 4px 6px 0;
}
.dir-msg.shake { animation: shake 0.3s ease; }
@keyframes shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.dir-table { display: flex; flex-direction: column; min-height: 0; margin-top: 8px; }
.dir-list {
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.dir-row {
  display: grid;
  grid-template-columns: 52px 96px 1fr 20px;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 10.5px;
  color: var(--ink);
  text-align: left;
  text-transform: lowercase;
  background: #ffffff77;
  border: none;
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.12s ease;
}
.dir-row:hover { background: var(--butter); }
.dir-hdr {
  background: none;
  cursor: default;
  font-weight: 800;
  font-size: 10.5px;
  opacity: 0.55;
  letter-spacing: 0.05em;
  padding-bottom: 2px;
}
.dir-row.dir-hot { background: #ffe3a9cc; box-shadow: inset 3px 0 0 var(--gold); }
.dir-no { font-variant-numeric: tabular-nums; font-weight: 700; opacity: 0.7; }
.dir-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dir-typing {
  font-family: var(--mono);
  font-size: 9.5px;
  white-space: nowrap;
  overflow: hidden;
  opacity: 0.8;
}
.dir-streak { text-align: center; font-weight: 800; color: var(--gold); }
.dir-foot {
  font-size: 10.5px;
  opacity: 0.5;
  padding: 8px 6px 0;
  text-align: center;
}

/* ---------- panel extras: portrait studio ---------- */

.portrait {
  width: 108px;
  height: 108px;
  margin: 0 auto 6px;
  border-radius: 50%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 38%, #ffe9c4, #ffd9ae 70%, #f2c493);
  border: var(--card-border);
  box-shadow: inset 0 -8px 16px rgba(74, 63, 53, 0.10), 0 4px 10px rgba(74, 63, 53, 0.12);
}
.portrait canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- panel extras: watch button + the page so far ---------- */

.btn-watch {
  width: 100%;
  margin-bottom: 4px;
  padding: 8px 14px;
  font-size: 12.5px;
  background: var(--cream);
}
.btn-watch.btn-watching { background: var(--sage); }

.page {
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.7;
  word-break: break-all;
  background: #fffdf6cc;
  border: var(--card-border);
  border-radius: 12px;
  box-shadow: inset 0 1px 4px rgba(74, 63, 53, 0.07);
  padding: 10px 14px;
  letter-spacing: 0.05em;
  opacity: 0.9;
}

/* small screens: tuck things in */
@media (max-width: 560px) {
  .hud { min-width: 0; padding: 10px 14px; }
  .hint { display: none; }
  .panel { top: auto; bottom: 12px; right: 12px; left: 12px; width: auto; max-height: 62vh; }
  .watchdock { display: none; }
  .ticker { max-width: calc(100vw - 24px); bottom: 12px; }
  .dir { max-height: 46vh; }
}

/* ---------- the adoption office: capture, owners, troop ---------- */

.btn-prof-in { background: var(--sage); }

.btn-capture {
  width: 100%;
  margin-bottom: 4px;
  padding: 9px 14px;
  font-size: 12.5px;
  color: #fff;
  background: linear-gradient(120deg, var(--rose), var(--peach));
  border: none;
  text-shadow: 0 1px 2px rgba(74, 63, 53, 0.25);
}
.btn-capture:hover { background: linear-gradient(120deg, #e08a8a, #f5b48d); transform: translateY(-1px) scale(1.015); }
.btn-capture.btn-release {
  color: var(--ink);
  background: var(--cream);
  border: var(--card-border);
  text-shadow: none;
}

.owner-badge {
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  border-radius: 999px;
  padding: 6px 12px;
  margin-bottom: 6px;
  animation: pop 0.25s ease-out;
}
.owner-mine { background: var(--sage); color: var(--ink); }
.owner-theirs { background: var(--butter); color: var(--ink); }

.signup-card { max-width: 400px; }
.signup-form { margin-top: 6px; }
.signup-rules {
  margin-top: 10px;
  font-size: 10.5px;
  opacity: 0.55;
  text-align: center;
}

.troop-row { cursor: default; }
.troop-row:hover { transform: none; }
.troop-actions { display: flex; gap: 6px; flex: none; }
.troop-actions .btn { padding: 6px 12px; font-size: 11px; box-shadow: none; }
.btn-free { background: var(--cream); }
.btn-free:hover { background: var(--rose); color: #fff; }
.troop-empty {
  padding: 22px 16px;
  text-align: center;
  font-size: 12.5px;
  opacity: 0.65;
  line-height: 1.6;
}

/* ---------- springier, cozier micro-animations ---------- */

.btn { transition: transform 0.18s cubic-bezier(0.34, 1.6, 0.64, 1), background 0.15s ease; }
.btn:hover { transform: translateY(-1.5px) scale(1.03); }
.btn:active { transform: translateY(0) scale(0.96); }

/* panel contents drift in one after another */
.panel.entering > * { animation: rise-soft 0.34s cubic-bezier(0.22, 0.9, 0.36, 1) both; }
.panel.entering > *:nth-child(2)  { animation-delay: 30ms; }
.panel.entering > *:nth-child(3)  { animation-delay: 55ms; }
.panel.entering > *:nth-child(4)  { animation-delay: 80ms; }
.panel.entering > *:nth-child(5)  { animation-delay: 100ms; }
.panel.entering > *:nth-child(6)  { animation-delay: 120ms; }
.panel.entering > *:nth-child(7)  { animation-delay: 140ms; }
.panel.entering > *:nth-child(8)  { animation-delay: 155ms; }
.panel.entering > *:nth-child(9)  { animation-delay: 170ms; }
.panel.entering > *:nth-child(10) { animation-delay: 185ms; }
.panel.entering > *:nth-child(n+11) { animation-delay: 200ms; }
@keyframes rise-soft {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: none; }
}

/* the portrait swings in with a touch of drama */
.panel.entering .portrait { animation: portrait-in 0.45s cubic-bezier(0.34, 1.45, 0.64, 1) both; }
@keyframes portrait-in {
  from { opacity: 0; transform: scale(0.6) translateY(-6px); }
  to   { opacity: 1; transform: none; }
}

/* leaderboard & directory rows cascade */
.lb-card.entering .lb-row { animation: rise-soft 0.3s ease-out both; }
.lb-card.entering .lb-row:nth-child(1) { animation-delay: 20ms; }
.lb-card.entering .lb-row:nth-child(2) { animation-delay: 45ms; }
.lb-card.entering .lb-row:nth-child(3) { animation-delay: 70ms; }
.lb-card.entering .lb-row:nth-child(4) { animation-delay: 95ms; }
.lb-card.entering .lb-row:nth-child(5) { animation-delay: 120ms; }
.lb-card.entering .lb-row:nth-child(n+6) { animation-delay: 145ms; }
