:root {
  --bg: #0f1226;
  --bg2: #161a36;
  --panel: #1c2145;
  --panel2: #232a55;
  --line: #2c3466;
  --text: #eef0ff;
  --muted: #9aa3d4;
  --brand: #6366f1;
  --brand2: #7c3aed;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --chip: #2a3160;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}
.app { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; position: relative; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); }
::placeholder { color: #6b74a8; }
.btn { background: var(--brand); color: #fff; border-radius: 10px; padding: 11px 14px; font-weight: 600; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: var(--panel2); color: var(--text); }
.btn.wide { width: 100%; }
.btn.sm { padding: 7px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { background: var(--danger); }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- Lobby ---------- */
.lobby { flex: 1; overflow-y: auto; padding: calc(var(--safe-top) + 20px) 18px calc(var(--safe-bottom) + 24px); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.brand img { width: 44px; height: 44px; border-radius: 12px; }
.brand h1 { font-size: 22px; margin: 0; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 16px; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.roomlist { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.room-item { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; text-align: left; width: 100%; transition: border-color .15s; }
.room-item:active { border-color: var(--brand); }
.room-item .r-ava { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand2)); font-weight: 700; font-size: 17px; flex: none; }
.room-item .r-main { flex: 1; min-width: 0; }
.room-item .r-name { font-weight: 600; font-size: 15px; }
.room-item .r-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.badge { background: var(--brand); color: #fff; border-radius: 999px; font-size: 12px; font-weight: 700;
  min-width: 22px; height: 22px; padding: 0 7px; display: grid; place-items: center; }
.badge.zero { background: var(--panel2); color: var(--muted); }
.saved-tag { font-size: 10px; font-weight: 600; color: var(--ok); background: #14361f; border-radius: 999px; padding: 1px 7px; margin-left: 7px; vertical-align: middle; }
.r-go { color: var(--muted); font-size: 22px; padding: 0 4px; }
.linklike { color: var(--muted); font-size: 13px; text-align: center; padding: 10px; width: 100%; text-decoration: underline; }
.empty { color: var(--muted); text-align: center; padding: 24px; font-size: 14px; }

/* ---------- Room ---------- */
.room { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: var(--bg2); border-bottom: 1px solid var(--line); }
.topbar .iconbtn { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-size: 20px; color: var(--muted); }
.topbar .iconbtn:active { background: var(--panel); }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b { display: block; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .title span { font-size: 11px; color: var(--muted); }

.tabs { display: flex; background: var(--bg2); border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 12px; font-weight: 600; color: var(--muted); position: relative; }
.tabs button.active { color: var(--text); }
.tabs button.active::after { content: ''; position: absolute; left: 20%; right: 20%; bottom: 0; height: 3px;
  background: var(--brand); border-radius: 3px 3px 0 0; }
.tabs .tab-badge { position: absolute; top: 7px; margin-left: 5px; background: var(--danger); color: #fff;
  font-size: 10px; min-width: 16px; height: 16px; border-radius: 999px; padding: 0 4px; display: inline-grid; place-items: center; }

.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- Chat ---------- */
.chat-scroll { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 82%; padding: 9px 12px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line);
  align-self: flex-start; word-break: break-word; }
.msg .time { font-size: 10px; color: var(--muted); margin-top: 4px; text-align: right; }
.msg.mine { align-self: flex-end; background: linear-gradient(135deg, var(--brand), var(--brand2)); border-color: transparent; }

/* chat profile circles: colored first-letter avatar + name, grouped per author */
.msg-line { display: flex; align-items: flex-start; gap: 8px; align-self: flex-start; max-width: 90%; }
.msg-line.cont { margin-top: -4px; }
.msg-col { display: flex; flex-direction: column; min-width: 0; }
.msg-line .msg { max-width: 100%; align-self: flex-start; }
.chat-ava { width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-size: 14px; font-weight: 800; color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35);
  user-select: none; -webkit-user-select: none; }
.chat-ava-sp { width: 34px; flex: none; }
.who { font-size: 11.5px; font-weight: 600; margin: 1px 0 3px 2px; }
.msg.system { align-self: center; background: transparent; border: none; color: var(--muted); font-size: 12px; text-align: center; }
.msg a { color: #c7d2fe; }
.filecard { display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; }
.filecard .fc-ic { width: 40px; height: 40px; border-radius: 9px; background: var(--panel2); display: grid; place-items: center; font-size: 20px; flex: none; }
.filecard .fc-name { font-weight: 600; font-size: 14px; word-break: break-all; }
.filecard .fc-sub { font-size: 11px; color: var(--muted); }
.file-preview { margin-top: 8px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #000; }
.file-preview img { width: 100%; display: block; }
.file-preview iframe { width: 100%; height: 260px; border: 0; background: #fff; }

/* replies */
.msg .reply-quote { border-left: 3px solid var(--brand); background: rgba(255,255,255,.07); padding: 5px 9px;
  border-radius: 7px; margin-bottom: 6px; font-size: 12px; cursor: pointer; }
.msg .reply-quote b { display: block; font-size: 11px; color: #c7d2fe; margin-bottom: 1px; }
.msg .reply-quote span { color: var(--muted); }
.msg.mine .reply-quote { background: rgba(255,255,255,.16); border-left-color: rgba(255,255,255,.6); }
.msg.mine .reply-quote b, .msg.mine .reply-quote span { color: #f0f0ff; }
.msg.flash { outline: 2px solid var(--brand); outline-offset: 2px; transition: outline-color .3s; }

/* task card inside a chat message */
.task-ref { display: flex; align-items: center; gap: 7px; width: 100%; text-align: left;
  background: #22364a; color: #cfe8ff; padding: 7px 10px; border-radius: 9px; margin-bottom: 6px; font-size: 12.5px; }
.msg.mine .task-ref { background: rgba(255,255,255,.16); color: #fff; }
.task-ref b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.task-ref .tr-go { font-size: 16px; opacity: .7; }

/* bubble footer: reply button + unread counter + time */
.msg-foot { display: flex; align-items: center; justify-content: flex-end; gap: 7px; margin-top: 4px; }
.msg-foot .time { margin-top: 0; }
.msg-reply { font-size: 12px; color: var(--muted); opacity: .8; padding: 0 2px; line-height: 1; }
.msg.mine .msg-reply { color: #dcdcff; }
.unread-n { font-size: 10px; font-weight: 800; color: #ffd54a; min-width: 10px; text-align: center; }

/* uploaded images */
.img-wrap { display: block; }
.img-wrap img { max-width: min(300px, 100%); max-height: 300px; border-radius: 10px; display: block; }
.filecard.expired { opacity: .6; }

/* reply compose bar */
.reply-bar { display: flex; align-items: center; gap: 9px; padding: 8px 14px; background: var(--panel);
  border-top: 1px solid var(--line); font-size: 12px; }
.reply-bar .rb-ic { color: var(--brand); font-size: 15px; }
.reply-bar .rb-main { flex: 1; min-width: 0; }
.reply-bar .rb-main b { font-size: 12px; color: #c7d2fe; }
.reply-bar .rb-snip { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar .rb-x { width: 28px; height: 28px; color: var(--muted); font-size: 13px; flex: none; }

/* task thread sheet */
.thread-list { max-height: 38vh; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }
.thread-msg { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  font-size: 13px; word-break: break-word; }
.thread-msg b { color: #c7d2fe; font-size: 12px; }
.thread-msg .th-time { display: block; font-size: 10px; color: var(--muted); margin-top: 3px; text-align: right; }

/* invite banner in the lobby */
.invite-banner { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }

.composer { display: flex; gap: 8px; padding: 10px 12px calc(var(--safe-bottom) + 10px); background: var(--bg2); border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { resize: none; max-height: 120px; min-height: 44px; }
.composer .iconbtn { width: 44px; height: 44px; border-radius: 10px; background: var(--panel2); display: grid; place-items: center; font-size: 20px; flex: none; }
.composer .send { background: var(--brand); }

/* ---------- Tasks ---------- */
.tasks-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg2); }
.filterseg { display: flex; background: var(--panel); border-radius: 9px; padding: 3px; gap: 3px; }
.filterseg button { padding: 6px 11px; font-size: 13px; border-radius: 7px; color: var(--muted); }
.filterseg button.active { background: var(--brand); color: #fff; }
.tasks-scroll { flex: 1; overflow-y: auto; padding: 8px 10px calc(var(--safe-bottom) + 88px); }
.task-list { position: relative; }

.task { display: flex; align-items: flex-start; gap: 10px; padding: 10px; border-radius: 11px; background: var(--panel);
  border: 1px solid var(--line); margin: 6px 0; touch-action: pan-y; position: relative;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.task.dragging { opacity: .3; }
.task.selected { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.task.flash { animation: taskflash 1.6s ease; }
@keyframes taskflash { 0%, 55% { background: #2b3f7a; border-color: var(--brand); } 100% { background: var(--panel); } }
.task.done .t-title { text-decoration: line-through; color: var(--muted); }
.task.cancelled .t-title { text-decoration: line-through; color: var(--muted); opacity: .7; }
.check { width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line); flex: none; margin-top: 1px;
  display: grid; place-items: center; font-size: 15px; color: transparent; background: var(--bg2); }
.task.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.task.cancelled .check { background: var(--panel2); border-color: var(--line); color: var(--muted); }
.t-body { flex: 1; min-width: 0; }
.t-title { font-size: 15px; font-weight: 500; word-break: break-word; }
.t-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; align-items: center; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); display: inline-flex; align-items: center; gap: 3px; }
.tag.assignee { background: #2b2f66; color: #c7d0ff; }
.tag.due { background: #33305e; color: #d6c9ff; }
.tag.due.soon { background: #4a3a1a; color: #ffd28a; }
.tag.due.over { background: #4a1f22; color: #ffb4b4; }
.tag.kids { background: #22364a; color: #a9d8ff; }
.t-details { font-size: 12.5px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.t-expand { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; color: var(--muted); flex: none; font-size: 12px; }
.t-expand.open { transform: rotate(90deg); }
.subtree { margin-left: 18px; border-left: 2px solid var(--line); padding-left: 6px; }

/* drag: the row itself lifts (clone), a thick indented line marks the drop spot */
.drop-into { outline: 2px dashed var(--ok); outline-offset: 1px; border-radius: 11px; }
.task.ghost { position: fixed; z-index: 100; margin: 0; pointer-events: none; opacity: .95;
  border-color: var(--brand); box-shadow: 0 16px 38px rgba(0,0,0,.55); background: var(--panel2); }
.task.ghost.nesting { border-color: var(--ok); }
.ins-line { position: fixed; z-index: 99; height: 4px; border-radius: 4px; background: var(--brand);
  box-shadow: 0 0 10px var(--brand); pointer-events: none; transition: left .07s linear, top .07s linear, width .07s linear; }
body.dragging-lock { user-select: none; -webkit-user-select: none; }
.t-chat { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; flex: none;
  font-size: 14px; color: var(--muted); position: relative; }
.t-chat .cnt { position: absolute; top: -4px; right: -5px; background: var(--brand); color: #fff;
  font-size: 9px; font-weight: 700; min-width: 14px; height: 14px; border-radius: 999px; padding: 0 3px;
  display: grid; place-items: center; }

/* precise-move toolbar (long-press then release without dragging) */
.move-bar { position: absolute; left: 10px; right: 10px; bottom: calc(var(--safe-bottom) + 12px);
  background: var(--panel2); border: 1px solid var(--brand); border-radius: 14px; padding: 10px 12px;
  z-index: 30; box-shadow: 0 12px 30px rgba(0,0,0,.5); }
.mv-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.mv-title { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-edit { color: #c7d2fe; font-size: 13px; font-weight: 600; padding: 4px 8px; border-radius: 8px; background: var(--panel); }
.mv-close { width: 28px; height: 28px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.mv-row { display: flex; gap: 6px; }
.mv-btn { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 4px 6px; display: grid; place-items: center; gap: 1px; }
.mv-btn b { font-size: 15px; line-height: 1; }
.mv-btn span { font-size: 10px; color: var(--muted); }
.mv-btn.off { opacity: .35; }
.mv-btn:not(.off):active { background: var(--chip); }

.fab { position: absolute; right: 18px; bottom: calc(var(--safe-bottom) + 20px); width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand2)); color: #fff; font-size: 28px; display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(79,70,229,.5); z-index: 20; }
.fab:active { transform: scale(.94); }

/* ---------- Modal / sheet ---------- */
.overlay { position: fixed; inset: 0; background: rgba(4,6,20,.6); backdrop-filter: blur(3px); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg2); width: 100%; max-width: 720px; border-radius: 20px 20px 0 0; border: 1px solid var(--line);
  padding: 8px 18px calc(var(--safe-bottom) + 20px); max-height: 92dvh; overflow-y: auto; animation: up .22s ease; }
.sheet.center { border-radius: 18px; align-self: center; margin: auto; max-width: 460px; }
.overlay.mid { align-items: center; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.grabber { width: 40px; height: 4px; background: var(--line); border-radius: 3px; margin: 8px auto 12px; }
.sheet h3 { margin: 4px 0 14px; font-size: 17px; }
.sheet .field { margin-bottom: 12px; }
.actions { display: flex; gap: 8px; margin-top: 16px; }
.actions .btn { flex: 1; }

.switch { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.switch:last-child { border-bottom: none; }
.switch .s-label b { font-size: 14px; }
.switch .s-label p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.toggle { width: 48px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.toggle::after { content: ''; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: left .15s; }
.toggle.on { background: var(--ok); }
.toggle.on::after { left: 23px; }
.checkline { display: flex; align-items: center; gap: 9px; margin-top: 10px; font-size: 14px; color: var(--muted); }
.checkbox { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--line); display: grid; place-items: center; color: transparent; flex: none; }
.checkbox.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: #000c; color: #fff;
  padding: 10px 16px; border-radius: 999px; font-size: 13px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 200; max-width: 90%; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
.dnd-times { display: flex; gap: 10px; align-items: center; }
.dnd-times input { text-align: center; }
select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' stroke='%239aa3d4' stroke-width='2' fill='none'/></svg>"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
