@font-face {
  font-family: "Monogram";
  src: url("fonts/monogram.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  color-scheme: light dark;
  overflow: hidden;
}

:root {
  --accent: #4486ff;
  --danger: #ff445f;
  --ink: #101010;
  --muted: #6f6f6f;
  --line: #101010;
  --soft-line: #d8e5ff;
  --grid-line: var(--soft-line);
  --paper: #ffffff;
  --paper-soft: #f7faff;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-soft: rgba(247, 250, 255, 0.86);
  --modal-backdrop: rgba(255, 255, 255, 0.82);
  --global-rainbow: linear-gradient(90deg, #ff4fd8, #ffdf5e, #66ff9a, #5cf7ff, #8478ff, #ff4fd8);
  --scheme-toggle-space: 0px;
  --page-padding: 24px;
  --page-padding-block: 48px;
}

html[data-scheme="light"] {
  color-scheme: light;
  --ink: #101010;
  --muted: #6f6f6f;
  --line: #101010;
  --soft-line: #d8e5ff;
  --paper: #ffffff;
  --paper-soft: #f7faff;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-soft: rgba(247, 250, 255, 0.86);
  --modal-backdrop: rgba(255, 255, 255, 0.82);
}

html[data-scheme="dark"] {
  color-scheme: dark;
  --ink: #f4f8ff;
  --muted: #a9b7cc;
  --line: #f4f8ff;
  --soft-line: #173463;
  --paper: #07101d;
  --paper-soft: #0c1728;
  --surface: rgba(7, 16, 29, 0.9);
  --surface-soft: rgba(12, 23, 40, 0.86);
  --modal-backdrop: rgba(7, 16, 29, 0.78);
}

html[data-scheme="system"] {
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  html[data-scheme="system"] {
    --ink: #f4f8ff;
    --muted: #a9b7cc;
    --line: #f4f8ff;
    --soft-line: #173463;
    --paper: #07101d;
    --paper-soft: #0c1728;
    --surface: rgba(7, 16, 29, 0.9);
    --surface-soft: rgba(12, 23, 40, 0.86);
    --modal-backdrop: rgba(7, 16, 29, 0.78);
  }
}

@keyframes rainbow-accent {
  0% {
    filter: hue-rotate(0deg);
  }

  100% {
    filter: hue-rotate(360deg);
  }
}

.rainbow-mode {
  animation: rainbow-accent 6s linear infinite;
}

.panel,
.app-window,
input,
button,
#messages,
.modal-panel,
.gif-message img,
.drawing-message img,
h1,
h2,
#status,
.meta,
.username,
.user-title,
.system,
.room-name {
  transition:
    background-color 240ms ease,
    border-color 240ms ease,
    box-shadow 240ms ease,
    color 240ms ease;
}

body {
  position: relative;
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Monogram", "Courier New", monospace;
  font-size: 22px;
  line-height: 1.25;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: var(--page-padding);
  image-rendering: pixelated;
  overflow-x: hidden;
  overflow-y: hidden;
  -webkit-text-size-adjust: 100%;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 16px 16px;
}

body.scheme-toggle-visible {
  --scheme-toggle-space: 52px;
}

html.users-panel-open,
body.users-panel-open {
  overflow: hidden;
}

.star-field {
  position: fixed;
  inset: 0 auto auto 0;
  width: 100vw;
  min-height: 100dvh;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.sparkle-star {
  position: absolute;
  width: 16px;
  height: 16px;
  background-repeat: no-repeat;
  background-size: 64px 16px;
  image-rendering: pixelated;
  animation: sparkle 1.2s steps(4) infinite;
}

@keyframes sparkle {
  from {
    background-position: 0 0;
  }

  to {
    background-position: -64px 0;
  }
}

.scheme-toggle {
  align-self: flex-end;
  margin-top: 14px;
  min-height: 36px;
  padding: 6px 10px;
}

.chat-shell {
  position: relative;
  z-index: 1;
  display: flex;
  width: min(920px, calc(100vw - var(--page-padding-block)));
  max-width: 100%;
  flex-direction: column;
}

body.lobby-mode .chat-shell {
  display: grid;
  width: min(1240px, calc(100vw - var(--page-padding-block)));
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 28px;
  align-items: start;
  flex-direction: unset;
  margin-right: 0;
}

.room-users-panel {
  position: absolute;
  top: 0;
  left: calc(100% + 14px);
  width: 180px;
  max-height: min(420px, calc(100svh - 48px));
  overflow-y: auto;
  border: 2px solid var(--accent);
  background: var(--surface);
  box-shadow: 4px 4px 0 var(--accent);
  padding: 14px;
}

.room-users-panel h2 {
  font-size: 24px;
  margin-bottom: 10px;
}

.room-users-panel ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.room-users-panel li {
  line-height: 1;
  word-break: break-word;
}

.panel {
  position: relative;
  border: 2px solid var(--accent);
  background: var(--surface);
  box-shadow:
    4px 4px 0 var(--accent);
  border-radius: 0;
  padding: 24px;
}

.version-badge {
  position: absolute;
  top: -34px;
  left: -2px;
  min-width: 64px;
  border: 2px solid var(--accent);
  background: var(--surface);
  box-shadow: 3px 3px 0 var(--accent);
  color: var(--accent);
  padding: 4px 8px;
  line-height: 1;
  text-align: center;
}

#chat-screen {
  position: relative;
  display: flex;
  height: min(820px, calc(100dvh - var(--page-padding-block) - var(--scheme-toggle-space)));
  min-height: min(560px, calc(100dvh - var(--page-padding-block) - var(--scheme-toggle-space)));
  max-height: calc(100dvh - var(--page-padding-block) - var(--scheme-toggle-space));
  flex-direction: column;
  overflow: visible;
}

.room-view {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

#chat-screen.hidden {
  display: none;
}

.hidden {
  display: none;
}

h1 {
  margin-top: 0;
  color: var(--accent);
  font-size: clamp(32px, 7vw, 48px);
  font-weight: 400;
  line-height: 1;
  text-shadow: none;
  text-transform: uppercase;
}

h2 {
  margin: 0;
  color: var(--accent);
  font-size: 32px;
  font-weight: 400;
  line-height: 1;
  text-transform: uppercase;
}

p {
  color: var(--muted);
}

input,
button {
  font: inherit;
  border-radius: 0;
  border: 2px solid var(--accent);
  padding: 8px 10px;
  min-height: 44px;
}

input {
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  outline: none;
  box-shadow: inset 2px 2px 0 var(--soft-line);
}

input:focus {
  border-color: var(--accent);
  box-shadow: inset 2px 2px 0 var(--accent);
}

.disabled-input {
  border-color: var(--soft-line);
  color: var(--muted);
  opacity: 0.55;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.checkbox-row input {
  width: 24px;
  min-height: 24px;
  box-shadow: none;
}

button {
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  margin-top: 12px;
  font-weight: 400;
  box-shadow: 3px 3px 0 var(--accent);
  text-transform: uppercase;
}

button:hover {
  background: var(--accent);
  color: var(--paper);
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 var(--line);
}

button:active {
  transform: translate(3px, 3px);
  box-shadow: none;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.title-group {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.room-description-display {
  margin: 0;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  word-break: break-word;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

#users-button,
#draw-button,
#lobby-button {
  margin-top: 0;
}

.exit-button {
  position: absolute;
  top: -22px;
  right: -22px;
  z-index: 2;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-color: var(--danger);
  background: var(--danger);
  color: var(--paper);
  box-shadow: 3px 3px 0 var(--accent);
  font-size: 28px;
  line-height: 1;
}

.exit-button:hover {
  background: var(--surface);
  color: var(--danger);
}

#status {
  color: var(--accent);
  text-shadow: none;
}

#lobby-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-right: 4px;
}

.room-list {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.friends-panel {
  position: relative;
  top: auto;
  left: auto;
  display: grid;
  width: 280px;
  margin-top: 86px;
  gap: 10px;
  max-height: min(620px, calc(100dvh - 150px));
  overflow-y: auto;
  border: 2px solid var(--accent);
  background: var(--surface);
  box-shadow: 4px 4px 0 var(--accent);
  padding: 14px;
}

.friends-panel.hidden {
  display: none;
}

body.room-window-mode .friends-panel.friend-window {
  position: fixed;
  width: 280px;
  min-width: min(240px, calc(100vw - 16px));
  min-height: min(260px, calc(100dvh - 16px));
  max-width: calc(100vw - 8px);
  max-height: calc(100dvh - 8px);
  margin-top: 0;
  resize: both;
  z-index: 22;
}

body.room-window-mode .friends-panel.friend-window .friends-header {
  cursor: move;
  user-select: none;
  touch-action: none;
}

body.room-window-mode .friends-panel.friend-window.is-dragging {
  opacity: 0.94;
}

.friends-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.friends-header h2 {
  font-size: 28px;
}

#add-friend-button {
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  margin-top: 0;
  padding: 0;
  font-size: 30px;
  line-height: 1;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

button:disabled:hover {
  background: var(--surface);
  color: var(--accent);
  transform: none;
  box-shadow: 3px 3px 0 var(--accent);
}

.friends-status,
.friends-empty {
  margin: 0;
  color: var(--muted);
}

.friends-list {
  display: grid;
  gap: 8px;
}

.friends-section-title {
  margin: 10px 0 0;
  color: var(--accent);
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  text-transform: uppercase;
}

.friend-row {
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  border: 2px solid var(--accent);
  background: transparent;
  overflow: hidden;
}

.friend-row:hover,
.friend-row:focus-within {
  background: var(--surface-soft);
}

.friend-row.joinable {
  cursor: pointer;
}

.friend-row.offline {
  opacity: 0.58;
  filter: grayscale(1);
}

.friend-info {
  display: grid;
  align-content: center;
  min-width: 0;
  padding: 7px 9px;
}

.friend-name,
.friend-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friend-name {
  color: var(--accent);
  line-height: 1;
}

.friend-meta {
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.friend-remove {
  display: none;
  align-self: center;
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  margin: 6px 6px 6px 0;
  padding: 0;
  border-color: var(--danger);
  background: var(--surface);
  color: var(--danger);
  box-shadow: none;
  line-height: 1;
}

.friend-row:hover .friend-remove,
.friend-row:focus-within .friend-remove {
  display: block;
}

.friend-remove:hover {
  background: var(--danger);
  color: var(--paper);
}

.friend-actions {
  display: flex;
  align-items: stretch;
}

.friend-actions button {
  min-height: 100%;
  margin-top: 0;
  padding: 4px 8px;
  box-shadow: none;
}

.friend-actions button:last-child {
  border-color: var(--danger);
  color: var(--danger);
}

.friend-actions button:last-child:hover {
  background: var(--danger);
  color: var(--paper);
}

.friend-pending-tag {
  align-self: center;
  margin-right: 8px;
  color: var(--muted);
  text-transform: uppercase;
}

.draw-panel {
  position: fixed;
  display: grid;
  width: 360px;
  gap: 12px;
  max-width: calc(100vw - 8px);
  max-height: calc(100dvh - 8px);
  overflow: auto;
  border: 2px solid var(--accent);
  background: var(--surface);
  box-shadow: 4px 4px 0 var(--accent);
  padding: 14px;
  z-index: 22;
}

.draw-panel.hidden {
  display: none;
}

.draw-panel.draw-window {
  min-width: min(300px, calc(100vw - 16px));
  min-height: min(420px, calc(100dvh - 16px));
  resize: both;
}

.draw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: move;
  user-select: none;
  touch-action: none;
}

.draw-header h2 {
  font-size: 28px;
}

.draw-toolbar,
.draw-actions,
.draw-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.draw-toolbar button,
.draw-actions button {
  flex: 1 1 84px;
  margin-top: 0;
  min-height: 40px;
  padding: 6px 8px;
}

.draw-toolbar button.active,
.draw-color.active {
  background: var(--accent);
  color: var(--paper);
}

.draw-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 2px solid var(--accent);
  background: #ffffff;
  box-shadow: inset 2px 2px 0 var(--soft-line);
  image-rendering: pixelated;
  touch-action: none;
}

.draw-color {
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  margin-top: 0;
  padding: 0;
  box-shadow: 2px 2px 0 var(--accent);
}

.draw-color[data-color="#ffffff"] {
  background:
    linear-gradient(45deg, #d8e5ff 25%, transparent 25% 75%, #d8e5ff 75%),
    linear-gradient(45deg, #d8e5ff 25%, #ffffff 25% 75%, #d8e5ff 75%);
  background-position: 0 0, 6px 6px;
  background-size: 12px 12px;
}

.draw-size-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  color: var(--accent);
  text-transform: uppercase;
}

.draw-size-row input {
  min-height: 30px;
  box-shadow: none;
}

.create-room-button {
  width: 56px;
  min-height: 56px;
  margin-top: 20px;
  padding: 0;
  font-size: 36px;
  line-height: 1;
}

.room-button {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-top: 0;
  padding: 18px;
  text-align: left;
}

.room-button.global-room {
  border-color: transparent;
  border-image: var(--global-rainbow) 1;
}

.room-button.global-room .room-name {
  color: var(--accent);
}

#chat-screen.global-room-active {
  border-color: transparent;
  border-image: var(--global-rainbow) 1;
}

#chat-screen.global-room-active #screen-title {
  color: var(--accent);
}

#chat-screen.global-room-active #messages,
#chat-screen.global-room-active #message-input,
#chat-screen.global-room-active #gif-button,
#chat-screen.global-room-active #chat-form button[type="submit"],
#chat-screen.global-room-active #users-button,
#chat-screen.global-room-active #draw-button {
  border-color: transparent;
  border-image: var(--global-rainbow) 1;
}

#chat-screen.global-room-active #gif-button,
#chat-screen.global-room-active #chat-form button[type="submit"],
#chat-screen.global-room-active #users-button,
#chat-screen.global-room-active #draw-button {
  background: var(--surface);
  background-clip: padding-box;
  color: var(--accent);
  box-shadow: 3px 3px 0 var(--accent);
}

#chat-screen.global-room-active #gif-button:hover,
#chat-screen.global-room-active #chat-form button[type="submit"]:hover,
#chat-screen.global-room-active #users-button:hover,
#chat-screen.global-room-active #draw-button:hover {
  background: var(--accent);
  color: var(--paper);
  box-shadow: 2px 2px 0 var(--line);
}

#chat-screen.global-room-active #message-input {
  box-shadow: inset 2px 2px 0 var(--soft-line);
}

#chat-screen.global-room-active #message-input:focus {
  border-color: transparent;
  border-image: var(--global-rainbow) 1;
  box-shadow: inset 2px 2px 0 var(--accent);
}

.room-users-panel.global-room-active,
.draw-panel.global-room-active,
.app-window.global-room-active {
  border-color: transparent;
  border-image: var(--global-rainbow) 1;
}

.room-users-panel.global-room-active h2,
.draw-panel.global-room-active h2 {
  color: var(--accent);
}

.room-users-panel.global-room-active .user-title {
  color: var(--muted);
}

.app-window.global-room-active .window-title {
  color: var(--accent);
}

.app-window.global-room-active .window-titlebar {
  border-bottom-color: transparent;
  border-image: var(--global-rainbow) 1;
}

.app-window.global-room-active .window-close {
  border-color: var(--danger);
  border-image: none;
  color: var(--danger);
  -webkit-text-fill-color: currentColor;
}

.draw-panel.global-room-active .draw-canvas,
.draw-panel.global-room-active .draw-toolbar button,
.draw-panel.global-room-active .draw-actions button,
.draw-panel.global-room-active .draw-color,
.draw-panel.global-room-active .draw-size-row input {
  border-color: transparent;
  border-image: var(--global-rainbow) 1;
}

.draw-panel.global-room-active .draw-toolbar button,
.draw-panel.global-room-active .draw-actions button,
.draw-panel.global-room-active .draw-color {
  box-shadow: 3px 3px 0 var(--accent);
}

.room-content {
  display: grid;
  gap: 6px;
}

.room-name {
  color: var(--accent);
}

.room-description,
.room-lock,
.room-count,
.empty-lobby {
  color: var(--muted);
}

.room-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex: 0 0 auto;
}

.room-count {
  flex: 0 0 auto;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--modal-backdrop);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  display: grid;
  width: min(520px, 100%);
  gap: 12px;
  border: 2px solid var(--accent);
  background: var(--surface);
  box-shadow: 4px 4px 0 var(--accent);
  padding: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions button {
  margin-top: 0;
}

.gif-form {
  display: flex;
  gap: 10px;
}

.gif-form input {
  flex: 1;
  min-width: 0;
}

.gif-form button {
  margin-top: 0;
}

.gif-status {
  min-height: 24px;
  margin: 0;
}

.gif-results {
  display: grid;
  max-height: min(420px, 50svh);
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
}

.gif-result {
  aspect-ratio: 1;
  margin-top: 0;
  padding: 0;
  overflow: hidden;
}

.gif-result img,
.gif-message img {
  display: block;
  width: 100%;
  image-rendering: auto;
}

.gif-result img {
  height: 100%;
  object-fit: cover;
}

.gif-message {
  display: block;
  max-width: min(320px, 100%);
  margin-top: 8px;
}

.gif-message img,
.drawing-message img {
  border: 2px solid var(--accent);
}

.drawing-message {
  display: block;
  max-width: min(320px, 100%);
  margin-top: 8px;
}

.drawing-message img {
  display: block;
  width: 100%;
  background: #ffffff;
  image-rendering: pixelated;
}

@keyframes wave-letter {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }
}

.wave-message {
  display: inline-flex;
  align-items: baseline;
}

.wave-message span {
  display: inline-block;
  animation: wave-letter 900ms ease-in-out infinite;
}

@keyframes shake-text {
  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }

  12% {
    transform: translate(-1px, 2px) rotate(-1deg);
  }

  24% {
    transform: translate(2px, -1px) rotate(1deg);
  }

  36% {
    transform: translate(-2px, -2px) rotate(0deg);
  }

  48% {
    transform: translate(2px, 2px) rotate(1deg);
  }

  60% {
    transform: translate(-1px, -2px) rotate(-1deg);
  }

  72% {
    transform: translate(2px, 1px) rotate(0deg);
  }

  84% {
    transform: translate(-2px, 1px) rotate(1deg);
  }
}

.shake-message {
  display: inline-block;
  max-width: 100%;
  animation: shake-text 260ms steps(2, end) infinite;
  transform-origin: center;
}

.video-player {
  flex: 0 0 auto;
  margin-top: 20px;
  border: 2px solid var(--accent);
  background: var(--surface-soft);
  box-shadow: inset 2px 2px 0 var(--soft-line);
  overflow: hidden;
}

.video-player iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
}

#messages {
  flex: 1;
  min-height: 0;
  height: auto;
  overflow-y: scroll;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  list-style: none;
  padding: 0 12px;
  margin: 20px 0;
  background: var(--surface-soft);
  border-radius: 0;
  border: 2px solid var(--accent);
  box-shadow: inset 2px 2px 0 var(--soft-line);
  scrollbar-color: var(--accent) var(--paper);
}

#messages::-webkit-scrollbar {
  width: 12px;
}

#messages::-webkit-scrollbar-track {
  background: var(--paper);
  border-left: 2px solid var(--accent);
}

#messages::-webkit-scrollbar-thumb {
  background: var(--accent);
}

#messages li {
  margin: 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--grid-line);
  line-height: 1.2;
  word-break: break-word;
  text-shadow: none;
}

#messages li:last-child {
  border-bottom: 0;
}

.meta {
  color: var(--accent);
}

.username {
  color: var(--accent);
}

.admin-badge {
  color: var(--danger);
}

.user-title {
  color: var(--muted);
}

.system {
  color: var(--accent);
}

.typing-indicator {
  display: flex;
  align-items: center;
  height: 24px;
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1;
  overflow: hidden;
}

#chat-form {
  display: flex;
  gap: 10px;
}

#name-form {
  display: grid;
  gap: 12px;
}

.name-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.name-actions button {
  margin-top: 0;
}

#chat-form input {
  flex: 1;
  min-width: 0;
}

#chat-form button {
  flex: 0 0 auto;
  margin-top: 0;
}

@media (max-width: 560px) {
  :root {
    --page-padding: 8px;
    --page-padding-block: 16px;
  }

  body {
    align-items: stretch;
    font-size: 21px;
  }

  .chat-shell {
    width: 100%;
  }

  .panel {
    padding: 14px;
    box-shadow: 3px 3px 0 var(--accent);
  }

  #name-screen {
    margin-top: 12svh;
  }

  #chat-screen {
    height: calc(100dvh - var(--page-padding-block) - var(--scheme-toggle-space));
    max-height: calc(100dvh - var(--page-padding-block) - var(--scheme-toggle-space));
  }

  h1 {
    font-size: clamp(30px, 12vw, 42px);
  }

  header {
    align-items: flex-start;
  }

  .header-actions {
    align-items: center;
    justify-content: flex-end;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 260px;
  }

  #status {
    order: 0;
    width: 100%;
    text-align: right;
  }

  #users-button {
    order: 1;
  }

  #draw-button {
    order: 2;
  }

  #lobby-button {
    order: 3;
  }

  #lobby-button {
    min-height: 36px;
    padding: 6px 8px;
  }

  #status {
    padding-top: 4px;
  }

  #messages {
    min-height: 180px;
    margin: 14px 0;
    padding: 0 10px;
  }

  .video-player {
    margin-top: 14px;
  }

  .video-player iframe {
    height: min(30svh, 190px);
    aspect-ratio: auto;
  }

  #chat-form {
    gap: 8px;
  }

  .room-button {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .modal-actions {
    flex-direction: column;
  }

  .gif-form {
    flex-direction: column;
  }

  .gif-results {
    grid-template-columns: repeat(2, 1fr);
  }

  #chat-form button {
    min-width: 72px;
  }
}

@media (max-width: 980px) {
  body.lobby-mode {
    align-items: stretch;
    justify-content: flex-start;
    padding: 0;
  }

  body.lobby-mode .chat-shell {
    display: grid;
    width: 100vw;
    max-width: none;
    margin-right: 0;
    grid-template-columns: calc(100vw - 48px) minmax(260px, calc(100vw - 32px));
    grid-auto-rows: max-content;
    gap: 16px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scroll-padding-inline: 8px;
    scroll-snap-type: x mandatory;
    padding: 8px 8px 18px;
    -webkit-overflow-scrolling: touch;
  }

  body.lobby-mode #chat-screen,
  body.lobby-mode .friends-panel {
    scroll-snap-align: start;
  }

  body.lobby-mode #chat-screen {
    grid-column: 1;
    width: calc(100vw - 48px);
    max-width: none;
  }

  body.lobby-mode .friends-panel {
    position: relative;
    top: auto;
    left: auto;
    grid-column: 2;
    width: min(320px, calc(100vw - 32px));
    margin-top: 0;
    max-height: calc(100dvh - 74px);
  }

  body.room-window-mode .friends-panel.friend-window {
    width: min(320px, calc(100vw - 16px));
    height: min(460px, calc(100dvh - 16px));
    resize: none;
  }

  body.room-window-mode .friends-panel.friend-window .friends-header {
    cursor: default;
    touch-action: auto;
  }

  body.lobby-mode .scheme-toggle {
    grid-column: 1;
    justify-self: end;
    scroll-snap-align: none;
  }

  .header-actions {
    align-items: center;
    justify-content: flex-end;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 260px;
  }

  #status {
    order: 0;
    width: 100%;
    text-align: right;
  }

  #users-button {
    order: 1;
  }

  #draw-button {
    order: 2;
  }

  #lobby-button {
    order: 3;
  }

  .exit-button {
    position: static;
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    background: var(--surface);
    color: var(--danger);
    box-shadow: 3px 3px 0 var(--danger);
  }

  .exit-button:hover {
    background: var(--danger);
    color: var(--paper);
  }
}

@media (max-width: 380px) {
  :root {
    --page-padding: 6px;
    --page-padding-block: 12px;
  }

  body {
    font-size: 19px;
  }

  .panel {
    padding: 12px;
  }

  #chat-screen {
    height: calc(100dvh - var(--page-padding-block) - var(--scheme-toggle-space));
    max-height: calc(100dvh - var(--page-padding-block) - var(--scheme-toggle-space));
  }

  input,
  button {
    padding: 8px;
  }

  #chat-form button {
    min-width: 64px;
  }
}

body.room-window-mode {
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
}

.room-window-mode .chat-shell {
  width: 100%;
  max-width: none;
  min-height: 100dvh;
}

body.room-window-mode .room-users-panel {
  position: fixed;
  right: auto;
  max-height: min(420px, calc(100dvh - 16px));
}

body.room-window-mode #chat-screen.room-window,
.app-window {
  position: fixed;
  display: flex;
  min-width: min(320px, calc(100vw - 16px));
  min-height: min(320px, calc(100dvh - 16px));
  max-width: calc(100vw - 8px);
  max-height: calc(100dvh - 8px);
  flex-direction: column;
  overflow: hidden;
  resize: both;
  z-index: 20;
}

body.room-window-mode #chat-screen.room-window {
  height: auto;
  padding: 18px;
}

body.room-window-mode #chat-screen.room-window header,
.window-titlebar {
  cursor: move;
  user-select: none;
  touch-action: none;
}

body.room-window-mode #chat-screen.room-window.is-dragging,
.app-window.is-dragging {
  opacity: 0.94;
}

body.room-window-mode #chat-screen.room-window .exit-button {
  position: static;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  background: var(--surface);
  color: var(--danger);
  box-shadow: 3px 3px 0 var(--danger);
}

body.room-window-mode #chat-screen.room-window .exit-button:hover {
  background: var(--danger);
  color: var(--paper);
}

.app-window {
  border: 2px solid var(--accent);
  background: var(--surface);
  box-shadow: 4px 4px 0 var(--accent);
  color: var(--ink);
}

.game-window {
  min-width: 484px;
  min-height: 468px;
}

.window-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
  min-height: 48px;
  border-bottom: 2px solid var(--accent);
  padding: 8px 10px;
  background: var(--surface-soft);
}

.window-title {
  color: var(--accent);
  font-size: 28px;
  line-height: 1;
  text-transform: uppercase;
}

.window-close {
  width: 36px;
  min-width: 36px;
  min-height: 36px;
  margin-top: 0;
  padding: 0;
  border-color: var(--danger);
  color: var(--danger);
  box-shadow: 2px 2px 0 var(--danger);
  line-height: 1;
}

.window-close:hover {
  background: var(--danger);
  color: var(--paper);
}

.game-frame-shell {
  position: relative;
  flex: 1;
  min-width: 480px;
  min-height: 416px;
  overflow: hidden;
  background: #000000;
}

.game-frame {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-width: 480px;
  min-height: 416px;
  border: 0;
  background: #000000;
  image-rendering: pixelated;
}

.game-window.is-resizing-game .game-frame {
  pointer-events: none;
}

.mobile-gamepad {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 120;
  display: none;
  height: 210px;
  pointer-events: none;
  touch-action: none;
  user-select: none;
}

.mobile-dpad {
  position: absolute;
  left: 22px;
  bottom: 22px;
  width: 168px;
  height: 168px;
  pointer-events: auto;
  touch-action: none;
}

.mobile-dpad-arm {
  position: absolute;
  background: rgba(220, 220, 220, 0.62);
  border-radius: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  pointer-events: none;
}

.mobile-dpad-up {
  left: 57px;
  top: 0;
  width: 54px;
  height: 66px;
}

.mobile-dpad-down {
  left: 57px;
  bottom: 0;
  width: 54px;
  height: 66px;
}

.mobile-dpad-left {
  left: 0;
  top: 57px;
  width: 66px;
  height: 54px;
}

.mobile-dpad-right {
  right: 0;
  top: 57px;
  width: 66px;
  height: 54px;
}

.mobile-gamepad.is-pressing-left .mobile-dpad-left,
.mobile-gamepad.is-pressing-right .mobile-dpad-right,
.mobile-gamepad.is-pressing-up .mobile-dpad-up,
.mobile-gamepad.is-pressing-down .mobile-dpad-down,
.mobile-gamepad-button.is-active {
  background: rgba(235, 235, 235, 0.78);
}

.mobile-gamepad-button {
  position: absolute;
  border: 0;
  padding: 0;
  background: rgba(220, 220, 220, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  pointer-events: auto;
  touch-action: none;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  color: transparent;
  cursor: default;
  transform: none;
}

.mobile-gamepad-button:hover,
.mobile-gamepad-button:active,
.mobile-gamepad-button:focus-visible {
  background: rgba(220, 220, 220, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  transform: none;
}

.mobile-gamepad-button.is-active {
  background: rgba(235, 235, 235, 0.78);
}

.mobile-gamepad-button-a {
  right: 22px;
  bottom: 92px;
  width: 104px;
  height: 104px;
  border-radius: 999px;
}

.mobile-gamepad-button-b {
  right: 54px;
  bottom: 18px;
  width: 86px;
  height: 50px;
  border-radius: 10px;
}

@media (max-width: 560px) {
  body.room-window-mode #chat-screen.room-window,
  .app-window {
    min-width: calc(100vw - 16px);
    min-height: min(280px, calc(100dvh - 16px));
  }

  body.room-window-mode #chat-screen.room-window {
    padding: 14px;
  }
}

@media (max-width: 980px) {
  .mobile-gamepad.is-visible {
    display: block;
  }

  .game-window {
    min-width: 0;
    min-height: 0;
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    resize: none;
  }

  .game-window .window-titlebar {
    cursor: default;
    touch-action: auto;
  }

  .game-frame-shell,
  .game-frame {
    min-width: 0;
    min-height: 0;
  }

  body.room-window-mode .chat-shell {
    display: grid;
    width: 100vw;
    min-height: 100dvh;
    grid-template-columns: calc(100vw - 48px) minmax(300px, calc(100vw - 32px));
    gap: 16px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scroll-padding-inline: 8px;
    scroll-snap-type: x mandatory;
    padding: 8px 8px 18px;
    -webkit-overflow-scrolling: touch;
  }

  body.room-window-mode #chat-screen.room-window {
    position: relative;
    grid-column: 1;
    width: calc(100vw - 48px) !important;
    height: calc(100dvh - 26px) !important;
    min-width: 0;
    min-height: min(420px, calc(100dvh - 26px));
    max-width: none;
    max-height: none;
    left: auto !important;
    top: auto !important;
    resize: none;
    scroll-snap-align: start;
  }

  body.room-window-mode #chat-screen.room-window header {
    cursor: default;
    touch-action: auto;
  }

  body.room-window-mode .draw-panel.draw-swipe-panel {
    position: relative;
    grid-column: 2;
    width: min(360px, calc(100vw - 32px));
    height: auto;
    min-width: 0;
    max-height: calc(100dvh - 26px);
    margin-top: 0;
    resize: none;
    scroll-snap-align: start;
  }

  body.room-window-mode .draw-panel.draw-swipe-panel .draw-header {
    cursor: default;
    touch-action: auto;
  }
}

