.topbar {
  display: contents;
}

.brand {
  position: fixed;
  top: max(3px, env(safe-area-inset-top));
  left: max(5px, env(safe-area-inset-left));
  z-index: 20;
  pointer-events: none;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: .02em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand img {
  width: 26px;
  height: 26px;
  border-radius: 6px;
}

/* Where the bottom dock sits. The status bar is flush with the corner; when the dock would run into
   it (narrow screens) ui/tiles.js adds body.dock-up and sets --bar-h to the bar's height. */
:root {
  --dock-bottom: max(18px, env(safe-area-inset-bottom));
}

body.dock-up {
  --dock-bottom: calc(var(--bar-h, 30px) + 10px);
}

/* A status bar from the bottom-left corner to the end of its text. It stops short of the log button
   in the bottom-right corner (40 px); when the whole line does not fit, ui/tiles.js stacks it into
   two lines after the room name. */
.status {
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 10;
  max-width: calc(100vw - 40px);
  box-sizing: border-box;
  overflow: hidden;
  padding: 6px 14px max(6px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  text-overflow: ellipsis;
  border: 1px solid var(--border);
  border-width: 1px 1px 0 0;
  border-radius: 0 14px 0 0;
  background: var(--float);
  backdrop-filter: blur(14px);
}

.status:empty {
  display: none;
}

/* The version of the code this page runs (version.txt), barely visible in the bottom-left corner of
   the welcome screen; in a room that corner belongs to the status bar. */
#version {
  position: fixed;
  left: max(8px, env(safe-area-inset-left));
  bottom: max(6px, env(safe-area-inset-bottom));
  font-size: 11px;
  line-height: 1;
  color: var(--muted);
  opacity: .4;
  pointer-events: none;
  user-select: none;
}

#version:empty,
body.joined #version {
  display: none;
}

/* In an encrypted room "🔐 secure room" is a button that shows the room password. */
.status .reveal {
  cursor: pointer;
}

.status .reveal:hover,
.status .reveal:focus-visible {
  text-decoration: underline;
  outline: none;
}

/* The room password, above the status bar; on narrow screens above the dock too, which it would
   otherwise cover. */
#roomPass {
  position: fixed;
  left: max(10px, env(safe-area-inset-left));
  bottom: calc(var(--bar-h, 30px) + 10px);
  z-index: 16;
  box-sizing: border-box;
  width: fit-content;
  max-width: calc(100vw - 20px);
  padding: 10px 40px 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

#roomPass .label {
  font-size: 12px;
  color: var(--muted);
}

#roomPass .secret {
  margin-top: 4px;
  font: 16px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* A passphrase of 7 words is 30-50 characters: narrow enough to wrap after a hyphen into two lines
     of about the same length (balance where the browser has it). */
  max-width: 26ch;
  text-wrap: balance;
  overflow-wrap: anywhere;
  user-select: all;
}

#roomPass button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 13px;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

#roomPass button:hover {
  color: var(--text);
  background: var(--surface-strong);
}

@media (max-width: 1180px) {
  #roomPass {
    bottom: calc(var(--dock-bottom) + 70px);
  }
}

/* The notice before the app reloads itself for a newer version (js/ui/update.js): in the middle of
   the screen, above everything including the password dialog. */
#update {
  width: min(420px, calc(100vw - 32px));
  box-sizing: border-box;
  padding: 24px;
  text-align: center;
  font-size: 16px;
  line-height: 1.45;
  /* A \n in the text of js/ui/update.js is a line break. */
  white-space: pre-line;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 22px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

#update::backdrop {
  background: rgba(5, 6, 10, .6);
  backdrop-filter: blur(4px);
}

#update .count {
  display: block;
  margin-top: 8px;
  font-size: 56px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--accent);
}

.status.stacked .part {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status.stacked .sep {
  display: none;
}

/* The theme button is flush with the top-right corner and the log button with the bottom-right one,
   like the status bar in the bottom-left: only the corner that faces the page is rounded, and only
   the two edges that face the page have a border. */
.topbar .icon-btn {
  position: fixed;
  right: env(safe-area-inset-right, 0px);
  z-index: 20;
  border-radius: 0;
}

#themeToggle {
  top: env(safe-area-inset-top, 0px);
  border-width: 0 0 1px 1px;
  border-bottom-left-radius: 14px;
}

#logToggle {
  bottom: env(safe-area-inset-bottom, 0px);
  border-width: 1px 0 0 1px;
}

/* The settings button stacks on the log button and takes the rounded corner, unless the JFCDES button
   (the cat's secret channel, shown only while it is on) is stacked on top of it. */
#settingsToggle {
  bottom: calc(env(safe-area-inset-bottom, 0px) + 40px);
  border-width: 1px 0 0 1px;
  border-top-left-radius: 14px;
}

#jfcdesToggle {
  bottom: calc(env(safe-area-inset-bottom, 0px) + 80px);
  border-width: 1px 0 0 1px;
  border-top-left-radius: 14px;
}

#jfcdesToggle[hidden] {
  display: none;
}

#jfcdesToggle:not([hidden]) ~ #settingsToggle {
  border-top-left-radius: 0;
}

.topbar .icon-btn,
.topbar .icon-btn:hover:not(:disabled) {
  background: var(--float);
  backdrop-filter: blur(14px);
}

.topbar .icon-btn:hover:not(:disabled) {
  transform: none;
}

.icon-btn {
  position: relative;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 24px;
  line-height: 1;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-strong);
  transition: transform .15s, background .15s, box-shadow .15s, opacity .15s;
}

.icon-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  background: var(--surface);
}

.icon-btn:active:not(:disabled) {
  transform: scale(.96);
}

.icon-btn:disabled {
  opacity: .4;
}

.icon-btn.small {
  width: 40px;
  height: 40px;
  font-size: 18px;
}

/* The chat and files buttons of the dock show which panel is open. */
.dock .icon-btn[aria-expanded="true"] {
  box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(109, 106, 247, .4);
}

/* The title row of the log, chat and files panels, with its own close button. */
.panelbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.panel-close {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.panel-close:hover {
  color: var(--text);
  background: var(--surface-strong);
}

.icon-btn[hidden] {
  display: none;
}

.icon-btn[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--ok), 0 0 18px rgba(52, 211, 153, .35);
}

.icon-btn[aria-pressed="false"]:not(:disabled)::after,
.avatar::after {
  content: "";
  position: absolute;
  width: 78%;
  height: 5px;
  border-radius: 3px;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--bg), 0 0 10px rgba(239, 68, 68, .55);
  transform: rotate(45deg);
}

.icon-btn[aria-pressed="false"]:not(:disabled):not(.danger) {
  border-color: color-mix(in srgb, var(--danger) 55%, transparent);
}

.icon-btn.danger {
  background: var(--danger);
  border-color: transparent;
}

.icon-btn.danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 85%, white);
}

#join-card {
  margin: auto;
  width: min(380px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 36px 28px 32px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--glass);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  animation: rise .5s ease both;
}

.logo {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  font-size: 36px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 30px rgba(109, 106, 247, .45);
}

.logo img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

#join-card h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: .02em;
}

.field {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}

.field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.field input {
  flex: 1;
  min-width: 0;
  padding: 14px 0;
  font-size: 16px;
  border: 0;
  outline: 0;
  background: transparent;
}

.field-btn {
  flex: none;
  padding: 4px 6px;
  font-size: 20px;
  line-height: 1;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.field-btn:hover {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.primary {
  width: 100%;
  padding: 14px 20px;
  font-size: 22px;
  font-weight: 600;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 26px rgba(109, 106, 247, .4);
  transition: transform .15s, filter .15s, box-shadow .15s;
}

.primary:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.08);
}

.primary:disabled {
  opacity: .6;
}

.dock {
  position: fixed;
  left: 50%;
  bottom: var(--dock-bottom);
  transition: bottom .25s ease;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  gap: 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  animation: dock-rise .4s ease both;
}

/* On a phone the dock stays centered and its buttons shrink with the screen, so that it still ends
   before the log button in the corner (72 px from the edge): 5 buttons + 4 gaps + padding fit in
   100vw - 144px. Below about 340 px the minimum size wins and the two can touch. */
@media (max-width: 520px) {
  .dock {
    gap: 6px;
    padding: 8px;
  }

  .dock .icon-btn {
    --size: clamp(34px, calc((100vw - 184px) / 5), 48px);
    width: var(--size);
    height: var(--size);
    font-size: calc(var(--size) * .45);
  }
}

body:not(.joined) .dock,
body:not(.joined) #grid {
  display: none;
}

body.joined #join-card {
  display: none;
}

#hints {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-bottom) + 70px);
  transition: bottom .25s ease;
  transform: translateX(-50%);
  z-index: 15;
  display: none;
  flex-direction: column;
  gap: 6px;
  width: min(460px, calc(100vw - 32px));
}

#hints.show {
  display: flex;
}

#hints div {
  padding: 8px 14px;
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  border: 1px solid color-mix(in srgb, var(--danger) 55%, transparent);
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.icon-btn[data-warn]:not(:disabled) {
  box-shadow: 0 0 0 2px #f59e0b, 0 0 18px rgba(245, 158, 11, .4);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

@keyframes dock-rise {
  from {
    opacity: 0;
    transform: translate(-50%, 14px);
  }
}
