@import url('https://fonts.googleapis.com/css2?family=Unbounded:wght@400;500;600;700;800;900&family=Montserrat:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #050304; --bg-2: #0a0607; --panel: #0d0809;
  --red: #ff1f2e; --red-bright: #ff3b48; --red-deep: #c20f1a; --red-soft: rgba(255,31,46,.14);
  --text: #f6f3f4; --muted: #a59ca0; --faint: #6f676b;
  --line: rgba(255,255,255,.08); --line-strong: rgba(255,255,255,.15);
  --glass: rgba(255,255,255,.03); --glass-2: rgba(255,255,255,.05);
  --green: #22c55e; --amber: #f59e0b;
  --font-display: "Unbounded", system-ui, sans-serif;
  --font-body: "Montserrat", system-ui, -apple-system, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-max: 1720px;
  --safe-x: clamp(18px, 4vw, 56px);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: var(--font-body); background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
ul { list-style: none; }

.wrap { width: 100%; max-width: var(--safe-max); margin: 0 auto;
  padding-left: max(var(--safe-x), env(safe-area-inset-left));
  padding-right: max(var(--safe-x), env(safe-area-inset-right)); }

h1, h2, h3 { font-family: var(--font-display); text-transform: uppercase; font-weight: 800; letter-spacing: -0.01em; }

/* ---------- header ---------- */
.ms-header { position: sticky; top: 0; z-index: 50; padding: 16px 0; background: rgba(10,6,7,.8);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.ms-header__row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.ms-brand { font-family: var(--font-display); font-weight: 800; font-size: 16px; letter-spacing: .03em; text-transform: uppercase; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ms-brand span { color: var(--red); }
.ms-brand img { height: 32px; width: auto; display: block; }
.ms-nav { display: flex; align-items: center; gap: 22px; }
.ms-nav a { color: var(--muted); font-size: 14px; font-weight: 500; transition: color .2s; white-space: nowrap; }

@media (max-width: 980px) {
  .ms-header__row { flex-wrap: wrap; row-gap: 10px; }
  .ms-search { order: 3; max-width: 100%; flex-basis: 100%; }
  .ms-nav { order: 2; gap: 14px; overflow-x: auto; }
}
@media (max-width: 560px) {
  .ms-brand img { height: 26px; }
  .ms-user span { display: none; }
  .ms-profile-head { flex-wrap: wrap; }
  .ms-profile-head .avatar, .ms-profile-head .avatar--fallback { width: 64px !important; height: 64px !important; font-size: 26px !important; }
}
.ms-nav a:hover, .ms-nav a.on { color: var(--text); }
.ms-user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }

/* ---------- avatars ---------- */
.avatar { border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--glass-2); }
.avatar--fallback { display: flex; align-items: center; justify-content: center; background: var(--red-soft);
  color: var(--red); font-weight: 800; font-family: var(--font-display); border-radius: 50%; flex-shrink: 0; }

/* ---------- search ---------- */
.ms-search { position: relative; flex: 1; max-width: 340px; }
.ms-search input { width: 100%; background: var(--glass-2); border: 1px solid var(--line); color: var(--text);
  padding: 9px 13px; font-family: var(--font-body); font-size: 13px; outline: none; }
.ms-search input:focus { border-color: var(--red); }
.ms-search__results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--panel);
  border: 1px solid var(--line-strong); max-height: 320px; overflow-y: auto; z-index: 60; }
.ms-search__row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; font-size: 13px; }
.ms-search__row:hover { background: var(--glass); }
.ms-search__empty { padding: 14px; color: var(--faint); font-size: 13px; text-align: center; }

/* ---------- layout ---------- */
main { padding: 40px 0 80px; }
.page-title { font-size: clamp(24px, 4vw, 34px); margin-bottom: 6px; }
.page-sub { color: var(--muted); font-size: 14px; margin-bottom: 28px; }
.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--5 { grid-template-columns: repeat(5, 1fr); }
.grid--6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 1300px) { .grid--6 { grid-template-columns: repeat(3, 1fr); } .grid--5 { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 900px) { .grid--4, .grid--5, .grid--6 { grid-template-columns: repeat(2, 1fr); } .grid--3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid--2, .grid--3, .grid--4, .grid--5, .grid--6 { grid-template-columns: 1fr; } }
@media (max-width: 860px) { #messages-layout { grid-template-columns: 1fr !important; } }
@media (max-width: 720px) { .gift-lines-cols { grid-template-columns: 1fr !important; } }
@media (max-width: 900px) { #obs-top-row { grid-template-columns: 1fr !important; } }

/* ---------- OBS preview with draggable layer boxes ---------- */
.obs-stage { position: relative; width: 100%; background: #000; overflow: hidden; user-select: none; }
.obs-stage img { width: 100%; height: 100%; display: block; object-fit: fill; }
.obs-overlay { position: absolute; inset: 0; }
.obs-box { position: absolute; border: 1.5px solid rgba(255,255,255,.35); cursor: move; box-sizing: border-box; }
.obs-box:hover { border-color: rgba(255,255,255,.7); }
.obs-box.selected { border-color: var(--red); border-width: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,.5); }
.obs-box.hidden-item { border-style: dashed; opacity: .45; }
.obs-box__label { position: absolute; top: -20px; left: -1px; background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700; padding: 2px 6px; white-space: nowrap; pointer-events: none;
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.obs-box.selected .obs-box__label { display: block; }
.obs-box__label { display: none; }
.obs-handle { position: absolute; width: 12px; height: 12px; background: var(--red); border: 2px solid #fff; box-sizing: border-box; }
.obs-handle[data-h="nw"] { left: -6px; top: -6px; cursor: nwse-resize; }
.obs-handle[data-h="ne"] { right: -6px; top: -6px; cursor: nesw-resize; }
.obs-handle[data-h="sw"] { left: -6px; bottom: -6px; cursor: nesw-resize; }
.obs-handle[data-h="se"] { right: -6px; bottom: -6px; cursor: nwse-resize; }
.obs-hint { color: var(--faint); font-size: 12px; margin-top: 8px; }
.obs-hint code { background: var(--glass-2); padding: 1px 5px; font-size: 11.5px; color: var(--text); }

/* ---------- toggle switch ---------- */
.ms-switch { display: inline-block; position: relative; width: 38px; height: 21px; cursor: pointer; }
.ms-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.ms-switch span { position: absolute; inset: 0; background: var(--glass-2); border: 1px solid var(--line); transition: background .2s, border-color .2s; }
.ms-switch span::before { content: ""; position: absolute; width: 13px; height: 13px; left: 3px; top: 3px;
  background: var(--faint); transition: transform .2s var(--ease), background .2s; }
.ms-switch input:checked + span { background: var(--red-soft); border-color: var(--red); }
.ms-switch input:checked + span::before { transform: translateX(17px); background: var(--red); }
.ms-switch input:disabled + span { opacity: .45; cursor: not-allowed; }

/* ---------- tabs ---------- */
.ms-tabs { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.ms-tabs button { padding: 9px 16px; background: var(--glass-2); border: 1px solid var(--line); color: var(--muted);
  font-family: var(--font-body); font-weight: 600; font-size: 13px; cursor: pointer;
  clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 9px, 100% 100%, 9px 100%, 0 calc(100% - 9px), 0 0); transition: all .2s; }
.ms-tabs button.active { background: var(--red); color: #fff; border-color: transparent; }

/* ---------- cover / profile hero ---------- */
.ms-cover { position: relative; height: 180px; margin-bottom: -60px; overflow: hidden; background: linear-gradient(135deg, #1a0508, #050304); }
.ms-cover img { width: 100%; height: 100%; object-fit: cover; opacity: .55; }
.ms-cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent, var(--bg)); }
.ms-profile-head { display: flex; align-items: flex-end; gap: 18px; position: relative; z-index: 1; margin-bottom: 24px; }
.ms-profile-head .avatar { width: 96px; height: 96px; border: 4px solid var(--bg); }
.ms-profile-head .avatar--fallback { width: 96px; height: 96px; border: 4px solid var(--bg); font-size: 40px; }

/* ---------- chamfered panel (2-layer border trick) ---------- */
.card { position: relative; z-index: 0; background: var(--line); padding: 1px;
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 18px 100%, 0 calc(100% - 18px), 0 0); }
.card::before { content: ""; position: absolute; inset: 1px; z-index: -1; background: var(--panel);
  clip-path: polygon(0 0, calc(100% - 17px) 0, 100% 17px, 100% 100%, 17px 100%, 0 calc(100% - 17px), 0 0); }
.card__inner { position: relative; z-index: 1; padding: 22px; }

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat__label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.stat__value { font-family: var(--font-display); font-weight: 800; font-size: clamp(22px, 3vw, 32px); }
.stat__value.red { color: var(--red); }

/* ---------- grouped stats: one chamfered card, hairline dividers via grid gap ---------- */
.stat-group { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1px; background: var(--line);
  position: relative; z-index: 0; margin-bottom: 16px;
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 18px 100%, 0 calc(100% - 18px), 0 0); }
.stat-cell { background: var(--panel); padding: 20px 22px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px;
  border: none; cursor: pointer; font-family: var(--font-body); font-weight: 600; font-size: 14px; white-space: nowrap;
  clip-path: polygon(0 0, calc(100% - 11px) 0, 100% 11px, 100% 100%, 11px 100%, 0 calc(100% - 11px), 0 0);
  transition: transform .2s var(--ease), opacity .2s, background .25s; }
.btn:hover { transform: translateY(-1px); }
.btn--primary { background: var(--red); color: #fff; }
.btn--ghost { background: var(--glass-2); border: 1px solid var(--line); color: var(--text); }
.btn--danger { background: rgba(239,68,68,.16); color: #ef4444; border: 1px solid rgba(239,68,68,.3); }
.btn--norppa { background: #003EFF; color: #fff; }
.btn--norppa img { height: 16px; display: block; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------- divider ---------- */
.ms-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.ms-divider::before, .ms-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- pills / badges ---------- */
.pill { display: inline-flex; align-items: center; font-size: 11px; font-weight: 700; letter-spacing: .03em;
  padding: 4px 9px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; text-transform: uppercase; }
.pill--green { color: var(--green); border-color: rgba(34,197,94,.3); background: rgba(34,197,94,.1); }
.pill--red { color: #ef4444; border-color: rgba(239,68,68,.3); background: rgba(239,68,68,.1); }
.pill--amber { color: var(--amber); border-color: rgba(245,158,11,.3); background: rgba(245,158,11,.1); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); }
.field input, .field select { background: var(--glass-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 13px; font-family: var(--font-body); font-size: 14px; outline: none; }
.field input:focus, .field select:focus { border-color: var(--red); }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

/* ---------- table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); }
th { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
tbody tr:hover { background: var(--glass); }
.table-wrap { overflow-x: auto; }

/* ---------- heatmap (github-style calendar) ---------- */
.heatmap { display: flex; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap__col { display: flex; flex-direction: column; gap: 3px; }
.heatmap__cell { width: 11px; height: 11px; background: var(--glass-2); }
.heatmap__cell[data-level="1"] { background: rgba(255,31,46,.25); }
.heatmap__cell[data-level="2"] { background: rgba(255,31,46,.5); }
.heatmap__cell[data-level="3"] { background: rgba(255,31,46,.75); }
.heatmap__cell[data-level="4"] { background: var(--red); }

/* ---------- loader ---------- */
.ms-loader { position: fixed; inset: 0; z-index: 200; background: var(--bg); display: flex; align-items: center;
  justify-content: center; transition: opacity .5s var(--ease); }
.ms-loader.is-done { opacity: 0; pointer-events: none; }
.ms-loader__mark { font-family: var(--font-display); font-weight: 800; color: var(--red); font-size: 20px; letter-spacing: .04em; text-transform: uppercase; }

/* ---------- empty state ---------- */
.empty { color: var(--faint); font-size: 14px; padding: 30px 0; text-align: center; }

/* ---------- tooltip ---------- */
/* Popup itself is a JS-driven portal appended to <body> (see app.js) —
   a plain CSS ::after popup would get clipped by any ancestor .card,
   since clip-path clips overflowing descendants same as overflow:hidden. */
.ms-tip { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border-radius: 50%;
  background: var(--glass-2); border: 1px solid var(--line); color: var(--faint); font-size: 10px; font-weight: 700;
  margin-left: 5px; cursor: help; position: relative; vertical-align: middle; }
.ms-tip:hover { color: var(--red); border-color: var(--red); }
.ms-tip-portal { position: fixed; display: none; background: var(--panel); border: 1px solid var(--line-strong);
  color: var(--text); font-size: 12px; font-weight: 400; padding: 9px 11px; max-width: 240px; text-align: left;
  z-index: 1000; box-shadow: 0 8px 30px rgba(0,0,0,.6); line-height: 1.45; text-transform: none; letter-spacing: normal; }

/* ---------- word cloud ---------- */
.ms-wordcloud { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 16px; padding: 30px 10px; min-height: 260px; }
.ms-wordcloud span { font-family: var(--font-display); font-weight: 800; color: var(--red); opacity: .55; line-height: 1; transition: transform .2s, opacity .2s; cursor: default; }
.ms-wordcloud span:hover { opacity: 1; transform: scale(1.08); }
.ms-wordcloud span:nth-child(3n+1) { color: var(--text); opacity: .8; }
.ms-wordcloud span:nth-child(5n+2) { color: var(--amber); opacity: .7; }

/* ---------- gifts ---------- */
.gift-card { cursor: pointer; transition: transform .2s var(--ease); }
.gift-card:hover { transform: translateY(-3px); }
.gift-card__icon { width: 100%; height: 120px; object-fit: cover; background: var(--glass-2); margin-bottom: 14px; }
.gift-card__icon--fallback { display: flex; align-items: center; justify-content: center; font-size: 40px; }

.gift-modal .modal__box { background: #1A1C1E; max-width: 460px; }
.gift-modal__header { background: #003EFF; margin: -26px -26px 20px; padding: 22px 26px; display: flex; align-items: center; gap: 14px;
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 0 100%); }
.gift-modal__header img { width: 44px; height: 44px; object-fit: cover; flex-shrink: 0; }
.gift-secret { position: relative; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); padding: 16px; margin: 14px 0;
  font-family: "Courier New", monospace; font-size: 15px; word-break: break-all; color: #fff; }
.gift-secret.blurred { filter: blur(7px); user-select: none; }
.gift-secret__reveal { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.35); cursor: pointer; font-size: 13px; font-weight: 600; color: #fff; }
.gift-secure-badge { display: inline-flex; align-items: center; gap: 6px; color: var(--green); font-size: 12px; font-weight: 600; margin-top: 4px; }
.gift-modal__footer { margin-top: 20px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--faint); }
.gift-modal__footer img { height: 14px; }
.gift-modal__footer a { display: inline-flex; align-items: center; gap: 6px; color: var(--faint); }
.gift-modal__footer a:hover { color: var(--text); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6); opacity: 0; transition: opacity .28s var(--ease); padding: 20px; }
.modal.open { opacity: 1; }
.modal[hidden] { display: none; }
.modal__box { width: 100%; max-width: 440px; background: var(--panel); box-shadow: inset 0 0 0 1px var(--line-strong);
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 18px 100%, 0 calc(100% - 18px), 0 0);
  padding: 26px; transform: translateY(14px) scale(.97); transition: transform .28s var(--ease); }
.modal.open .modal__box { transform: none; }
.modal__title { font-size: 18px; margin-bottom: 16px; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
