/* ==========================================================================
   KeepTalk — Stylesheet

   1. Design tokens
   2. Base
   3. Shared components
   4. App shell (header, footer, screens)
   5. Home screen
   6. Form screens (Create, Join, Credentials)
   7. Chat screen
   8. Accessibility
   ========================================================================== */


/* ==========================================================================
   1. Design tokens
   ========================================================================== */

:root {
  --bg: #f3f6fc;
  --card: #ffffff;
  --tx: #172033;
  --mut: #64748b;
  --pri: #2563eb;
  --onpri: #ffffff;
  --me: #dbeafe;
  --them: #ffffff;
  --bd: #dbe3ef;
  --err: #dc2626;
  --on: #16a34a;

  --fade: background-color .35s ease, color .35s ease, border-color .35s ease, box-shadow .35s ease;
  --ring: 0 0 0 3px rgba(37, 99, 235, .1);
  --msg-shadow: 0 1px 3px rgba(0, 0, 0, .07);


  /* Layout spacing (scales with the screen) */
  --edge: clamp(14px, 4.5vw, 32px);      /* side padding of screen content */
  --gutter: clamp(16px, 5vw, 64px);      /* side padding of header and footer */
  --mark: 42px;                          /* logo square */
  --app-header-space: calc(64px + env(safe-area-inset-top));
  --app-footer-space: calc(40px + env(safe-area-inset-bottom));
}

[data-theme=dark] {
  --bg: #0b1220;
  --card: #172338;
  --tx: #e5edf9;
  --mut: #94a3b8;
  --pri: #3b82f6;
  --onpri: #071426;
  --me: #173b70;
  --them: #172338;
  --bd: #2b3b54;
  --err: #f87171;
  --on: #22c55e;
}

/* ==========================================================================
   2. Base
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--tx);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

html {
  overflow-x: hidden;
}

/* While chatting, the document itself never scrolls. */
html:has(body.inchat) {
  overflow: hidden;
  overscroll-behavior: none;
}

body.inchat {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

/* Smooth light/dark switching. Components that need their own transition
   list include var(--fade) themselves. */
html,
body,
.screen,
.app-header,
.app-footer,
.chead,
.msg,
.icon,
.sheet,
#replyBar,
.form-card,
.create-code-panel {
  transition: var(--fade);
}


/* ==========================================================================
   3. Shared components
   ========================================================================== */

/* ---------- Buttons ---------- */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 52px;
  padding: 14px 22px;
  border: 0;
  border-radius: 11px;
  background: var(--pri);
  color: var(--onpri);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--fade), transform .2s ease, opacity .2s ease;
}

.btn:hover {
  transform: translateY(-2px);
  opacity: .94;
}

.btn.alt {
  border: 1px solid var(--bd);
  background: var(--card);
  color: var(--tx);
}

.btn svg {
  flex: 0 0 auto;
  width: 19px;
  height: 19px;
}

/* ---------- Icon button (chat) ---------- */

.icon {
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--bd);
  background: var(--bg);
  cursor: pointer;
}

/* ---------- Error text ---------- */

.err {
  min-height: 1.4em;
  color: var(--err);
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Sprite container ---------- */

.sprite {
  position: absolute;
  width: 0;
  height: 0;
}

/* ---------- Animated theme switch ---------- */

.theme-toggle {
  --tg-width: 92px;
  --tg-height: 42px;
  --tg-option: 40px;
  --tg-thumb: 34px;
  --tg-icon: 19px;
  --tg-edge: 3px;

  position: relative;
  flex-shrink: 0;
  width: var(--tg-width);
  height: var(--tg-height);
  padding: 0;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--bd);
  border-radius: 30px;
  background: var(--card);
  cursor: pointer;
  transition: background-color .35s ease, border-color .35s ease;
}

.theme-toggle:focus-visible {
  outline: 3px solid var(--pri);
  outline-offset: 4px;
}

.theme-option {
  position: absolute;
  top: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  width: var(--tg-option);
  height: var(--tg-option);
  color: var(--mut);
  pointer-events: none;
  transition: color .3s ease, opacity .3s ease;
}

.theme-sun {
  left: var(--tg-edge);
}

.theme-moon {
  right: var(--tg-edge);
}

.theme-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: var(--tg-thumb);
  height: var(--tg-thumb);
  border-radius: 50%;
  background: var(--pri);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .16);
  pointer-events: none;
  transition: left .35s cubic-bezier(.22, 1, .36, 1), background-color .35s ease;
}

.theme-toggle svg {
  display: block;
  width: var(--tg-icon);
  height: var(--tg-icon);
}

.theme-toggle.is-dark .theme-thumb {
  left: calc(100% - var(--tg-thumb) - 3px);
}

/* Hide the option that sits under the thumb. */
.theme-toggle.is-dark .theme-moon,
.theme-toggle:not(.is-dark) .theme-sun {
  opacity: 0;
}

@media (max-width: 380px) {
  .theme-toggle {
    --tg-width: 76px;
  }
}


/* ==========================================================================
   4. App shell
   Header and footer are fixed; every non-chat screen scrolls with the page.
   ========================================================================== */

/* ---------- Header ---------- */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--app-header-space);
  padding:
    calc(10px + env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    10px
    max(var(--gutter), env(safe-area-inset-left));
  border-bottom: 1px solid var(--bd);
  background: var(--card);
}

.brand {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: transparent;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
  display: block;
}

.brand-details {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.brand-details strong {
  font-size: 18px;
  letter-spacing: -.5px;
}

.brand-details small {
  color: var(--mut);
  font-size: clamp(8px, 2.3vw, 9px);
  font-weight: 700;
  letter-spacing: 1.5px;
}

/* ---------- Footer (always attached to the bottom) ---------- */

.app-footer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: var(--app-footer-space);
  padding:
    8px
    max(var(--gutter), env(safe-area-inset-right))
    calc(8px + env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
  border-top: 1px solid var(--bd);
  background: var(--card);
  color: var(--tx);
  font-size: 12px;
  font-weight: 700;
}

body.inchat .app-header,
body.inchat .app-footer,
body.keyboard-open .app-footer {
  display: none;
}

/* ---------- Screens ---------- */

.screen {
  display: flex;
  flex-direction: column;
}

/* Non-chat screens sit in normal flow: they are at least one screen tall,
   leave room for the fixed header and footer, and scroll with the page. */
.screen:not(#chat) {
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: var(--app-header-space);
  padding-bottom: var(--app-footer-space);
}

.app-screen {
  padding-right: max(var(--edge), env(safe-area-inset-right));
  padding-left: max(var(--edge), env(safe-area-inset-left));
  background:
    radial-gradient(ellipse at 50% 35%, rgba(37, 99, 235, .07), transparent 65%),
    var(--bg);
}

@media (max-width: 520px) {
  :root {
    --app-header-space: calc(60px + env(safe-area-inset-top));
    --app-footer-space: calc(44px + env(safe-area-inset-bottom));
    --mark: 38px;
  }

  .app-footer {
    justify-content: center;
    padding-top: 6px;
    font-size: 11px;
  }
}

/* Short landscape screens: a slimmer header and footer give content more room. */
@media (max-height: 500px) {
  :root {
    --app-header-space: calc(50px + env(safe-area-inset-top));
    --app-footer-space: calc(34px + env(safe-area-inset-bottom));
    --mark: 32px;
  }

  .app-header {
    padding-top: calc(6px + env(safe-area-inset-top));
    padding-bottom: 6px;
  }

  .app-footer {
    padding-top: 4px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
  }
}


/* ==========================================================================
   5. Home screen
   ========================================================================== */

.home-center {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 4.2vh, 32px);
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(20px, 5vh, 64px) 0;
  text-align: center;
}

.home-content {
  width: 100%;
}

.home-eyebrow {
  margin-bottom: clamp(14px, 2.6vh, 22px);
  color: var(--pri);
  font-size: clamp(9px, 1.4vw, 11px);
  font-weight: 800;
  letter-spacing: .22em;
}

.home-content h1 {
  color: var(--tx);
  font-size: clamp(32px, 4.6vw + 18px, 72px);
  font-weight: 800;
  letter-spacing: -.04em;
  line-height: 1.08;
}

.home-description {
  max-width: 520px;
  margin: clamp(14px, 2.6vh, 22px) auto 0;
  color: var(--mut);
  font-size: clamp(14px, .9vw + 11px, 18px);
  line-height: 1.7;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 14px;
  width: 100%;
}

.home-actions .btn {
  min-width: 190px;
}

.home-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: var(--mut);
  font-size: clamp(11px, .5vw + 9.5px, 13px);
}

.home-check {
  flex-shrink: 0;
  width: 19px;
  height: 19px;
  color: var(--on);
}

@media (max-width: 520px) {
  .home-actions {
    flex-direction: column;
    flex-wrap: nowrap;
  }

  .home-actions .btn {
    width: 100%;
    min-width: 0;
  }

  .home-note {
    text-align: center;
  }
}

@media (max-height: 500px) {
  .home-center {
    gap: 14px;
    padding: 14px 0;
  }

  .home-content h1 {
    font-size: clamp(28px, 9vh, 44px);
  }

  .home-description {
    margin-top: 10px;
    line-height: 1.5;
  }
}


/* ==========================================================================
   6. Form screens (Create, Join, Credentials)
   ========================================================================== */

/* ---------- Layout ---------- */

.form-layout {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 2.4vh, 22px);
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(14px, 3vh, 32px) 0;
}

/* ---------- Back button ---------- */

.back-btn {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--bd);
  border-radius: 10px;
  background: var(--card);
  color: var(--mut);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--fade);
}

.back-btn:hover {
  border-color: var(--pri);
  color: var(--pri);
}

.back-btn svg {
  width: 17px;
  height: 17px;
}

/* ---------- Card ---------- */

.form-card {
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 3vh, 26px);
  width: 100%;
  max-width: 490px;
  padding: clamp(20px, 4.5vw, 40px) clamp(16px, 5vw, 40px);
  border: 1px solid var(--bd);
  border-radius: clamp(18px, 3vw, 22px);
  background: var(--card);
  box-shadow: 0 16px 45px rgba(15, 35, 75, .07);
}

.card-heading {
  text-align: center;
}

.card-label {
  display: inline-block;
  margin-bottom: clamp(8px, 1.6vh, 13px);
  color: var(--pri);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 2px;
}

.card-heading h2 {
  color: var(--tx);
  font-size: clamp(23px, 1.2vw + 19px, 32px);
  letter-spacing: -.03em;
  line-height: 1.2;
}

.card-heading p {
  max-width: 370px;
  margin: clamp(8px, 1.6vh, 12px) auto 0;
  color: var(--mut);
  font-size: clamp(13px, .4vw + 11.5px, 14px);
  line-height: 1.65;
}

.card-note {
  margin-top: -10px;
  color: var(--mut);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

/* ---------- Fields ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  color: var(--tx);
  font-size: 13px;
  font-weight: 700;
}

.input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: clamp(48px, 7vh, 54px);
  padding: 0 clamp(12px, 3.5vw, 15px);
  border: 1px solid var(--bd);
  border-radius: 11px;
  background: var(--bg);
  transition: var(--fade);
}

.input-wrap:focus-within {
  border-color: var(--pri);
  box-shadow: var(--ring);
}

.input-wrap svg {
  flex: 0 0 19px;
  width: 19px;
  height: 19px;
  color: var(--mut);
}

.input-wrap input {
  width: 100%;
  min-width: 0;
  padding: 12px 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 14px;
}

.input-wrap input::placeholder {
  color: var(--mut);
  opacity: .8;
}

/* Monospaced, upper-case variant used for room codes. */
.code-input input {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.code-input input::placeholder {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

/* ---------- Create: room code panel ---------- */

.create-code-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2vh, 17px);
  width: 100%;
  padding: clamp(14px, 2.6vh, 22px) 12px;
  border: 1px solid var(--bd);
  border-radius: 16px;
  background: var(--bg);
}

.create-code-label {
  color: var(--mut);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.8px;
}

.create-code {
  width: 100%;
  padding: 6px 4px;
  color: var(--tx);
  font: 700 clamp(19px, 5.4vw, 29px)/1.2 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: clamp(1px, .5vw, 3px);
  overflow-wrap: anywhere;
  text-align: center;
  user-select: all;
}

.create-copy {
  gap: 10px;
  width: 100%;
  max-width: 230px;
  min-height: 46px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
}

.create-copy svg {
  width: 17px;
  height: 17px;
}

/* ---------- Join ---------- */

.join-icon {
  display: grid;
  place-items: center;
  width: clamp(48px, 9vh, 64px);
  height: clamp(48px, 9vh, 64px);
  margin: 4px auto clamp(12px, 2.4vh, 19px);
  border-radius: 18px;
  background: rgba(37, 99, 235, .09);
  color: var(--pri);
}

.join-icon svg {
  display: block;
  width: 58%;
  height: 58%;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 100%;
}

.join-hint {
  color: var(--mut);
  font-size: 11px;
  line-height: 1.5;
}

.join-error {
  margin: -5px 0;
}

/* ---------- Credentials ---------- */

.creds-fields {
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2.4vh, 19px);
}

.creds-error {
  margin-top: -12px;
}

.creds-pin-wrap {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(8px, 2.6vw, 12px);
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
}

.creds-digit {
  display: block;
  width: 100%;
  min-width: 0;
  height: clamp(54px, 8.5vh, 62px);
  padding: 0;
  border: 1px solid var(--bd);
  border-radius: 12px;
  outline: none;
  background: var(--bg);
  caret-color: var(--pri);
  font: 700 clamp(22px, 6vw, 25px) ui-monospace, Menlo, Consolas, monospace;
  text-align: center;
  transition: var(--fade);
}

.creds-digit:focus {
  border-color: var(--pri);
  box-shadow: var(--ring);
}

/* ---------- Short screens (landscape phones, split view) ---------- */

@media (max-height: 600px) {
  .form-layout {
    justify-content: flex-start;
  }

  .form-card {
    padding-top: 20px;
    padding-bottom: 20px;
  }
}


/* ==========================================================================
   7. Chat screen
   ========================================================================== */

/* ---------- Shell ---------- */

#chat {
  position: fixed;
  top: 0;
  left: 50%;
  width: min(100%, 960px);
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pan-y;
  transform: translateX(-50%);
  border-right: 1px solid var(--bd);
  border-left: 1px solid var(--bd);
  background: var(--bg);
  box-shadow: 0 0 36px rgba(15, 35, 75, .06);
}

/* No text selection in the chat; the hold menu replaces it. */
#chat,
#chat * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#chat textarea {
  -webkit-user-select: text;
  user-select: text;
}

#list ::selection,
#list::selection {
  background: transparent;
}

/* Message bubbles and the menus opened from them are never selectable. */
.msg,
.msg *,
.overlay,
.overlay * {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

/* ---------- Header ---------- */

.chead {
  --hbd: color-mix(in srgb, var(--bd) 65%, var(--pri));

  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  border-bottom: 1px solid var(--bd);
  background: var(--card);
}

/* Left: rounded-square back button, vertically centred across both rows */
.chead .back {
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  border: 1.5px solid var(--hbd);
  border-radius: 16px;
  background: transparent;
  color: var(--tx);
}

/* Centre: room code above username */
.chead-main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.room-code {
  max-width: 100%;
  overflow: hidden;
  color: var(--tx);
  font: 700 19px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  letter-spacing: .6px;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 27px;
  padding: 0 14px;
  overflow: hidden;
  border: 1.5px solid var(--hbd);
  border-radius: 999px;
  background: transparent;
  color: var(--tx);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.user-pill {
  max-width: 100%;
  text-overflow: ellipsis;
}

/* Right: two round buttons side by side, presence pill underneath */
.chead-side {
  display: flex;
  flex: 0 0 102px;
  flex-direction: column;
  gap: 4px;
}

.chead-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.chead-actions .icon {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 1.5px solid var(--hbd);
  border-radius: 50%;
  background: transparent;
  color: var(--tx);
}

.chead-actions .icon svg {
  width: 22px;
  height: 22px;
}

.presence {
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 25px;
  padding: 0 10px;
  color: var(--tx);
}

#status {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--mut);
}

.dot.on {
  background: var(--on);
}

/* ---------- Messages ---------- */

#list {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 7px;
  min-height: 0;
  padding: 14px clamp(12px, 3vw, 28px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: none contain;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: var(--bd) transparent;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(37, 99, 235, .025), transparent 65%),
    var(--bg);
}

#list::-webkit-scrollbar {
  width: 5px;
}

#list::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background: var(--bd);
}

.msg {
  max-width: min(78%, 620px);
  padding: 9px 12px 6px;
  border: 1px solid var(--bd);
  border-radius: 14px;
  background: var(--them);
  box-shadow: var(--msg-shadow);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.msg.me {
  align-self: flex-end;
  border-color: transparent;
  border-bottom-right-radius: 4px;
  background: var(--me);
}

.msg.them {
  align-self: flex-start;
  border-top-left-radius: 4px;
}

.msg .tm {
  display: block;
  margin-top: 4px;
  color: var(--mut);
  font-size: 10px;
  opacity: .8;
  text-align: right;
  white-space: nowrap;
}

.msg.flash {
  animation: flash 1.5s ease-out;
}

@keyframes flash {
  0%,
  55% {
    box-shadow: 0 0 0 3px var(--pri);
    filter: brightness(1.15);
  }

  100% {
    box-shadow: var(--msg-shadow);
    filter: none;
  }
}

.quote {
  margin-bottom: 6px;
  padding: 6px 8px;
  overflow: hidden;
  border-left: 3px solid var(--pri);
  border-radius: 6px;
  background: rgba(127, 127, 127, .15);
  color: var(--mut);
  font-size: 13px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.quote b {
  display: block;
  color: var(--pri);
  font-size: 12px;
}

/* ---------- Reply preview ---------- */

#replyBar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 7px 10px;
  border-top: 1px solid var(--bd);
  border-left: 3px solid var(--pri);
  background: var(--card);
}

#replyBar > div {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#replyBar b {
  display: block;
  margin-bottom: 2px;
  color: var(--pri);
}

#rbX {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

#rbX svg {
  width: 16px;
  height: 16px;
}

/* ---------- Composer ---------- */

.cfoot {
  display: flex;
  flex: 0 0 auto;
  background: transparent;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
}

#chat.kb .cfoot {
  padding-bottom: 8px;
}

/* One rounded container holds the text field and the send button. */
.composer {
  display: flex;
  flex: 1 1 auto;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
  padding: 6px 6px 6px 20px;
  border: 1.5px solid var(--bd);
  border-radius: 26px;           /* fixed radius: stays the same as the bar grows taller */
  background: transparent;       /* no background at all */
  box-shadow: none;
  transition: border-color .25s ease, box-shadow .25s ease;
}

.composer:focus-within {
  border-color: var(--pri);
  box-shadow: var(--ring);
}

#msgIn {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  max-height: 140px;
  padding: 9px 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 15px;
  line-height: 1.45;
}

#msgIn::placeholder {
  color: var(--mut);
  opacity: .85;
}

/* Rounded-square send button, dimmed until there is something to send. */
.send {
  display: grid;
  flex: 0 0 40px;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;            /* circular button */
  background: var(--pri);
  color: var(--onpri);
  opacity: .4;
  cursor: pointer;
  transition: var(--fade), transform .18s ease, opacity .2s ease;
}

.send.ready {
  opacity: 1;
}

.send:active {
  transform: scale(.92);
}

.send svg {
  width: 18px;
  height: 18px;
}

/* ---------- Message actions, delete confirmation and toast ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .45);
}

.sheet {
  width: min(calc(100% - 32px), 260px);
  padding: 6px;
  border: 1px solid var(--bd);
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 16px 45px rgba(15, 35, 75, .22);
}

.sheet button {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border: 0;
  border-radius: 10px;
  background: none;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.sheet button:hover {
  background: var(--bg);
}

.sheet .danger {
  color: var(--err);
}

/* Delete confirmation: always centred. */
#confirm {
  padding: 16px;
}

.dialog {
  width: 100%;
  max-width: 340px;
  padding: 22px 20px 18px;
  border: 1px solid var(--bd);
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 16px 45px rgba(15, 35, 75, .2);
}

.dialog h3 {
  font-size: 18px;
  letter-spacing: -.3px;
}

.dialog p {
  margin-top: 8px;
  color: var(--mut);
  font-size: 14px;
  line-height: 1.6;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.dialog-actions .btn {
  flex: 1;
  min-height: 46px;
  padding: 10px 14px;
}

.btn.danger {
  background: var(--err);
  color: #fff;
}

#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  z-index: 20;
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--tx);
  color: var(--bg);
  font-size: 14px;
  transform: translateX(-50%);
}

/* ---------- Responsive ---------- */

@media (max-width: 760px) {
  #chat {
    left: 0;
    width: 100%;
    transform: none;
    border-right: 0;
    border-left: 0;
    box-shadow: none;
  }

  #list {
    padding: 12px 10px;
  }

  .msg {
    max-width: 86%;
  }
}

@media (max-width: 380px) {
  .chead {
    gap: 10px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .chead .back {
    flex-basis: 46px;
    width: 46px;
    height: 46px;
    border-radius: 14px;
  }

  .chead-side {
    flex-basis: 96px;
  }

  .chead-actions {
    gap: 8px;
  }

  .chead-actions .icon {
    flex-basis: 44px;
    width: 44px;
    height: 44px;
  }

  .room-code {
    font-size: 16px;
    letter-spacing: .3px;
  }

  .pill {
    font-size: 12px;
  }

  .msg {
    max-width: 90%;
  }

  .cfoot {
    padding-right: 10px;
    padding-left: 10px;
  }

  .composer {
    padding-left: 14px;
  }

}

@media (max-height: 500px) and (max-width: 760px) {
  .chead {
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .cfoot {
    padding-top: 5px;
    padding-bottom: 5px;
  }
}


/* ==========================================================================
   8. Accessibility
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
