/* Planit Poker. Hand-written, no framework, no build step.
   Palette as custom properties, dark mode via prefers-color-scheme. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #eceef1;
  --border: #d4d8de;
  --text: #1c2430;
  --text-muted: #5c6673;
  --accent: #0b6bcb;
  --accent-text: #ffffff;
  --ready: #1f9254;
  --danger: #b3261e;
  --radius: 8px;
  --shadow: 0 1px 3px rgb(16 24 40 / 8%), 0 1px 2px rgb(16 24 40 / 6%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d;
    --surface: #1d232b;
    --surface-alt: #262e38;
    --border: #39424e;
    --text: #e8ecf1;
    --text-muted: #9aa5b3;
    --accent: #4d9bf0;
    --accent-text: #0b1220;
    --ready: #46c07f;
    --danger: #ef8079;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 1.5rem 1rem 3rem;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2 { line-height: 1.25; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── shared ──────────────────────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.panel__heading {
  margin: 0 0 .75rem;
  font-size: 1.05rem;
  letter-spacing: .01em;
}

.field {
  display: block;
  margin: .9rem 0 .35rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field--sub { margin-top: .75rem; font-weight: 500; }

.input {
  width: 100%;
  padding: .55rem .7rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.input--code {
  text-transform: uppercase;
  letter-spacing: .25em;
  font-weight: 600;
}

.textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9rem;
  resize: vertical;
}

.hint {
  margin: .4rem 0 0;
  font-size: .82rem;
  color: var(--text-muted);
}

.btn {
  padding: .55rem 1rem;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
}

.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--primary:hover { filter: brightness(1.08); }

.btn--ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn--ghost:hover { background: var(--surface-alt); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.alert {
  margin: .75rem 0;
  padding: .6rem .8rem;
  border-radius: var(--radius);
  border: 1px solid var(--danger);
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  font-size: .9rem;
}

.alert--banner {
  border-color: var(--border);
  color: var(--text);
  background: var(--surface-alt);
}

/* ── landing ─────────────────────────────────────────────────────────────── */

.landing { max-width: 56rem; margin: 0 auto; }
.landing__title { margin: 0 0 .25rem; font-size: 1.9rem; }
.landing__tagline { margin: 0 0 1.5rem; color: var(--text-muted); }

.landing__panels {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr;
  align-items: start;
}

@media (min-width: 52rem) {
  .landing__panels { grid-template-columns: 1.4fr 1fr; }
}

.deck-editor {
  margin: 1rem 0 0;
  padding: .25rem 0 0;
  border: 0;
}

.deck-editor legend { padding: 0; }

#create-btn, #join-btn { margin-top: 1.1rem; width: 100%; }

/* ── room ────────────────────────────────────────────────────────────────── */

.room { max-width: 60rem; margin: 0 auto; }

.room__header {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.25rem;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.room__identity, .room__controls {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: center;
}

.room__label { font-size: .85rem; color: var(--text-muted); }

.room__code {
  font-size: 1.35rem;
  letter-spacing: .22em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.toggle {
  display: inline-flex;
  gap: .4rem;
  align-items: center;
  font-size: .9rem;
}

.toggle input:disabled + span { color: var(--text-muted); }

/* Full-width on the landing panels, where it sits in a stack of fields. */
.toggle--block {
  display: flex;
  margin: .9rem 0 .2rem;
}

.room__table, .room__deck { margin-top: 1.5rem; }

.room__tablehead {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  align-items: baseline;
  justify-content: space-between;
}

.readiness { margin: 0; font-size: .9rem; color: var(--text-muted); }

.participants {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin: .75rem 0 0;
  padding: 0;
  list-style: none;
}

.participant {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  align-items: center;
  min-width: 6rem;
  padding: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.participant__name {
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .9rem;
  font-weight: 600;
}

.participant__name--you::after {
  content: " (you)";
  font-weight: 400;
  color: var(--text-muted);
}

.participant__host {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent);
}

/* The slot is empty until there is something to show — no placeholder box.
   Shape and fill both change between states, so colour is never the only
   signal that somebody has voted. */
.participant__card {
  display: grid;
  place-items: center;
  width: 3.1rem;
  height: 4.3rem;
  border-radius: 6px;
  border: 2px solid transparent;
  background: transparent;
  font-size: 1.1rem;
  font-weight: 700;
  overflow: hidden;
  padding: 0 .2rem;
  text-align: center;
  word-break: break-word;
}

/* Somebody in the room but not in the round. Rendered in the card slot so the
   table keeps one grid, and muted so spectators never outweigh the voters. */
.participant__card--spectator {
  color: var(--text-muted);
  opacity: .7;
  font-size: 1.3rem;
}

.participant--spectating .participant__name { color: var(--text-muted); }

/* Waiting for this person to pick a card. Muted, so a table full of question
   marks does not shout louder than the people who have actually voted. */
.participant__card--waiting {
  color: var(--text-muted);
  opacity: .55;
  font-weight: 600;
}

.participant__card--voted {
  border-style: solid;
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
}

.participant__card--revealed {
  border-style: solid;
  border-color: var(--accent);
  background: var(--surface);
  animation: flip .28s ease-out;
}

@keyframes flip {
  from { transform: rotateY(90deg); opacity: .3; }
  to   { transform: rotateY(0);     opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .participant__card--revealed { animation: none; }
}

.participant__promote {
  padding: .15rem .45rem;
  font-size: .72rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.participant__promote:hover { color: var(--text); background: var(--surface-alt); }

/* ── deck ────────────────────────────────────────────────────────────────── */

/* Must survive a hostile deck: 300 cards stay contained, a 2000-character
   label ellipsises rather than pushing the participant list off screen. */
.deck {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .75rem;
  max-height: 40vh;
  overflow-y: auto;
  padding: .15rem;
}

.deck--preview {
  max-height: 11rem;
  padding: .5rem;
  background: var(--surface-alt);
  border-radius: var(--radius);
}

.card {
  min-width: 3.4rem;
  max-width: 10rem;
  height: 4.6rem;
  padding: .3rem .5rem;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--accent); }

.card[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.card:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.deck--preview .card { cursor: default; box-shadow: none; height: 3.4rem; font-size: .9rem; }

/* ── actions ─────────────────────────────────────────────────────────────── */

.room__actions {
  display: flex;
  gap: .75rem;
  align-items: center;
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.room__actions .btn { min-width: 10rem; }

/* The host's "everyone is in" signal — the whole reason this is a live app. */
#reveal.ready {
  background: var(--ready);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ready) 28%, transparent);
}

#waiting-note { margin: 0; }

/* ── dialog ──────────────────────────────────────────────────────────────── */

.dialog {
  width: min(34rem, 92vw);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog__body { padding: 1.25rem; }

.dialog__actions {
  display: flex;
  gap: .6rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* ── rounds rail ─────────────────────────────────────────────────────────── */

/* Single column on narrow screens: the rail drops below the table rather than
   squeezing it. Two columns once there is room, rail fixed-width so the table
   keeps the space it gains. */
.room__layout {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
  margin-top: .5rem;
}

@media (min-width: 60rem) {
  .room__layout { grid-template-columns: minmax(0, 1fr) 17rem; }
}

.room__main { min-width: 0; }

.room__rail {
  align-self: start;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* The topic being voted on, beside the session code. */
.room__topic {
  flex-basis: 100%;
  margin: .25rem 0 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.room__topic::before {
  content: "▸ ";
  color: var(--accent);
}

.rounds {
  margin: 0 0 .75rem;
  padding: 0;
  list-style: none;
  max-height: 22rem;
  overflow-y: auto;
}

.round {
  display: flex;
  gap: .4rem;
  align-items: center;
  padding: .3rem .1rem;
  border-bottom: 1px solid var(--border);
}

.round:last-child { border-bottom: 0; }

.round__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  font: inherit;
  font-size: .9rem;
  color: var(--text);
  background: none;
  border: 0;
  padding: .15rem 0;
}

button.round__title { cursor: pointer; }
button.round__title:hover { color: var(--accent); }

.round--active .round__title { font-weight: 700; }
.round--active .round__title::before { content: "▸ "; color: var(--accent); }
.round--done .round__title { color: var(--text-muted); }

.round__estimate {
  flex: none;
  min-width: 1.6rem;
  padding: .05rem .35rem;
  text-align: center;
  font-size: .8rem;
  font-weight: 700;
  color: var(--accent-text);
  background: var(--accent);
  border-radius: 999px;
}

.round__remove {
  flex: none;
  padding: 0 .25rem;
  font-size: 1rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: 0;
  cursor: pointer;
}
.round__remove:hover { color: var(--danger); }

.rounds__controls { border-top: 1px solid var(--border); padding-top: .5rem; }
.rounds__add { display: flex; gap: .4rem; }
.rounds__add .input { min-width: 0; }
.rounds__bulk { width: 100%; margin-top: .5rem; font-size: .85rem; }

/* ── agree on an estimate ────────────────────────────────────────────────── */

.room__agree {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.room__agree .deck { max-height: 14rem; }
.room__agree .card { height: 3.4rem; font-size: .95rem; }

/* ── reveal summary ──────────────────────────────────────────────────────── */

.stats {
  margin: 1rem 0 0;
  padding: .5rem .75rem;
  font-size: .92rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-alt);
  border-radius: var(--radius);
  border-left: 3px solid var(--border);
}

.stats--unanimous { border-left-color: var(--ready); }

/* ── avatars ─────────────────────────────────────────────────────────────── */

.participant__avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  padding: 2px;
  /* Keep the generated 5x5 grid crisp rather than smoothed into mush. */
  image-rendering: pixelated;
}

/* ── your own vote ───────────────────────────────────────────────────────── */

/* A disabled card is dimmed, but the one you picked has to stay readable:
   after a reveal it is the only way to see what you voted. */
.card--mine:disabled {
  opacity: 1;
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

/* What you voted on a round that has already been closed out. */
.round__yours {
  flex: none;
  font-size: .72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── table pill ──────────────────────────────────────────────────────────── */

/* The one thing the whole room looks at: prompt, then action, then answer. */
.pill {
  display: grid;
  place-items: center;
  /* The host can reveal early, so the prompt and the button can be up at the
     same time and must not touch. */
  gap: .75rem;
  min-height: 7rem;
  margin: 1.5rem 0;
  padding: 1.25rem;
  text-align: center;
  background: var(--surface-alt);
  border-radius: 1.25rem;
}

.pill__status {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-muted);
}

.pill__result {
  font-size: 3.5rem;
  line-height: 1;
  font-weight: 800;
  color: var(--accent);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill__result--counting { opacity: .55; }

.pill .btn { min-width: 12rem; font-size: 1.05rem; padding: .7rem 1.25rem; }

/* Whole-room signal that the cards are face up. */
.room--revealed .pill { background: color-mix(in srgb, var(--accent) 12%, var(--surface-alt)); }

/* ── results ─────────────────────────────────────────────────────────────── */

.room__results { margin-top: 1.25rem; }

/* One bar per distinct value, ordered by the deck so the spread is readable. */
.dist {
  display: flex;
  align-items: flex-end;
  gap: .6rem;
  height: 5.5rem;
  padding-bottom: .25rem;
}

.dist__col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 2.2rem;
}

.dist__count { font-size: .75rem; color: var(--text-muted); }

.dist__bar {
  width: 1.9rem;
  min-height: .35rem;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
}

.dist__label {
  margin-top: .3rem;
  max-width: 4rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .8rem;
  font-weight: 700;
}

/* The sentence that says what to do next. */
.verdict {
  margin: .75rem 0 .25rem;
  font-size: 1rem;
  font-weight: 700;
}

.verdict--good { color: var(--ready); }
.verdict--warn { color: var(--danger); }

/* ── deck context ────────────────────────────────────────────────────────── */

/* Context sits where the eyes already are — just above the cards. */
.deck__topic {
  margin: 0 0 .25rem;
  text-align: center;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── rail extras ─────────────────────────────────────────────────────────── */

.rounds__summary {
  margin: -.4rem 0 .6rem;
  font-size: .82rem;
  color: var(--text-muted);
}

.round__id {
  flex: none;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text-muted);
  min-width: 2.1rem;
}

.round__estimate--input {
  width: 3rem;
  padding: .1rem .3rem;
  text-align: center;
  font: inherit;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* ── misc ────────────────────────────────────────────────────────────────── */

/* Someone who sat the round out stays listed but recedes. */
.participant--out { opacity: .45; }

.lonely {
  margin: .75rem 0 0;
  text-align: center;
  font-size: .9rem;
  color: var(--text-muted);
}

.linkish {
  font: inherit;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

.btn--quiet { color: var(--text-muted); border-color: transparent; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
