:root {
  --bg: #f5f4fa;
  --card: #ffffff;
  --text: #1d1d1f;
  --text-2: #8e8e93;
  --purple: #7c3aed;
  --purple-deep: #6d28d9;
  --purple-light: #a78bfa;
  --purple-soft: rgba(124, 58, 237, 0.08);
  --danger: #ff375f;
  --radius: 22px;
  --shadow: 0 10px 30px rgba(76, 29, 149, 0.1);
  --blur: saturate(180%) blur(20px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: var(--bg);
  background-image: var(--bg-image, none);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  font-size: 16px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.5) 0%,
    rgba(255, 255, 255, 0.24) 34%,
    rgba(255, 255, 255, 0.3) 100%
  );
}

body.capturing::before { display: none !important; }

::selection { background: rgba(124, 58, 237, 0.22); }

button { touch-action: manipulation; font-family: inherit; }
button:focus-visible, a:focus-visible { outline: 2px solid rgba(124, 58, 237, 0.55); outline-offset: 2px; }

.hidden { display: none !important; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
  padding: 0 26px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-bottom: 1px solid rgba(76, 29, 149, 0.08);
}

.topbar-title {
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 4px;
}

.topbar-title::before {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
}

.topbar-nav { display: flex; gap: 4px; margin-left: 18px; }

.topbar-actions { display: flex; gap: 6px; margin-left: auto; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: 0.2s;
}

.icon-btn:hover { background: var(--purple-soft); color: var(--purple); }

.nav-btn {
  border: none;
  background: transparent;
  font: inherit;
  font-size: 15px;
  color: var(--text-2);
  padding: 8px 15px;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.25s;
}

.nav-btn:hover { color: var(--text); background: rgba(0, 0, 0, 0.05); }

.nav-btn.active {
  color: var(--purple);
  background: var(--purple-soft);
  font-weight: 600;
}

/* ---------- layout ---------- */
main {
  max-width: 1060px;
  margin: 0 auto;
  padding: 34px 26px 90px;
}

.page { display: none; }
.page.active { display: block; animation: page-in 0.45s ease; }

@keyframes page-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.page-title { font-size: 26px; font-weight: 700; margin-bottom: 22px; }

/* ---------- home ---------- */
.hero { text-align: center; padding: 54px 0 30px; }

.hero-title {
  font-size: 56px;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(120deg, var(--purple-deep), var(--purple-light));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.entry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  max-width: 840px;
  margin: 0 auto 42px;
}

.entry-card {
  border: none;
  cursor: pointer;
  background: var(--card);
  border-radius: 24px;
  padding: 34px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.3s;
}

.entry-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 40px rgba(76, 29, 149, 0.16);
}

.entry-card.drop { animation: drop-in 0.7s cubic-bezier(0.22, 0.9, 0.3, 1) both; }
.entry-card:nth-child(1).drop { animation-delay: 0.1s; }
.entry-card:nth-child(2).drop { animation-delay: 0.24s; }
.entry-card:nth-child(3).drop { animation-delay: 0.38s; }
.entry-card:nth-child(4).drop { animation-delay: 0.52s; }
.entry-card:nth-child(5).drop { animation-delay: 0.66s; }
.entry-card:nth-child(6).drop { animation-delay: 0.8s; }

@keyframes drop-in {
  from { opacity: 0; transform: translateY(-46px); }
  to { opacity: 1; transform: none; }
}

.entry-icon {
  width: 54px;
  height: 54px;
  border-radius: 17px;
  background: var(--purple-soft);
  color: var(--purple);
  display: grid;
  place-items: center;
}

.entry-name { font-size: 18px; font-weight: 600; }

/* ---------- snake ---------- */
.snake-wrap {
  max-width: 840px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.snake-head { display: flex; width: 100%; align-items: baseline; justify-content: space-between; }
.snake-head h2 { font-size: 20px; font-weight: 700; }
#snake-score { font-size: 15px; color: var(--purple); font-weight: 600; font-variant-numeric: tabular-nums; }

#snake-canvas {
  width: 100%;
  max-width: 400px;
  height: auto;
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(124, 58, 237, 0.14);
  touch-action: manipulation;
}

.dpad { display: grid; gap: 6px; justify-items: center; }
.dpad-row { display: flex; gap: 6px; }

.dpad-btn {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: none;
  background: rgba(124, 58, 237, 0.1);
  color: var(--purple);
  font-size: 17px;
  cursor: pointer;
  transition: 0.2s;
}

.dpad-btn:active { transform: scale(0.92); background: rgba(124, 58, 237, 0.22); }

.snake-flex {
  display: flex;
  gap: 18px;
  width: 100%;
  align-items: stretch;
  justify-content: center;
  flex-wrap: wrap;
}

.snake-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 280px;
  max-width: 400px;
}

.lb {
  width: 240px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(124, 58, 237, 0.14);
  padding: 14px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.lb-title { font-weight: 700; font-size: 15px; margin-bottom: 8px; color: var(--purple); }

.lb-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: 320px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 14px;
}

.lb-row.mine { background: var(--purple-soft); }

.lb-rank { width: 20px; color: var(--text-2); font-variant-numeric: tabular-nums; font-weight: 600; }
.lb-row:nth-child(1) .lb-rank,
.lb-row:nth-child(2) .lb-rank,
.lb-row:nth-child(3) .lb-rank { color: var(--purple); }

.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; color: var(--purple); font-variant-numeric: tabular-nums; }
.lb-empty { color: var(--text-2); font-size: 13px; padding: 8px 4px; }

/* ---------- tools ---------- */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 18px; }

.tool-card {
  background: var(--card);
  border-radius: 24px;
  padding: 32px 26px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 18px;
  transition: transform 0.3s, box-shadow 0.3s;
}

.tool-card:hover { transform: translateY(-4px); box-shadow: 0 16px 40px rgba(76, 29, 149, 0.16); }

.tool-card.drop { animation: drop-in 0.6s cubic-bezier(0.22, 0.9, 0.3, 1) both; }
.tool-card:nth-child(1).drop { animation-delay: 0.05s; }
.tool-card:nth-child(2).drop { animation-delay: 0.18s; }

.tool-icon {
  width: 54px;
  height: 54px;
  flex-shrink: 0;
  border-radius: 17px;
  background: var(--purple-soft);
  color: var(--purple);
  display: grid;
  place-items: center;
}

.tool-name { font-size: 19px; font-weight: 600; }

/* ---------- logs ---------- */
.logs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }

.log-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  box-shadow: var(--shadow);
  animation: pop-in 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.log-card.new { animation: pop-in 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.log-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; padding-right: 30px; word-break: break-word; }
.log-content { font-size: 15px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.log-date { font-size: 12px; color: var(--text-2); margin-top: 14px; font-variant-numeric: tabular-nums; }

.log-x {
  position: absolute;
  top: 13px;
  right: 13px;
  width: 29px;
  height: 29px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-2);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: 0.2s;
}

.log-x:hover { background: rgba(255, 55, 95, 0.12); color: var(--danger); }

.add-fab {
  position: fixed;
  right: 30px;
  bottom: 30px;
  z-index: 40;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid rgba(124, 58, 237, 0.28);
  background: rgba(124, 58, 237, 0.14);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--purple);
  font-size: 27px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.2);
  transition: 0.25s;
}

.add-fab:hover { background: rgba(124, 58, 237, 0.26); transform: scale(1.07); }

.empty { text-align: center; color: var(--text-2); padding: 70px 0; font-size: 15px; grid-column: 1 / -1; }

/* ---------- chat ---------- */
.chat-wrap {
  max-width: 760px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-list {
  height: 52vh;
  max-height: 560px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px;
}

.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: rgba(124, 58, 237, 0.25); border-radius: 3px; }

.msg {
  align-self: flex-start;
  max-width: 78%;
  background: #f2f0f8;
  border-radius: 16px;
  padding: 10px 14px;
  animation: pop-in 0.3s ease;
}

.msg.own {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--purple), #8b5cf6);
}

.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.msg-head b { font-size: 13px; color: var(--purple); }
.msg-head span { font-size: 11px; color: var(--text-2); opacity: 0.85; font-variant-numeric: tabular-nums; }
.msg.own .msg-head b { color: #fff; }
.msg.own .msg-head span { color: rgba(255, 255, 255, 0.75); }
.msg-text { font-size: 15px; word-break: break-word; white-space: pre-wrap; }
.msg.own .msg-text { color: #fff; }

.chat-bar { display: flex; gap: 10px; }

.chat-bar input {
  flex: 1;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid rgba(124, 58, 237, 0.22);
  font: inherit;
  font-size: 16px;
  outline: none;
  background: #faf9fd;
  color: var(--text);
  transition: 0.2s;
}

.chat-bar input:focus {
  border-color: var(--purple);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.12);
}

/* ---------- shares ---------- */
.share-info {
  max-width: 760px;
  margin: 0 auto 18px;
  background: linear-gradient(120deg, rgba(124, 58, 237, 0.1), rgba(167, 139, 250, 0.16));
  border: 1px solid rgba(124, 58, 237, 0.2);
  border-radius: 18px;
  padding: 16px 20px;
}

.share-info-title { font-weight: 700; font-size: 15px; color: var(--purple); margin-bottom: 6px; }
.share-info p { font-size: 13px; color: var(--text-2); line-height: 1.7; }

.shares-grid {
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.share-card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: pop-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.share-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.share-title { font-size: 15px; font-weight: 700; word-break: break-word; padding-right: 4px; }
.share-head .log-x { position: static; flex-shrink: 0; }

.share-meta { display: flex; flex-direction: column; gap: 3px; }
.share-file { font-size: 12px; color: var(--text-2); word-break: break-all; }
.share-owner { font-size: 12px; color: var(--purple); font-weight: 600; }

.share-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }

.share-status { font-size: 12px; color: var(--text-2); }
.share-status.ok { color: #2f9e63; font-weight: 600; }

.mon-btn.dl { padding: 7px 18px; }
.mon-btn.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-2);
}

.file-pick {
  display: block;
  text-align: center;
  padding: 11px 0;
  border-radius: 14px;
  border: 1px dashed rgba(124, 58, 237, 0.4);
  color: var(--purple);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
  margin-bottom: 8px;
}

.file-pick:hover { background: var(--purple-soft); }
.file-pick input { display: none; }

.share-file-name {
  font-size: 12px;
  color: var(--text-2);
  word-break: break-all;
  min-height: 16px;
  margin-bottom: 4px;
}

/* ---------- schedule ---------- */
.sched-head { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-bottom: 20px; }
.sched-head .page-title { margin-bottom: 0; }

.sched-switch { display: flex; background: rgba(124, 58, 237, 0.08); border-radius: 999px; padding: 4px; }

.sched-switch-btn {
  border: none;
  background: transparent;
  font: inherit;
  font-size: 14px;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-2);
  transition: 0.2s;
}

.sched-switch-btn.active { background: #fff; color: var(--purple); font-weight: 600; box-shadow: 0 2px 8px rgba(76, 29, 149, 0.14); }

.sched-nav { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.sched-nav .nav-arrow {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: none;
  background: #fff;
  box-shadow: 0 2px 10px rgba(76, 29, 149, 0.1);
  cursor: pointer;
  font-size: 18px;
  color: var(--text);
  display: grid;
  place-items: center;
  transition: 0.2s;
}

.sched-nav .nav-arrow:hover { background: var(--purple-soft); color: var(--purple); }

#sched-today {
  height: 38px;
  padding: 0 16px;
  border-radius: 12px;
  border: none;
  background: #fff;
  box-shadow: 0 2px 10px rgba(76, 29, 149, 0.1);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--purple);
  transition: 0.2s;
}

#sched-today:hover { background: var(--purple-soft); }

#sched-label { font-size: 15px; font-weight: 600; min-width: 130px; text-align: center; font-variant-numeric: tabular-nums; }

/* month */
.week-row {
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: 0.25s;
}

.week-row:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(76, 29, 149, 0.15); }

.week-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.week-title { font-weight: 700; font-size: 15px; }
.week-range { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.week-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }

.mday {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0 6px;
  border-radius: 12px;
  cursor: pointer;
  transition: 0.2s;
}

.mday:hover { background: var(--purple-soft); }

.mday-num { font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.mday.dim .mday-num { color: #c9c6d6; }

.mday.today .mday-num {
  color: #fff;
  background: var(--purple);
  border-radius: 999px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
}

.mday-badge { font-size: 11px; color: var(--purple); font-weight: 600; height: 13px; line-height: 13px; font-variant-numeric: tabular-nums; }

/* week */
.week-grid { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }

.wday {
  flex: 1;
  min-width: 82px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 20px 8px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: 0.25s;
}

.wday:hover { transform: translateY(-3px); box-shadow: 0 12px 32px rgba(76, 29, 149, 0.15); }

.wday-name { font-size: 13px; color: var(--text-2); font-weight: 600; }
.wday-num { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.wday.today .wday-num { color: var(--purple); }

.wday-badge {
  font-size: 12px;
  color: var(--purple);
  background: var(--purple-soft);
  border-radius: 999px;
  padding: 2px 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.wday-badge:empty { display: none; }

/* day */
.day-wrap { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.day-scroll { max-height: 70vh; overflow-y: auto; }
.day-inner { position: relative; height: 1440px; cursor: crosshair; }

.day-scroll::-webkit-scrollbar { width: 6px; }
.day-scroll::-webkit-scrollbar-thumb { background: rgba(124, 58, 237, 0.25); border-radius: 3px; }
.day-scroll::-webkit-scrollbar-track { background: transparent; }

.day-hour {
  position: absolute;
  left: 0;
  width: 64px;
  text-align: right;
  padding-right: 8px;
  transform: translateY(-50%);
  color: var(--text-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.day-line { position: absolute; left: 72px; right: 0; height: 1px; background: rgba(124, 58, 237, 0.1); }
.day-tick { position: absolute; left: 72px; width: 12px; height: 1px; background: rgba(124, 58, 237, 0.25); }

.day-now {
  position: absolute;
  left: 72px;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--purple), transparent);
  z-index: 2;
  pointer-events: none;
}

.day-now::before {
  content: "";
  position: absolute;
  left: 0;
  top: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--purple);
}

.day-note {
  position: absolute;
  left: 88px;
  right: 14px;
  background: linear-gradient(120deg, rgba(124, 58, 237, 0.13), rgba(167, 139, 250, 0.2));
  border: 1px solid rgba(124, 58, 237, 0.22);
  border-radius: 14px;
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: baseline;
  transition: 0.2s;
}

.day-note:hover { background: linear-gradient(120deg, rgba(124, 58, 237, 0.2), rgba(167, 139, 250, 0.28)); }

.day-note-time { font-size: 12px; color: var(--purple); font-weight: 700; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.day-note-text { font-size: 14px; color: var(--text); word-break: break-word; }

/* ---------- gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  background: linear-gradient(155deg, #6d28d9 0%, #7c3aed 40%, #a78bfa 75%, #8b5cf6 100%);
  background-size: 300% 300%;
  animation: grad-shift 14s ease infinite;
}

.gate.show { display: flex; }

.gate-bg { position: absolute; inset: 0; overflow: hidden; }

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(64px);
  opacity: 0.5;
  animation: float 16s ease-in-out infinite;
}

.b1 { width: 340px; height: 340px; background: #c4b5fd; top: -90px; left: -70px; }
.b2 { width: 280px; height: 280px; background: #f0abfc; bottom: -70px; right: -50px; animation-delay: -5s; }
.b3 { width: 210px; height: 210px; background: #ffffff; opacity: 0.32; top: 38%; left: 56%; animation-delay: -10s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(46px, 34px) scale(1.12); }
  66% { transform: translate(-34px, -22px) scale(0.94); }
}

@keyframes grad-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .gate, .blob { animation: none; }
}

.gate-card {
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: 28px;
  padding: 42px 38px;
  width: min(400px, 100%);
  text-align: center;
  box-shadow: 0 24px 80px rgba(46, 10, 90, 0.35);
  animation: gate-in 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes gate-in {
  from { opacity: 0; transform: translateY(26px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.gate-logo {
  width: 58px;
  height: 58px;
  border-radius: 19px;
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  color: #fff;
}

.gate-t { font-size: 30px; font-weight: 800; line-height: 1; }

.gate-card h1 { font-size: 28px; font-weight: 700; margin-bottom: 18px; }
.gate-sub { font-size: 14px; color: var(--text-2); margin-bottom: 24px; }

.gate-tabs {
  display: flex;
  background: rgba(124, 58, 237, 0.1);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 16px;
}

.gate-tab {
  flex: 1;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 14px;
  padding: 8px 0;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-2);
  transition: 0.2s;
}

.gate-tab.active {
  background: #fff;
  color: var(--purple);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(76, 29, 149, 0.12);
}

.gate-pane { display: flex; flex-direction: column; gap: 10px; }

.gate-pane input {
  width: 100%;
  padding: 13px 16px;
  border-radius: 14px;
  border: 1px solid rgba(124, 58, 237, 0.25);
  background: #fff;
  font: inherit;
  font-size: 16px;
  outline: none;
  transition: 0.2s;
}

.gate-pane input:focus { border-color: var(--purple); box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.13); }

.gate-pane .btn { flex: none; width: 100%; }

.link-btn {
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--purple);
  cursor: pointer;
  text-align: center;
  padding: 4px;
}

.link-btn:hover { text-decoration: underline; }

.gate-actions { display: flex; gap: 10px; margin-top: 14px; }

.btn {
  flex: 1;
  padding: 13px 0;
  border-radius: 14px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: 0.2s;
}

.btn:disabled { opacity: 0.6; cursor: default; }

.btn-ghost { background: rgba(124, 58, 237, 0.08); color: var(--purple); }
.btn-ghost:hover { background: rgba(124, 58, 237, 0.15); }

.btn-primary {
  background: linear-gradient(135deg, var(--purple), #8b5cf6);
  color: #fff;
  box-shadow: 0 8px 20px rgba(124, 58, 237, 0.32);
}

.btn-primary:hover { filter: brightness(1.06); }

.gate-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(28, 10, 60, 0.36);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade-in 0.25s;
}

@keyframes fade-in { from { opacity: 0; } }

.modal {
  background: #fff;
  border-radius: 24px;
  padding: 26px;
  width: min(430px, 100%);
  box-shadow: 0 24px 80px rgba(46, 10, 90, 0.3);
  animation: pop-in 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal h3 { font-size: 19px; font-weight: 700; margin-bottom: 14px; }
.modal-text { color: var(--text-2); font-size: 15px; margin-bottom: 8px; line-height: 1.6; }

.modal input,
.modal textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(124, 58, 237, 0.22);
  font: inherit;
  font-size: 16px;
  outline: none;
  resize: vertical;
  margin-bottom: 12px;
  background: #faf9fd;
  color: var(--text);
  transition: 0.2s;
}

.modal input:focus,
.modal textarea:focus {
  border-color: var(--purple);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.12);
}

.modal textarea { margin-bottom: 0; }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.btn-sm {
  padding: 10px 22px;
  border-radius: 12px;
  border: none;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
}

.btn-cancel { background: rgba(0, 0, 0, 0.06); color: var(--text); }
.btn-cancel:hover { background: rgba(0, 0, 0, 0.1); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-confirm { background: linear-gradient(135deg, var(--purple), #8b5cf6); color: #fff; box-shadow: 0 6px 16px rgba(124, 58, 237, 0.28); }
.btn-confirm:hover { filter: brightness(1.06); }

.note-time-label { color: var(--purple); font-weight: 600; font-size: 14px; margin-bottom: 10px; }

/* ---------- background picker ---------- */
.bg-opts { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 4px; }

.bg-opt {
  width: 108px;
  cursor: pointer;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid transparent;
  background: #fff;
  transition: 0.2s;
}

.bg-opt:hover { transform: translateY(-2px); }
.bg-opt.cur { border-color: var(--purple); }

.bg-thumb { width: 108px; height: 68px; object-fit: cover; display: block; }

.bg-swatch { width: 108px; height: 68px; background: var(--bg); }
.bg-swatch.def { background: linear-gradient(135deg, #f5f4fa 0%, #e6e2f2 100%); }

.bg-opt-label {
  font-size: 11px;
  color: var(--text-2);
  padding: 4px 6px 6px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- settings ---------- */
.acc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 15px;
}

.acc-row span { color: var(--text-2); }
.acc-row b { font-weight: 600; }

.acc-divider { margin: 14px 0 8px; font-size: 13px; color: var(--text-2); font-weight: 600; }

/* ---------- monitor ---------- */
.page-title.sub { font-size: 20px; margin-top: 30px; }

.mon-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px 18px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.mon-main { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 4px; }

.mon-user { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.mon-user b { font-size: 16px; }

.mon-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--purple);
  background: var(--purple-soft);
  border-radius: 999px;
  padding: 2px 9px;
}

.mon-badge.admin { color: #fff; background: linear-gradient(135deg, var(--purple), var(--purple-light)); }
.mon-badge.self { color: var(--text-2); background: rgba(0, 0, 0, 0.06); }

.mon-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.mon-actions { display: flex; gap: 8px; }

.mon-btn {
  border: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  background: rgba(124, 58, 237, 0.1);
  color: var(--purple);
  transition: 0.2s;
}

.mon-btn:hover { background: rgba(124, 58, 237, 0.2); }
.mon-btn.danger { background: rgba(255, 55, 95, 0.1); color: var(--danger); }
.mon-btn.danger:hover { background: rgba(255, 55, 95, 0.2); }

.mon-badge.online { color: #2f9e63; background: rgba(47, 158, 99, 0.12); }

.user-stats { display: flex; gap: 20px; }

.u-stat { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 44px; }
.u-stat b { font-size: 16px; color: var(--purple); font-variant-numeric: tabular-nums; }
.u-stat span { font-size: 11px; color: var(--text-2); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  z-index: 130;
  transform: translate(-50%, 14px);
  background: rgba(28, 25, 38, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  padding: 11px 22px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  transition: 0.3s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- AI assistant ---------- */
.ai-fab {
  position: fixed;
  left: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 70;
  display: flex;
}

.ai-ball {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
  box-shadow: 0 8px 22px rgba(124, 58, 237, 0.28);
  display: grid;
  place-items: center;
  touch-action: none;
  transition: transform 0.2s;
  opacity: 0.92;
}

.ai-ball:active { transform: scale(0.94); }

.ai-page {
  flex: 1;
  min-height: 0;
  max-width: none;
  margin: 0 auto;
  width: 100%;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.ai-immersive {
  overflow: hidden;
  overscroll-behavior: none;
}

#page-ai.active {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: 1000px;
  padding: calc(6px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 60;
  min-width: 0;
}

body.ai-immersive .topbar { display: none; }

.ai-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px 0;
  flex-shrink: 0;
}

.ai-exit {
  display: flex;
  align-items: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--purple);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 10px 6px 0;
  cursor: pointer;
}

.ai-exit:active { opacity: 0.6; }

.ai-top-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--purple);
  opacity: 0.85;
}

.ai-page .ai-list {
  flex: 1;
  min-height: 0;
  height: auto;
  max-height: none;
  padding: 14px 16px;
}

.ai-bar { flex-shrink: 0; }

.ai-list {
  flex: 1;
  min-height: 120px;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 6px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-text { overflow-wrap: anywhere; }

.ai-msg,
.ai-page,
.ai-bar { min-width: 0; }

.ai-code { max-width: 100%; }

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0;
}

.ai-list::-webkit-scrollbar { width: 6px; }
.ai-list::-webkit-scrollbar-thumb { background: rgba(124, 58, 237, 0.25); border-radius: 3px; }

.ai-msg {
  max-width: 88%;
  border-radius: 16px;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
  animation: pop-in 0.25s ease;
}

.ai-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--purple), #8b5cf6);
  color: #fff;
}

.ai-msg.assistant { align-self: flex-start; background: #f4f2fa; }

.ai-thumb {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  margin-bottom: 8px;
  object-fit: cover;
}

.ai-code {
  background: rgba(0, 0, 0, 0.82);
  color: #f2f2f2;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  overflow-x: auto;
  margin: 6px 0;
  white-space: pre-wrap;
}

.ai-msg.user .ai-code { background: rgba(0, 0, 0, 0.32); }

.ai-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(76, 29, 149, 0.08);
}

.ai-att {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 12px;
  border: none;
  background: var(--purple-soft);
  color: var(--purple);
  display: grid;
  place-items: center;
  cursor: pointer;
}

#ai-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 9px 12px;
  border-radius: 14px;
  border: 1px solid rgba(124, 58, 237, 0.22);
  background: #faf9fd;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  outline: none;
  transition: 0.2s;
}

#ai-input:focus {
  border-color: var(--purple);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.12);
}

.ai-send {
  flex-shrink: 0;
  padding: 10px 16px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--purple), #8b5cf6);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.ai-send:disabled { opacity: 0.55; cursor: default; }

.ai-pending {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 0;
}

.ai-pending img {
  height: 54px;
  border-radius: 8px;
  border: 1px solid rgba(124, 58, 237, 0.2);
}

.ai-pending-x {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-2);
  cursor: pointer;
}

.crop-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(20, 10, 40, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.crop-box {
  background: #fff;
  border-radius: 20px;
  padding: 14px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 24px 70px rgba(20, 10, 40, 0.4);
}

.crop-tip { font-size: 13px; color: var(--text-2); text-align: center; }

#crop-canvas {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  touch-action: none;
  cursor: crosshair;
  background: #f5f4fa;
}

.crop-actions { display: flex; gap: 8px; justify-content: flex-end; }

.lasso-overlay {
  position: fixed;
  inset: 0;
  z-index: 105;
  background: rgba(20, 10, 40, 0.12);
}

#lasso-canvas {
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.lasso-bar {
  position: fixed;
  left: 50%;
  top: calc(14px + env(safe-area-inset-top));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(20, 10, 40, 0.84);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.lasso-bar .btn-sm { padding: 7px 14px; }

.sc-url-row b {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  font-size: 12px;
  color: var(--purple);
}

.sc-hint { font-size: 12px; line-height: 1.6; color: var(--text-2); margin: -2px 0 4px; }

/* ---------- API settings ---------- */
.api-form {
  max-width: 760px;
  margin: 0 auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.api-group { display: flex; flex-direction: column; gap: 8px; }

.api-label { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 10px; }

.api-state {
  font-size: 12px;
  font-weight: 600;
  color: var(--danger);
  background: rgba(255, 55, 95, 0.1);
  padding: 2px 8px;
  border-radius: 999px;
}

.api-state.ok { color: #2f9e63; background: rgba(47, 158, 99, 0.12); }

.api-key-row { display: flex; gap: 8px; }
.api-key-row input { flex: 1; }

.api-form input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid rgba(124, 58, 237, 0.2);
  background: #faf9fd;
  font: inherit;
  font-size: 16px;
  outline: none;
  transition: 0.2s;
}

.api-form input:focus {
  border-color: var(--purple);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.12);
}

.api-row { display: flex; align-items: center; gap: 10px; }
.api-sub { font-size: 13px; color: var(--text-2); width: 88px; flex-shrink: 0; }

.api-actions { display: flex; justify-content: flex-end; gap: 10px; }

.api-result {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
  min-height: 18px;
}

.api-test-row { display: flex; gap: 8px; align-items: baseline; }
.api-test-row b { width: 70px; flex-shrink: 0; }
.api-test-row.ok b { color: #2f9e63; }
.api-test-row.bad b { color: var(--danger); }
.api-clear { flex-shrink: 0; }

/* ---------- AI conversations & notebook ---------- */
.ai-conv-btn {
  margin-left: auto;
  border: none;
  background: rgba(124, 58, 237, 0.1);
  color: var(--purple);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  max-width: 62%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-menu {
  position: absolute;
  left: 4px;
  bottom: 62px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-menu-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(124, 58, 237, 0.25);
  background: rgba(255, 255, 255, 0.94);
  color: var(--purple);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(76, 29, 149, 0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: pop-in 0.2s ease;
}

.ai-menu-btn:active { transform: scale(0.94); }

.conv-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 46vh;
  overflow-y: auto;
}

.conv-row { display: flex; align-items: center; gap: 6px; border-radius: 12px; }
.conv-row.cur { background: var(--purple-soft); }

.conv-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  border: none;
  background: transparent;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}

.conv-title {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-meta { font-size: 11px; color: var(--text-2); }

.conv-del {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-2);
  cursor: pointer;
  flex-shrink: 0;
}

.conv-del:hover { background: rgba(255, 55, 95, 0.12); color: var(--danger); }

.conv-empty { color: var(--text-2); font-size: 13px; padding: 10px; text-align: center; }

.nb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.nb-head .page-title { margin-bottom: 0; }

.nb-wrap { display: flex; gap: 14px; align-items: flex-start; }

.nb-side {
  width: 220px;
  flex-shrink: 0;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 10px;
}

.nb-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 60vh;
  overflow-y: auto;
}

.nb-row { display: flex; align-items: center; gap: 4px; border-radius: 12px; }
.nb-row.cur { background: var(--purple-soft); }

.nb-row-main {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: transparent;
  padding: 9px 10px;
  cursor: pointer;
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--text);
}

.nb-row-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nb-row-count { font-size: 11px; color: var(--text-2); }

.nb-row-del {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-2);
  cursor: pointer;
  flex-shrink: 0;
}

.nb-row-del:hover { background: rgba(255, 55, 95, 0.12); color: var(--danger); }

.nb-empty { color: var(--text-2); font-size: 13px; padding: 10px; text-align: center; }

.nb-main { flex: 1; min-width: 0; }

.nb-current {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--purple);
  margin-bottom: 10px;
}

.nb-convert {
  margin-left: auto;
  border: none;
  background: var(--purple-soft);
  color: var(--purple);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
}

.nb-convert:active { opacity: 0.7; }

.nb-clip {
  background: linear-gradient(120deg, rgba(124, 58, 237, 0.12), rgba(167, 139, 250, 0.2));
  border: 1px solid rgba(124, 58, 237, 0.22);
  border-radius: 18px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.nb-clip-head { font-size: 13px; font-weight: 700; color: var(--purple); margin-bottom: 8px; }
.nb-clip-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }

.nb-items { display: flex; flex-direction: column; gap: 10px; }

.nb-item {
  position: relative;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.nb-item-content { font-size: 15px; line-height: 1.7; overflow-wrap: anywhere; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    row-gap: 4px;
    padding: 8px 12px 4px;
  }
  .topbar-title { order: 1; font-size: 17px; }
  .topbar-actions { order: 2; margin-left: auto; gap: 8px; }
  .icon-btn { width: 36px; height: 36px; flex-shrink: 0; }
  .topbar-nav {
    order: 3;
    width: 100%;
    margin-left: 0;
    gap: 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .topbar-nav::-webkit-scrollbar { display: none; }
  .topbar-nav .nav-btn {
    flex-shrink: 0;
    padding: 9px 12px;
    font-size: 14px;
    white-space: nowrap;
  }
  main { padding: 18px 12px 92px; }
  .hero { padding: 34px 0 20px; }
  .hero-title { font-size: 40px; }
  .page-title { font-size: 22px; }
  .entry-grid { grid-template-columns: 1fr; gap: 12px; margin-bottom: 26px; }
  .entry-card { padding: 22px 18px; flex-direction: row; justify-content: flex-start; gap: 16px; }
  .entry-icon { width: 46px; height: 46px; border-radius: 14px; }
  .entry-name { font-size: 17px; }
  .snake-wrap { padding: 16px; }
  .snake-flex { flex-direction: column; align-items: stretch; }
  .snake-main { max-width: 100%; }
  .lb { width: 100%; }
  .tool-grid { grid-template-columns: 1fr; }
  .sched-head { gap: 10px; }
  .sched-switch { width: 100%; }
  .sched-switch-btn { flex: 1; padding: 9px 0; }
  .sched-nav { width: 100%; margin-left: 0; justify-content: space-between; gap: 6px; }
  #sched-label { min-width: 0; flex: 1; font-size: 14px; }
  .week-days { gap: 2px; }
  .mday { padding: 6px 0 4px; }
  .mday-num { font-size: 13px; }
  .week-grid { padding-bottom: 4px; }
  .wday { min-width: 74px; padding: 14px 6px 12px; }
  .day-hour { width: 56px; font-size: 11px; }
  .day-line, .day-tick { left: 62px; }
  .day-note { left: 74px; right: 8px; }
  .add-fab { right: 16px; bottom: 16px; width: 54px; height: 54px; }
  .chat-wrap { padding: 12px; border-radius: 18px; }
  .chat-list { height: 52vh; }
  .msg { max-width: 88%; }
  .chat-bar { gap: 8px; }
  .chat-bar input { padding: 10px 12px; }
  .mon-row { padding: 12px; gap: 10px; }
  .mon-main { flex-basis: 100%; min-width: 0; }
  .mon-actions { width: 100%; }
  .mon-btn { flex: 1; padding: 10px 0; }
  .user-stats { width: 100%; justify-content: space-around; gap: 6px; }
  .share-info { padding: 14px; }
  .shares-grid { grid-template-columns: 1fr; }
  .modal { padding: 20px; border-radius: 20px; }
  .modal-actions { flex-wrap: wrap; }
  .btn-sm { flex: 1; }
  .gate-card { padding: 32px 22px; border-radius: 24px; }
  .bg-opts { gap: 8px; }
  .bg-opt { width: 96px; }
  .bg-thumb, .bg-swatch { width: 96px; height: 62px; }
  .toast { bottom: 20px; max-width: calc(100vw - 32px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ai-page .ai-list { min-height: 120px; }
  .api-row { flex-wrap: wrap; }
  .api-sub { width: 100%; }
  .nb-wrap { flex-direction: column; }
  .nb-side { width: 100%; }
  .nb-list { flex-direction: row; overflow-x: auto; max-height: none; }
  .nb-row { flex-shrink: 0; }
  .ai-msg { max-width: 92%; }
  .ai-fab { left: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .ai-list { min-height: 90px; }
  .sc-url-row b { max-width: 150px; }
  .crop-actions .btn-sm { flex: 1; }
}

/* Server-side device class: keep the topbar from crowding on phones/tablets */
body.device-mobile .topbar,
body.device-tablet .topbar {
  height: auto;
  flex-wrap: wrap;
  row-gap: 4px;
  padding: 8px 12px 4px;
}
body.device-mobile .topbar-title,
body.device-tablet .topbar-title { order: 1; }
body.device-mobile .topbar-actions,
body.device-tablet .topbar-actions { order: 2; margin-left: auto; }
body.device-mobile .topbar-nav,
body.device-tablet .topbar-nav {
  order: 3;
  width: 100%;
  margin-left: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
body.device-mobile .topbar-nav::-webkit-scrollbar,
body.device-tablet .topbar-nav::-webkit-scrollbar { display: none; }
body.device-mobile .topbar-nav .nav-btn,
body.device-tablet .topbar-nav .nav-btn { flex-shrink: 0; white-space: nowrap; }
