:root {
  --sky: #e8f4ff;
  --sky-deep: #bfe0ff;
  --mint: #e6f8ef;
  --sun: #fff4e0;
  --ink: #1f3350;
  --ink-soft: #5b7086;
  --water: #35a3ff;
  --eyes: #28c08a;
  --stretch: #ff9f43;
  --card: #ffffff;
  --line: #dbe8f4;
  --shadow: 0 10px 30px rgba(31, 51, 80, 0.08);
  --radius: 26px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, #fff9ec 0%, transparent 42%),
    radial-gradient(circle at 88% 6%, #e6f3ff 0%, transparent 40%),
    linear-gradient(160deg, #f6fbff 0%, #eef7f2 100%);
}

body { overflow-x: hidden; }

.stage {
  max-width: 1500px;
  margin: 0 auto;
  padding: clamp(14px, 2vw, 28px);
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 1.6vw, 22px);
  min-height: 100vh;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }

.logo {
  width: 58px; height: 58px;
  border-radius: 20px;
  background: linear-gradient(140deg, #5eb8ff, #2f8ef0);
  color: #fff;
  font-size: 30px;
  font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 8px 20px rgba(53, 163, 255, 0.35);
}

h1 {
  margin: 0;
  font-size: clamp(24px, 2.6vw, 36px);
  letter-spacing: 1px;
}

.tagline {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: clamp(13px, 1.1vw, 16px);
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.badge {
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 14px;
  color: var(--ink-soft);
  box-shadow: var(--shadow);
}
.badge.live { color: #10875a; border-color: #b7e8d2; background: #f2fdf8; }
.badge.offline { color: #a4651a; border-color: #f5ddb7; background: #fffaf0; }

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(420px, 1.9fr) minmax(250px, 0.8fr);
  gap: clamp(12px, 1.4vw, 20px);
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(16px, 1.6vw, 24px);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.panel-head h2 { margin: 0; }

.panel h2 {
  margin: 0 0 14px;
  font-size: clamp(17px, 1.4vw, 21px);
  font-weight: 700;
}
.panel h2 small {
  font-size: 0.62em;
  font-weight: 400;
  color: var(--ink-soft);
  margin-left: 4px;
}

/* 身份条：和三张卡片放在一起，明确"点卡片记在谁头上" */
.who {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 14px;
  border-radius: 999px;
  background: #eef7ff;
  border: 2px solid #cfe8ff;
  font-size: clamp(14px, 1.15vw, 17px);
  transition: border-color .15s ease, background .15s ease;
}
.who:focus-within { border-color: var(--water); background: #fff; }
.who.need { border-color: #ff9f43; background: #fff7ec; animation: nudge .35s ease 2; }
@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.who-label { color: var(--ink-soft); white-space: nowrap; }
.who-input {
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: transparent;
  border: none;
  outline: none;
  width: 7.5em;
  min-width: 4em;
  padding: 2px 0;
  text-align: left;
}
.who-input::placeholder { font-weight: 400; color: #9db4c9; }
.who-edit { font-size: 0.85em; opacity: .55; }

.cards-hint {
  margin: 0 0 12px;
  font-size: clamp(12px, 1vw, 14px);
  color: #7d93a8;
}
.cards-hint.done { color: #10875a; }

/* ---------- 倒计时 ---------- */
.timer-panel { align-items: center; text-align: center; }

.ring-wrap { position: relative; width: min(72%, 250px); aspect-ratio: 1; }

.ring { width: 100%; height: 100%; transform: rotate(-90deg); }

.ring-bg, .ring-fg {
  fill: none;
  stroke-width: 14;
  stroke-linecap: round;
}
.ring-bg { stroke: #eaf2fa; }
.ring-fg {
  stroke: var(--water);
  stroke-dasharray: 603;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.6s linear, stroke 0.4s ease;
}

.ring-label {
  position: absolute; inset: 0;
  display: grid; place-content: center;
  gap: 2px;
}
.ring-label span {
  font-size: clamp(32px, 3.4vw, 46px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.ring-label small { color: var(--ink-soft); font-size: 13px; }

.timer-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; justify-content: center; }

.hint { color: var(--ink-soft); font-size: 14px; margin: 12px 0 0; line-height: 1.6; }

/* ---------- 卡片 ---------- */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(10px, 1.2vw, 18px); flex: 1; }

.card {
  position: relative;
  border: 2px solid transparent;
  border-radius: 24px;
  background: #f7fbff;
  cursor: pointer;
  padding: clamp(14px, 1.6vw, 22px) 12px;
  display: grid;
  grid-template-areas: "emoji" "title" "sub" "count" "tap";
  justify-items: center;
  align-content: center;
  gap: 6px;
  font: inherit;
  color: var(--ink);
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
  min-height: clamp(150px, 26vh, 300px);
}
.card .emoji { grid-area: emoji; }
.card .card-title { grid-area: title; }
.card .card-sub { grid-area: sub; }
.card .card-count { grid-area: count; }
.card .card-tap { grid-area: tap; }
.card:hover { transform: translateY(-4px); box-shadow: 0 14px 26px rgba(31, 51, 80, 0.12); }
.card:active { transform: translateY(0) scale(0.985); }
.card:focus-visible { outline: 3px solid var(--water); outline-offset: 3px; }

.card .emoji { font-size: clamp(38px, 4.4vw, 62px); line-height: 1; }
.card .card-title { font-size: clamp(21px, 2vw, 30px); font-weight: 700; white-space: nowrap; }
.card .card-sub { font-size: clamp(12px, 1vw, 15px); color: var(--ink-soft); white-space: nowrap; }

.card .card-count {
  margin-top: 4px;
  padding: 3px 12px;
  border-radius: 999px;
  background: #fff;
  font-weight: 700;
  font-size: clamp(12px, 1vw, 15px);
  color: var(--ink-soft);
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(31, 51, 80, 0.08);
}
.card .card-tap {
  font-size: clamp(11px, .9vw, 13px);
  color: #93a8bd;
  white-space: nowrap;
}

.card.water { background: #eef7ff; border-color: #cfe8ff; }
.card.eyes { background: #eefaf3; border-color: #c9f0dd; }
.card.stretch { background: #fff7ec; border-color: #ffe0bd; }

.card.water .card-count { color: var(--water); }
.card.eyes .card-count { color: var(--eyes); }
.card.stretch .card-count { color: #d97b12; }

.card.pop { animation: pop 0.42s ease; }
@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.07); box-shadow: 0 0 0 8px rgba(53, 163, 255, 0.16); }
  100% { transform: scale(1); }
}

/* ---------- 小卫士说话 ---------- */
.say {
  margin-top: clamp(12px, 1.4vw, 18px);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px 16px;
  min-height: 84px;
}
.say[hidden] { display: none; }
.say-avatar { font-size: 26px; line-height: 1.2; }
.say-body { min-width: 0; }
.heard {
  margin: 0 0 6px;
  font-size: clamp(12px, 1vw, 14px);
  color: #7d93a8;
}
.heard::before { content: "🎤 我听到："; }
.say p { margin: 0; font-size: clamp(15px, 1.3vw, 19px); line-height: 1.7; white-space: pre-wrap; }
.say.thinking p::after {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--water);
  animation: blink 0.9s infinite ease-in-out;
}
@keyframes blink { 0%, 100% { opacity: 0.2; } 50% { opacity: 1; } }

/* ---------- 榜单 ---------- */
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; overflow: auto; }
.rank li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 14px;
  background: #f7fbff;
  font-size: clamp(14px, 1.1vw, 17px);
}
.rank li .medal { font-size: 17px; text-align: center; }
.rank li .nickname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank li .score { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.rank li:nth-child(1) { background: #fff8e6; }
.rank li:nth-child(2) { background: #f6f9fc; }
.rank li:nth-child(3) { background: #fdf5ee; }
.rank-foot { margin-top: auto; padding-top: 12px; display: flex; justify-content: flex-end; }

/* ---------- 底部输入 ---------- */
.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 10px;
  box-shadow: var(--shadow);
}

.composer-label {
  padding-left: 8px;
  font-size: clamp(13px, 1.05vw, 15px);
  color: var(--ink-soft);
  white-space: nowrap;
}
.composer input {
  font: inherit;
  font-size: clamp(15px, 1.2vw, 17px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 15px;
  background: #fbfdff;
  color: var(--ink);
  min-width: 0;
}
.composer input:focus { outline: 2px solid var(--sky-deep); border-color: var(--sky-deep); }

button { font: inherit; cursor: pointer; border-radius: 14px; border: 1px solid transparent; transition: filter 0.15s ease, transform 0.1s ease; }
button:active { transform: translateY(1px); }

.primary {
  background: linear-gradient(140deg, #5eb8ff, #2f8ef0);
  color: #fff;
  font-weight: 700;
  padding: 13px 22px;
  font-size: clamp(15px, 1.2vw, 17px);
  box-shadow: 0 8px 18px rgba(53, 163, 255, 0.28);
}
.primary:hover { filter: brightness(1.05); }
.primary:disabled { filter: grayscale(0.5); opacity: 0.7; cursor: not-allowed; }

.talk {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 2px solid #cfe3f5;
  color: #2f8ef0;
  font-weight: 700;
  padding: 11px 18px;
  font-size: clamp(14px, 1.1vw, 16px);
  white-space: nowrap;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.talk:hover { background: #f2f9ff; border-color: #a9cdf3; }
.talk .talk-icon { font-size: 1.15em; }
.talk:disabled { opacity: 0.5; cursor: not-allowed; }

.talk.recording {
  background: #ff4d4f;
  border-color: #ff4d4f;
  color: #fff;
  animation: pulse-rec 1s ease-in-out infinite;
}
.talk.recording .talk-text::after { content: ""; }
@keyframes pulse-rec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.45); }
  50% { box-shadow: 0 0 0 10px rgba(255, 77, 79, 0); }
}

.ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--ink-soft);
  padding: 10px 16px;
  font-size: 15px;
}
.ghost:hover { background: #f4f9ff; }
.ghost.small { padding: 7px 14px; font-size: 13px; }

.linklike {
  background: none; border: none; padding: 0 2px;
  color: #2f8ef0; text-decoration: underline; font-size: inherit;
}

.privacy { margin: 0; text-align: center; color: #8aa0b6; font-size: 13px; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr 1.6fr; }
  .rank-panel { grid-column: 1 / -1; }
  .rank { max-height: 190px; }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  .card {
    min-height: 0;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "emoji title count"
      "emoji sub   tap";
    justify-items: start;
    align-content: center;
    column-gap: 14px;
    row-gap: 4px;
    padding: 16px 18px;
    text-align: left;
  }
  .card .emoji { grid-row: 1 / span 2; font-size: 40px; align-self: center; }
  .card .card-count { margin-top: 0; justify-self: end; }
  .card .card-tap { justify-self: end; }
  .composer { grid-template-columns: 1fr 1fr; }
  .composer .composer-label { grid-column: 1 / -1; padding-left: 2px; }
  .composer .chat { grid-column: 1 / -1; }
  .ring-wrap { width: min(180px, 50%); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

/* ================= 进入密码门 ================= */
body.locked .stage { display: none; }

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 10%, #fff9ec 0%, transparent 45%),
    linear-gradient(160deg, #f2f9ff 0%, #eaf6f0 100%);
  z-index: 100;
}
.gate[hidden] { display: none; }

.gate-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 18px 48px rgba(31, 51, 80, 0.14);
  padding: 34px 30px 26px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.gate-icon { font-size: 40px; line-height: 1; }
.gate-card h2 { margin: 4px 0 0; font-size: clamp(20px, 2vw, 26px); }
.gate-sub { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.6; }

.gate-input {
  font: inherit;
  font-size: 20px;
  letter-spacing: 3px;
  text-align: center;
  padding: 14px 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fbfdff;
  color: var(--ink);
}
.gate-input:focus { outline: none; border-color: var(--water); background: #fff; }

.gate-error {
  margin: 0;
  color: #d4380d;
  font-size: 14px;
  min-height: 20px;
}
.gate-btn { padding: 14px; font-size: 17px; }
.gate-hint { margin: 4px 0 0; font-size: 12px; color: #9aabbb; }

.gate.shake .gate-card { animation: nudge 0.35s ease 2; }

/* ================= 对话记录 ================= */
.chat-log {
  margin-top: clamp(12px, 1.4vw, 18px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: clamp(120px, 22vh, 240px);
  overflow-y: auto;
  padding-right: 4px;
}
.chat-log[hidden] { display: none; }

.turn { display: flex; flex-direction: column; gap: 6px; }

.turn-row { display: flex; gap: 8px; align-items: flex-start; }
.turn-row.me { justify-content: flex-end; }

.turn-bubble {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: clamp(14px, 1.15vw, 16px);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.turn-row.me .turn-bubble { background: #e8f4ff; border: 1px solid #cfe8ff; }
.turn-row.bot .turn-bubble { background: #f8fbff; border: 1px solid var(--line); }

.turn-avatar {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 15px;
  background: #eef7ff;
}
.turn-avatar.bot { background: #eefaf3; }

.turn-tools {
  margin: 4px 0 0;
  font-size: 12px;
  color: #7d93a8;
}

/* ================= 知识库弹窗 ================= */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(22, 38, 58, 0.45);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 90;
}
.modal[hidden] { display: none; }

.modal-card {
  width: min(880px, 100%);
  max-height: min(86vh, 900px);
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(15, 30, 50, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 10px;
}
.modal-head h2 { margin: 0; font-size: clamp(17px, 1.5vw, 21px); }
.kb-count { font-size: 0.7em; color: var(--ink-soft); font-weight: 400; }
.modal-close {
  border: none; background: #f2f6fa; color: #5b7086;
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 15px; cursor: pointer;
}
.modal-close:hover { background: #e6eef7; }
.modal-sub {
  margin: 0 22px 12px;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.6;
}
.kb-tabs {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 0 22px 12px;
  border-bottom: 1px solid var(--line);
}
.kb-tab {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 13px;
  cursor: pointer;
}
.kb-tab.on { background: #e8f4ff; border-color: #a9cdf3; color: #1c6fbe; font-weight: 700; }

.kb-list { overflow-y: auto; padding: 14px 22px 18px; display: flex; flex-direction: column; gap: 10px; }
.kb-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fbfdff;
}
.kb-item h3 {
  margin: 0 0 6px;
  font-size: clamp(14px, 1.2vw, 16px);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.kb-tag {
  font-size: 11px;
  font-weight: 400;
  padding: 1px 8px;
  border-radius: 999px;
  background: #e8f4ff;
  color: #2f6fa8;
}
.kb-text { margin: 0; font-size: 13.5px; line-height: 1.7; color: #2a3d54; }
.kb-meta { margin: 6px 0 0; font-size: 11.5px; color: #8aa0b6; }
.modal-foot {
  padding: 10px 22px 16px;
  font-size: 12px;
  color: #8aa0b6;
  border-top: 1px solid var(--line);
}

/* ================= 学生切换 ================= */
.who-wrap { position: relative; display: inline-flex; align-items: center; gap: 6px; }

.who-switch {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: clamp(12px, 1vw, 14px);
  cursor: pointer;
  white-space: nowrap;
}
.who-switch:hover { background: #f4f9ff; border-color: #bfe0ff; color: #2f8ef0; }

.who-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(31, 51, 80, 0.16);
  padding: 6px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.who-menu[hidden] { display: none; }
.who-menu-title {
  padding: 6px 10px 4px;
  font-size: 11.5px;
  color: #93a8bd;
}
.who-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: none;
  background: transparent;
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: clamp(13px, 1.05vw, 15px);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.who-item:hover { background: #eef7ff; }
.who-item.on { background: #e8f4ff; font-weight: 700; }
.who-item .cur { font-size: 11px; color: #2f8ef0; }
.who-empty { padding: 10px; font-size: 12.5px; color: #93a8bd; }

/* 未填昵称时的输入区 */
.composer.locked { background: #f7fafc; }
.composer input:disabled {
  background: #f1f5f9;
  color: #a9bccd;
  cursor: not-allowed;
  border-style: dashed;
}
.composer.locked .primary { filter: grayscale(1); opacity: .55; box-shadow: none; }
.composer.locked .talk { opacity: .55; }

/* 录音音量条：固定占位（不用时透明），这样录音时不会挤压发送按钮 */
.talk-wrap { display: flex; align-items: center; gap: 8px; }
.mic-level {
  width: 56px;
  height: 26px;
  border-radius: 13px;
  background: #e3ecf6;
  box-shadow: inset 0 0 0 1px rgba(15, 52, 84, .08);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
.mic-level.on { opacity: 1; }
.mic-level > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 13px;
  background: linear-gradient(90deg, #7fd1a5, #2fa864);
  transition: width .08s linear;
}
@media (max-width: 640px) {
  .mic-level { width: 36px; }
}
