:root {
  --bg: #1f1a14;
  --panel: rgba(250, 244, 232, 0.94);
  --ink: #3b2a1d;
  --muted: #7a6754;
  --accent: #b5562f;
  --line: #d9ccb6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  /* a dim gallery wall behind the framed painting */
  background: radial-gradient(ellipse at 50% 40%, #3b3029 0%, #221b16 60%, #15110d 100%) fixed var(--bg);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

#stage {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
  cursor: grab;
  user-select: none;
}
#stage.dragging, #stage:active { cursor: grabbing; }

/* While the painting loads: a warm, softly pulsing canvas in the frame and no
   bunny; then both fade in together (scene.js drops .loading). */
#world .canvas { fill: #4a3b2c; animation: canvas-pulse 1.6s ease-in-out infinite; }
#world .painting, #world .bunny { transition: opacity .4s ease; }
#world.loading .painting, #world.loading .bunny { opacity: 0; }
#world:not(.loading) .canvas { animation: none; }
@keyframes canvas-pulse { 50% { fill: #5a4836; } }

[data-mode=edit] .bunny [data-bone] { cursor: pointer; }
[data-mode=seek] #stage { cursor: crosshair; }
[data-mode=seek] #stage:active { cursor: grabbing; }
[data-mode=seek] #overlay { pointer-events: none; }
[hidden] { display: none !important; }

/* overlay handles, sized in screen pixels */
#overlay .guide { stroke: #fff; stroke-width: 1.5; stroke-dasharray: 3 3; opacity: .7; pointer-events: none; }
#overlay .pivot { fill: none; stroke: #fff; stroke-width: 1.5; pointer-events: none; }
#overlay .handle { fill: rgba(181, 86, 47, .85); stroke: #fff; stroke-width: 2; cursor: grab; }
#overlay .handle:hover { fill: var(--accent); r: 10; }
#overlay .anchor { fill: #2f6f8f; stroke: #fff; stroke-width: 2; cursor: move; }

#panel {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 300px;
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
}

summary { cursor: pointer; font-size: 15px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 10px; }

.row {
  display: grid;
  grid-template-columns: 96px 1fr 44px;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  font-size: 13px;
}
.row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.row input[type=range] { width: 100%; accent-color: var(--accent); }

h3 {
  margin: 12px 0 4px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

#outfit select {
  font: inherit;
  font-size: 13px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
#outfit .swatches { display: flex; gap: 5px; }
#outfit .swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 50%;
}
#outfit .swatch.on { outline: 2px solid var(--accent); outline-offset: 1px; }
#outfit input[type=color] {
  width: 44px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 10px 0;
}
button {
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }

button.primary, a.button { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: #b3261e; }
button:disabled { opacity: .45; cursor: default; }
a.button, label.button {
  display: block;
  text-align: center;
  text-decoration: none;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.muted { color: var(--muted); }

input[type=text], input:not([type]), input[type=password] {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
.inline { display: flex; gap: 6px; }
.inline input { flex: 1; }

.card {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
}
.close {
  position: absolute;
  top: 6px;
  right: 8px;
  border: 0;
  background: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
}

/* ---- zoom buttons (both pages) ---- */
#zoom {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
}
#zoom button {
  width: 42px;
  height: 40px;
  border: 0;
  border-radius: 0;
  background: none;
  font-size: 20px;
  line-height: 1;
}
#zoom button + button { border-top: 1px solid var(--line); }
#zoom button:hover { background: rgba(181, 86, 47, .12); }
.admin #zoom { right: auto; left: 332px; }

/* ---- player ---- */
#brand {
  position: fixed;
  top: 12px;
  left: 12px;
  padding: 9px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
  font-size: 14px;
}
#brand span { color: var(--muted); }

#hud {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 10px 8px 16px;
  background: var(--panel);
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
  white-space: nowrap;
}
#hud .timer { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 3.2em; }
#hud .strikes { display: flex; gap: 6px; }
#hud .strikes span {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
}
#hud .strikes span.on { background: #b3261e; border-color: #b3261e; color: #fff; }
#hud .strikes span.on::before { content: "✕"; }
#hud button { border-radius: 999px; padding: 6px 12px; }
#hud button small { opacity: .7; margin-left: 2px; }

#rival {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 12px;
  border-radius: 999px;
  background: #2f6f8f;
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
}

#toast {
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(31, 26, 20, .88);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#overlay .pin circle { stroke: #fff; stroke-width: 2.5; }
#overlay .pin path { fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
#overlay .pin.miss circle { fill: #b3261e; }
#overlay .pin.hit circle { fill: #2e7d4f; }

#overlay .found-ring {
  fill: none;
  stroke: #f2c14e;
  stroke-width: 4;
  filter: drop-shadow(0 0 6px rgba(242, 193, 78, .9));
  animation: pulse 1.4s ease-in-out infinite;
}
#overlay .found-ring.lost { stroke: #fff; stroke-dasharray: 10 7; filter: drop-shadow(0 0 4px rgba(0, 0, 0, .8)); }
@keyframes pulse { 50% { stroke-width: 7; } }

/* Score first (big time, then where it sits among today's players); the
   leaderboard is further down the card. */
#result {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 100px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px 22px 16px;
  text-align: center;
}
#result h2 { margin: 0; font-size: 20px; }
#result p { margin: 0 0 10px; color: var(--muted); }
.eyebrow {
  margin: 0 0 2px !important;
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.small { font-size: 12.5px; }
#result .score {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin: 2px 0 4px;
  color: var(--muted);
  text-align: left;
  line-height: 1.3;
}
#resultTime {
  font: 700 60px/1 Georgia, "Times New Roman", serif;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
#resultTime:empty { display: none; }

#dist { min-height: 24px; margin-bottom: 6px; }
#dist .dist { display: block; width: 100%; height: auto; color: #2f6f8f; overflow: visible; }
.dist .curve { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linejoin: round; }
.dist .axis { stroke: var(--line); stroke-width: 1.5; }
.dist text { font-size: 10.5px; fill: var(--muted); text-anchor: middle; font-variant-numeric: tabular-nums; }
.dist line.you { stroke: var(--accent); stroke-width: 2.2; }
.dist circle.you { fill: var(--accent); stroke: #fff; stroke-width: 1.5; }
.dist text.you { fill: var(--accent); font-weight: 700; letter-spacing: .1em; }
#dist .caption {
  margin: 2px 0 6px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #2f6f8f;
}
#resultVs { padding: 8px; border-radius: 8px; background: rgba(47, 111, 143, .1); color: var(--ink) !important; }
#nameForm { text-align: left; margin: 6px 0 4px; }
#nameForm label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }

#board { text-align: left; margin-top: 4px; }
#board h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; float: right; }
#board ol { list-style: none; margin: 0; padding: 0; }
#board li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; padding: 4px 6px; border-radius: 6px; }
#board li.me { background: rgba(181, 86, 47, .14); font-weight: 600; }
#board li.gap { display: block; text-align: center; color: var(--muted); padding: 0; }
#board .rank { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
#board .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board .t { font-variant-numeric: tabular-nums; }

#archive {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100dvh - 84px);
  overflow: auto;
  padding: 16px 18px;
}
#archive h2 { margin: 0 0 6px; font-size: 20px; }
#archive ul { list-style: none; margin: 0; padding: 0; }
#archive li a {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 8px;
  padding: 8px 6px;
  border-top: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}
#archive li a:hover { background: rgba(255, 255, 255, .6); }
#archive li.current a { font-weight: 600; }
#archive .no { color: var(--muted); }
#archive .play { color: var(--accent); font-weight: 600; }

/* ---- curtain + intro ---- */
/* Hidden until the curtain opens: nothing to do (or peek at) behind it yet. */
.curtained #hud, .curtained #zoom, .curtained #rival { visibility: hidden; }

#curtain { position: fixed; inset: 0; overflow: hidden; }
#curtain .drape {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 51%;
  /* velvet folds: dark troughs, lit crests */
  background:
    linear-gradient(rgba(0, 0, 0, .45), transparent 22%, transparent 75%, rgba(0, 0, 0, .5)),
    repeating-linear-gradient(90deg, #4a0710 0, #7d111c 18px, #b0202e 34px, #c8343f 40px, #9a1824 52px, #61101a 66px, #4a0710 76px);
}
#curtain .left { left: 0; transform-origin: left; box-shadow: 8px 0 24px rgba(0, 0, 0, .55); }
#curtain .right { right: 0; transform-origin: right; box-shadow: -8px 0 24px rgba(0, 0, 0, .55); }
#curtain .valance {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: clamp(44px, 9vh, 90px);
  background:
    linear-gradient(transparent 72%, #d8b24a 72%, #f2d27a 80%, #a8821e 88%, transparent 88%),
    repeating-linear-gradient(90deg, #5e0a14 0, #9d1a27 30px, #5e0a14 60px);
  -webkit-mask: radial-gradient(42px 18px at 50% 100%, transparent 98%, #000) 0 0 / 84px 100%;
  mask: radial-gradient(42px 18px at 50% 100%, transparent 98%, #000) 0 0 / 84px 100%;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .6));
}
#curtain.open { pointer-events: none; animation: curtain-fade .4s ease 1.7s forwards; }
#curtain.open .drape { animation: curtain-gather 1.8s cubic-bezier(.65, 0, .25, 1) forwards; }
#curtain.open .valance { animation: curtain-lift 1.2s cubic-bezier(.65, 0, .25, 1) .5s forwards; }
@keyframes curtain-gather { to { transform: scaleX(.08); } }
@keyframes curtain-lift { to { transform: translateY(-110%); } }
@keyframes curtain-fade { to { opacity: 0; } }

#intro {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 20px 24px 22px;
  background: #faf4e8;
  text-align: center;
  animation: intro-in .5s ease both;
}
#intro h2 { margin: 2px 0 8px; font: 700 28px/1.1 Georgia, "Times New Roman", serif; }
#intro p { margin: 0 0 10px; }
#introVs { padding: 8px; border-radius: 8px; background: rgba(47, 111, 143, .1); }
#flopsy { display: block; width: 120px; height: 160px; margin: 4px auto 0; overflow: visible; }
#flopsy .bunny.change { animation: flopsy-pop .35s ease; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes flopsy-pop { 40% { scale: 1.06 .94; } }
@keyframes intro-in { from { opacity: 0; transform: translate(-50%, -46%); } }
button.big { width: 100%; margin-top: 6px; padding: 11px 14px; font-size: 16px; font-weight: 600; border-radius: 10px; }

@media (prefers-reduced-motion: reduce) {
  #curtain.open { animation-duration: .01s; animation-delay: 0s; }
  #curtain.open .drape, #curtain.open .valance, #intro, #flopsy .bunny.change { animation-duration: .01s; animation-delay: 0s; }
}

/* ---- admin ---- */
.side {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 300px;
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
}
.side h2 { margin: 0 0 4px; font-size: 16px; font-weight: 400; }
.buttons.stack { grid-template-columns: 1fr; }

.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.thumb { padding: 0; overflow: hidden; display: flex; flex-direction: column; border-width: 2px; }
.thumb img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.thumb span { font-size: 10.5px; padding: 2px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb.on { border-color: var(--accent); }
.upload { border: 1px dashed var(--muted); background: #fff; }

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-head button { padding: 2px 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-grid em { font-style: normal; font-size: 10.5px; text-align: center; color: var(--muted); }
.cal-grid .day {
  aspect-ratio: 1;
  padding: 0;
  position: relative;
  font-size: 12px;
  border-radius: 6px;
  background: #fff;
}
.cal-grid .day.past { color: var(--muted); }
.cal-grid .day.has {
  background: linear-gradient(rgba(0, 0, 0, .25), rgba(0, 0, 0, .25)), var(--thumb) center / cover;
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 2px #000;
}
.cal-grid .day.today { box-shadow: inset 0 0 0 2px #2f6f8f; }
.cal-grid .day.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
#dayInfo { font-size: 12.5px; margin: 8px 0 0; }
.unsaved { color: var(--accent); font-weight: 600; }
#status { font-size: 12.5px; min-height: 1.2em; margin: 4px 0 0; color: #2e7d4f; }
#status.error, .error { color: #b3261e; }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 16, 12, .7);
}
.modal form { width: min(340px, calc(100vw - 32px)); padding: 20px; }
.modal h2 { margin: 0 0 10px; }
.modal label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }

/* Wide screens: dock the result card left so the revealed bunny (centred) stays in view. */
@media (min-width: 960px) {
  #result { left: 16px; top: 64px; bottom: auto; transform: none; max-height: calc(100dvh - 84px); }
}

@media (max-width: 600px) {
  #panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: auto;
    max-height: 55dvh;
    border-radius: 12px 12px 0 0;
    padding: 10px 16px;
  }
  #brand { left: 50%; transform: translateX(-50%); padding: 6px 12px; font-size: 13px; }
  #hud { top: 52px; gap: 10px; }
  #rival { top: 104px; }
  #toast { top: 140px; }
  #archive { top: 52px; }
  #resultTime { font-size: 50px; }
  #zoom { bottom: auto; top: 50%; right: 10px; transform: translateY(-50%); }
}
