:root {
  --ink: #1d1420;
  --cream: #fff8ec;
  --maroon: #7b1e3c;
  --band: #9b1d4a;
  --gold: #ffc23a;
  --silver: #c9d1d9;
  --bronze: #d08a4c;
  --jac: #8f6fd8;
  --bin: #2c6b47;
  --display: 'Lilita One', 'Arial Black', Impact, sans-serif;
  --body: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #1d1420;
  color: var(--ink);
  font-family: var(--body);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(circle at 20% 10%, #3b2a4a 0, transparent 40%),
    radial-gradient(circle at 85% 90%, #4a1f33 0, transparent 45%),
    #1d1420;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 0 3px #00000055, 0 20px 60px #00000080;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ------------------------------------------------------------ overlays */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(29, 20, 32, 0.42);
  z-index: 10;
}
.screen.show { display: grid; animation: fade 0.18s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  position: relative;
  width: 100%;
  max-width: 660px;
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 8px 8px 0 var(--ink);
  padding: 24px 28px;
  animation: pop 0.25s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: scale(0.94); } to { transform: scale(1); } }

.card-title {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(28px, 4.5vw, 40px);
  line-height: 1.05;
  margin: 0;
}

.eyebrow {
  font-family: var(--display);
  color: var(--band);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 15px;
}

.blurb { font-size: 17px; line-height: 1.5; font-weight: 600; margin: 14px 0; }

.btn-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }

.btn {
  font-family: var(--display);
  font-size: 20px;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 11px 22px 12px;
  box-shadow: 4px 4px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--gold); }
.btn:focus-visible, .event-card:focus-visible, input:focus-visible {
  outline: 4px solid var(--jac);
  outline-offset: 3px;
}
.btn[disabled] { cursor: default; }

kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 1px 7px 2px;
  font-family: var(--display);
  font-size: 0.95em;
  text-align: center;
  background: #fff;
  border: 2px solid var(--ink);
  border-bottom-width: 4px;
  border-radius: 7px;
}

/* --------------------------------------------------------------- title */
.title-card {
  max-width: 920px;
  display: grid;
  grid-template-columns: minmax(200px, 330px) 1fr;
  gap: 8px 28px;
  align-items: center;
}
.emblem {
  width: 100%;
  height: auto;
  filter: drop-shadow(4px 6px 0 #00000030);
  animation: bob 3.2s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-6px) rotate(-1deg); } }

.wordmark {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(44px, 8vw, 86px);
  line-height: 0.95;
  margin: 0;
  letter-spacing: 0.01em;
  -webkit-text-stroke: 7px var(--ink);
  paint-order: stroke fill;
}
.w-bin { color: var(--maroon); }
.w-lym { color: var(--gold); }

.ribbon {
  display: inline-block;
  margin-top: 10px;
  padding: 6px 30px 7px;
  font-family: var(--display);
  font-size: clamp(18px, 2.6vw, 26px);
  letter-spacing: 0.12em;
  color: #fff;
  background: var(--jac);
  clip-path: polygon(0 0, 100% 0, 94% 50%, 100% 100%, 0 100%, 6% 50%);
}

.tagline {
  font-weight: 900;
  font-size: clamp(17px, 2.2vw, 22px);
  margin: 10px 0 14px;
}

.name-field { display: flex; flex-direction: column; gap: 4px; max-width: 320px; }
.name-field span { font-family: var(--display); font-size: 15px; color: var(--band); text-transform: uppercase; letter-spacing: 0.06em; }
.name-field input {
  font-family: var(--display);
  font-size: 22px;
  padding: 8px 14px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}

.title-best { margin-top: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 800; }
.tally-chip { background: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 2px 9px; font-size: 15px; }

.disclaimer {
  grid-column: 1 / -1;
  margin: 10px 0 0;
  font-size: 13px;
  font-weight: 600;
  opacity: 0.7;
  text-align: center;
}

/* --------------------------------------------------------- event grid */
.event-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.event-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 2px 12px;
  align-items: center;
  text-align: left;
  font-family: var(--body);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}
.event-card:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); background: #fffdf5; }
.event-card:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.ev-icon { grid-row: 1 / 3; font-size: 38px; }
.ev-text { display: flex; flex-direction: column; }
.ev-num { font-family: var(--display); color: var(--band); font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; }
.ev-name { font-family: var(--display); font-size: 20px; line-height: 1.1; }
.ev-sport { font-size: 13px; font-weight: 700; opacity: 0.7; }
.ev-best { grid-column: 2; display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 14px; }

/* --------------------------------------------------------------- intro */
.intro-head { display: flex; gap: 16px; align-items: center; }
.intro-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  font-size: 42px;
  background: var(--gold);
  border: 4px solid var(--ink);
  border-radius: 50%;
}
.sport { font-weight: 800; opacity: 0.7; margin-top: 2px; }
.howto { background: #fff; border: 3px dashed var(--ink); border-radius: 14px; padding: 12px 16px; }
.howto p { margin: 6px 0; font-weight: 700; line-height: 1.55; }
.howto-label { font-family: var(--display); color: var(--band); text-transform: uppercase; letter-spacing: 0.06em; font-size: 14px; }
.target { color: var(--bin); }
.best:empty { display: none; }

/* -------------------------------------------------------------- result */
.result-card { text-align: center; max-width: 560px; }
.result-medal { display: flex; justify-content: center; margin: 4px 0 8px; }
.result-title { font-family: var(--display); font-weight: 400; font-size: clamp(40px, 7vw, 64px); margin: 0; line-height: 1; -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; }
.result-title.gold { color: var(--gold); }
.result-title.silver { color: var(--silver); }
.result-title.bronze { color: var(--bronze); }
.result-title.none { color: #fff; }
.result-score { font-family: var(--display); font-size: 28px; margin-top: 6px; }
.result-pb { font-weight: 900; color: var(--band); min-height: 1.2em; }
.result-extra { font-weight: 700; font-size: 14px; opacity: 0.8; margin: 8px 0 0; }
.result-extra:empty { display: none; }
.result-table { list-style: none; margin: 12px auto 0; padding: 0; max-width: 380px; text-align: left; }
.result-table:empty { display: none; }
.result-table li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; padding: 5px 10px; border-radius: 10px; font-weight: 800; }
.result-table li.me { background: var(--gold); border: 2px solid var(--ink); }
.result-table .pos { font-family: var(--display); }
.result-table .val { font-family: var(--display); }

.quip {
  margin: 16px 0 0;
  padding: 12px 16px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.4;
}
.quip p { margin: 0; }
.quip footer { margin-top: 6px; font-size: 13px; opacity: 0.65; font-weight: 700; }
.result-card .btn-row { justify-content: center; }

.medal {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 92px;
  height: 92px;
  margin-top: 34px;
  border: 4px solid var(--ink);
  border-radius: 50%;
  font-family: var(--display);
  font-size: 40px;
  color: #00000055;
  animation: swing 1.6s ease-in-out infinite;
  transform-origin: 50% -36px;
}
.medal::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  width: 46px;
  height: 40px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, var(--band) 0 45%, var(--maroon) 55% 100%);
  clip-path: polygon(0 0, 100% 0, 70% 100%, 30% 100%);
  border-bottom: 3px solid var(--ink);
}
.medal::after { position: relative; }
.medal.gold { background: radial-gradient(circle at 35% 30%, #fff4c4, var(--gold) 45%, #d99a12); }
.medal.gold::after { content: '1'; }
.medal.silver { background: radial-gradient(circle at 35% 30%, #fff, var(--silver) 45%, #8f9aa6); }
.medal.silver::after { content: '2'; }
.medal.bronze { background: radial-gradient(circle at 35% 30%, #ffe0c2, var(--bronze) 45%, #9a5b2a); }
.medal.bronze::after { content: '3'; }
.medal.none { background: radial-gradient(circle at 35% 30%, #fff, #ddd 50%, #aaa); font-size: 38px; color: #000; }
.medal.none::after { content: '🗑️'; }
.medal.small { width: 22px; height: 22px; margin: 0; border-width: 2px; font-size: 11px; animation: none; }
.medal.small::before { display: none; }
.medal.small.none::after { content: ''; }
@keyframes swing { 50% { transform: rotate(-6deg); } }

.small-card { max-width: 440px; text-align: center; }
.small-card .btn-row { justify-content: center; }

/* ------------------------------------------------------------ ceremony */
.screen.ceremony { background: transparent; place-items: center end; }
.ceremony-card { max-width: 380px; text-align: center; margin-right: 2vw; }
.cer-tally { font-family: var(--display); font-size: 34px; margin: 8px 0 10px; white-space: pre; }
.cer-rank-label { font-weight: 800; opacity: 0.7; }
.cer-rank { font-family: var(--display); font-size: 26px; color: var(--band); line-height: 1.15; margin: 2px 0 10px; }
.cer-list { list-style: none; margin: 0; padding: 0; text-align: left; font-weight: 800; font-size: 15px; }
.cer-list li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 2px dotted #00000022; }
.ceremony-card .btn-row { justify-content: center; }
.ceremony-card .btn { font-size: 17px; padding: 9px 16px 10px; }

/* ---------------------------------------------------- in-game buttons */
.icon-btn {
  position: absolute;
  top: 8px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 18px;
  color: #fff;
  background: rgba(29, 20, 32, 0.72);
  border: 2px solid #ffffff55;
  border-radius: 50%;
  cursor: pointer;
  z-index: 5;
}
#btn-mute { right: 8px; }
#btn-pause { right: 56px; display: none; }
#btn-pause.show { display: grid; }
.pause-bars { width: 13px; height: 15px; border-left: 4px solid #fff; border-right: 4px solid #fff; }

.touch {
  position: fixed;
  inset: 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 6;
}
.touch.show { display: flex; }
.touch-side { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.touch-side.right { margin-left: auto; }
.tbtn {
  pointer-events: auto;
  width: 82px;
  height: 82px;
  font-family: var(--display);
  font-size: 30px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
  border: 4px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 5px 0 var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.tbtn.wide { width: 150px; border-radius: 44px; font-size: 24px; }
.tbtn.down { background: var(--gold); transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }

/* --------------------------------------------------------- small/narrow */
@media (max-width: 720px) {
  .title-card { grid-template-columns: 1fr; text-align: center; padding: 18px; }
  .emblem { width: 170px; margin: 0 auto; }
  .name-field { margin: 0 auto; }
  .title-card .btn-row, .title-best { justify-content: center; }
  .event-grid { grid-template-columns: 1fr; }
  .card { padding: 18px; }
  .screen.ceremony { place-items: end center; }
  .ceremony-card { margin: 0; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .card { padding: 14px 18px; box-shadow: 5px 5px 0 var(--ink); }
  .title-card { grid-template-columns: 170px 1fr; }
  .wordmark { font-size: 48px; }
  .tagline { margin: 6px 0 8px; }
  .card-title { font-size: 26px; }
  .intro-icon { width: 54px; height: 54px; font-size: 30px; border-width: 3px; }
  .blurb { font-size: 14px; line-height: 1.4; margin: 8px 0; }
  .howto { padding: 8px 12px; }
  .howto p { font-size: 14px; margin: 4px 0; line-height: 1.4; }
  .btn-row { margin-top: 10px; }
  .btn { font-size: 17px; padding: 8px 16px 9px; }
  .medal { width: 64px; height: 64px; font-size: 28px; margin-top: 30px; }
  .result-title { font-size: 38px; }
  .result-score { font-size: 22px; }
  .quip { font-size: 15px; padding: 8px 12px; margin-top: 10px; }
  .tbtn { width: 68px; height: 68px; font-size: 26px; }
  .tbtn.wide { width: 124px; font-size: 20px; }
  .touch-side { gap: 10px; }
}

@media (orientation: portrait) and (pointer: coarse) {
  #app::before {
    content: '↻  Turn your phone sideways for maximum bin';
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 14px;
    font-family: var(--display);
    font-size: 15px;
    color: var(--ink);
    background: var(--gold);
    border: 3px solid var(--ink);
    border-radius: 999px;
    white-space: nowrap;
    z-index: 4;
  }
}

@media (prefers-reduced-motion: reduce) {
  .emblem, .medal { animation: none; }
  .card, .screen.show { animation: none; }
}
