.app {
  position: relative;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    'top top'
    'party chat';
  height: 100vh;
  height: 100dvh;
  /* Set from JS: in-app browsers (Messenger, Instagram) report 100dvh taller than what is visible. */
  height: var(--app-height, 100dvh);
  max-width: 1280px;
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: rgba(10, 8, 16, 0.35);
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 15, 26, 0.75);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--gold);
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-shadow: 0 0 18px rgba(214, 177, 92, 0.35);
}

.brand-die {
  display: inline-block;
  transition: transform 0.6s ease;
}

.brand:hover .brand-die {
  transform: rotate(360deg);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.round-short {
  display: none;
}

.round-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-right: 0.25rem;
}

.party {
  grid-area: party;
  padding: 1rem;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: rgba(18, 15, 26, 0.45);
}

.party-title {
  font-family: var(--font-display);
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.75rem;
}

.party-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.party-member {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  transition: opacity 0.4s, filter 0.4s;
}

.party-member.is-dm {
  border-color: rgba(179, 39, 63, 0.6);
  background: linear-gradient(135deg, rgba(179, 39, 63, 0.18), var(--bg-panel));
}

/* Whoever sank the last proposed date. */
.party-member.is-blocker {
  border-color: var(--danger);
  box-shadow: 0 0 14px rgba(224, 80, 74, 0.45);
}

.party-member.is-blocker .party-portrait img {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(224, 80, 74, 0.45);
}

.party-member.is-blocker .party-portrait::after {
  content: '\2717';
  position: absolute;
  top: -6px;
  left: -6px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
}

.party-member.is-left {
  opacity: 0.4;
  filter: grayscale(1);
}

.party-portrait {
  position: relative;
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
}

.party-portrait img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--member-colour, var(--gold));
  background: var(--bg-raised);
}

.party-icon {
  position: absolute;
  right: -4px;
  bottom: -4px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  font-size: 0.78rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-deep);
}

.party-info {
  flex: 1;
  min-width: 0;
}

.party-name {
  font-weight: 600;
}

.party-char {
  font-size: 0.82rem;
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.party-class {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.planner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: rgba(18, 15, 26, 0.8);
}

/*
 * Phones scroll the page itself rather than an inner chat box. In-app browsers (Messenger) only hand
 * swipes to a page that can scroll, and only collapse their header, revealing the bottom of the
 * page, when it does. The top bar, party and date picker stay pinned with position: sticky.
 */
@media (max-width: 767.98px) {
  /* Bootstrap makes page scrolling smooth; following new messages needs it to jump straight there. */
  :root {
    scroll-behavior: auto;
  }

  body {
    overflow: visible;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      'top'
      'party'
      'chat';
    /* The extra pixel keeps the page scrollable even when the chat is short. */
    height: auto;
    min-height: calc(var(--app-height, 100dvh) + 1px);
    border: 0;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(18, 15, 26, 0.96);
  }

  /* One compact line: die, sanity, round, buttons. Large text wraps the sanity meter onto its own line. */
  .topbar {
    flex-wrap: wrap;
    gap: 0.4rem 0.6rem;
    padding: 0.4rem 1rem;
  }

  .brand {
    font-size: 1.1rem;
  }

  .brand-title,
  .round-word {
    display: none;
  }

  .round-short {
    display: inline;
  }

  .topbar-actions {
    gap: 0.35rem;
  }

  .party {
    position: sticky;
    top: var(--topbar-height, 0px);
    z-index: 19;
    background: rgba(18, 15, 26, 0.96);
    padding: 0.35rem 1rem;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .party-title,
  .party-name-title,
  .party-char,
  .party-class {
    display: none;
  }

  .party-list {
    flex-direction: row;
    gap: 0.15rem;
  }

  .party-member {
    flex: 0 0 auto;
    min-width: 3.25rem;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.15rem;
    border: 0;
    background: transparent;
  }

  .party-member.is-dm {
    background: transparent;
  }

  .party-portrait {
    flex-basis: 32px;
    width: 32px;
    height: 32px;
  }

  .party-icon {
    display: none;
  }

  .frustration {
    height: 4px;
    margin-top: 0.2rem;
  }

  .party-info {
    width: 100%;
  }

  .party-name {
    font-size: 0.7rem;
    line-height: 1.2;
    text-align: center;
  }

  .planner {
    position: sticky;
    bottom: 0;
    z-index: 20;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem 0.5rem;
    background: rgba(18, 15, 26, 0.96);
  }
}

@media (max-width: 359.98px) {
  .round-badge {
    display: none;
  }
}
