:root {
  color-scheme: dark;
  font: 16px/1.4 var(--chat-font, system-ui, sans-serif);
  --surface: #17212b;
  --chat-bg: #0e1621;
  --text: #f5f5f5;
  --muted: #92a3b2;
  --accent: #70baf5;
  --bubble-bg: #182533;
  --key-bg: #213040d5;
  --bubble-width: 430px;
  --bubble-radius: 16px;
  --thread-gutter: 40px;
  --message-font-size: 13px;
  --message-line-height: 17.5px;
  background: var(--chat-bg);
  color: var(--text);
}
* { box-sizing: border-box; }
body, h1, h2, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; cursor: pointer; background: transparent; }
button:disabled { opacity: .6; cursor: default; }
button, input, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.chat { display: grid; grid-template-rows: auto 1fr auto; height: 100vh; height: 100dvh; }
.bar { background: var(--surface); }
.frame { width: 100%; padding-inline: 12px; }
.identity { display: flex; align-items: center; gap: 12px; padding-block: 10px; }
header.bar { padding-top: env(safe-area-inset-top); }
.avatar { display: grid; place-items: center; flex: 0 0 40px; height: 40px; border-radius: 50%; background: #32648b; font-size: 20px; font-weight: 600; }
.identity-text { min-width: 0; }
h1, h2 { font-size: 17px; line-height: 1.35; }
#profile { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
#history { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.thread { padding: 8px 16px 10px 14px; }
#history.intro-visible { display: grid; align-items: center; }
#intro { max-width: 21rem; margin-inline: auto; padding: 16px 20px; border-radius: 16px; background: var(--surface); }
#intro p { margin-top: 5px; font-size: 15px; }
#start { display: block; width: 100%; min-height: 54px; color: var(--accent); font-size: 17px; font-weight: 650; }
#messages { display: grid; gap: 6px; }
.message {
  position: relative; justify-self: start; min-width: 0;
  margin-inline-start: var(--thread-gutter);
  max-width: min(var(--bubble-width), calc(100% - var(--thread-gutter)));
  font-size: var(--message-font-size); line-height: var(--message-line-height);
}
.message.out { justify-self: end; margin-inline: 0; }
.sender-avatar {
  position: absolute; inset-inline-end: calc(100% + 8px); bottom: 0;
  width: 33px; height: 33px; border-radius: 50%; object-fit: cover;
  display: grid; place-items: center; background: #32648b;
  font-size: 15px; font-weight: var(--chat-medium);
}
.message:has(+ .message:not(.out)) .sender-avatar { visibility: hidden; }
.bubble { position: relative; max-width: 100%; background: var(--bubble-bg); border-radius: var(--bubble-radius) var(--bubble-radius) var(--bubble-radius) 6px; }
.out .bubble { background: #2b5278; border-radius: var(--bubble-radius) var(--bubble-radius) 6px var(--bubble-radius); }
.message:has(.keys) .bubble { border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; }
.message-text { display: flow-root; padding: 6px 11px 8px; overflow-wrap: anywhere; white-space: pre-wrap; }
.message-text strong { font-weight: var(--chat-medium); }
.bubble:has(> .message-time) .message-text::after { content: ''; display: inline-block; vertical-align: bottom; width: 3em; }
.message-time { position: absolute; inset: auto 10px 4px auto; color: #6d7f8f; font-size: 13px; font-weight: 400; line-height: var(--message-line-height); }
.out .message-time { color: #94b4cf; }
.bubble:not(:has(.message-text)) > .message-time { inset: auto 5px 5px auto; padding: 1px 5px; border-radius: 7px; background: #0008; color: #fff; pointer-events: none; }
.bubble > .media-frame { position: relative; overflow: hidden; border-radius: inherit; }
.bubble:has(.message-text) > .media-frame { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
/* Match caption and keyboard width to the displayed media, including portrait photos. */
.message:has(.media-frame :is(img, video)) { min-width: min(200px, calc(100% - var(--thread-gutter))); }
.message:has(.media-frame :is(img, video)) :is(.message-text, .keys) { container-type: inline-size; }
.media-frame img, .media-frame video { display: block; min-width: min(200px, 100%); max-width: 100%; max-height: 430px; height: auto; object-fit: contain; }
.media-frame video { background: #101010; }
.media-duration { position: absolute; z-index: 1; top: 6px; left: 6px; border-radius: 7px; padding: 1px 6px; background: #0007; color: white; font-size: 12px; line-height: 16px; pointer-events: none; }
.media-progress { position: absolute; z-index: 1; inset: auto 0 0; width: 100%; height: 4px; border: 0; background: #c8cbce; accent-color: #5288c1; appearance: none; pointer-events: none; }
.media-progress::-webkit-progress-bar { background: #c8cbce; }
.media-progress::-webkit-progress-value { background: #5288c1; }
.media-progress::-moz-progress-bar { background: #5288c1; }
.media-open { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; }
.media-open:focus-visible { outline-offset: -3px; }
.media-viewer {
  position: fixed; inset: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%;
  margin: 0; border: 0; padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: #0b0e12f5; color: white;
}
.media-viewer::backdrop { background: #090c10; }
.media-viewer[open] { display: flex; flex-direction: column; }
.viewer-media { display: grid; place-items: center; flex: 1; min-height: 0; overflow: hidden; }
.viewer-media img, .viewer-media video { display: block; max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; }
.viewer-tools { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding-block: 4px; }
.viewer-tools a, .viewer-tools button { min-height: 40px; padding: 8px 12px; border-radius: 8px; background: #26333e; color: white; font: inherit; text-decoration: none; }
.bubble a { color: var(--accent); overflow-wrap: anywhere; text-decoration: none; }
.bubble a:hover { text-decoration: underline; }
.media-cover { display: block; width: min(19rem,65vw); min-height: 7rem; background: #25394b; border-radius: inherit; color: var(--accent); }
.download { display: inline-flex; align-items: center; min-height: 40px; margin-inline: 11px; color: var(--accent); }
.keys { display: grid; gap: 2px; margin-top: 2px; }
.key-row { display: flex; gap: 2px; }
.key-row button, .key-row a {
  flex: 1 1 0; min-width: 0; min-height: 36px; padding: 4px 10px;
  border-radius: 6px; background: var(--key-bg); font-size: inherit;
  line-height: inherit; font-weight: var(--chat-medium); overflow-wrap: anywhere;
}
.key-row a { display: grid; place-items: center; text-align: center; color: var(--text); text-decoration: none; }
.key-row:last-child > :first-child { border-bottom-left-radius: var(--bubble-radius); }
.key-row:last-child > :last-child { border-bottom-right-radius: var(--bubble-radius); }
.notice { margin: 0; padding-top: 6px; color: var(--accent); overflow-wrap: anywhere; }
#bot-alert, #copy-dialog {
  width: min(21rem, calc(100% - 2rem)); max-height: calc(100% - 2rem); padding: 20px 20px 10px;
  border: 1px solid #304458; border-radius: 12px; background: var(--surface); color: var(--text);
  box-shadow: 0 12px 40px #0006;
}
#bot-alert::backdrop, #copy-dialog::backdrop { background: #0009; }
#copy-value { display: block; width: 100%; margin-top: 10px; font: inherit; }
#bot-alert-text { white-space: pre-wrap; overflow-wrap: anywhere; }
#bot-alert form, #copy-dialog form { margin-top: 12px; text-align: end; }
#bot-alert button, #copy-dialog button { min-width: 48px; min-height: 44px; color: var(--accent); font-weight: 600; }
#progress { display: block; color: var(--muted); padding-bottom: 4px; font-size: 13px; }
.card { max-width: 25rem; margin-top: 14px; padding: 16px; background: var(--surface); border-radius: 14px; }
.card p { color: var(--muted); margin: 6px 0 10px; }
#telegram-login {
  width: min(25rem, calc(100vw - 32px));
  border: 1px solid #435669;
  border-radius: 14px;
  padding: 20px;
  background: var(--surface);
  color: var(--text);
}
#telegram-login::backdrop { background: rgb(0 0 0 / 68%); }
#telegram-login h2 { margin: 0 0 8px; }
#telegram-login p { margin: 0 0 10px; color: var(--muted); }
#telegram-login-link { display: grid; place-items: center; color: var(--text); text-decoration: none; }
.primary { margin-top: 7px; min-height: 44px; padding: 8px 14px; background: #437da8; border-radius: 8px; font-weight: 600; }
.composer-bar { padding-bottom: env(safe-area-inset-bottom); }
.composer-bar > .frame { padding-inline: 8px; }
#composer { position: relative; display: flex; align-items: center; min-height: 46px; }
#command-list {
  position: absolute; z-index: 1; bottom: 100%; inset-inline-start: 0;
  width: min(24rem, 100%); max-height: min(53dvh, 24rem); overflow-y: auto;
  overscroll-behavior: contain; padding: 4px; border-radius: 12px;
  background: var(--surface); border: 1px solid #304458; box-shadow: 0 4px 16px #0005;
}
#command-list button {
  display: grid; align-items: center; grid-template-columns: 5.2rem 1fr; gap: 8px;
  width: 100%; min-height: 44px; padding: 7px 10px; border-radius: 7px; text-align: start;
}
#command-list button strong { color: var(--accent); }
#command-list button span { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
#command-list button:hover, #command-list button:focus-visible { background: #253748; }
#menu {
  height: 30px; padding-inline: 12px; border-radius: 15px; background: #2f6ea5;
  color: white; font-weight: var(--chat-medium); font-size: var(--message-font-size);
}
.icon { flex: 0 0 44px; height: 46px; padding: 0; display: grid; place-items: center; border-radius: 50%; color: #6c7883; }
.icon svg { display: block; }
#attach svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#send { color: #5288c1; }
#send svg { width: 24px; height: 24px; fill: currentColor; }
#draft { flex: 1; min-width: 0; height: 44px; border: 0; padding: 0 4px; background: transparent; font-size: var(--message-font-size); }
#draft:focus { outline: none; }
#draft::placeholder { color: #6d7883; }
#draft:focus::placeholder { color: #4f5b67; }
.feedback { display: flex; align-items: center; gap: 10px; padding-top: 8px; }
#error { flex: 1; color: #ffd3be; font-size: 14px; overflow-wrap: anywhere; }
#refresh { color: var(--accent); min-height: 44px; font-size: 14px; }
@media (hover: hover) {
  button:hover:enabled { filter: brightness(1.18); }
  .key-row button:hover:enabled, .key-row a:hover { background: #283949; filter: none; }
}
@media (pointer: coarse) {
  :root { --message-font-size: 16px; --message-line-height: 21px; }
  .key-row button, .key-row a { min-height: 44px; font-size: 14px; }
  #composer { min-height: 50px; }
  #menu { height: 34px; border-radius: 18px; }
  #draft { font-size: 16px; }
}
@media (max-width: 540px) {
  .thread { padding-inline: 8px; }
  .message { --thread-gutter: 34px; }
  .sender-avatar { width: 28px; height: 28px; inset-inline-end: calc(100% + 6px); }
  .card { max-width: 100%; }
  .media-frame img, .media-frame video { max-height: 60dvh; }
}
