:root {
  color-scheme: light;
  --ink: #311520;
  --muted: #766873;
  --line: #ddd4d7;
  --paper: #f5f1ee;
  --panel: #ffffff;
  --main: #4a1c2b;
  --main-deep: #32121d;
  --accent: #c9a27e;
  --accent-strong: #9b6c49;
  --accent-soft: #f4e7da;
  --warn: #b42318;
  --sent: #f4e7da;
  --received: #efe9ea;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(74, 28, 43, 0.13), rgba(201, 162, 126, 0.2)),
    var(--paper);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.app-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px;
  display: flex;
}

.hidden {
  display: none !important;
}

.lobby,
.room {
  width: 100%;
}

.lobby {
  display: grid;
  align-content: center;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 40px;
}

.brand-block {
  align-self: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.7rem, 9vw, 5.4rem);
  line-height: 0.92;
  letter-spacing: 0;
  color: var(--main-deep);
}

.lobby-panel {
  width: 100%;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 18px 60px rgba(74, 28, 43, 0.14);
}

.primary-action,
.secondary-action,
.small-button,
.join-row button,
.composer button,
.image-button {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

.primary-action {
  width: 100%;
  color: #fffaf7;
  background: var(--main);
}

.primary-action:hover,
.join-row button:hover,
.composer button:hover {
  background: var(--main-deep);
}

.join-form {
  margin-top: 22px;
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 10px;
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 162, 126, 0.34);
}

.join-row button,
.composer button {
  color: #fffaf7;
  background: var(--main);
}

.error-text {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--warn);
  font-size: 0.94rem;
  font-weight: 700;
}

.room {
  min-height: calc(100vh - 56px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 16px;
}

.room-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(74, 28, 43, 0.14);
}

.room-code-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.room-code-row h1 {
  font-size: clamp(2rem, 8vw, 3.7rem);
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.status-badge {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.82);
  font-size: 0.86rem;
  font-weight: 800;
}

.status-badge.connected {
  color: #7b4f32;
  border-color: rgba(201, 162, 126, 0.62);
  background: rgba(244, 231, 218, 0.96);
}

.secondary-action,
.small-button,
.image-button {
  color: var(--main);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
}

.secondary-action:hover,
.small-button:hover,
.image-button:hover {
  color: var(--accent-strong);
  border-color: rgba(201, 162, 126, 0.68);
  background: var(--accent-soft);
}

.chat-wrap {
  position: relative;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.84);
}

.messages {
  height: 100%;
  max-height: calc(100vh - 230px);
  min-height: 360px;
  margin: 0;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  list-style: none;
}

.message {
  max-width: min(76%, 620px);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-wrap: anywhere;
}

.message.self {
  align-self: flex-end;
  background: var(--sent);
}

.message.peer {
  align-self: flex-start;
  background: var(--received);
}

.message.system {
  align-self: center;
  max-width: 88%;
  color: var(--muted);
  background: transparent;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
}

.message img {
  display: block;
  width: min(100%, 420px);
  max-height: 420px;
  border-radius: 8px;
  object-fit: contain;
}

.image-preview-button {
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 8px;
  display: block;
  background: transparent;
  cursor: zoom-in;
}

.image-preview-button:focus-visible {
  outline: 3px solid rgba(201, 162, 126, 0.72);
  outline-offset: 3px;
}

.message .meta {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--accent-strong);
  background: rgba(245, 241, 238, 0.9);
  font-size: 1.2rem;
  font-weight: 900;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 90px;
  gap: 10px;
}

.image-button {
  margin: 0;
  cursor: pointer;
}

.image-modal {
  width: min(94vw, 980px);
  max-height: 92vh;
  border: 1px solid rgba(201, 162, 126, 0.48);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: rgba(255, 250, 247, 0.98);
  box-shadow: 0 24px 80px rgba(50, 18, 29, 0.28);
}

.image-modal::backdrop {
  background: rgba(50, 18, 29, 0.68);
}

.image-modal-frame {
  max-height: 92vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.image-modal-header,
.image-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
}

.image-modal-header {
  border-bottom: 1px solid var(--line);
}

.image-modal-header h2 {
  margin: 0;
  color: var(--main-deep);
  font-size: 1rem;
  letter-spacing: 0;
}

.image-modal-body {
  min-height: 260px;
  padding: 16px;
  display: grid;
  place-items: center;
  overflow: auto;
  background: #f8f5f2;
}

.image-modal-body img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 8px;
  object-fit: contain;
}

.image-modal-footer {
  border-top: 1px solid var(--line);
}

.image-modal-footer p {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.icon-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--main);
  background: #fff;
  font-weight: 800;
}

.icon-button:hover {
  color: var(--accent-strong);
  border-color: rgba(201, 162, 126, 0.68);
  background: var(--accent-soft);
}

@media (max-width: 720px) {
  .app-shell {
    padding: 18px;
  }

  .lobby {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .room-header {
    display: grid;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .composer {
    grid-template-columns: 1fr 1fr;
  }

  .composer input[type="text"],
  #messageInput {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .image-button,
  .composer button {
    grid-row: 2;
  }

  .message {
    max-width: 92%;
  }

  .image-modal-footer {
    display: grid;
  }

  .image-modal-actions {
    justify-content: stretch;
  }

  .image-modal-actions .small-button {
    flex: 1 1 140px;
  }
}
