/* Study rooms (public/js/costudy.js). Desktop and tablet: a floating drawer on
   the right that leaves the page usable. Phone: a full-screen sheet that sits
   on the visual viewport, so the keyboard never covers the composer. */

/* ── Pixel creatures ─────────────────────────────────────────────────── */
/* Motion moves the whole creature (a composited transform), never the
   shapes inside its SVG, so a room full of them costs a phone nothing. */
.cs-av { position: relative; display: inline-flex; align-items: flex-end; justify-content: center;
  width: var(--cs-size, 40px); height: calc(var(--cs-size, 40px) * 0.84); flex: none; line-height: 0; }
.cs-av svg { display: block; overflow: visible; stroke: none !important; }
.cs-av .cs-eyes-shut { display: none; }
.cs-av .cs-zz { position: absolute; top: -2px; right: -4px; display: none; font: 700 calc(var(--cs-size, 40px) * 0.26)/1 var(--font-mono, monospace);
  color: var(--text-secondary); pointer-events: none; }
.cs-av--studying svg { animation: cs-bob 1.2s steps(2, jump-none) infinite; will-change: transform; }
.cs-av--busy::after { content: ''; position: absolute; top: 14%; right: -6%; width: 18%; height: 18%;
  border-radius: 50%; background: #F6C85F; box-shadow: 0 0 0 2px var(--surface-2, #142137); }
.cs-av--idle .cs-eyes, .cs-av--away .cs-eyes { display: none; }
.cs-av--idle .cs-eyes-shut, .cs-av--away .cs-eyes-shut { display: inline; }
.cs-av--idle .cs-zz { display: block; animation: cs-zz 2.6s ease-in-out infinite; will-change: transform, opacity; }
.cs-av--away { opacity: 0.45; }
.cs-av--away svg { filter: grayscale(1); }

@keyframes cs-bob { 0% { transform: translateY(0); } 50% { transform: translateY(calc(var(--cs-size, 40px) * -0.05)); } 100% { transform: translateY(0); } }
@keyframes cs-zz { 0% { opacity: 0; transform: translate(0, 4px) scale(0.8); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(4px, -8px) scale(1.15); } }

/* ── Entry points (portal header, class menu) ───────────────────────── */
.cs-entry[hidden] { display: none !important; }
.cs-entry { position: relative; }
.cs-entry__av { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; flex: none; }
.cs-entry__av .cs-av { width: 22px; height: 19px; }
.cs-entry__badge { position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; box-sizing: border-box;
  background: var(--danger, #e5484d); color: #fff; font: 700 10.5px/18px var(--font-ui, system-ui); text-align: center; pointer-events: none; }
.cs-entry__badge[hidden] { display: none; }
.cs-entry.is-live .cs-entry__av::after { content: ''; position: absolute; right: -3px; bottom: -1px; width: 8px; height: 8px; border-radius: 50%;
  background: #4ade80; box-shadow: 0 0 0 2px var(--surface-2, #142137); }
.cs-entry--header { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; }
.cs-entry--header .cs-entry__label { font-weight: 600; font-size: 14px; white-space: nowrap; }
.cs-entry--header .cs-entry__badge { top: -4px; right: -4px; }
.cs-entry--tab .tab-icon { display: inline-flex; align-items: center; justify-content: center; }
.cs-entry--tab .cs-entry__av, .cs-entry--tab .cs-entry__av .cs-av { width: 17px; height: 17px; }
.cs-entry--tab .cs-entry__av svg { width: 17px !important; height: 15px !important; }
.cs-entry--tab .cs-entry__badge { top: 4px; right: 6px; }
.cs-entry--drawer .cs-entry__badge { position: static; margin-left: auto; }
@media (max-width: 768px), (max-height: 500px) and (orientation: landscape) and (pointer: coarse) {
  .cs-entry--header { width: 40px; padding: 0; justify-content: center; }
  .cs-entry--header .cs-entry__label { display: none; }
}

/* ── Panel ───────────────────────────────────────────────────────────── */
.cs-panel { position: fixed; z-index: calc(var(--z-modal, 20000) - 1); top: 16px; right: 16px; bottom: 16px; width: min(400px, calc(100vw - 32px));
  display: flex; flex-direction: column; overflow: hidden; border-radius: 18px; border: 1px solid var(--line, rgba(255,255,255,.1));
  /* Touch tablets: opaque (the surface colour is translucent in some themes,
     so it is laid over the page background); blurring the page behind is
     what made touch devices stutter. Mouse screens and phones: see below. */
  background: linear-gradient(var(--surface-2, #142137), var(--surface-2, #142137)), var(--bg-primary, #0b1220);
  color: var(--text-primary); box-shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  font-family: var(--font-ui, system-ui); opacity: 0; transform: translateX(16px);
  transition: opacity .18s ease, transform .2s cubic-bezier(.2, .8, .2, 1); contain: layout paint; }
.cs-panel.is-open { opacity: 1; transform: none; }
.cs-panel[hidden] { display: none; }
.cs-panel .btn { white-space: nowrap; }

.cs-head { position: relative; display: flex; align-items: center; gap: 12px; padding: 14px 12px 12px 18px;
  border-bottom: 1px solid var(--line-subtle, rgba(255,255,255,.06)); }
.cs-head__text { flex: 1; min-width: 0; }
.cs-head__title { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 17px; font-weight: 700; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-head__sub { margin: 2px 0 0; font-size: 12.5px; color: var(--text-secondary); }
.cs-head__actions { display: flex; gap: 2px; }
.cs-icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; flex: none; padding: 0;
  border: 0; border-radius: 10px; background: transparent; color: var(--text-secondary); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.cs-icon-btn svg { width: 20px; height: 20px; }
.cs-icon-btn:hover:not(:disabled) { background: var(--fill-hover, rgba(255,255,255,.05)); color: var(--text-primary); }
.cs-icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cs-icon-btn:disabled { opacity: .4; cursor: default; }
.cs-back { width: 32px; height: 32px; margin-left: -8px; }

.cs-menu { position: absolute; right: 52px; top: 52px; z-index: 3; min-width: 200px; padding: 6px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2, #142137); box-shadow: 0 16px 40px rgba(0,0,0,.35); }
.cs-menu button { display: block; width: 100%; padding: 11px 12px; border: 0; border-radius: 8px; background: none; color: var(--text-primary);
  font: 500 14px/1.2 var(--font-ui, system-ui); text-align: left; cursor: pointer; }
.cs-menu button:hover { background: var(--fill-hover); }
.cs-menu button.is-danger { color: var(--danger, #e5484d); }

.cs-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; overscroll-behavior: contain; }
.cs-section { margin: 18px 0 8px; font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted, var(--text-secondary)); }
.cs-input { width: 100%; min-height: 44px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-3, rgba(0,0,0,.2)); color: var(--text-primary); font: 15px/1.4 var(--font-ui, system-ui); box-sizing: border-box; }
.cs-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.cs-link { padding: 4px 8px; border: 0; background: none; color: var(--accent-light, var(--accent)); font: 600 13.5px/1.2 var(--font-ui, system-ui); cursor: pointer; }

/* Lobby */
.cs-lobby { padding: 8px 18px 20px; }
.cs-hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 18px 8px 6px; }
.cs-hero__me { display: inline-flex; padding: 18px 20px 12px; border: 0; border-radius: 24px; cursor: pointer;
  background: radial-gradient(circle at 50% 70%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%); }
.cs-hero__name { margin: 8px 0 0; font-size: 16px; font-weight: 700; }
.cs-hero__hint { max-width: 300px; margin: 10px 0 0; font-size: 13.5px; line-height: 1.5; color: var(--text-secondary); }
.cs-invites { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cs-invite { display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; align-items: center; padding: 12px; border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line)); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.cs-invite__text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cs-invite__text strong { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-invite__text span { font-size: 12.5px; color: var(--text-secondary); }
.cs-invite__btns { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }
.cs-start { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.cs-start__btn { min-height: 48px; font-size: 15px; }

/* Room */
.cs-room { overflow: hidden; }
.cs-members { list-style: none; margin: 0; padding: 12px 12px 10px; display: flex; gap: 8px; overflow-x: auto; flex: none;
  scrollbar-width: none; border-bottom: 1px solid var(--line-subtle); scroll-snap-type: x proximity; }
.cs-members::-webkit-scrollbar { display: none; }
.cs-member { position: relative; flex: none; width: 104px; padding: 10px 6px 8px; border-radius: 14px; text-align: center;
  background: var(--surface-3, rgba(0,0,0,.15)); scroll-snap-align: start; }
.cs-member.is-invited { opacity: .6; }
.cs-member__av { position: relative; display: flex; justify-content: center; height: 48px; align-items: flex-end; }
.cs-member__crown { position: absolute; top: -6px; left: 12px; font-size: 13px; color: #F6C85F; text-shadow: 0 1px 0 rgba(0,0,0,.4); }
.cs-member__name { margin-top: 6px; font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-member__status { margin-top: 2px; font-size: 11.5px; line-height: 1.3; color: var(--text-secondary);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; height: 3.9em; overflow-wrap: anywhere; }
.cs-member__x { position: absolute; top: 2px; right: 2px; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 8px; background: transparent; color: var(--text-muted, var(--text-secondary)); cursor: pointer; opacity: 0; }
.cs-member__x svg { width: 14px; height: 14px; }
.cs-member:hover .cs-member__x, .cs-member__x:focus-visible { opacity: 1; }
@media (hover: none) { .cs-member__x { opacity: .7; } }

.cs-log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.cs-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.cs-msg.is-cont { margin-top: -6px; }
.cs-msg.is-cont .cs-msg__name { display: none; }
.cs-msg.is-cont .cs-msg__av { visibility: hidden; }
.cs-msg__av { flex: none; width: 28px; padding-bottom: 18px; }
.cs-msg__main { min-width: 0; max-width: 82%; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.cs-msg__name { font-size: 12px; font-weight: 700; color: var(--text-secondary); padding-left: 2px; }
.cs-msg__bubble { padding: 9px 13px; border-radius: 16px 16px 16px 6px; background: var(--surface-3, rgba(0,0,0,.2));
  border: 1px solid var(--line-subtle); font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.cs-msg__time { font-size: 10.5px; color: var(--text-muted, var(--text-secondary)); padding: 0 4px; }
.cs-msg.is-mine { justify-content: flex-end; }
.cs-msg.is-mine .cs-msg__main { align-items: flex-end; }
.cs-msg.is-mine .cs-msg__bubble { border-radius: 16px 16px 6px 16px; background: var(--accent); border-color: transparent;
  color: var(--on-accent, #fff); }
.cs-msg--sys { justify-content: center; }
.cs-msg--sys span { padding: 4px 12px; border-radius: 999px; background: var(--fill-hover); font-size: 12px; color: var(--text-secondary); text-align: center; }

.cs-card { width: min(320px, 100%); padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface-1, rgba(255,255,255,.03)); text-align: left; box-sizing: border-box; }
.cs-card__meta { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-secondary); }
.cs-card__meta svg { width: 14px; height: 14px; flex: none; color: var(--accent-light, var(--accent)); }
.cs-card__meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The content is shown whole; a long one is cut at about a screenful's
   third with a fade and a "See all" that opens it in place. */
/* Only a long page's prose is cut (about nine lines, with a fade); a
   question and its answers always show whole. */
.cs-card__text { position: relative; max-height: 13.5em; overflow: hidden; }
/* The fade is a mask on the text itself, so it is right on any card
   background, solid or showing the theme through. */
.cs-card.is-long:not(.is-expanded) .cs-card__text {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 3em), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 3em), transparent); }
.cs-card.is-expanded .cs-card__text { max-height: none; }
.cs-card__title { margin-top: 6px; font-size: 14.5px; font-weight: 700; line-height: 1.4; overflow-wrap: anywhere; white-space: pre-line; }
.cs-card__text { margin-top: 6px; font-size: 13.5px; line-height: 1.5; color: var(--text-secondary); white-space: pre-line; overflow-wrap: anywhere; }
.cs-card__opts { list-style: upper-alpha; margin: 10px 0 0; padding: 0 0 0 22px; display: flex; flex-direction: column; gap: 6px; }
.cs-opt { padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); font-size: 13.5px; line-height: 1.35; overflow-wrap: anywhere; }
.cs-opt::marker { color: var(--text-secondary); font-weight: 700; font-size: 12px; }
.cs-opt.is-picked { border-color: var(--accent); color: var(--accent-light, var(--accent)); }
.cs-card__pick { margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.cs-card__more { margin-top: 8px; padding: 0; min-height: 32px; border: 0; background: none; color: var(--accent-light, var(--accent));
  font: 700 13px/1.2 var(--font-ui, system-ui); cursor: pointer; }
.cs-card__more[hidden] { display: none; }

.cs-compose { flex: none; padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line-subtle); }
.cs-compose__card[hidden] { display: none; }
.cs-chip { position: relative; margin: 2px 2px 8px; }
.cs-chip .cs-card { width: 100%; border-style: dashed; }
.cs-chip .cs-card__body { max-height: 96px; overflow: hidden; }
.cs-chip .cs-card__more { display: none; }
.cs-chip__x { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 8px; background: var(--surface-2); color: var(--text-secondary); cursor: pointer; }
.cs-chip__x svg { width: 14px; height: 14px; }
.cs-compose__row { display: flex; align-items: flex-end; gap: 6px; }
.cs-text { flex: 1; resize: none; max-height: 120px; padding: 11px 14px; border-radius: 22px; overflow-y: hidden; }
.cs-send { color: var(--accent-light, var(--accent)); }
.cs-compose.is-busy .cs-text { font-size: 13.5px; }

.cs-ended { flex: none; display: flex; justify-content: center; padding: 14px 14px calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-subtle); }

/* Invite */
.cs-pick { padding: 14px 14px 0; overflow: hidden; }
.cs-search { flex: none; }
.cs-mates { list-style: none; flex: 1; min-height: 0; overflow-y: auto; margin: 10px -4px 0; padding: 0 4px; }
.cs-mate { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 10px; border-radius: 12px; cursor: pointer; }
.cs-mate:hover { background: var(--fill-hover); }
.cs-mate input { position: absolute; opacity: 0; pointer-events: none; }
.cs-mate__text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cs-mate__text strong { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-mate__text span { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-tag { flex: none; padding: 3px 8px; border-radius: 999px; background: var(--fill-hover); font-size: 11px; color: var(--text-secondary); }
.cs-tag.is-online { color: #4ade80; background: rgba(74, 222, 128, .1); }
.cs-check { flex: none; width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line); box-sizing: border-box; transition: all .15s; }
.cs-mate input:checked ~ .cs-check { border-color: var(--accent); background: var(--accent)
  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5L20 7'/%3E%3C/svg%3E") center/14px no-repeat; }
.cs-mate input:focus-visible ~ .cs-check { outline: 2px solid var(--accent); outline-offset: 2px; }
.cs-mate.is-disabled { cursor: default; opacity: .55; }
.cs-mate.is-disabled .cs-check { visibility: hidden; }
.cs-pick__foot { flex: none; padding: 12px 0 calc(14px + env(safe-area-inset-bottom, 0px)); }
.cs-pick__foot .btn { width: 100%; min-height: 48px; }
.cs-empty { padding: 30px 10px; text-align: center; color: var(--text-secondary); font-size: 14px; }
.cs-loading { display: flex; justify-content: center; gap: 6px; padding: 30px; }
.cs-loading span { width: 8px; height: 8px; background: var(--text-muted, var(--text-secondary)); animation: cs-dots 1s steps(2) infinite; }
.cs-loading span:nth-child(2) { animation-delay: .2s; }
.cs-loading span:nth-child(3) { animation-delay: .4s; }
@keyframes cs-dots { 50% { opacity: .25; } }

/* Avatar editor */
.cs-ed { padding: 0 16px; }
.cs-ed__stage { display: flex; justify-content: center; padding: 26px 0 14px; margin: 0 -16px;
  background: radial-gradient(circle at 50% 75%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 65%); }
.cs-ed__opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 8px; }
.cs-ed__opt { display: flex; align-items: center; justify-content: center; min-height: 56px; padding: 6px; border-radius: 12px;
  border: 2px solid transparent; background: var(--surface-3, rgba(0,0,0,.15)); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.cs-ed__opt:hover { border-color: var(--line); }
.cs-ed__opt.is-on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.cs-ed__opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cs-swatch { width: 28px; height: 28px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
/* Outside the scrolling list, so it stays put at the bottom however the
   list scrolls or rubber-bands. */
.cs-ed { padding-bottom: 16px; }
.cs-ed__foot { flex: none; display: flex; gap: 10px; padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-subtle); }
.cs-ed__foot .btn { flex: 1; min-height: 48px; }

/* ── Keyboard up ──────────────────────────────────────────────────────
   The room's layout stays the same when the keyboard opens or closes (no
   tiles or header changing size); only a card being written about shrinks
   to its title so the field stays in view. */
.cs-panel.is-compact .cs-chip .cs-card { max-height: none; padding: 8px 40px 8px 12px; }
.cs-panel.is-compact .cs-chip .cs-card__text, .cs-panel.is-compact .cs-chip .cs-card__opts,
.cs-panel.is-compact .cs-chip .cs-card__pick { display: none; }
.cs-panel.is-compact .cs-chip .cs-card__body { max-height: none; }
.cs-panel.is-compact .cs-chip .cs-card__title { margin-top: 2px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Computers and tablets ─────────────────────────────────────────────
   The panel is opaque everywhere: the frosted glass let the page show
   through and made the room harder to read. */

/* Wide screens: a side panel docked to the right edge. The page makes room
   for it instead of lying underneath, so the lesson stays readable beside
   the room and nothing (the language/theme pill included) is covered. */
@media (min-width: 1200px) and (min-height: 501px) {
  .cs-panel { top: 0; right: 0; bottom: 0; width: var(--cs-side-w, 380px); border-radius: 0; border: 0;
    border-left: 1px solid var(--line, rgba(255,255,255,.1)); box-shadow: -12px 0 32px rgba(0, 0, 0, 0.18);
    transform: translateX(24px); }
  body { transition: padding-right .2s cubic-bezier(.2, .8, .2, 1); }
  body.cs-open { padding-right: var(--cs-side-w, 380px); }
  body.cs-open .floating-actions { right: calc(var(--cs-side-w, 380px) + var(--space-8, 32px)); }
  /* Nothing of the page lies under the docked panel, only the theme's own
     background, so the panel lets it show as the page does: a light tint of
     the surface, no blur. */
  .cs-panel { background: color-mix(in srgb, var(--surface-1, #0f1a2c) 55%, transparent); box-shadow: none; }
  /* With a theme scene on, the site keeps anything carrying role="dialog"
     solid; the docked panel is part of the page, so it takes the page's
     translucent surfaces instead and the scene shows through its cards too. */
  html[data-ambient] .cs-panel.cs-panel {
    --surface-0: color-mix(in srgb, var(--s0) 45%, transparent);
    --surface-1: color-mix(in srgb, var(--s1) 55%, transparent);
    --surface-2: color-mix(in srgb, var(--s2) 62%, transparent);
    --surface-3: color-mix(in srgb, var(--s3) 60%, transparent);
    --bg-primary: var(--surface-0); --bg-secondary: var(--surface-2); --bg-card: var(--surface-1); --bg-input: var(--surface-3);
    background: color-mix(in srgb, var(--s1) 35%, transparent);
  }
  /* Its menu still floats over it and stays solid. */
  html[data-ambient] .cs-panel .cs-menu { background: var(--s2); }
}
@media (min-width: 1600px) and (min-height: 501px) { :root { --cs-side-w: 420px; } }

/* Narrower computers and tablets: a floating card that ends above the
   language/theme pill instead of covering it. */
@media (min-width: 769px) and (max-width: 1199px), (min-width: 1200px) and (max-height: 500px) and (pointer: fine) {
  .cs-panel { width: min(380px, calc(100vw - 32px)); bottom: 84px; }
}

/* ── Phone (same query as the rest of the site) ─────────────────────── */
@media (max-width: 768px), (max-height: 500px) and (orientation: landscape) and (pointer: coarse) {
  /* Pinned to the four edges; only with the keyboard up does the script set
     its height (see syncSheet in costudy.js). */
  .cs-panel { top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: auto; border-radius: 0; border: 0;
    overscroll-behavior: none;
    transform: none; padding-top: env(safe-area-inset-top, 0px); box-sizing: border-box; will-change: transform; }
  .cs-panel.is-open { transform: none; }
  .cs-head { padding: 10px 6px 10px 16px; position: relative; z-index: 3; will-change: transform; }
  .cs-panel.kb-open .cs-compose, .cs-panel.kb-open .cs-pick__foot { padding-bottom: 8px; }
  .cs-body { overscroll-behavior: contain; overflow-x: hidden; touch-action: pan-y; }
  .cs-panel { overflow-x: hidden; touch-action: pan-y; }
  .cs-members { touch-action: pan-x; overscroll-behavior-x: contain; }
  /* Members are compact on a phone from the start, so the chat has room
     with the keyboard up and nothing has to change size when it opens. */
  .cs-members { padding: 10px 10px 8px; }
  .cs-member { width: 100px; padding: 8px 6px 6px; }
  .cs-member__av { height: 36px; }
  .cs-member__av .cs-av { width: 42px; height: 35px; }
  .cs-member__av svg { width: 42px; height: 35px; }
  .cs-member__name { margin-top: 4px; font-size: 12.5px; }
  .cs-member__status { -webkit-line-clamp: 2; height: 2.6em; font-size: 11px; }
  .cs-msg__main { max-width: 86%; }
  .cs-text { font-size: 16px; } /* no zoom on focus in iOS */
  .cs-input { font-size: 16px; }
  body.cs-open { overflow: hidden; }
  /* The sheet covers the whole screen, so the page under it is set aside
     (and stops painting) and the sheet lets the theme's own background show
     through - no blur needed, nothing for the phone to recompute. */
  body.cs-open .screen.active, body.cs-open .floating-actions, body.cs-open #mobile-sidebar,
  body.cs-open .site-footer { visibility: hidden; }
  .cs-panel { background: transparent; box-shadow: none; }
  .cs-head, .cs-members, .cs-compose { border-color: var(--line-subtle, rgba(255,255,255,.06)); }
}

@media (prefers-reduced-motion: reduce) {
  .cs-av svg, .cs-av .cs-zz, .cs-panel { animation: none !important; transition: none !important; }
  .cs-av--idle .cs-zz { opacity: 1; }
}

.cs-kb-proxy { position: fixed !important; top: calc(env(safe-area-inset-top, 0px) + 8px) !important; }

@media print { .cs-panel, .cs-entry { display: none !important; } }
