/* Chat, levels, application — same soft language as app.css (rounded cards,
   hairlines, soft shadows, one blue). Tokens come from app.css :root. */

/* ---------- nav badge ---------- */
.nav a, .tabbar a { position: relative; }
.nbadge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--ink-2); color: var(--surface);
  font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; line-height: 1;
}
.nbadge.at { background: var(--danger); color: #fff; }
.tabbar .nbadge { position: absolute; top: 4px; left: calc(50% + 6px); }

/* ---------- chat layout ---------- */
main.chat-main { padding-bottom: 20px; }
.chat {
  display: grid; grid-template-columns: 220px minmax(0, 1fr) 248px; gap: 16px;
  height: calc(100dvh - 57px - 40px); min-height: 420px;
}
.chans, .members { padding: 12px; overflow-y: auto; }
.chans-h, .mem-h { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); padding: 6px 8px; }
.mem-h { margin-top: 10px; }
.mem-h:first-child { margin-top: 0; }
.chan {
  width: 100%; display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 9px 10px; border-radius: 12px;
  cursor: pointer; color: var(--ink-2); font-weight: 600; font-size: 15px; text-align: left; min-height: 44px;
}
.chan .ic { width: 18px; height: 18px; display: grid; place-items: center; color: var(--ink-3); flex: none; }
.chan .ic svg { width: 18px; height: 18px; }
.chan .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan:hover { background: var(--line); color: var(--ink); }
.chan.on { background: var(--brand-soft); color: var(--brand-text); }
.chan.on .ic { color: var(--brand-text); }
.chan.has-unread { color: var(--ink); }
.cbadge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--ink-2); color: var(--surface);
  font-size: 12px; font-weight: 700; display: inline-grid; place-items: center;
}
.cbadge.at { background: var(--danger); color: #fff; }

.convo { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.convo-h { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.convo-h .ttl { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.convo-h .ttl .ic { width: 36px; height: 36px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-text); display: grid; place-items: center; flex: none; }
.convo-h .ttl .ic svg { width: 18px; height: 18px; }
.convo-h h2 { margin: 0; font-size: 17px; }
.convo-h .small { display: block; }
.mem-toggle { display: none; }
.livenote { font-size: 13px; color: var(--ink-2); background: color-mix(in srgb, var(--warning) 12%, transparent); padding: 6px 16px; }

.msgs { position: relative; flex: 1; overflow-y: auto; padding: 8px 0 12px; overscroll-behavior: contain; }
.msgs .empty { padding: 64px 16px; }
.older { display: flex; justify-content: center; padding: 6px; }
.daysep { display: flex; align-items: center; gap: 10px; padding: 14px 16px 6px; color: var(--ink-3); font-size: 12px; font-weight: 600; }
.daysep::before, .daysep::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.daysep.new { color: var(--danger); }
.daysep.new::before, .daysep.new::after { background: color-mix(in srgb, var(--danger) 40%, transparent); }

.msg { position: relative; display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 10px; padding: 6px 16px; }
.msg.grouped { padding-top: 1px; }
.msg:hover { background: color-mix(in srgb, var(--line) 50%, transparent); }
.msg.at-me { background: color-mix(in srgb, var(--warning) 9%, transparent); box-shadow: inset 3px 0 0 var(--warning); }
.msg .gut { display: flex; justify-content: center; }
.msg .gut .ts { font-size: 11px; color: var(--ink-3); visibility: hidden; padding-top: 3px; }
.msg:hover .gut .ts { visibility: visible; }
.avatar.sm-av { width: 36px; height: 36px; font-size: 14px; cursor: default; position: relative; flex: none; }
.msg .meta { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.msg .meta b { font-size: 15px; }
.msg .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.deleted .txt { font-size: 14px; }
.msg .acts { position: absolute; right: 12px; top: -10px; display: none; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 2px; }
.msg:hover .acts, .msg:focus-within .acts { display: flex; }
.msg .acts .btn { min-height: 30px; padding: 0 10px; font-size: 13px; }
.editbox { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.editbox textarea { min-height: 64px; }
.row-btns { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.rbadge { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.rbadge.team { background: var(--brand-soft); color: var(--brand-text); }
.rbadge.amb { background: color-mix(in srgb, var(--coffee) 22%, transparent); color: color-mix(in srgb, var(--coffee) 55%, var(--ink)); }
.rbadge.muted { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.mention { background: var(--brand-soft); color: var(--brand-text); border-radius: 6px; padding: 0 3px; font-weight: 600; }
.mention.me { background: color-mix(in srgb, var(--warning) 22%, transparent); color: color-mix(in srgb, var(--warning) 60%, var(--ink)); }
.cafelink { border: 0; background: color-mix(in srgb, var(--success) 14%, transparent); color: color-mix(in srgb, var(--success) 60%, var(--ink)); border-radius: 6px; padding: 0 3px; font: inherit; font-weight: 600; cursor: pointer; }
.cafecards { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.cafecard {
  display: inline-flex; align-items: center; gap: 10px; padding: 8px 12px 8px 8px; border-radius: 14px; border: 1px solid var(--line-2);
  background: var(--surface-alt); cursor: pointer; text-align: left; max-width: 100%; min-height: 44px;
}
.cafecard .ic { width: 32px; height: 32px; border-radius: 10px; background: color-mix(in srgb, var(--coffee) 24%, transparent); display: grid; place-items: center; color: color-mix(in srgb, var(--coffee) 60%, var(--ink)); flex: none; }
.cafecard .ic svg { width: 18px; height: 18px; }
.cafecard b { display: block; font-size: 14px; }
.cafecard small { color: var(--ink-3); font-size: 12px; }
.cafecard:hover { border-color: var(--brand); }

.composer { position: relative; border-top: 1px solid var(--line); padding: 10px 12px 8px; }
.cform { display: flex; gap: 8px; align-items: flex-end; }
.cform textarea { min-height: 48px; max-height: 180px; resize: none; border-radius: 16px; padding: 12px 14px; }
.cform .send { width: 48px; padding: 0; flex: none; border-radius: 16px; }
.composer .hint { padding: 4px 4px 0; }
.composer-note { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--ink-2); padding: 12px; font-size: 14px; text-align: center; }
.composer-note svg { width: 16px; height: 16px; flex: none; }
.suggest {
  position: absolute; left: 12px; right: 12px; bottom: calc(100% - 4px); z-index: 5; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 6px; display: flex; flex-direction: column; max-height: 280px; overflow-y: auto;
}
.suggest button { display: flex; align-items: baseline; gap: 8px; border: 0; background: none; padding: 10px 12px; border-radius: 12px; text-align: left; cursor: pointer; min-height: 44px; }
.suggest button .k { color: var(--ink-3); font-weight: 700; }
.suggest button small { color: var(--ink-3); margin-left: auto; font-size: 12px; }
.suggest button.on, .suggest button:hover { background: var(--brand-soft); }

.mrow { position: relative; display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 12px; opacity: .55; }
.mrow.on { opacity: 1; }
.mrow:hover { background: var(--line); }
.mrow .mn { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.mrow .mn b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.mrow .avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--ink-3); border: 2px solid var(--surface); }
.mrow.on .avatar .dot { background: var(--success); }
.iconbtn.sm-ic { width: 32px; height: 32px; background: transparent; }
.modmenu { position: absolute; right: 4px; top: calc(100% - 4px); z-index: 6; display: flex; flex-direction: column; padding: 4px; min-width: 180px; }
.modmenu .btn { justify-content: flex-start; }

@media (max-width: 1100px) {
  .chat { grid-template-columns: 200px minmax(0, 1fr); }
  .members { display: none; }
  .mem-toggle { display: grid; }
  .chat.show-members .members {
    display: block; position: fixed; right: 16px; top: 72px; bottom: 24px; width: min(300px, calc(100vw - 32px)); z-index: 45; box-shadow: var(--shadow-lg);
  }
}
@media (max-width: 760px) {
  main.chat-main { padding: 8px 0 0; }
  .chat {
    grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: 8px;
    height: calc(100dvh - 57px - 8px - 66px - env(safe-area-inset-bottom));
  }
  .chans { display: flex; gap: 6px; overflow-x: auto; padding: 0 16px; background: none; border: 0; box-shadow: none; scrollbar-width: none; }
  .chans::-webkit-scrollbar { display: none; }
  .chans-h { display: none; }
  .chan { width: auto; flex: none; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); padding: 6px 14px; min-height: 40px; font-size: 14px; }
  .chan .ic { display: none; }
  .convo { border-radius: var(--r-sheet) var(--r-sheet) 0 0; border-bottom: 0; }
  .convo-h { padding: 10px 12px 10px 16px; }
  .msg { grid-template-columns: 36px minmax(0, 1fr); padding: 6px 12px; gap: 8px; }
  .avatar.sm-av { width: 32px; height: 32px; font-size: 13px; }
  .msg .acts { position: static; display: none; grid-column: 2; justify-self: start; background: none; border: 0; box-shadow: none; padding: 0; margin-top: -2px; }
  .msg.sel .acts { display: flex; }
  .msg:hover .acts { display: none; }
  .msg.sel:hover .acts { display: flex; }
  .msg .acts .btn { min-height: 28px; padding: 0 8px; font-size: 12px; color: var(--ink-3); }
  .composer .hint { display: none; }
  .chat.show-members .members { top: 64px; bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* ---------- level page ---------- */
.levelpage { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; max-width: 1100px; margin: 0 auto; align-items: start; }
.lvcol { display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 900px) { .levelpage { grid-template-columns: 1fr; } }
.section h3 { margin: 0; }
.section h2 { margin: 0; }
.lvhero { gap: 16px; }
.lvbig { display: flex; align-items: center; gap: 16px; }
.lvnum {
  width: 72px; height: 72px; border-radius: 22px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, #7FB8D9, var(--brand)); color: #fff; font-weight: 700; font-size: 26px; box-shadow: var(--shadow);
}
.lvstats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lvstats > div { background: var(--surface-alt); border-radius: var(--r-sm); padding: 12px 14px; display: flex; flex-direction: column; }
.lvstats .big { font-size: 28px; font-weight: 700; line-height: 1.1; }
.lvnext { font-weight: 600; color: var(--brand-text); }

.lvbar { list-style: none; margin: 0; padding: 0; position: relative; display: flex; flex-direction: column; gap: 6px; }
/* The vertical track runs through the knobs; --fill is measured from the bottom (L1). */
.lvbar::before, .lvbar::after { content: ''; position: absolute; left: 21px; width: 6px; border-radius: 3px; bottom: 24px; }
.lvbar::before { top: 24px; background: var(--line-2); }
.lvbar::after { height: calc((100% - 48px) * var(--fill) / 100); background: linear-gradient(to top, var(--brand), #7FB8D9); }
.lvnode { position: relative; z-index: 1; display: flex; gap: 14px; align-items: flex-start; padding: 6px 0; }
.lvnode .knob {
  width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: var(--surface); border: 2px solid var(--line-2); color: var(--ink-3);
}
.lvnode .knob svg { width: 20px; height: 20px; }
.lvnode.reached .knob { background: var(--brand); border-color: var(--brand); color: #fff; }
.lvnode.current .knob { box-shadow: 0 0 0 6px var(--brand-soft); }
.lvtxt { flex: 1; min-width: 0; padding-top: 2px; display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.lvt { display: flex; gap: 8px; align-items: baseline; }
.lvr { font-weight: 600; }
.lvnode:not(.reached) .lvr { color: var(--ink-2); }
.rstate { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line); color: var(--ink-2); margin-top: 2px; }
.rstate svg { width: 12px; height: 12px; }
.rstate.pending { background: color-mix(in srgb, var(--warning) 16%, transparent); color: color-mix(in srgb, var(--warning) 65%, var(--ink)); }
.rstate.granted { background: color-mix(in srgb, var(--success) 15%, transparent); color: color-mix(in srgb, var(--success) 60%, var(--ink)); }

.lbcard h3 { gap: 8px; flex-wrap: wrap; }
.lbrow { display: flex; align-items: center; gap: 12px; padding: 8px 6px; border-top: 1px solid var(--line); }
.lbrow:first-child { border-top: 0; }
.lbrow.me { background: var(--brand-soft); border-radius: 12px; border-top-color: transparent; }
.lbrow .rank { width: 28px; text-align: center; font-weight: 700; color: var(--ink-3); flex: none; }
.lbrow .rank.r1 { color: #C9962B; }
.lbrow .rank.r2 { color: #8E8E9A; }
.lbrow .rank.r3 { color: #B07A4F; }
.lbrow .mn { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: center; }
.lbrow .mn b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lbrow .cnt { font-size: 18px; }

.appcard { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-alt); }
.apph { display: flex; gap: 10px; align-items: center; }
.appcard .why { white-space: pre-wrap; overflow-wrap: anywhere; }
.rwrow { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.rwrow:first-of-type { border-top: 0; }
.rwrow .mn { flex: 1; min-width: 160px; display: flex; flex-direction: column; }
.past summary { cursor: pointer; padding: 4px 0; }
.pastrow { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* ---------- application ---------- */
.applycard { max-width: 480px !important; }
.perks { list-style: none; margin: 0; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; background: var(--brand-soft); border-radius: var(--r-sm); }
.perks li { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 14px; }
.perks svg { width: 16px; height: 16px; color: var(--brand-text); flex: none; }
