/* ------------------------------------------------------------------
   ClassIsland 推送 · Cupertino / Apple HIG
   - 系统字体优先，字距随字号收紧，行高随字号放松
   - 分组列表（inset grouped）、胶囊按钮、分段控件、毛玻璃导航栏
   - 亮/暗色跟随系统，尊重「减弱动态效果」「降低透明度」「增强对比度」
   ------------------------------------------------------------------ */

:root {
  color-scheme: light dark;

  /* Color — iOS 系统色 */
  --bg: #f2f2f7;                 /* systemGroupedBackground */
  --card: #ffffff;               /* secondarySystemGroupedBackground */
  --card-alt: #ffffff;
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);   /* secondaryLabel */
  --label-3: rgba(60, 60, 67, 0.3);   /* tertiaryLabel */
  --separator: rgba(60, 60, 67, 0.29);
  --fill: rgba(120, 120, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.08);
  --blue: #007aff;
  --blue-tint: rgba(0, 122, 255, 0.12);
  --red: #ff3b30;
  --orange: #ff9500;
  --orange-text: #b25000;
  --green: #34c759;
  --nav-bg: rgba(249, 249, 249, 0.82);
  --nav-edge: rgba(255, 255, 255, 0.5);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px -18px rgba(0, 0, 0, 0.25);
  --shadow-raised: 0 2px 10px rgba(0, 0, 0, 0.1);

  /* Type — 系统字体栈，SF Pro 优先 */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "PingFang SC",
    "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --radius-list: 12px;
  --radius-card: 16px;
  --nav-h: 52px;
  --gutter: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-alt: #2c2c2e;
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.65);
    --fill: rgba(120, 120, 128, 0.24);
    --fill-2: rgba(120, 120, 128, 0.16);
    --blue: #0a84ff;
    --blue-tint: rgba(10, 132, 255, 0.18);
    --red: #ff453a;
    --orange: #ff9f0a;
    --orange-text: #ffb340;
    --green: #30d158;
    --nav-bg: rgba(22, 22, 24, 0.8);
    --nav-edge: rgba(255, 255, 255, 0.12);
    --shadow-card: none;
    --shadow-raised: 0 2px 10px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p, ul, ol { margin: 0; }

a { color: var(--blue); text-decoration: none; }

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--fill-2);
  border-radius: 6px;
  padding: 0.15em 0.4em;
  word-break: break-all;
}

[hidden], .hidden { display: none !important; }

/* ---------------------------------------------------------------- 通用 */

.secondary { color: var(--label-2); font-size: 15px; line-height: 1.45; }
.footnote { color: var(--label-2); font-size: 13px; line-height: 1.45; }
.error { color: var(--red); font-size: 14px; min-height: 1.2em; }
.counter { margin-left: auto; color: var(--label-2); font-size: 13px; font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.35);
  border-radius: 8px;
}

/* 导航栏：毛玻璃 */
.nav {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
  padding-top: env(safe-area-inset-top);
}

.nav-inner {
  max-width: 1080px;
  margin: 0 auto;
  height: var(--nav-h);
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.nav-leading, .nav-trailing { display: flex; align-items: center; gap: 10px; min-width: 0; }
.nav-title { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.nav-title-small { font-size: 15px; font-weight: 600; color: var(--label); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.clock { font-size: 15px; color: var(--label-2); font-variant-numeric: tabular-nums; }

/* 按钮 */
button {
  font: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  color: var(--blue);
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  height: 44px;
  padding: 0 22px;
  border-radius: 980px;
  background: var(--blue);
  color: #fff;
  font-size: 17px;
  font-weight: 590;
  letter-spacing: -0.01em;
  transition: opacity 120ms ease, transform 120ms ease;
}

.btn-primary:active { opacity: 0.7; transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.35; transform: none; cursor: default; }

.btn-tinted {
  height: 40px;
  padding: 0 18px;
  border-radius: 980px;
  background: var(--fill);
  color: var(--blue);
  font-size: 15px;
  font-weight: 590;
  transition: background 120ms ease;
}

.btn-tinted:active { background: var(--separator); }

.btn-plain {
  color: var(--blue);
  font-size: 15px;
  padding: 6px 4px;
  border-radius: 8px;
  transition: opacity 120ms ease;
}

.btn-plain:active { opacity: 0.45; }
.btn-plain.destructive { color: var(--red); }
.btn-plain:disabled { color: var(--label-3); cursor: default; }

/* 输入 */
input, textarea {
  font: inherit;
  color: var(--label);
  background: var(--fill);
  border: 0;
  border-radius: 10px;
  padding: 11px 14px;
  outline: none;
  width: 100%;
  transition: box-shadow 140ms ease;
}

input::placeholder, textarea::placeholder { color: var(--label-3); }

input:focus, textarea:focus { box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.22); }

/* 分组列表 */
.list {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--card);
  border-radius: var(--radius-list);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.list > li { position: relative; }
.list > li + li::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}

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

.group-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--label-2);
  letter-spacing: 0.02em;
  margin: 0 0 8px 4px;
}

.card {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.notice {
  background: var(--fill-2);
  border: 0.5px solid var(--separator);
  border-radius: var(--radius-list);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--label-2);
}

/* 状态点 */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--label-3);
  flex: none;
  transition: background 300ms ease;
}

.dot.live { background: var(--green); }
.dot.connecting { background: var(--orange); }
.dot.down { background: var(--red); }

.badge {
  font-size: 13px;
  font-weight: 400;
  color: var(--label-3);
  white-space: nowrap;
}

/* 分段控件 */
.segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--fill);
  border-radius: 9px;
}

.segmented button {
  font-size: 13px;
  font-weight: 500;
  color: var(--label);
  padding: 6px 13px;
  border-radius: 7px;
  white-space: nowrap;
  transition: background 160ms ease, box-shadow 160ms ease, color 160ms ease;
}

.segmented button[aria-checked="true"] {
  background: var(--card);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.02);
}

@media (prefers-color-scheme: dark) {
  .segmented button[aria-checked="true"] { background: #636366; }
}

/* ---------------------------------------------------------------- 登录 / 加入 */

.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px 20px calc(32px + env(safe-area-inset-bottom));
}

.auth-card {
  width: min(420px, 100%);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.auth-icon {
  width: 76px;
  height: 76px;
  border-radius: 18px;
  background: linear-gradient(180deg, #4aa5ff, #007aff);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 20px -6px rgba(0, 122, 255, 0.55);
  margin-bottom: 6px;
}

.auth-icon svg { width: 38px; height: 38px; color: #fff; }

.auth-card h1 {
  font-size: 28px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-form { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 10px; }
.auth-form .btn-primary { width: 100%; }

.auth-card .footnote { margin-top: 4px; }

/* ---------------------------------------------------------------- 接收端 */

.display {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: clamp(24px, 5vw, 64px) var(--gutter);
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.empty-state {
  color: var(--label-3);
  font-size: 17px;
}

.message-card {
  width: min(1180px, 100%);
  background: var(--card);
  border-radius: clamp(20px, 2.4vw, 32px);
  padding: clamp(28px, 5vw, 72px);
  box-shadow: var(--shadow-card);
  text-align: center;
  animation: rise 320ms cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.kind-tag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 15px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: clamp(14px, 2vw, 26px);
}

.kind-tag::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.kind-important .kind-tag { color: var(--orange-text); }
.kind-urgent .kind-tag { color: var(--red); }

.message-body {
  font-size: clamp(34px, 5.6vw, 82px);
  line-height: 1.08;
  font-weight: 650;
  letter-spacing: -0.025em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.message-foot {
  margin-top: clamp(16px, 2.4vw, 28px);
  display: flex;
  justify-content: center;
  gap: 14px;
  color: var(--label-2);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.history {
  padding: 0 var(--gutter) calc(20px + env(safe-area-inset-bottom));
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
}

.history .list { max-height: 30vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.history li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 11px 16px;
}

.history time {
  color: var(--label-2);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  flex: none;
}

.history span { font-size: 15px; overflow-wrap: anywhere; }
.history li.kind-important span { color: var(--label); font-weight: 590; }
.history li.kind-urgent span { color: var(--red); font-weight: 590; }

/* ---------------------------------------------------------------- 教师控制台 */

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px var(--gutter) calc(48px + env(safe-area-inset-bottom));
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

.col-side, .col-main { min-width: 0; }

.who { color: var(--label-2); font-size: 15px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.rooms button {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 11px 16px;
  color: var(--label);
  border-radius: 0;
  transition: background 120ms ease;
}

.rooms button:active { background: var(--fill-2); }
.rooms button.active { background: var(--fill-2); }
.rooms button.active .room-line span { font-weight: 590; }

.room-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.room-line span { font-size: 17px; }
.room-line code { font-size: 13px; color: var(--label-2); background: none; padding: 0; }
.room-meta { font-size: 13px; color: var(--label-2); }

.rooms li.hint { padding: 12px 16px; color: var(--label-2); font-size: 15px; }

.create-row { display: flex; gap: 8px; margin-top: 10px; }
.create-row input { flex: 1; }

/* 编辑区 */
.composer-card { overflow: hidden; }

.composer-card textarea {
  background: transparent;
  border-radius: 0;
  padding: 16px;
  min-height: 118px;
  resize: vertical;
  line-height: 1.45;
}

.composer-card textarea:focus { box-shadow: inset 0 0 0 2px var(--blue-tint); }

.composer-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 0.5px solid var(--separator);
}

.composer-hint {
  padding: 0 16px 14px;
  color: var(--label-2);
  font-size: 13px;
}

/* 房间信息行 */
.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  position: relative;
}

.info-row + .info-row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}

.info-label { color: var(--label-2); font-size: 15px; flex: none; }
.info-value { display: flex; align-items: center; gap: 6px; min-width: 0; justify-content: flex-end; flex-wrap: wrap; }
.info-value code {
  background: none;
  padding: 0;
  max-width: 46ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--label-2);
  font-size: 13px;
}

.presence { display: flex; align-items: center; gap: 8px; color: var(--label-2); font-size: 15px; }
.presence b { color: var(--label); font-weight: 590; font-variant-numeric: tabular-nums; }

/* 已发送 */
.sent-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
}

.sent-main { flex: 1; min-width: 0; }
.sent-text { font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.sent-meta { color: var(--label-2); font-size: 13px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.sent-item .retract { flex: none; }

.empty-hint { padding: 14px 16px; color: var(--label-2); font-size: 15px; }

/* ---------------------------------------------------------------- 其它 */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  max-width: min(90vw, 420px);
  padding: 10px 18px;
  border-radius: 980px;
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid var(--separator);
  box-shadow: var(--shadow-raised);
  color: var(--label);
  font-size: 15px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 50;
}

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

.page-head { padding: 6px 0 22px; }

.large-title {
  font-size: 34px;
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: -0.022em;
}

.page-sub { margin-top: 4px; color: var(--label-2); font-size: 15px; }

@media (hover: hover) {
  .rooms button:hover { background: var(--fill-2); }
  .btn-plain:hover { background: var(--fill-2); }
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; gap: 24px; }
  .who { display: none; }
  .history .list { max-height: 34vh; }
  .stage { padding: 20px 16px 0; }
}

@media (max-width: 520px) {
  .nav-inner { gap: 8px; }
  .clock, #conn-text { display: none; }

  .composer-controls { flex-direction: column; align-items: stretch; gap: 10px; }
  .composer-controls .segmented { width: 100%; }
  .composer-controls .segmented button { flex: 1; text-align: center; }
  .composer-controls .counter { order: 2; margin-left: 0; text-align: right; }
  #send-btn { order: 3; width: 100%; }

  .info-row { flex-direction: column; align-items: flex-start; gap: 4px; }
  .info-value { justify-content: flex-start; }
}

/* 无障碍偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .message-card { animation: none; }
  .dot { animation: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .nav, .toast {
    background: var(--card);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  :root {
    --separator: rgba(60, 60, 67, 0.55);
    --label-2: rgba(60, 60, 67, 0.8);
  }
  .card, .list { border: 1px solid var(--separator); }
}
