:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1c1f24;
  --muted: #646b75;
  --border: #dcdfe4;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --mine: #e6efff;
  --danger: #b42318;
  --ok: #157f3c;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2025;
    --surface-2: #262a31;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --border: #343941;
    --accent: #5b95ee;
    --accent-text: #0b1220;
    --mine: #1f2d45;
    --danger: #f97066;
    --ok: #4ade80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Noto Sans", sans-serif;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.55; cursor: default; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 9px 11px;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 4px; font-weight: 500; }

/* Card screens (home, join) */
.card-screen { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card {
  width: 100%; max-width: 440px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px 24px; display: grid; gap: 18px;
}
.card > p { margin: 0; }
.stack { display: grid; gap: 12px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* Room */
#room { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.title-block { display: flex; align-items: center; gap: 10px; min-width: 0; }
.title-block h1 { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 0.8rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
#video-btn[aria-pressed="true"] { border-color: var(--ok); color: var(--ok); }

.room-body { flex: 1; display: flex; min-height: 0; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#messages { list-style: none; margin: 0; padding: 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(680px, 88%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; }
.msg.mine { align-self: flex-end; background: var(--mine); }
.msg-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted); }
.msg-head strong { color: var(--text); font-size: 0.9rem; }
.msg-text { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-original { margin: 4px 0 0; font-size: 0.85rem; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; border-top: 1px dashed var(--border); padding-top: 4px; }
.msg-pending { font-style: italic; color: var(--muted); }
.hide-original .msg-original { display: none; }
.system-line { align-self: center; font-size: 0.82rem; color: var(--muted); }

.composer { position: relative; border-top: 1px solid var(--border); background: var(--surface); padding: 10px 16px 14px; display: grid; gap: 8px; }
.composer-options { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.85rem; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; color: var(--muted); }
.toggle input { width: auto; }
.toggle select { width: auto; padding: 3px 6px; }
#chat-form { display: flex; gap: 8px; align-items: flex-end; }
#chat-input { resize: none; max-height: 160px; }
.mic { padding: 8px; width: 42px; height: 42px; justify-content: center; border-radius: 50%; flex: none; }
.mic svg { width: 22px; height: 22px; fill: currentColor; }
.mic[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 25%, transparent); } }
#send-btn { height: 42px; }

.people { width: 260px; border-left: 1px solid var(--border); background: var(--surface); padding: 16px; overflow-y: auto; }
.people h2 { margin-bottom: 10px; }
#people-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
#people-list li { display: grid; gap: 1px; }
#people-list .who { font-weight: 600; display: flex; gap: 6px; align-items: center; }
#people-list .meta { font-size: 0.82rem; color: var(--muted); }
.cam-dot { font-size: 0.75rem; color: var(--ok); font-weight: 500; }
.only-mobile { display: none; }

/* Replies and mentions */
.msg-actions { margin-left: auto; display: inline-flex; gap: 2px; }
.msg-head .reply-btn { border: none; background: none; padding: 0 2px; font-size: 0.8rem; color: var(--muted); opacity: 0; }
.msg:hover .reply-btn, .reply-btn:focus-visible { opacity: 1; }
@media (hover: none) { .msg-head .reply-btn { opacity: 1; } }
.reply-btn:hover { color: var(--accent); background: none; }
.msg-quote {
  display: block; width: 100%; text-align: left; margin: 4px 0 2px; padding: 4px 8px;
  border: none; border-left: 3px solid var(--accent); border-radius: 4px;
  background: var(--surface-2); color: var(--muted); font-size: 0.85rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-quote strong { color: var(--text); margin-right: 6px; }
.mention { color: var(--accent); font-weight: 600; }
.msg.mentions-me { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.msg.flash { animation: flash 1.6s; }
@keyframes flash { 30% { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); } }
.reply-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 10px; border-left: 3px solid var(--accent); border-radius: 6px; background: var(--surface-2);
}
.reply-bar > div { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-text { color: var(--muted); margin-left: 6px; }
.reply-bar button { border: none; background: none; padding: 2px 6px; }
.emoji-btn { font-size: 1.2rem; line-height: 1; }
.emoji-pop {
  position: fixed; z-index: 50; display: flex; gap: 2px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.18);
}
.emoji-pop[hidden] { display: none; }
.emoji-pop.grid { display: grid; grid-template-columns: repeat(8, 36px); max-width: calc(100vw - 16px); }
.emoji-pop button { border: none; background: none; width: 36px; height: 36px; padding: 0; font-size: 1.25rem; justify-content: center; border-radius: 8px; }
.emoji-pop button:hover, .emoji-pop button:focus-visible { background: var(--surface-2); }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.reaction { padding: 1px 8px; font-size: 0.85rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.reaction.mine { border-color: var(--accent); color: var(--accent); }
.mention-menu {
  position: absolute; left: 16px; bottom: calc(100% - 4px); z-index: 4;
  list-style: none; margin: 0; padding: 4px; min-width: 240px; max-width: calc(100% - 32px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.15);
}
.mention-menu li { padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.mention-menu li span { color: var(--muted); font-size: 0.85rem; }
.mention-menu li[aria-selected="true"], .mention-menu li:hover { background: var(--surface-2); }

/* Minutes dialog */
dialog {
  width: min(820px, calc(100% - 32px)); max-height: calc(100% - 48px);
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text);
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog-head, .dialog-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; flex-wrap: wrap; }
.dialog-head { border-bottom: 1px solid var(--border); }
.dialog-foot { border-top: 1px solid var(--border); }
.dialog-head button { border: none; font-size: 1.1rem; }
.tabs { display: flex; gap: 4px; padding: 10px 18px 0; flex-wrap: wrap; }
.tabs button { border-radius: 8px 8px 0 0; border-bottom: none; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.minutes { padding: 6px 22px 16px; overflow-y: auto; flex: 1; border-top: 1px solid var(--border); }
.minutes h1 { font-size: 1.3rem; margin: 14px 0 6px; }
.minutes h2 { font-size: 1.1rem; margin: 16px 0 6px; }
.minutes h3 { font-size: 1rem; margin: 12px 0 4px; }
.minutes ul, .minutes ol { padding-left: 22px; }
.minutes table { border-collapse: collapse; width: 100%; }
.minutes td, .minutes th { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.minutes-working { padding: 32px 0; text-align: center; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-size: 0.9rem; z-index: 10;
}

@media (max-width: 760px) {
  .only-mobile { display: inline-flex; }
  .people { position: fixed; inset: 0 0 0 auto; width: min(300px, 85%); z-index: 5; transform: translateX(100%); transition: transform 0.2s; visibility: hidden; }
  .people.open { transform: none; visibility: visible; box-shadow: -4px 0 20px rgb(0 0 0 / 0.2); }
  .msg { max-width: 94%; }
  .topbar { padding: 8px 12px; }
  .actions button { padding: 6px 10px; }
}

@media print {
  body { background: #fff; color: #000; }
  body > *:not(dialog) { display: none !important; }
  dialog { position: static; border: none; width: 100%; max-height: none; }
  .dialog-head, .dialog-foot, .tabs { display: none !important; }
  .minutes { overflow: visible; border: none; }
}
