:root {
  --red: #8f1d22; --red-dark: #6e1418; --red-soft: #f7e9e9;
  --ink: #1d1d1f; --ink-2: #4a4a4f; --muted: #7a7a80; --line: #e6e2dc;
  --bg: #f6f4f0; --card: #fff; --ok: #1f7a4d; --ok-soft: #e6f4ec; --warn: #a15c00; --warn-soft: #fff3e0;
  --bad: #b3261e; --bad-soft: #fdecea; --grey-soft: #f0efed;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-text-size-adjust: 100%; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.3; }
h2 { font-size: 1.35rem; } h3 { font-size: 1.1rem; } h4 { font-size: 1rem; color: var(--ink-2); }
p { margin: 0 0 .6em; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .strong { font-weight: 600; } .mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; } .struck { text-decoration: line-through; color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.spacer { height: 12px; }
.center-load { padding: 64px 16px; text-align: center; color: var(--muted); }

/* buttons & inputs */
.btn { appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 9px; padding: 8px 14px; font: inherit; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; transition: background .15s, border-color .15s, opacity .15s; text-decoration: none; }
.btn:hover { border-color: #cfc9c1; background: #faf9f7; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, .tab:focus-visible, .chip:focus-visible, .switch:focus-visible { outline: 3px solid rgba(143,29,34,.3); outline-offset: 1px; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.light { background: #fff; color: var(--ink); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.loading { opacity: .6; pointer-events: none; }
.linkish { background: none; border: 0; color: var(--red); padding: 0; font: inherit; font-size: .85rem; cursor: pointer; }
input, textarea, select { width: 100%; font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; background: #fff; }
textarea { resize: vertical; line-height: 1.6; }
label { display: block; font-weight: 500; margin: 14px 0 6px; font-size: .92rem; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 6px; }
.form-error { color: var(--bad); min-height: 1.4em; margin: 10px 0; font-size: .9rem; }

/* auth pages */
.auth-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 16px; background: radial-gradient(1200px 500px at 50% -10%, #f2dede 0%, transparent 60%), var(--bg); }
.auth-top { width: 100%; max-width: 440px; display: flex; justify-content: flex-end; }
.auth-card { width: 100%; max-width: 440px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 28px 26px; margin-top: 4vh; }
.auth-card h2 { margin-top: 18px; }
.auth-card .btn.block { margin-top: 8px; }
.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 46px; height: 46px; border-radius: 11px; background: var(--red); color: #fff; font-weight: 700; display: grid; place-items: center; letter-spacing: .5px; flex: none; }
.brand-mark.small { width: 34px; height: 34px; font-size: .8rem; border-radius: 8px; }
.brand-name { font-weight: 700; }
.brand-sub { color: var(--muted); font-size: .82rem; }

/* app frame */
.top { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-inner { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.who { color: var(--ink-2); font-weight: 500; padding: 0 6px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewas { width: auto; max-width: 240px; padding: 6px 8px; font-size: .88rem; background: var(--red-soft); border-color: #e9caca; }
.viewas-banner { background: #3a2a10; color: #ffe8b8; padding: 10px 16px; display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; font-size: .92rem; position: sticky; top: 59px; z-index: 19; }
.tabs-wrap { background: #fff; border-bottom: 1px solid var(--line); }
.tabs { max-width: 1180px; margin: 0 auto; padding: 0 12px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tab { border: 0; background: none; font: inherit; color: var(--ink-2); padding: 12px 14px; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 500; }
.tab.active { color: var(--red); border-bottom-color: var(--red); }
.content { max-width: 1180px; margin: 0 auto; padding: 20px 16px 96px; }
.stack > * + * { margin-top: 16px; }

/* cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card.success { border-left: 4px solid var(--ok); }
.card.empty { text-align: center; color: var(--ink-2); padding: 40px 18px; }
.error-card { border-left: 4px solid var(--bad); }
.error-card .btn { margin-top: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.inline { display: flex; gap: 8px; }
.inline .num { max-width: 110px; }
.inline .btn { flex: none; white-space: nowrap; }

/* photos */
.photo { position: relative; background: linear-gradient(135deg, #ece6df, #ddd5cc); border-radius: 10px; overflow: hidden; flex: none; display: grid; place-items: center; color: #8b8178; font-weight: 600; }
.photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .25s; }
.photo.loaded img { opacity: 1; }
.photo.loaded .ph-fallback { visibility: hidden; }
.photo.sm { width: 40px; height: 48px; border-radius: 7px; font-size: .75rem; }
.photo.md { width: 96px; height: 120px; }
.photo.lg { width: 120px; height: 150px; font-size: 1.4rem; }
.photo.mentor-photo { width: 100%; aspect-ratio: 4 / 5; border-radius: 10px 10px 0 0; font-size: 2rem; }

/* person */
.person { display: flex; gap: 18px; align-items: flex-start; }
.person-body { flex: 1; min-width: 0; }
.person-name h3 { margin: 0; }
.person-name .sub { color: var(--ink-2); font-weight: 500; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 10px 0 0; font-size: .92rem; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; }
.title { color: var(--red); font-size: .9rem; font-weight: 500; margin-bottom: 8px; }
.statement { white-space: pre-wrap; }
.statement-box { margin-top: 12px; background: var(--bg); border-radius: 9px; padding: 10px 12px; }
.statement-box .label { font-size: .78rem; color: var(--muted); margin-bottom: 2px; }
.statement-box p { margin: 0; white-space: pre-wrap; }
.editor-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 8px; }
.counter { color: var(--muted); font-size: .85rem; }

/* mentors grid */
.grid.mentors-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.mentor { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; border: 2px solid transparent; transition: border-color .15s, transform .15s; }
.mentor.selected { border-color: var(--red); }
.mentor-body { padding: 14px; display: flex; flex-direction: column; flex: 1; }
.mentor-body h3 { margin-bottom: 4px; }
.mentor-body .btn { margin-top: auto; }
.clamp-wrap { margin-bottom: 12px; }
.clamp { display: -webkit-box; -webkit-line-clamp: var(--lines); -webkit-box-orient: vertical; overflow: hidden; color: var(--ink-2); font-size: .9rem; white-space: pre-wrap; margin: 0; }
.clamp.open { -webkit-line-clamp: unset; display: block; }
.result-title { text-align: center; color: var(--ink-2); font-weight: 500; }
.result-mentor { max-width: 320px; margin: 0 auto; }
.chosen-list { margin: 8px 0 0; padding-left: 20px; font-weight: 600; }
.sticky-bar { position: fixed; bottom: 0; left: 0; right: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(6px); border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; justify-content: center; align-items: center; gap: 16px; z-index: 15; }
.pick-count { font-weight: 600; }

/* phase bar */
.phase { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-radius: 10px; font-size: .92rem; }
.phase.open { background: var(--ok-soft); color: var(--ok); }
.phase.closed { background: var(--grey-soft); color: var(--ink-2); }
.phase .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.phase .deadline { color: var(--ink-2); }

/* mentor student list */
.list { display: grid; gap: 12px; }
.list.tight { gap: 6px; }
.student-row { display: flex; gap: 16px; justify-content: space-between; align-items: flex-start; }
.student-row > .person { flex: 1; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; flex: none; }
.actions { display: flex; gap: 8px; }
.actions.wrap { flex-wrap: wrap; }
.student-row.status-matched { opacity: .5; filter: grayscale(1); }
.student-row.status-accepted { border-left: 4px solid var(--ok); }
.student-row.flagged { border-left: 4px solid var(--red); }
.counter-bar { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--grey-soft); color: var(--ink-2); white-space: nowrap; }
.badge.pending, .badge.st-waiting { background: var(--warn-soft); color: var(--warn); }
.badge.accepted, .badge.st-matched { background: var(--ok-soft); color: var(--ok); }
.badge.rejected, .badge.st-both { background: var(--bad-soft); color: var(--bad); }
.badge.matched, .badge.st-never { background: var(--grey-soft); color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: var(--warn); margin-top: 2px; }
.search { max-width: 320px; }

/* admin */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stat-v { font-size: 1.7rem; font-weight: 700; }
.stat-v small { font-size: .95rem; color: var(--muted); font-weight: 500; }
.stat-l { color: var(--muted); font-size: .85rem; }
.switch-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: 0; }
.switch { position: relative; border: 0; background: #d9d4cd; width: 76px; height: 32px; border-radius: 999px; cursor: pointer; display: flex; align-items: center; justify-content: flex-end; padding: 0 10px; color: #fff; font: inherit; font-size: .8rem; font-weight: 600; transition: background .2s; }
.switch .knob { position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch.on { background: var(--ok); justify-content: flex-start; }
.switch.on .knob { left: 48px; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.chip.active { background: var(--red); border-color: var(--red); color: #fff; }
.table-wrap { overflow-x: auto; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fbfaf8; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table td.num { text-align: center; white-space: nowrap; }
.table td.full { color: var(--bad); font-weight: 600; }
.cell-person { display: flex; gap: 10px; align-items: center; min-width: 200px; }
.unmatched-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 14px; }
.gallery figure { margin: 0; text-align: center; font-size: .82rem; }
.gallery .photo { margin: 0 auto 6px; }
.report { list-style: none; padding: 0; margin: 10px 0 0; font-size: .85rem; max-height: 240px; overflow: auto; }
.report .ok { color: var(--ok); } .report .bad { color: var(--bad); }

/* modal & toast */
.modal-wrap { position: fixed; inset: 0; background: rgba(20,16,12,.45); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .15s; }
.modal { background: #fff; border-radius: 14px; max-width: 460px; width: 100%; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-body { margin: 8px 0 18px; color: var(--ink-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: max-content; max-width: 92vw; }
.toast { background: #1d1d1f; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: .92rem; transition: opacity .4s, transform .4s; }
.toast.bad { background: var(--bad); } .toast.warn { background: var(--warn); }
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes fade { from { opacity: 0; } }

/* small screens */
@media (max-width: 760px) {
  .two-col, .stats { grid-template-columns: 1fr 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .student-row { flex-direction: column; }
  .row-side { flex-direction: row; align-items: center; justify-content: space-between; width: 100%; }
  .photo.lg { width: 92px; height: 115px; }
  .person { gap: 14px; }
  .grid.mentors-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .brand-text { display: none; }
  .who { display: none; }
  .viewas { max-width: 150px; }
  .viewas-banner { top: 57px; }
  .content { padding: 14px 12px 96px; }
}
@media (max-width: 420px) {
  .grid.mentors-grid { grid-template-columns: 1fr 1fr; }
  .mentor-body { padding: 10px; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dt { margin-top: 4px; font-size: .8rem; }
}

/* motion: quiet, quick, and off for people who prefer reduced motion */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.content > *, .auth-card { animation: rise .32s cubic-bezier(.2,.7,.2,1) both; }
.grid.mentors-grid > *, .list > * { animation: rise .35s cubic-bezier(.2,.7,.2,1) both; }
.grid.mentors-grid > *:nth-child(2), .list > *:nth-child(2) { animation-delay: .03s; }
.grid.mentors-grid > *:nth-child(3), .list > *:nth-child(3) { animation-delay: .06s; }
.grid.mentors-grid > *:nth-child(4), .list > *:nth-child(4) { animation-delay: .09s; }
.grid.mentors-grid > *:nth-child(n+5), .list > *:nth-child(n+5) { animation-delay: .12s; }
.modal { animation: pop .2s cubic-bezier(.2,.7,.2,1); }
.mentor, .card, .stat { transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease, opacity .3s ease, filter .3s ease; }
.mentor:hover { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(0,0,0,.05), 0 12px 28px rgba(0,0,0,.09); }
.tab { transition: color .2s ease, border-color .2s ease; }
.tab:hover { color: var(--red); }
.btn:active:not(:disabled) { transform: scale(.97); }
.photo img { transition: opacity .35s ease; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
.no-anim .list > *, .no-anim > * { animation: none; }
.two-col.tight { gap: 12px; }
.two-col.tight label { margin-top: 6px; }
.modal:has(.wide-form) { max-width: 760px; }
