/* synapses — design tokens */
:root {
  --ink: #1B1E2B;
  --ink-soft: #565B70;
  --paper: #F6F5F2;
  --card: #FFFFFF;
  --line: #E6E4DE;
  --violet: #5B5BD6;
  --violet-deep: #4747BD;
  --spark: #FFB454;
  --danger: #D6485B;
  --radius: 16px;
  --font-body: 'Noto Sans JP', system-ui, sans-serif;
  --font-display: 'Zen Maru Gothic', 'Noto Sans JP', sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 15px; }
img, video { display: block; max-width: 100%; }
a { color: var(--violet); }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---- brand ---- */
.brand { font-family: var(--font-display); font-weight: 700; letter-spacing: .02em; display: inline-flex; align-items: center; gap: .5em; }
.brand .mark { width: 22px; height: 22px; flex: none; }

/* ---- auth screen ---- */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 80% -10%, #ECEBFF 0%, var(--paper) 55%); }
.auth-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 24px; padding: 32px 28px; box-shadow: 0 12px 40px rgba(27,30,43,.08); }
.auth-card h1 { font-family: var(--font-display); font-size: 28px; margin-bottom: 4px; }
.auth-card .tagline { color: var(--ink-soft); font-size: 13px; margin-bottom: 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--ink-soft); margin-bottom: 4px; }
.field input { width: 100%; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #FCFBF9; }
.field input:focus { border-color: var(--violet); outline: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 12px; border: none; font-weight: 700; font-size: 15px; }
.btn-primary { background: var(--violet); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--violet-deep); }
.btn-ghost { background: transparent; color: var(--violet); }
.auth-switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--ink-soft); }
.err { color: var(--danger); font-size: 13px; margin: 8px 0; min-height: 1.2em; }

/* ---- home (room list) ---- */
.topbar { background: var(--ink); color: #fff; padding: 14px 18px; padding-top: max(14px, env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between; }
.topbar .brand { font-size: 19px; color: #fff; }
.topbar .user { font-size: 13px; color: #B9BDD1; display: flex; align-items: center; gap: 10px; }
.topbar .user button { background: none; border: none; color: #B9BDD1; font-size: 12px; text-decoration: underline; }
.home-body { flex: 1; overflow-y: auto; padding: 18px; max-width: 640px; width: 100%; margin: 0 auto; }
.home-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.home-head h2 { font-family: var(--font-display); font-size: 18px; }
.btn-new { background: var(--violet); color: #fff; border: none; border-radius: 999px; padding: 9px 18px; font-weight: 700; font-size: 14px; }
.room-card { display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; cursor: pointer; transition: transform .08s ease; }
.room-card:hover { transform: translateY(-1px); border-color: #CFCDF5; }
.room-avatar { width: 44px; height: 44px; border-radius: 14px; background: linear-gradient(135deg, var(--violet), #8B7BE8);
  color: #fff; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 18px; flex: none; }
.room-info { min-width: 0; flex: 1; }
.room-info .name { font-weight: 700; }
.room-info .last { font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-meta { font-size: 11px; color: var(--ink-soft); text-align: right; flex: none; }
.empty { text-align: center; color: var(--ink-soft); padding: 48px 12px; font-size: 14px; }

/* ---- chat room ---- */
.chat-header { background: var(--ink); color: #fff; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px; flex: none; }
.chat-header .back { background: none; border: none; color: #fff; font-size: 22px; line-height: 1; padding: 4px 6px; }
.chat-header .title { font-family: var(--font-display); font-weight: 700; font-size: 16px; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header .members { font-size: 12px; color: #B9BDD1; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: #6A6F85; flex: none; }
.conn.live { background: var(--spark); animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,180,84,.5); } 50% { box-shadow: 0 0 0 6px rgba(255,180,84,0); } }
.chat-header .invite-btn { background: rgba(255,255,255,.12); border: none; color: #fff; border-radius: 999px;
  padding: 7px 14px; font-size: 13px; font-weight: 500; }

.msgs { flex: 1; overflow-y: auto; padding: 16px 14px 8px; }
.msgs-inner { max-width: 720px; margin: 0 auto; }
.date-sep { text-align: center; margin: 14px 0; }
.date-sep span { font-size: 11px; color: var(--ink-soft); background: #ECEAE4; border-radius: 999px; padding: 3px 12px; }
.sys { text-align: center; font-size: 12px; color: var(--ink-soft); margin: 10px 0; }

.row { display: flex; margin-bottom: 2px; align-items: flex-end; gap: 8px; }
.row.mine { justify-content: flex-end; }
.row .avatar { width: 32px; height: 32px; border-radius: 50%; background: #D9D7F2; color: var(--violet-deep);
  display: grid; place-items: center; font-size: 13px; font-weight: 700; flex: none; visibility: hidden; }
.row.head .avatar { visibility: visible; }
.col { max-width: 76%; display: flex; flex-direction: column; }
.row.mine .col { align-items: flex-end; }
.sender { font-size: 11px; color: var(--ink-soft); margin: 8px 0 2px 4px; }
.bubble-line { display: flex; align-items: flex-end; gap: 6px; }
.row.mine .bubble-line { flex-direction: row-reverse; }
.bubble { padding: 9px 13px; border-radius: 18px; background: var(--card); border: 1px solid var(--line);
  word-break: break-word; white-space: pre-wrap; }
.row.head:not(.mine) .bubble { border-top-left-radius: 6px; }
.row.mine .bubble { background: var(--violet); border-color: var(--violet); color: #fff; }
.row.mine.head .bubble { border-top-right-radius: 6px; }
.bubble.media { padding: 4px; overflow: hidden; background: var(--card); border-color: var(--line); }
.bubble.media img, .bubble.media video { border-radius: 14px; max-height: 320px; max-width: min(76vw, 360px); cursor: pointer; }
.stamp { font-size: 10px; color: var(--ink-soft); flex: none; padding-bottom: 2px; }

/* composer */
.composer { flex: none; background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.composer-inner { max-width: 720px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: #F0EFFA; color: var(--violet);
  font-size: 20px; display: grid; place-items: center; flex: none; }
.icon-btn:hover { background: #E4E2F7; }
.composer textarea { flex: 1; resize: none; border: 1.5px solid var(--line); border-radius: 20px;
  padding: 9px 15px; max-height: 120px; background: #FCFBF9; line-height: 1.5; }
.composer textarea:focus { border-color: var(--violet); outline: none; }
.send-btn { background: var(--violet); color: #fff; }
.send-btn:disabled { background: #C9C8E8; cursor: default; }
.upload-note { max-width: 720px; margin: 6px auto 0; font-size: 12px; color: var(--ink-soft); display: none; }
.upload-note.on { display: block; }

/* ---- modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(27,30,43,.45); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: var(--card); border-radius: 20px; padding: 24px; width: 100%; max-width: 400px; }
.modal h3 { font-family: var(--font-display); margin-bottom: 14px; }
.modal .rowline { display: flex; gap: 10px; margin-bottom: 12px; }
.modal select { flex: 1; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: #FCFBF9; }
.invite-link { background: #F0EFFA; border: 1px dashed var(--violet); border-radius: 12px; padding: 12px;
  font-size: 12px; word-break: break-all; margin: 12px 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.member-list { margin: 4px 0 14px; font-size: 14px; }
.member-list li { list-style: none; padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.member-list .avatar-s { width: 26px; height: 26px; border-radius: 50%; background: #D9D7F2; color: var(--violet-deep);
  display: grid; place-items: center; font-size: 11px; font-weight: 700; }

/* lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(13,14,22,.92); z-index: 60; display: grid; place-items: center; padding: 16px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 92dvh; border-radius: 8px; }

/* invite page */
.invite-hero { text-align: center; margin-bottom: 20px; }
.invite-hero .mark-big { width: 56px; height: 56px; margin: 0 auto 10px; }
.invite-hero .room { font-family: var(--font-display); font-size: 22px; font-weight: 700; }
.invite-hero .by { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }

@media (max-width: 520px) {
  .col { max-width: 84%; }
  .chat-header .invite-btn { padding: 6px 11px; font-size: 12px; }
}

/* ---- call overlay (Phase 2) ---- */
.call-overlay { position: fixed; inset: 0; background: #0D0E16; z-index: 40; display: flex; flex-direction: column; }
.call-head { color: #B9BDD1; font-size: 13px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 8px; font-family: var(--font-display); }
.cdot { width: 8px; height: 8px; border-radius: 50%; background: var(--spark); animation: pulse 2.4s ease-in-out infinite; }
.cgrid { flex: 1; display: grid; gap: 6px; padding: 6px; place-content: stretch; grid-template-columns: 1fr; }
.cgrid[data-n="2"] { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.cgrid[data-n="3"], .cgrid[data-n="4"] { grid-template-columns: 1fr 1fr; }
.cgrid[data-n="5"], .cgrid[data-n="6"] { grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; }
@media (min-width: 800px) {
  .cgrid[data-n="2"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
}
.ctile { position: relative; background: #1B1E2B; border-radius: 14px; overflow: hidden; min-height: 0; }
.ctile video { width: 100%; height: 100%; object-fit: cover; }
.ctile video.mirror { transform: scaleX(-1); }
.ctile .cavatar { position: absolute; inset: 0; display: none; place-items: center;
  font-family: var(--font-display); font-size: 42px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--violet), #8B7BE8); }
.ctile.novideo .cavatar { display: grid; }
.ctile.novideo video { visibility: hidden; }
.ctile .cname { position: absolute; left: 8px; bottom: 8px; font-size: 11px; color: #fff;
  background: rgba(13,14,22,.55); padding: 2px 9px; border-radius: 999px; }
.ctile.bad { outline: 2px solid var(--danger); }
.cbar { display: flex; justify-content: center; gap: 14px; padding: 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom)); }
.cbtn { width: 52px; height: 52px; border-radius: 50%; border: none; font-size: 22px;
  background: rgba(255,255,255,.12); color: #fff; display: grid; place-items: center; }
.cbtn.off { background: rgba(214,72,91,.35); }
.cbtn.on { background: var(--violet); }
.cbtn.leave { background: var(--danger); }
.call-btn.oncall { background: var(--spark); color: var(--ink); font-weight: 700; animation: pulse 2.4s ease-in-out infinite; }

/* ---- effects menu (Phase 3) ---- */
.fxmenu { position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(88px + env(safe-area-inset-bottom));
  background: #1B1E2B; border: 1px solid rgba(255,255,255,.16); border-radius: 14px;
  padding: 8px; display: flex; flex-direction: column; gap: 4px; z-index: 45;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.fxmenu button { background: none; border: none; color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 9px; text-align: left; white-space: nowrap; }
.fxmenu button.act { background: var(--violet); }
