:root {
  --bg: #0b0b10;
  --card: #16161f;
  --line: #2a2a38;
  --text: #f2f2f7;
  --muted: #8b8ba0;
  --accent: #ff3d6e;
  --good: #2ecc71;
  --bad: #ff4757;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px env(safe-area-inset-bottom);
}

.top {
  width: 100%;
  max-width: 520px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0 6px;
}

.logo {
  margin: 0;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.logo .num {
  color: var(--muted);
  font-size: 16px;
  font-weight: 600;
  margin-left: 10px;
  letter-spacing: 0;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

main {
  width: 100%;
  max-width: 520px;
  flex: 1;
}

/* While playing, the whole round fits the screen: the cards share the space left over
   and give it up first (image, then long text scrolls inside the card). */
body.playing {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
body.playing main { display: flex; flex-direction: column; min-height: 0; }
body.playing .foot { display: none; }

#game:not([hidden]) {
  flex: 1;
  min-height: 0;
  max-height: 900px;
  display: flex;
  flex-direction: column;
}

.progress {
  display: flex;
  gap: 6px;
  margin: 2px 0 10px;
  flex: none;
}

.progress i {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
}

.progress i.good { background: var(--good); }
.progress i.bad { background: var(--bad); }
.progress i.now { background: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.25s, transform 0.25s;
  flex: 0 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Only cards with an image take the spare height; text-only cards stay as tall as their text. */
.card.has-media { flex-grow: 1; }

.card.win { border-color: var(--good); }
.card.lose { border-color: var(--bad); }
.card.enter { animation: slideUp 0.35s ease-out; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: none; }
}

.who {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 14px;
  white-space: nowrap;
  flex: none;
}
.who .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.who .handle { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.who .date { color: var(--muted); margin-left: auto; padding-left: 8px; font-size: 13px; }

.text {
  font-size: 16px;
  line-height: 1.35;
  margin: 6px 0 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  flex: 0 1 auto;
  min-height: 2.7em;
  overflow-y: auto;
  scrollbar-width: none;
}
.text[hidden] { display: none; }
/* Fades the last line when a long post has to scroll inside its card. */
.text.more { mask-image: linear-gradient(to bottom, #000 calc(100% - 1.2em), transparent); }

@media (max-height: 640px) {
  .text { font-size: 15px; }
  .likes { font-size: 23px; }
  .btn { min-height: 50px; }
}

/* Takes whatever height is left; game.js hides it when that gets too small to be useful. */
.media {
  position: relative;
  margin: 0 0 8px;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  flex: 1 1 0;
  min-height: 0;
  max-height: 340px;
}
.media[hidden] { display: none; }

/* Not enough height for a full-width image: show it as a thumbnail beside the text instead. */
.card.thumb {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr) auto;
  column-gap: 12px;
}
.card.thumb .who, .card.thumb .bottom { grid-column: 1 / -1; }
.card.thumb .text { grid-column: 1; grid-row: 2; }
.card.thumb .text[hidden] + .media { grid-column: 1 / -1; justify-self: start; }
.card.thumb .media {
  grid-column: 2;
  grid-row: 2;
  width: 76px;
  height: 76px;
  max-height: calc(100% - 14px);
  align-self: start;
  margin: 6px 0 8px;
  border-radius: 10px;
}
.card.thumb .media .play { width: 30px; height: 30px; font-size: 13px; }

.media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media .play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 22px;
  display: grid;
  place-items: center;
}

.media .play[hidden] { display: none; }

.bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  flex: none;
}

.src { color: var(--muted); font-size: 13px; padding: 6px 0 6px 12px; }
.src[hidden] { display: none; }

.likes {
  font-size: 26px;
  line-height: 1.1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.likes .heart { color: var(--accent); }
.hidden-likes .likes .count { color: var(--muted); }

.vs {
  text-align: center;
  color: var(--muted);
  margin: 6px 0;
  font-size: 14px;
  flex: none;
}

.vs b { color: var(--text); }

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.choices, .btn.next {
  flex: none;
  margin: 10px 0 12px;
}
.choices[hidden], .btn.next[hidden] { display: none; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  min-height: 54px;
  padding: 0 20px;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  background: var(--line);
  cursor: pointer;
  width: 100%;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.up { background: var(--good); color: #062b14; }
.btn.down { background: var(--bad); }
.btn.next, .btn.share { background: var(--accent); }
.btn.share { margin-top: 16px; }

#result { text-align: center; padding-top: 24px; }
#result h2 { font-size: 26px; margin: 0 0 12px; }

.grid {
  font-size: 40px;
  letter-spacing: 6px;
  margin: 8px 0 20px;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-bottom: 8px;
}

.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 26px; }
.stats span { color: var(--muted); font-size: 13px; }

.copied { color: var(--good); margin: 8px 0 0; }
.next-in { color: var(--muted); margin-top: 20px; }
.next-in b { color: var(--text); font-variant-numeric: tabular-nums; }

dialog {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: min(420px, calc(100vw - 32px));
  padding: 20px 22px;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin-top: 0; }
.small { font-size: 13px; color: var(--muted); }

.foot {
  color: var(--muted);
  font-size: 12px;
  padding: 24px 0 16px;
  text-align: center;
}

/* Very short screens (landscape phones): let the page scroll instead of squashing the cards. */
@media (max-height: 480px) {
  body.playing { height: auto; overflow: visible; }
  body.playing .card { flex: none; }
  body.playing .media { flex: none; height: 120px; }
}
