:root { --game-toolbar-size: 52px; }

body:has(.game-toolbar) .game-shell {
  padding-block-end: calc(var(--game-toolbar-size) + var(--safe-bottom) + 18px);
}
body:has(.game-toolbar):has(.phase-dock, .scene-night .host-advance-dock):not(:has(.recruitment)) .game-shell {
  padding-block-end: calc(var(--game-toolbar-size) + var(--dock-space));
}
:root:has(.game-toolbar) { scroll-padding-block-end: calc(var(--game-toolbar-size) + var(--safe-bottom) + 12px); }
body:has(.game-toolbar) :is(.phase-dock, .host-advance-dock) {
  inset-block-end: calc(var(--game-toolbar-size) + var(--safe-bottom));
}

.game-toolbar {
  position: fixed;
  z-index: 6;
  inset: auto 0 0;
  display: flex;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  padding: 3px max(var(--gutter), var(--safe-right)) calc(3px + var(--safe-bottom)) max(var(--gutter), var(--safe-left));
  border-block-start: 1px solid var(--studio-edge, #637669);
  background: var(--studio-surface, #1a3025);
}
.game-toolbar .game-tool {
  position: relative;
  flex: 1 1 0;
  max-width: 104px;
  min-height: 45px;
  gap: 6px;
  padding: 4px;
  color: var(--ink);
  font-size: .83rem;
}
.game-tool::before {
  flex: 0 0 auto;
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 1px solid currentColor;
  content: "";
}
.game-tool[data-tool='chat']::before { border-radius: 3px 3px 3px 0; }
.game-tool[data-tool='mic']::before { width: 7px; height: 12px; border-radius: 5px; box-shadow: 0 3px 0 -1px currentColor; }
.game-tool:is([data-tool='card'], [data-tool='clues'])::before { height: 13px; border-radius: 2px; transform: rotate(-7deg); }
.game-tool[data-tool='menu']::before {
  height: 9px;
  border-width: 1px 0;
  background: linear-gradient(currentColor, currentColor) center / 100% 1px no-repeat;
}
.game-tool:is([aria-expanded='true'], [data-mic='on']) { color: var(--studio-accent, #f8cc78); }
.game-tool[data-mic='muted']::before { opacity: .55; }
.game-tool[data-unread='true']::after {
  position: absolute;
  inset: 6px 13px auto auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--studio-accent, #f8cc78);
  content: "";
}

.scene-lobby {
  width: min(100%, 740px);
  padding-block: 7px 4px;
}
.scene-lobby .scene-main { gap: clamp(10px, 2vw, 17px); }
.scene-lobby .lobby-invite {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, auto);
  align-items: center;
  gap: 3px 8px;
  padding: 9px 12px;
  border: 1px solid var(--studio-edge, #687264);
  border-radius: 8px;
  background: var(--studio-surface, #22372c);
  box-shadow: none;
}
.scene-lobby .lobby-invite::before { display: none; }
.scene-lobby .room-code-group { grid-row: span 2; min-width: 0; }
.scene-lobby .room-code { font-size: clamp(1.33rem, 5.5vw, 2.5rem); letter-spacing: .1em; white-space: nowrap; }
.scene-lobby .lobby-invite .mode-tag { justify-self: end; min-height: 0; padding-block: 0; }
.scene-lobby .invite-actions { flex-wrap: nowrap; justify-content: end; min-width: 0; gap: 3px; }
.scene-lobby .invite-actions .button { flex: 0 1 auto; padding-inline: 7px; }
.scene-lobby .invite-manual { grid-column: 1 / -1; }
.scene-lobby .lobby-table {
  padding: 10px;
  border: 1px solid var(--studio-edge, #687264);
  border-radius: 9px;
  background: var(--studio-surface, #22372c);
  box-shadow: 0 8px 20px #0a120d36;
}
.scene-lobby .roster-header { padding: 0 1px 5px; border-block-end: 1px solid #a8b7a133; }
.scene-lobby .seat-count { padding: 0; border: 0; background: none; }
.scene-lobby .roster-list { align-items: stretch; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 11px; }
.scene-lobby .roster-list .lobby-seat {
  grid-template-columns: auto minmax(0, 1fr);
  align-content: center;
  align-items: center;
  justify-items: start;
  gap: 6px;
  min-height: 55px;
  padding: 5px 1px;
  border-block-end: 1px solid #b2bf9d29;
  text-align: start;
}
.scene-lobby .lobby-seat .seat-copy { justify-items: start; }
.scene-lobby .lobby-seat .player-avatar { width: 32px; height: 32px; margin: 0; border-width: 1px; }
.scene-lobby .lobby-seat .player-name { font-size: .81rem; font-weight: 690; }
.scene-lobby .lobby-seat .seat-markers { display: flex; flex-wrap: wrap; gap: 2px 5px; min-width: 0; }
.scene-lobby .lobby-seat :is(.player-tag, .social-seat-status) { font-size: .65rem; }
.scene-lobby .lobby-seat .social-seat-status { color: var(--muted); }
.scene-lobby .lobby-seat:is([data-activity='seated'], [data-activity='voice']) .social-seat-status { color: #c4d3b9; }
.scene-lobby .lobby-seat[data-activity='speaking'] .player-avatar,
.voice-seat[data-activity='speaking'] .player-avatar { outline: 2px solid #c9db98; outline-offset: 1px; }
.scene-lobby .lobby-seat[data-activity='offline'] .player-avatar { filter: saturate(.3); }
.scene-lobby .lobby-seat > :is(.seat-remove, .seat-edit) {
  inset: 50% auto auto 0;
  align-items: end;
  justify-items: start;
  transform: translateY(-48%);
}
.scene-lobby .lobby-actions { width: 100%; gap: 5px; }
.scene-lobby .lobby-actions[data-ready='true'] .lobby-readiness { color: var(--studio-accent, #f8cc78); }
.scene-lobby .lobby-actions .lobby-start { min-height: 46px; max-width: none; }

.game-menu-dialog { width: min(94vw, 420px); }
.game-menu-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 12px; }
.game-menu-actions [data-focus='resume-room'], .game-menu-error { grid-column: 1 / -1; }
.game-menu-error:empty { display: none; }
.game-menu-actions .button { min-height: 44px; padding: 5px; }
.game-menu-actions .menu-leave { color: var(--muted); }
.game-menu-actions .menu-close { color: #f5c0ad; }

.room-action-dialog { width: min(94vw, 420px); }
.room-action-copy,
.room-action-connection,
.room-action-error {
  margin: 0;
  padding: 12px 16px 0;
  overflow-wrap: anywhere;
}
.room-action-connection,
.room-action-error { color: var(--gold-light); }
.room-action-error:empty { display: none; }
.room-action-buttons {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px;
}
.room-action-buttons .button { flex: 1 1 auto; min-height: 44px; }

.vote-waiting {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  padding: 9px 12px;
  border: 1px solid var(--studio-edge);
  border-radius: 8px;
  background: var(--studio-surface);
  color: var(--studio-ink);
  font-size: .85rem;
}
.vote-waiting > strong { color: var(--studio-accent); }
.vote-waiting-names { display: flex; flex-wrap: wrap; gap: 3px 12px; margin: 0; padding: 0; list-style: none; }
.vote-waiting-names li { overflow-wrap: anywhere; }
.result-choice { overflow-wrap: anywhere; font-size: .88rem; }
.result-choice bdi { font-weight: 700; }

.chat-panel { min-width: 0; }
.chat-panel .chat-log { align-content: start; }
.scene-lobby .chat-panel { border-block-start: 1px solid var(--studio-edge, #687264); padding-block-start: 11px; }
.chat-panel > h3 { color: var(--ink); }
.chat-line {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  max-width: min(98%, 540px);
  border: 1px solid #b1c0aa2d;
  border-radius: 6px;
}
.chat-line .player-avatar { flex: 0 0 auto; width: 25px; height: 25px; }
.chat-copy { min-width: 0; }
.chat-byline { display: flex; flex-wrap: wrap; gap: 3px 9px; align-items: baseline; }
.chat-author { color: var(--studio-accent, #f8cc78); font-weight: 720; }
.chat-time { color: var(--muted); font-size: .71rem; }
.chat-panel .voice-mute { color: var(--studio-accent, #f8cc78); }
.voice-seat-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0; list-style: none; }
.voice-seat { display: flex; align-items: center; gap: 5px; max-width: 100%; padding: 3px 6px; }
.voice-seat .player-avatar { flex: 0 0 auto; width: 25px; height: 25px; }
.voice-seat .social-seat-status { font-size: .71rem; color: var(--muted); }
.voice-seat .peer-mute { min-height: 44px; padding: 4px 6px; font-size: .77rem; }

.scene-vote .stage-progress { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 9px; }
.scene-vote .stage-progress .player-cue { grid-column: 1 / -1; order: -1; }
.scene-vote .ballot-meter { grid-column: 1 / -1; order: 1; width: 100%; height: 6px; accent-color: var(--studio-accent, #f8cc78); }
.scene-vote .vote-pending { font-size: .82rem; justify-self: end; }
.scene-vote .stage-progress .phase-time { grid-column: 1 / -1; justify-self: start; order: 2; }
.scene-vote .stage-progress[data-locked='true']:has(.phase-time) {
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
}
.scene-vote .stage-progress[data-locked='true'] .phase-time { grid-column: 3; grid-row: 1; }
.scene-vote .stage-progress[data-locked='true'] .vote-pending { grid-column: 2; grid-row: 1; }
.ballot-fieldset { min-width: 0; padding: 0; margin: 0; border: 0; }
.vote-seat {
  display: grid;
  min-width: 0;
  align-content: start;
  border: 1px solid var(--studio-edge, #687264);
  border-radius: 7px;
  background: var(--studio-surface, #22372c);
}
.vote-seat:has(.vote-remind) { grid-template-columns: minmax(0, 1fr) auto; }
.vote-seat .vote-option {
  min-height: 54px;
  padding: 5px 7px;
  border: 1px solid transparent;
  background: none;
  box-shadow: none;
}
.vote-seat .vote-seat-identity {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  padding-inline-end: 12px;
  min-width: 0;
}
.vote-seat:has(.vote-remind) .vote-seat-identity { padding-inline-end: 0; }
.vote-seat .player-avatar { width: 28px; height: 28px; }
.vote-seat .vote-mark { inset-inline-start: 21px; }
.vote-seat .vote-seat-copy { display: grid; min-width: 0; text-align: start; font-size: .84rem; line-height: 1.16; }
.vote-seat .vote-seat-copy > :is(.vote-connection, .vote-status) { color: var(--muted); font-size: .71rem; }
.vote-seat[data-vote-status='locked'] .vote-status { color: #d5e8bd; }
.vote-seat[data-absent='true'] .vote-connection { color: #efb8aa; }
.vote-seat[data-you='true'] .vote-connection { color: var(--studio-accent, #f8cc78); }
.vote-seat .vote-seat-static { padding: 6px 7px; min-height: 54px; }
.vote-seat .vote-seat-static .vote-seat-identity { padding-inline-end: 0; }
.vote-seat .vote-option:has(:checked) :is(.vote-status, .vote-connection) { color: #4c401e; }
.vote-seat .vote-remind {
  align-self: center;
  min-width: 44px;
  min-height: 44px;
  padding: 3px;
  color: var(--studio-accent, #f8cc78);
  font-size: .71rem;
}
.vote-reminder-note {
  padding: 8px 10px;
  border-inline-start: 3px solid var(--studio-accent, #f8cc78);
  background: var(--studio-surface, #22372c);
  color: var(--ink);
}

@media (min-width: 650px) {
  .scene-lobby .roster-list { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 410px) {
  .scene-vote .social-vote-list { grid-template-columns: minmax(0, 1fr); }
  .scene-lobby .scene-header h2 { font-size: clamp(1.98rem, 7vw, 2.75rem); }
  .scene-lobby .roster-list .lobby-seat { min-height: 46px; padding-block: 3px; }
}
@media (orientation: portrait) {
  .scene-lobby .chat-log { min-block-size: clamp(100px, 40svh, 350px); max-block-size: clamp(126px, 52svh, 410px); }
  .scene-lobby:has(.lobby-actions[data-host='true']) .chat-log { min-block-size: clamp(100px, 28svh, 260px); }
}
@media (max-width: 600px), (orientation: landscape) and (max-height: 500px) {
  body:has(.game-toolbar .game-tool):has(.lobby-actions[data-host='true']) .game-shell {
    padding-block-end: calc(var(--game-toolbar-size) + var(--safe-bottom) + 105px);
  }
  .scene-lobby .lobby-actions[data-host='true'] {
    position: fixed;
    z-index: 4;
    inset: auto 0 calc(var(--game-toolbar-size) + var(--safe-bottom));
    margin-inline: auto;
    width: min(100%, 500px);
    padding: 6px max(var(--gutter), var(--safe-right)) 7px max(var(--gutter), var(--safe-left));
    background: var(--studio-surface, #1a3025);
  }
}
@media (orientation: landscape) and (max-height: 500px) {
  :root { --game-toolbar-size: 48px; }
  .game-toolbar .game-tool { min-height: 44px; }
  .game-toolbar { padding-block: 1px calc(2px + var(--safe-bottom)); }
  .scene-lobby .scene-header h2 { font-size: clamp(1.9rem, 5vw, 2.6rem); }
  .scene-lobby .chat-log { min-height: 65px; }
}
@media (min-width: 600px) and (orientation: landscape) and (max-height: 500px) {
  .scene-vote .social-vote-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scene-lobby .scene-main:has(.lobby-table) {
    grid-template-columns: minmax(0, .74fr) minmax(0, 1.26fr);
    align-items: start;
  }
  .scene-lobby .lobby-invite { grid-column: 1; }
  .scene-lobby .lobby-invite .room-code { font-size: 1.75rem; }
  .scene-lobby .room-code-group { grid-row: auto; }
  .scene-lobby .invite-actions { grid-column: 1 / -1; margin-inline-start: 0; }
  .scene-lobby .lobby-table { grid-column: 2; grid-row: 1 / span 2; }
  .scene-lobby .roster-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scene-lobby .roster-list .lobby-seat { min-height: 43px; padding-block: 3px; }
  .scene-lobby:has(.lobby-table) .lobby-actions[data-host='true'] {
    position: static;
    margin: 0;
    align-self: start;
    padding: 0;
    background: none;
  }
  body:has(.game-toolbar .game-tool):has(.scene-lobby .lobby-table) .game-shell {
    padding-block-end: calc(var(--game-toolbar-size) + var(--safe-bottom) + 18px);
  }
}
