/* 公屏 v2 (11-24). The talk was glass lines dissolving into the light: on a moving background the words were hard to
   read, older lines faded out, every group carried 忍住 · 公开 · 16:55, and on a phone the round left room for one or
   two lines with no way to see more (the bar that opened it was hidden).
   Now: one solid panel everywhere (the room, 观战, phone and computer).
   - The bar on top always says who can read it: 只有你们俩 / 观众看得到 · N 人在看 (the empty input says it too).
   - The other side's lines open with an initial, a name and a role; my own lines need no name.
   - Time and a change of who can read it are one centred line between messages (chat.js paintMeta), not a tag per group.
   - Game moments (指令, 我快到了, 准许 …) are outlined chips on the sender's side, so they never read as typed words.
   - Emoji and saved phrases sit behind the smiley in the input.
   - Phone: folded, the newest lines stay in the page; a tap on the bar opens the whole talk as a sheet over the room
     (app.js setTalkOpen; a tap on the dimmed room, Esc or the next screen folds it).
   - 观战: 说停 on the left, 忍住 on the right, each in its own colour.
   Loaded after night.css, so equal specificity wins here; !important only where night.css / room.css used it. */

.chat-panel[data-mode] {
  --talk-bg: #1c0a18f2;
  --talk-line: #ffffff17;
  --them: #43193c;
  --me-ink: #2b0a18;
  --lead: #ff8fb1;
  --follow: #ffb07a;
  position: relative; display: flex; flex-direction: column; min-height: 0;
  border: 1px solid var(--talk-line) !important; border-radius: 20px !important; background: var(--talk-bg) !important;
  box-shadow: 0 10px 30px #0000004d !important; padding: 0 !important; overflow: hidden;
}

/* The bar. */
.chat-panel .talk-bar { flex: none; display: flex; align-items: center; justify-content: flex-start; gap: 8px; width: 100%; min-height: 34px; margin: 0; padding: 5px 12px 5px 14px !important;
  border: 0; border-bottom: 1px solid var(--talk-line); border-radius: 0; background: none; color: var(--soft); font: inherit; text-align: left; }
.chat-panel button.talk-bar { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.chat-panel .talk-title { flex: none; font-size: 13px; font-weight: 700; letter-spacing: .16em; color: #fff; }
.chat-panel .chat-scope { display: inline-flex; align-items: center; gap: 5px; min-width: 0; padding: 2px 9px; border-radius: 99px; overflow: hidden;
  font-size: 11.5px; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; color: #d9d0ff; background: #a99bff21; }
.chat-panel .chat-scope::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chat-panel .chat-scope[data-scope="public"] { color: #ffc0d4; background: #ff4f8f2b; }
.chat-panel .chat-scope[data-scope="watch"] { color: var(--soft); background: #ffffff12; }
.chat-panel .talk-open-label { flex: none; display: inline-flex; align-items: center; gap: 2px; margin-left: auto; color: var(--dim); font-size: 12px; }
.chat-panel .talk-open-label svg { width: 16px; height: 16px; transition: transform .25s var(--out); }
.chat-panel .talk-less-text, .room[data-talk="open"] .chat-panel .talk-more-text { display: none; }
.room[data-talk="open"] .chat-panel .talk-less-text { display: inline; }
.room[data-talk="open"] .chat-panel .talk-open-label svg { transform: rotate(180deg); }

/* The lines. Nothing fades: an older line is as readable as the newest. */
.chat-panel .chat-scroll { display: flex; flex-direction: column; padding: 4px 12px 8px !important; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: #ffffff26 transparent; -webkit-mask-image: none !important; mask-image: none !important; }
.chat-panel .chat-scroll::-webkit-scrollbar { width: 4px; }
.chat-panel .chat-scroll::-webkit-scrollbar-thumb { background: #ffffff26; border-radius: 4px; }
.chat-panel .chat-empty, .chat-panel .chat-empty[hidden] + .chat-log { margin-top: auto; }
.chat-panel .chat-empty { padding: 10px 0 4px; color: var(--dim); font-size: 13px; text-align: center; }
.chat-panel .chat-log { display: flex; flex-direction: column; gap: 3px; }
.chat-panel .chat-log > li { opacity: 1 !important; transform-origin: left bottom; animation: talk-in .3s var(--out) both; }
.chat-panel .chat-log > li.settled { animation: none; }
.chat-panel .chat-log > li.mine { transform-origin: right bottom; }
@keyframes talk-in { from { opacity: 0; transform: translateY(6px) scale(.96); } to { opacity: 1; transform: none; } }

.chat-panel .chat-item { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; border: 0 !important; }
.chat-panel .chat-item.mine { align-items: flex-end; }
.chat-panel .chat-item:not(.continued) { margin-top: 5px; }
.chat-panel .chat-item[data-side="lead"] { --side: var(--lead); }
.chat-panel .chat-item[data-side="follow"] { --side: var(--follow); }

/* Time / who can read it: one centred line. */
.chat-panel .chat-sep { display: flex; align-items: center; gap: 10px; align-self: stretch; margin: 6px 0 3px; color: var(--dim); font-size: 11px; letter-spacing: .06em; white-space: nowrap; }
.chat-panel .chat-sep::before, .chat-panel .chat-sep::after { content: ""; flex: 1; height: 1px; background: var(--talk-line); }
.chat-panel .chat-sep[data-scope="public"] { color: #ffb3cb; }
.chat-panel .chat-sep[data-scope="private"] { color: #cfc4ff; }

/* Who: initial, name, role. */
.chat-panel .chat-meta { display: flex; align-items: center; gap: 6px; max-width: 100%; padding: 0 2px !important; color: var(--soft) !important; font-size: 12px !important; letter-spacing: 0 !important; }
.chat-panel .chat-meta time { display: none; }
.chat-panel .chat-avatar { flex: none; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--side, var(--lead)); color: var(--me-ink); font-size: 11px; font-weight: 800; line-height: 1; }
.chat-panel .chat-author { min-width: 0; overflow: hidden; color: #fff; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.chat-panel .chat-role { flex: none; padding: 0 6px; border: 1px solid var(--side, var(--lead)); border-radius: 99px; color: var(--side, var(--lead)); font-size: 10.5px; line-height: 16px; }

/* Bubbles: solid, white on plum for the other side, ink on rose for mine. */
.chat-panel .chat-bubble { max-width: min(80%, 34em); margin: 0; padding: 7px 12px !important; border: 0 !important; border-radius: 16px !important;
  background: var(--them) !important; box-shadow: none !important; color: #fff; font-size: 15px !important; line-height: 1.5; text-shadow: none !important; overflow-wrap: anywhere; }
.chat-panel .chat-item.theirs:not(.continued) .chat-bubble { border-top-left-radius: 5px !important; }
.chat-panel .chat-item.mine .chat-bubble { background: linear-gradient(135deg, #ffb0c8, #ff7ba3) !important; color: var(--me-ink); font-weight: 500; }
.chat-panel .chat-item.mine:not(.continued) .chat-bubble { border-top-right-radius: 5px !important; }
.chat-panel .chat-item.emoji-only .chat-bubble { padding: 0 2px !important; background: none !important; font-size: 30px !important; line-height: 1.2; }
.chat-panel .chat-item.pending .chat-bubble { opacity: .62; }
.chat-panel .chat-item.failed .chat-bubble { box-shadow: inset 0 0 0 1.5px var(--danger) !important; }
.chat-panel .chat-state { color: var(--dim); font-size: 11.5px; }
.chat-panel .chat-state:empty { display: none; }

/* 观战: 说停 left, 忍住 right, each side its own colour. */
.chat-panel[data-mode="watch"] .chat-item[data-side="lead"] .chat-bubble { background: #4a1838 !important; }
.chat-panel[data-mode="watch"] .chat-item[data-side="follow"] { align-items: flex-end; }
.chat-panel[data-mode="watch"] .chat-item[data-side="follow"] .chat-meta { flex-direction: row-reverse; }
.chat-panel[data-mode="watch"] .chat-item[data-side="follow"] .chat-bubble { background: #4a2620 !important; border-top-left-radius: 16px !important; }
.chat-panel[data-mode="watch"] .chat-item[data-side="follow"]:not(.continued) .chat-bubble { border-top-right-radius: 5px !important; }

/* Game moments: outlined chips on the sender's side, the kind in a small label. */
.chat-panel .chat-note { display: flex; align-items: baseline; gap: 6px; margin: 4px 0 1px; padding: 0; font-family: var(--sans) !important; font-size: 13.5px !important; animation: talk-in .3s var(--out) both; }
.chat-panel .chat-note.mine { justify-content: flex-end; }
.chat-panel .chat-note .chat-note-label { order: 0 !important; flex: none; color: var(--dim); font-size: 11px; }
.chat-panel .chat-note.mine .chat-note-label { order: 2 !important; }
.chat-panel .chat-note .chat-note-text { max-width: 80%; padding: 4px 11px; border: 1px solid #ff8fb147; border-radius: 12px; background: none !important;
  color: #ffd9e5; font-family: var(--sans); overflow-wrap: anywhere; }
.chat-panel .chat-note[data-kind="card"] .chat-note-text { border-color: #ffad6b59; color: #ffd8b5; }
.chat-panel .chat-note[data-kind="harsh"] .chat-note-text { border-color: #ff2d5566; color: #ffa3b5; }
.chat-panel .chat-note[data-kind="edge"] .chat-note-text { border-color: #ff4f8f; background: #ff4f8f2e !important; color: #fff; font-weight: 700; }
.chat-panel .chat-note[data-kind="ask"] .chat-note-text { border-color: #ffad6b66; color: var(--slow); }
.chat-panel .chat-note[data-kind="grant"] .chat-note-text { border-color: #f2cb9f73; color: var(--champagne-2); }
.chat-panel .chat-note[data-kind="warn"] .chat-note-text { border-color: #ff7a7a73; color: #ffc9c9; }

.chat-panel .chat-typing { padding: 4px 0 0; }
.chat-panel .chat-typing .chat-bubble { padding: 9px 12px !important; border-top-left-radius: 5px !important; }
.chat-panel .chat-jump { flex: none; align-self: center; margin: 2px auto 0; padding: 4px 14px; border: 0; border-radius: 99px; background: #ff8fb1; color: var(--me-ink);
  font-size: 12px; font-weight: 700; box-shadow: 0 4px 14px #ff4f8466; }

/* The input: smiley, field, send. The tray (emoji, saved phrases, 编辑) opens above it. */
.chat-panel .chat-form { display: grid; gap: 6px; padding: 6px 10px 10px !important; border-top: 1px solid var(--talk-line); }
.chat-panel .chat-slot, .chat-panel .chat-quick { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chat-panel .chat-slot::-webkit-scrollbar, .chat-panel .chat-quick::-webkit-scrollbar { display: none; }
.room .room-talk .chat-panel .chat-quick:not([hidden]) { display: flex !important; }
.chat-panel .chat-compose { display: flex; align-items: center; gap: 4px; padding: 3px; border: 1px solid #ffffff1f !important; border-radius: 999px !important; background: #ffffff10 !important; }
.chat-panel .chat-compose:focus-within { border-color: #ff8fb17a !important; }
.chat-panel .chat-more { flex: none; display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--soft); cursor: pointer; }
.chat-panel .chat-more svg { width: 22px; height: 22px; }
.chat-panel .chat-more[aria-expanded="true"] { background: #ff8fb12b; color: #ffd0de; }
.chat-panel .chat-compose input { flex: 1; min-width: 0; min-height: 38px !important; padding: 6px 4px !important; border: 0 !important; border-radius: 0; background: none !important;
  box-shadow: none !important; color: #fff; font-size: 15px; outline: none; }
.chat-panel .chat-compose input::placeholder { color: #f0d9e36b; }
.chat-panel .chat-send { width: 38px !important; height: 38px !important; }
.chat-panel .chat-count { flex: none; padding-right: 4px; }

/* ---------- The room ---------- */
.room .room-talk { gap: 6px; border: 0 !important; background: none !important; box-shadow: none !important; padding: 0 !important; }

@media (max-width: 899px) {
  /* Folded: the newest lines at a fixed height (the stage gives way first, never the other way round). */
  .room .room-talk .chat-panel { border-radius: 18px !important; }
  .room[data-view="play"] .room-talk .talk-bar, .room[data-view="meet"] .room-talk .talk-bar { min-height: 30px; padding-block: 3px !important; }
  .room[data-view="play"] .room-talk .chat-scroll, .room[data-view="meet"] .room-talk .chat-scroll { flex: none !important; max-height: none !important; min-height: 0 !important; }
  .room[data-view="play"] .room-talk .chat-scroll { height: clamp(64px, 12dvh, 116px); }
  .room[data-view="play"][data-role="lead"] .room-talk .chat-scroll { height: clamp(44px, 8dvh, 80px); }
  .room[data-view="meet"] .room-talk .chat-scroll { height: clamp(60px, 13dvh, 120px); }
  .room[data-view="play"] .room-talk .chat-form, .room[data-view="meet"] .room-talk .chat-form { padding: 5px 8px 8px !important; }
  /* In a round the folded talk keeps one row: the role's rail. Emoji and phrases are in the open talk. */
  .room[data-view="play"]:not([data-talk="open"]) .room-talk .chat-more { display: none; }
  .room[data-view="play"]:not([data-talk="open"]) .room-talk .chat-quick { display: none !important; }
  .room[data-view="play"]:not([data-talk="open"]) .room-talk .chat-compose { padding-left: 10px; }

  /* Folded, a tap on the lines opens the whole talk too. */
  .room:not([data-talk="open"]) .room-talk .chat-scroll { cursor: pointer; }

  /* Open: the whole talk as a sheet over the dimmed room. */
  .room[data-talk="open"] .room-talk { position: fixed !important; inset: 0; z-index: 58; display: flex !important; flex-direction: column; justify-content: flex-end;
    margin: 0 !important; background: #0b040ad1 !important; animation: talk-dim .22s ease-out both; }
  .room[data-talk="open"] .room-talk > .room-safety { display: none !important; }
  .room[data-talk="open"] .room-talk .chat-panel { flex: none; height: min(80dvh, 700px); border-bottom: 0 !important; border-radius: 22px 22px 0 0 !important;
    padding-bottom: env(safe-area-inset-bottom) !important; box-shadow: 0 -16px 48px #0009 !important; animation: talk-up .32s var(--out) both; }
  .room[data-talk="open"] .room-talk .talk-bar { min-height: 46px; padding-block: 8px !important; }
  .room[data-talk="open"] .room-talk .chat-scroll { flex: 1 1 auto !important; height: auto !important; max-height: none !important; min-height: 0 !important; }
  .room[data-talk="open"] .room-talk .chat-form { padding: 8px 10px 10px !important; }
}
/* Short phones (an iPhone SE in Safari is 375×553): 说停's deck leaves the talk no room for a bar, so folded it becomes a
   small 展开 tag over the corner of the lines (no height of its own); who can read it is still in the empty input. */
@media (max-width: 899px) and (max-height: 700px) {
  .room[data-view="play"][data-role="lead"]:not([data-talk="open"]) .room-talk .talk-bar { position: absolute; top: 0; right: 0; z-index: 2; width: auto; min-height: 24px;
    padding: 2px 8px 2px 10px !important; border: 0; border-bottom-left-radius: 12px; background: #2a1026; }
  .room[data-view="play"][data-role="lead"]:not([data-talk="open"]) .room-talk .talk-bar .talk-title,
  .room[data-view="play"][data-role="lead"]:not([data-talk="open"]) .room-talk .talk-bar .chat-scope { display: none; }
  .room[data-view="play"][data-role="lead"]:not([data-talk="open"]) .room-talk .chat-scroll { padding-top: 6px !important; }
}
/* The shortest phones (≤600 px tall): 说停's deck already takes most of the screen, and the talk had 72 px for 150 px of
   content (the same before v2). Folded, it keeps the newest line and the input; the rail is in the open talk and in 说一句. */
@media (max-width: 899px) and (max-height: 600px) {
  .room[data-view="play"][data-role="lead"] .stage-stack { grid-template-rows: auto minmax(96px, 1fr) auto auto !important; }
  .room[data-view="play"][data-role="lead"]:not([data-talk="open"]) .room-talk .chat-slot { display: none !important; }
  .room[data-view="play"][data-role="lead"]:not([data-talk="open"]) .room-talk .chat-scroll { height: 29px; padding: 0 12px !important; }
  .room[data-view="play"][data-role="lead"]:not([data-talk="open"]) .room-talk .chat-form { padding: 4px 6px 6px !important; }
  .room[data-view="play"][data-role="lead"]:not([data-talk="open"]) .room-talk .chat-compose input { min-height: 34px !important; }
  .room[data-view="play"][data-role="lead"]:not([data-talk="open"]) .room-talk .chat-send { width: 34px !important; height: 34px !important; }
}
@keyframes talk-dim { from { background-color: #0b040a00; } }
@keyframes talk-up { from { transform: translateY(40px); opacity: .4; } }

/* Computers: the talk is a full-height column beside the stage, on every screen of the room; nothing to open. */
@media (min-width: 900px) {
  .chat-panel .talk-open-label { display: none; }
  .chat-panel button.talk-bar { cursor: default; pointer-events: none; }
  .room[data-view="meet"] .room-talk .chat-panel, .room[data-view="result"] .room-talk .chat-panel { height: min(calc(100dvh - var(--head, 64px) - 40px), 720px); }
  .room .room-talk .chat-panel { flex: 1 1 auto; }
  .room .room-talk .chat-scroll { flex: 1 1 auto; height: auto !important; min-height: 120px; max-height: none !important; }
}

/* ---------- 观战 ---------- */
.watch-panel .room-chat.chat-panel { max-height: none !important; }
.watch-panel .room-chat.chat-panel .chat-scroll { min-height: 96px; }
@media (max-width: 899px) {
  .watch-panel .room-chat.chat-panel .talk-bar { min-height: 30px; padding-block: 3px !important; }
  .watch-panel .room-chat.chat-panel .chat-scroll { flex: none !important; height: clamp(96px, calc(34dvh - 92px), 236px); min-height: 0 !important; max-height: none !important; }
}
@media (min-width: 900px) {
  .watch-panel .room-chat.chat-panel .chat-scroll { flex: 1 1 auto; max-height: 46dvh !important; }
}

/* ---------- 忍住's 不舒服，先停: a quiet pill on the clock's line, top left of the stage ----------
   It sat between the stage and the talk, big and pink, the loudest thing on the screen after the light. It is still one
   tap away in the same place every round (app.js puts it in the stage for 忍住 on every screen), just not shouting. */
.room-stage[data-role="follow"] > .room-safety { position: absolute; top: 2px; left: 0; z-index: 4; padding: 0 !important; }
.room-stage[data-role="follow"] > .room-safety .button { min-height: 30px !important; padding: 0 10px !important; gap: 4px; border: 1px solid #ffffff21 !important;
  background: #ffffff0a !important; box-shadow: none !important; color: #f0d9e3a6 !important; font-size: 12px !important; font-weight: 500; }
.room-stage[data-role="follow"] > .room-safety .button [data-icon] svg, .room-stage[data-role="follow"] > .room-safety .button svg { width: 13px; height: 13px; }
.room-stage[data-role="follow"] > .room-safety .button:hover, .room-stage[data-role="follow"] > .room-safety .button:focus-visible { color: #fff !important; border-color: #ffffff47 !important; }

@media (prefers-reduced-motion: reduce) {
  .chat-panel .chat-log > li, .chat-panel .chat-note, .room[data-talk="open"] .room-talk, .room[data-talk="open"] .room-talk .chat-panel { animation: none !important; }
}

/* The keyboard (11-24). iOS keeps the page size when it opens, so anything pinned to the bottom (the open 公屏, a room
   panel such as 说一句, a sheet such as 自己写一张) slid under it: 「点了打字栏后看不见」. app.js measures what the
   keyboard covers (--kb; 0 where the browser resizes the page, e.g. Android, and on computers). */
@media (max-width: 899px) {
  .room[data-talk="open"] .room-talk { bottom: var(--kb, 0px) !important; }
  .room[data-talk="open"] .room-talk .chat-panel { max-height: calc(100dvh - var(--kb, 0px) - 12px) !important; }
}
@media (max-width: 899px) { .room-sheet { bottom: var(--kb, 0px); max-height: min(74dvh, calc(100dvh - var(--kb, 0px) - 16px)); } }
@media (max-width: 759px) {
  dialog { margin-bottom: var(--kb, 0px); max-height: calc(92dvh - var(--kb, 0px)); }
}
