:root {
  --ink: #2a2118;
  --panel: rgba(46, 32, 20, 0.74);
  --mud: #5c3a1c;
  --brown: #6b4524;
  --red: #e0453a;
  --blue: #3a7be0;
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #a9d8f0; color: #fff; }
button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }
[hidden] { display: none !important; }
kbd, code {
  font: 700 0.85em/1 ui-monospace, monospace;
  padding: 0.15em 0.4em;
  border-radius: 0.3em;
  background: #f1e8dc;
  border: 1px solid #d3c2ab;
  color: var(--ink);
}
.t0 { color: #ffb3a8; }
.t1 { color: #a9cbff; }

/* ---------- Scene ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; }
#scene3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* ---------- Top: toolbar, the two teams and the rope meter ---------- */
#hud-top {
  position: fixed; left: 0; right: 0; top: 0;
  display: flex; align-items: flex-start; gap: 2vw;
  padding: 2vh 2vw;
  z-index: 10;
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }
#toolbar, #toolbar-space { display: flex; gap: 0.5vw; flex: 0 0 auto; width: 19vh; }
#toolbar button {
  width: 5.4vh; height: 5.4vh;
  border-radius: 1.4vh;
  border: none;
  background: var(--panel);
  font-size: 2.8vh;
  cursor: pointer;
  color: #fff;
  display: grid; place-items: center;
}
#toolbar button:hover { background: rgba(46, 32, 20, 0.92); }

#scores { flex: 1; display: flex; justify-content: space-between; align-items: flex-start; gap: 2vw; }
.score {
  width: min(28vw, 40vh);
  background: var(--panel);
  border-radius: 2vh;
  padding: 0.6vh 1.6vh 0.8vh;
  display: flex; align-items: center; gap: 1vh;
  border: 0.4vh solid transparent;
  transition: border-color 0.3s, transform 0.3s;
}
.score .pet { font-size: 3.6vh; line-height: 1; }
.score .name { flex: 1; min-width: 0; font-size: 3.4vh; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score .pips { display: flex; gap: 0.6vh; }
.score .pips i {
  width: 2.2vh; height: 2.2vh; border-radius: 50%;
  border: 0.35vh solid rgba(255, 255, 255, 0.6);
}
.score.team0 .pips i.won { background: var(--red); border-color: #fff; }
.score.team1 .pips i.won { background: var(--blue); border-color: #fff; }
.score.team1 { flex-direction: row-reverse; text-align: right; }
.score.team0 { border-color: var(--red); }
.score.team1 { border-color: var(--blue); }
.score.ahead { transform: scale(1.04); }

/* Where the middle of the rope is, between the two edges of the pit */
#meter { flex: 1; max-width: 42vh; padding-top: 1.6vh; }
#meter .track {
  position: relative; height: 2.6vh;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 1.3vh;
  box-shadow: 0 0.3vh 0.8vh rgba(0, 0, 0, 0.2);
}
#meter .pit { position: absolute; top: 0; bottom: 0; width: 9%; background: var(--mud); }
#meter .pit.left { left: 0; border-radius: 1.3vh 0 0 1.3vh; }
#meter .pit.right { right: 0; border-radius: 0 1.3vh 1.3vh 0; }
#meter .ticks { position: absolute; inset: 0 9%; display: flex; justify-content: space-between; align-items: center; }
#meter .ticks i { width: 0.3vh; height: 1.2vh; background: rgba(0, 0, 0, 0.25); border-radius: 0.2vh; }
#meter .ticks i.mid { height: 2vh; background: rgba(0, 0, 0, 0.5); }
#meter .marker {
  position: absolute; top: -0.9vh; left: 50%;
  width: 2.4vh; height: 4.4vh; margin-left: -1.2vh;
  background: linear-gradient(90deg, #e8392f 50%, #fff 50%);
  border: 0.3vh solid #fff;
  border-radius: 0.6vh;
  box-shadow: 0 0.3vh 0.8vh rgba(0, 0, 0, 0.35);
  transition: left 0.9s cubic-bezier(.2, .9, .3, 1.15);
}

/* ---------- The question, over the sky ---------- */
#card {
  position: fixed; left: 50%; top: 14.5vh;
  translate: -50% 0;
  width: min(66vw, 124vh);
  z-index: 9;
  text-align: center;
  background: rgba(255, 252, 246, 0.95);
  color: var(--ink);
  border-radius: 3vh;
  padding: 1.4vh 3vh 1.8vh;
  box-shadow: 0 1vh 3vh rgba(0, 0, 0, 0.25);
  border-top: 1.2vh solid var(--brown);
}
#card.pop { animation: pop 0.45s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes pop { from { transform: scale(0.9); opacity: 0.3; } to { transform: scale(1); opacity: 1; } }
#card p { margin: 0; }
#prompt { font-size: clamp(18px, 3.4vh, 48px); font-weight: 700; line-height: 1.25; color: #6e5d4a; }
#prompt .t0 { color: #c23328; font-weight: 800; }
#prompt .t1 { color: #2a62c0; font-weight: 800; }
#question { font-size: clamp(26px, 7vh, 110px); font-weight: 800; line-height: 1.12; margin-top: 0.6vh !important; overflow-wrap: anywhere; }
#question.long { font-size: clamp(22px, 4.8vh, 72px); }
#answer {
  display: inline-block;
  margin-top: 1vh !important;
  font-size: clamp(20px, 4.6vh, 64px); font-weight: 800; line-height: 1.15;
  background: #e5f6e3; color: #1f6b2a;
  border-radius: 1.6vh; padding: 0.2vh 2.4vh;
}

/* The computer's clock: when it fills up, the computer answers */
#clock { margin-top: 1.2vh; display: flex; align-items: center; gap: 1.6vh; }
#clock span { font-size: clamp(14px, 2.4vh, 32px); font-weight: 700; color: #6e5d4a; white-space: nowrap; }
#clock .bar { flex: 1; height: 2.4vh; border-radius: 1.2vh; background: #ece2d4; overflow: hidden; }
#clock .bar i { display: block; height: 100%; width: 0; border-radius: 1.2vh; background: var(--blue); }
#clock.late .bar i { background: #f0a02c; }
#clock.last .bar i { background: var(--red); animation: blink 0.3s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.55; } }

/* One player types the answer */
#typed { display: flex; gap: 1.2vh; margin-top: 1.4vh; }
#typed input {
  flex: 1; min-width: 0;
  font-size: clamp(20px, 4.6vh, 56px); font-weight: 800;
  padding: 0.4vh 2vh;
  border: 0.5vh solid #d9c9b2; border-radius: 1.6vh;
  color: var(--ink); background: #fff;
}
#typed input:focus { outline: none; border-color: var(--red); }
#typed button {
  border: none; border-radius: 1.6vh;
  padding: 0 3.4vh;
  font-size: clamp(20px, 4vh, 48px); font-weight: 800;
  background: #5fd068; color: #0e3a1a; cursor: pointer;
  box-shadow: 0 0.6vh 0 #2f8f3a;
}
#typed button:active { transform: translateY(0.5vh); box-shadow: none; }
#typed input:disabled, #typed button:disabled { opacity: 0.5; }

/* What the computer says, over its team */
#bubble {
  position: fixed; z-index: 8;
  translate: -50% -100%;
  background: #fff; color: var(--ink);
  border: 0.5vh solid var(--blue);
  border-radius: 2.4vh;
  padding: 0.6vh 2.4vh;
  font-size: clamp(20px, 4.6vh, 60px); font-weight: 800; line-height: 1.15;
  white-space: nowrap;
  max-width: 46vw; overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 0.8vh 2vh rgba(0, 0, 0, 0.25);
  animation: pop 0.35s cubic-bezier(.2, .9, .3, 1.4);
}
#bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -2.2vh; margin-left: -1.4vh;
  border: 1.4vh solid transparent; border-top-color: var(--blue);
}
#bubble .verdict { margin-left: 1.2vh; }
#bubble .verdict.yes { color: #2f8f3a; }
#bubble .verdict.no { color: #c4493a; }

/* ---------- Bottom: buttons for each moment ---------- */
#controls {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  padding: 0 2vw 2.4vh;
  z-index: 10;
  pointer-events: none;
}
.row {
  pointer-events: auto;
  display: flex; gap: 1.6vh; align-items: stretch; flex-wrap: wrap; justify-content: center;
  background: var(--panel);
  border-radius: 2.6vh;
  padding: 1.4vh;
}
.row button {
  border: none;
  border-radius: 1.8vh;
  font-weight: 800; line-height: 1;
  cursor: pointer;
  min-height: 8vh;
  padding: 0 3.4vh;
  font-size: 3.8vh;
  box-shadow: 0 0.6vh 0 rgba(0, 0, 0, 0.3);
}
.row button:active { transform: translateY(0.5vh); box-shadow: none; }
.row button:disabled { opacity: 0.45; cursor: default; transform: none; }
.pick {
  background: #fff; color: var(--ink);
  border: 0.6vh solid var(--brown) !important;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 0.6vh;
  padding: 1.2vh 3.4vh !important;
  min-width: 34vh;
  text-align: left;
}
.pick b { font-size: 4.4vh; }
.pick span { font-size: 2.4vh; font-weight: 700; color: #6e5d4a; }
.got { min-width: 30vh; color: #fff; }
.got.team0 { background: var(--red); box-shadow: 0 0.6vh 0 #9b2c22; }
.got.team1 { background: var(--blue); box-shadow: 0 0.6vh 0 #23519b; }
#reveal, #g-reveal { background: rgba(255, 255, 255, 0.2); color: #fff; }
#right { background: #5fd068; color: #0e3a1a; min-width: 24vh; box-shadow: 0 0.6vh 0 #2f8f3a; }
#wrong { background: #ff8a7a; color: #5a1009; min-width: 24vh; box-shadow: 0 0.6vh 0 #c4493a; }
.row .small { background: transparent; color: #fff; font-size: 2.4vh; box-shadow: none; text-decoration: underline; padding: 0 1.4vh; }
.go { background: #ffd23f; color: #4a3300; box-shadow: 0 0.6vh 0 #c99a12 !important; min-width: 30vh; }

/* ---------- Setup menu ---------- */
#setup {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 20;
  background: radial-gradient(ellipse at center, rgba(30, 24, 18, 0.45), rgba(14, 10, 6, 0.8));
  overflow: auto;
  padding: 3vh 2vw;
}
.panel {
  width: min(960px, 94vw);
  background: rgba(255, 252, 246, 0.97);
  color: var(--ink);
  border-radius: 28px;
  padding: 26px 34px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
.logo { margin: 0; font-size: 50px; line-height: 1; font-weight: 800; color: var(--mud); letter-spacing: -0.5px; }
.tagline { margin: 8px 0 18px; font-size: 19px; line-height: 1.35; color: #5a4a38; }
.panel h2 { margin: 0 0 8px; font-size: 20px; }
.panel h3 { margin: 0 0 6px; font-size: 17px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-bottom: 14px; }
.cards.three { grid-template-columns: repeat(3, 1fr); }
.cards button {
  border: 3px solid #e6d8c4;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  display: flex; flex-direction: column; justify-content: flex-start;
}
.cards button:hover { transform: translateY(-2px); }
.cards button[aria-pressed='true'] { border-color: var(--brown); background: #f6efe6; }
.cards b { display: block; font-size: 21px; line-height: 1.1; }
.cards span { display: block; font-size: 15px; color: #6e5d4a; line-height: 1.3; }
.src { margin: -4px 0 16px; padding: 12px 14px; background: #f6efe6; border-radius: 16px; }
.src .cards { margin-bottom: 0; }
.help-line { margin: 0 0 8px; font-size: 15px; color: #5a4a38; line-height: 1.4; }
.help-line:empty { display: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.two label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 16px; }
textarea, .panel input, select {
  border: 2px solid #d9c9b2; border-radius: 10px;
  padding: 6px 10px; font-size: 16px; color: var(--ink); background: #fff;
}
.panel input:disabled { background: #f1ebe2; color: #6e5d4a; }
textarea { resize: vertical; font-size: 15px; line-height: 1.4; }
.teams { margin-bottom: 16px; }
.team { display: flex; flex-direction: column; gap: 8px; }
.team0 input { border-color: var(--red); }
.team1 input { border-color: var(--blue); }
.pets { display: flex; flex-wrap: wrap; gap: 6px; }
.pets button {
  display: flex; align-items: center; gap: 4px;
  border: 2px solid #e6d8c4; border-radius: 999px;
  background: #fff; color: var(--ink);
  padding: 2px 10px 2px 6px;
  font-size: 15px; font-weight: 700; cursor: pointer;
}
.pets button span { font-size: 20px; line-height: 1.2; }
.team0 .pets button[aria-checked='true'] { border-color: var(--red); background: #fdeceb; }
.team1 .pets button[aria-checked='true'] { border-color: var(--blue); background: #ebf2fd; }
.make { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 8px; }
.make label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; }
.make .grow { flex: 1; min-width: 240px; }
.primary-small, .add, .set button {
  border: 2px solid var(--brown); background: var(--brown); color: #fff;
  border-radius: 999px; padding: 6px 18px; font-weight: 800; cursor: pointer;
}
.primary-small:disabled { opacity: 0.5; cursor: wait; }
#sets { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.set { display: flex; gap: 8px; align-items: stretch; }
.set .use {
  flex: 1; text-align: left; background: #fff; color: var(--ink);
  border: 3px solid #e6d8c4; border-radius: 12px; padding: 4px 12px;
}
.set[aria-current='true'] .use { border-color: var(--brown); }
.set .use b { font-size: 18px; margin-right: 10px; }
.set .use span { font-size: 14px; color: #6e5d4a; }
.set .del { background: #fff; color: #9b2c22; border-color: #e6c3bd; border-radius: 12px; }
.qlist { margin: 0 0 6px; padding-left: 26px; display: flex; flex-direction: column; gap: 5px; max-height: 340px; overflow: auto; }
.qlist li { display: flex; gap: 5px; align-items: flex-start; }
.qlist textarea, .qlist input { flex: 1; min-width: 0; font-size: 14px !important; line-height: 1.3; padding: 4px 8px !important; }
/* The whole question shows, however long */
.qlist textarea { resize: none; field-sizing: content; min-height: 2em; }
.qlist input.a { flex: 0 0 30%; }
.qlist button { border: none; background: none; color: #9b2c22; font-size: 16px; cursor: pointer; padding: 2px 4px; }
.add { background: #fff; color: var(--brown); font-size: 14px; padding: 3px 12px; }
.buttons { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 18px; }
.buttons button {
  border: 2px solid var(--brown);
  background: #fff;
  color: var(--brown);
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 19px; font-weight: 800;
  cursor: pointer;
}
.buttons button.primary { background: var(--brown); color: #fff; font-size: 22px; padding: 12px 40px; box-shadow: 0 6px 0 #3e2712; }
.buttons button.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #3e2712; }
.buttons button:disabled { opacity: 0.45; cursor: default; }
#play-note { font-weight: 700; color: #9b2c22; }
#offline-status { margin: 10px 0 0; font-size: 15px; font-weight: 700; color: #2e7d4a; }
.help { margin-top: 16px; font-size: 15px; color: #5a4a38; }
.help summary { cursor: pointer; font-weight: 700; }
.help ul { padding-left: 20px; line-height: 1.5; }

@media (max-width: 700px) {
  .cards.three, .two { grid-template-columns: 1fr; }
  .panel { padding: 18px; }
  .logo { font-size: 38px; }
}

/* Phones held upright: size things by the width instead of the height */
@media (max-aspect-ratio: 1/1) {
  #hud-top { flex-wrap: wrap; gap: 2vw; padding: 3vw; }
  #toolbar { width: 100%; gap: 2vw; }
  #toolbar-space { display: none; }
  #toolbar button { width: 10vw; height: 10vw; font-size: 5vw; border-radius: 2.6vw; }
  #scores { gap: 2vw; flex-wrap: wrap; }
  .score { width: auto; flex: 1; padding: 1.2vw 2.4vw; border-radius: 3vw; border-width: 0.8vw; gap: 1.6vw; }
  .score .pet { font-size: 6vw; }
  .score .name { font-size: 5vw; }
  .score .pips i { width: 3.4vw; height: 3.4vw; border-width: 0.6vw; }
  #meter { order: 3; flex-basis: 100%; max-width: none; padding: 1vw 8vw 0; }
  #meter .track { height: 3.6vw; border-radius: 1.8vw; }
  #meter .marker { top: -1.4vw; width: 3.6vw; height: 6.4vw; margin-left: -1.8vw; }
  #card { width: 94vw; top: 42vw; padding: 2vw 4vw 3vw; border-radius: 4vw; border-top-width: 2vw; }
  #prompt { font-size: 4.4vw; }
  #question { font-size: 9vw; }
  #question.long { font-size: 6vw; }
  #answer { font-size: 6.5vw; }
  #clock span { font-size: 3.6vw; }
  #clock .bar { height: 3.4vw; }
  #typed input { font-size: 6vw; border-width: 0.8vw; }
  #typed button { font-size: 5.4vw; }
  #bubble { font-size: 6vw; border-width: 0.8vw; }
  #controls { padding: 0 3vw 4vw; }
  .row { gap: 2.4vw; padding: 2.4vw; border-radius: 4vw; }
  .row button { min-height: 13vw; font-size: 5.4vw; padding: 0 4vw; border-radius: 3vw; }
  #right, #wrong, .got { min-width: 34vw; }
  .row .small { font-size: 4vw; }
  .pick { min-width: 0; flex: 1; padding: 2.4vw 3vw !important; border-width: 1vw !important; }
  .pick b { font-size: 5.6vw; }
  .pick span { font-size: 3.4vw; }
  .go { min-width: 50vw; }
}
