:root {
  color-scheme: light;
  --ink: #30394d;
  --muted: #7d879a;
  --paper: #edf2f8;
  --card: rgba(250, 252, 255, 0.88);
  --line: rgba(76, 91, 122, 0.14);
  --accent: #7d7db8;
  --accent-dark: #62649f;
  --green: #5f9298;
  --shadow: 0 24px 70px rgba(70, 84, 116, 0.12);
  --lavender-soft: #ece9f8;
  --lavender-text: #6f6ab0;
  --aqua-soft: #ddf1ee;
  --aqua-text: #4a8f92;
  --blue-soft: #e2ecf7;
  --blue-text: #5b7a99;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(139, 137, 194, 0.17), transparent 28rem),
    radial-gradient(circle at 90% 85%, rgba(102, 165, 175, 0.14), transparent 30rem),
    var(--paper);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

button, input { font: inherit; }
button { color: inherit; }

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.95' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.09'/%3E%3C/svg%3E");
}

.shell { width: min(1100px, calc(100% - 32px)); margin: 0 auto; padding: 38px 0 64px; }
.brand { display: flex; align-items: center; gap: 13px; margin-bottom: 34px; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; color: #fffaf1; background: var(--ink); border-radius: 15px 15px 15px 5px; font: 700 23px/1 serif; }
.brand h1 { margin: 1px 0 0; font: 700 25px/1.1 "Microsoft YaHei", sans-serif; letter-spacing: .08em; }
.eyebrow { margin: 0; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .26em; }
.view { display: none; }
.view.active { display: grid; }
#homeView { grid-template-columns: 1.15fr .85fr; gap: 28px; align-items: stretch; }

.hero-card, .panel, .game-card, .history-section, .round-panel, .record {
  border: 1px solid rgba(255,255,255,.7);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.hero-card { min-height: 570px; padding: clamp(34px, 6vw, 72px); border-radius: 34px 12px 34px 34px; position: relative; overflow: hidden; }
.hero-card::after { content: "同"; position: absolute; right: -28px; bottom: -105px; color: rgba(72,80,111,.04); font: 700 330px/1 serif; transform: rotate(-8deg); }
.hero-kicker { display: inline-block; margin: 0 0 22px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 99px; color: var(--green); font-size: 13px; font-weight: 700; }
.hero-card h2 { margin: 0; font: 800 clamp(44px, 6vw, 77px)/1.08 "Microsoft YaHei", sans-serif; letter-spacing: -.055em; }
.hero-card h2 span { color: var(--accent); }
.hero-copy { position: relative; z-index: 1; max-width: 570px; margin: 30px 0 40px; color: var(--muted); font-size: 16px; line-height: 1.9; }
.steps { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 10px; }
.steps span { padding: 11px 14px; border-radius: 12px; background: rgba(100,108,145,.07); font-size: 13px; }
.steps b { margin-right: 6px; color: var(--accent); font-size: 10px; }

.home-panel { display: flex; flex-direction: column; justify-content: center; padding: 38px; border-radius: 12px 34px 34px 34px; }
.field, .word-field { display: grid; gap: 9px; }
.field span, .word-field span, .option-label { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .06em; }
input { width: 100%; border: 1px solid var(--line); outline: none; background: rgba(255,255,255,.58); transition: .2s; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(125,125,184,.14); }
.field input, .join-row input, .word-field input { height: 52px; padding: 0 16px; border-radius: 14px; }
.server-settings { margin-top: 18px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; }
.server-settings summary { cursor: pointer; color: var(--green); font-size: 12px; font-weight: 800; }
.server-settings[open] summary { margin-bottom: 14px; }
.server-settings p { margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.create-options { display: grid; gap: 20px; margin: 28px 0; }
.option-group { display: grid; gap: 9px; }
.segmented { display: flex; gap: 8px; }
.segmented button { flex: 1; padding: 11px 8px; border: 1px solid var(--line); border-radius: 12px; background: transparent; cursor: pointer; }
.segmented button.selected { color: white; border-color: var(--ink); background: var(--ink); }
.primary-button, .secondary-button { border: 0; cursor: pointer; font-weight: 800; transition: transform .18s, background .18s, opacity .18s; }
.primary-button:hover, .secondary-button:hover { transform: translateY(-1px); }
.primary-button { min-height: 53px; padding: 0 20px; color: white; border-radius: 15px; background: var(--accent); box-shadow: 0 10px 25px rgba(106,104,167,.2); }
.primary-button:hover { background: var(--accent-dark); }
.primary-button span { float: right; }
.primary-button:disabled { cursor: not-allowed; opacity: .5; transform: none; }
.secondary-button { min-height: 53px; padding: 0 24px; border-radius: 15px; color: white; background: var(--green); }
.divider { display: flex; align-items: center; gap: 10px; margin: 29px 0 17px; color: var(--muted); font-size: 11px; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.join-row { display: flex; gap: 10px; }
.join-row input { text-transform: uppercase; letter-spacing: .15em; }

/* ---------------- 房间 ---------------- */
#roomView { max-width: 720px; margin: 0 auto; gap: 16px; }
.room-topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: rgba(255,255,255,.5); cursor: pointer; }
.room-code-wrap { display: grid; justify-items: center; gap: 2px; }
.room-code-wrap > span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .15em; }
.room-code { padding: 0; border: 0; background: none; cursor: pointer; font-size: 22px; font-weight: 900; letter-spacing: .2em; }
.connection-badge { justify-self: end; color: var(--green); font-size: 11px; font-weight: 700; }
.connection-badge::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #72a3aa; box-shadow: 0 0 0 4px rgba(114,163,170,.14); }
.connection-badge.offline { color: #b8763f; }
.connection-badge.offline::before { background: #d39a63; box-shadow: 0 0 0 4px rgba(211,154,99,.16); }

.game-card { padding: clamp(22px, 4vw, 42px); border-radius: 30px 12px 30px 30px; text-align: center; }
.round-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.round-row #roundLabel { margin-left: auto; }
.timer-inline { min-width: 46px; padding: 3px 10px; color: var(--accent-dark); border-radius: 99px; background: var(--lavender-soft); font-size: 13px; font-weight: 900; letter-spacing: 0; text-align: center; }
.game-card h2 { margin: 14px 0 8px; font-size: clamp(24px, 4.6vw, 38px); letter-spacing: -.035em; }
.game-card > p { margin: 0 auto; max-width: 520px; color: var(--muted); font-size: 13px; line-height: 1.7; }

/* 玩家状态：一排小卡片，谁交了、谁掉线一眼看清 */
.players { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 8px; margin: 22px 0 0; }
.player { min-height: 92px; display: grid; place-items: center; align-content: center; gap: 5px; padding: 10px 6px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.55); transition: background .2s, border-color .2s; }
.player.self { border-color: rgba(125,125,184,.5); background: rgba(125,125,184,.09); }
.player.done { border-color: rgba(95,146,152,.45); background: rgba(221,241,238,.75); }
.player-avatar { width: 32px; height: 32px; display: grid; place-items: center; color: white; border-radius: 50%; background: var(--green); font-size: 13px; font-weight: 900; }
.player-tone-0 .player-avatar { background: #8986c2; }
.player-tone-1 .player-avatar { background: #6ea3a7; }
.player-tone-2 .player-avatar { background: #7893ad; }
.player-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 800; }
.player-status { color: var(--muted); font-size: 10px; }
.player.done .player-status { color: var(--aqua-text); font-weight: 800; }
.player-word { color: var(--accent-dark); font-size: clamp(15px, 3.6vw, 22px); font-weight: 900; word-break: break-all; line-height: 1.2; }
.empty-player { opacity: .42; border-style: dashed; }
.player.offline { opacity: .55; border-style: dashed; background: rgba(255,255,255,.25); }
.player.offline .player-avatar { background: #b9bec9; }

.thinking-controls { display: grid; grid-template-columns: 1fr 155px; gap: 10px; align-items: end; margin-top: 20px; text-align: left; }
.host-controls { display: grid; gap: 8px; margin-top: 16px; }
.host-note { color: var(--muted); font-size: 12px; }
.ready-button { color: var(--accent-dark); background: var(--lavender-soft); box-shadow: none; opacity: 1 !important; }

/* 词语横条：像附件里那样，一行两个词，中间 × / ✓ */
.record-rounds { display: grid; gap: 14px; }
.round-block { display: grid; gap: 6px; }
.round-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.bars { display: flex; align-items: stretch; }
.bar { flex: 1 1 0; min-width: 0; min-height: 46px; display: grid; place-items: center; padding: 8px 8px; border-radius: 12px; font-size: clamp(15px, 4.2vw, 20px); font-weight: 900; line-height: 1.2; word-break: break-all; text-align: center; }
.bar.tone-0 { color: var(--lavender-text); background: var(--lavender-soft); }
.bar.tone-1 { color: var(--aqua-text); background: var(--aqua-soft); }
.bar.tone-2 { color: var(--blue-text); background: var(--blue-soft); }
.bar.mine { box-shadow: inset 0 0 0 2px rgba(125,125,184,.35); }
.bar.win { box-shadow: inset 0 0 0 2px rgba(125,125,184,.45); }
.bar-sep { flex: 0 0 26px; display: grid; place-items: center; color: #a6adbc; font-size: 16px; font-weight: 700; }
.bar-sep.win { color: var(--accent); }
/* 人多的时候词条会变窄，字号跟着收，别让词折成两行 */
.bars[data-count="4"] .bar { font-size: clamp(13px, 3.6vw, 18px); }
.bars[data-count="5"] .bar { font-size: clamp(12px, 3.2vw, 16px); }
.bars[data-count="4"] .bar-sep,
.bars[data-count="5"] .bar-sep { flex-basis: 18px; font-size: 12px; }

.round-panel { padding: 18px 20px; border-radius: 20px; }
.round-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.round-panel-head > span { color: var(--accent-dark); font-size: 13px; font-weight: 900; letter-spacing: .04em; }
.text-button { padding: 2px 6px; border: 0; color: var(--muted); background: none; cursor: pointer; font-size: 12px; }

.history-section { padding: 18px 20px; border-radius: 20px; }
.history-toggle { display: block; width: 100%; margin: 0 0 12px; padding: 4px; border: 0; color: var(--accent-dark); background: transparent; cursor: pointer; font-size: 12px; font-weight: 900; letter-spacing: .06em; }
.history { display: grid; gap: 14px; }
.round-label .badge { margin-left: 6px; padding: 1px 7px; border-radius: 99px; background: rgba(125,125,184,.12); color: var(--accent-dark); font-size: 10px; font-weight: 800; }
.round-label .badge.win { background: var(--accent); color: #fff; }

/* 一局结束后的联想记录页（照附件做的） */
.record { padding: 26px clamp(18px, 5vw, 40px) 24px; border-radius: 28px; }
.record-brand { margin: 0; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .04em; }
.record h2 { margin: 10px 0 8px; text-align: center; font-size: clamp(22px, 5.4vw, 34px); letter-spacing: -.02em; color: var(--accent-dark); }
.record-sub { margin: 0 0 4px; text-align: center; color: var(--muted); font-size: 14px; }
.record-meta { margin: 0 0 22px; text-align: center; color: #9aa2b1; font-size: 12px; }
.record-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--line); }
.record-note { margin: 14px 0 0; text-align: center; color: #9aa2b1; font-size: 11px; }

.hidden { display: none !important; }
.toast { position: fixed; left: 50%; bottom: 25px; z-index: 5; padding: 11px 17px; color: white; border-radius: 99px; background: rgba(48,57,77,.92); box-shadow: 0 8px 30px rgba(50,61,86,.18); opacity: 0; transform: translate(-50%, 15px); pointer-events: none; transition: .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 780px) {
  .shell { width: min(100% - 20px, 1100px); padding: 16px 0 40px; }
  .brand { margin-bottom: 18px; }
  #homeView { grid-template-columns: 1fr; }
  .hero-card { min-height: auto; padding: 37px 27px; border-radius: 28px 10px 28px 28px; }
  .hero-card h2 { font-size: 45px; }
  .hero-copy { margin: 24px 0; font-size: 14px; }
  .home-panel { padding: 27px; border-radius: 10px 28px 28px 28px; }
}

/* 手机上：整体缩小一档，一屏里能同时看见状态、输入框和好几轮历史 */
@media (max-width: 780px) {
  body:has(#roomView.active) .brand { display: none; }
  body:has(#roomView.active) .shell { padding-top: 10px; }
  #roomView { gap: 10px; max-width: 100%; }
  .room-topbar { grid-template-columns: 40px 1fr 40px; }
  .icon-button { width: 36px; height: 36px; font-size: 15px; }
  .room-code { font-size: 18px; }
  .connection-badge { font-size: 0; }
  .connection-badge::before { margin: 0; }

  .game-card { padding: 14px 14px 16px; border-radius: 20px 8px 20px 20px; }
  .game-card h2 { margin: 8px 0 4px; font-size: 19px; }
  .game-card > p { font-size: 11px; line-height: 1.5; }
  .round-row { font-size: 10px; }
  .timer-inline { min-width: 40px; padding: 2px 8px; font-size: 11px; }

  .players { margin-top: 12px; grid-template-columns: repeat(auto-fit, minmax(62px, 1fr)); gap: 6px; }
  .player { min-height: 66px; padding: 7px 4px; border-radius: 12px; gap: 3px; }
  .player-avatar { width: 22px; height: 22px; font-size: 10px; }
  .player-name { font-size: 10px; }
  .player-status { font-size: 9px; }
  .player-word { font-size: 13px; }

  .thinking-controls { grid-template-columns: 1fr auto; gap: 8px; margin-top: 12px; }
  .thinking-controls .word-field span { display: none; }
  .thinking-controls input { height: 44px; padding: 0 12px; border-radius: 12px; font-size: 16px; }
  .thinking-controls .primary-button { min-height: 44px; padding: 0 16px; border-radius: 12px; }
  .host-controls { margin-top: 10px; }
  .host-controls .primary-button, .host-controls .secondary-button { min-height: 44px; border-radius: 12px; }
  .host-note { font-size: 11px; }

  .round-panel, .history-section { padding: 12px 14px; border-radius: 16px; }
  .round-panel-head { margin-bottom: 8px; }
  .record-rounds { gap: 9px; }
  .round-block { gap: 4px; }
  .round-label { font-size: 11px; }
  .bar { min-height: 38px; padding: 6px; border-radius: 10px; font-size: 16px; }
  .bar-sep { flex-basis: 20px; font-size: 14px; }

  .record { padding: 20px 16px; border-radius: 20px; }
  .record h2 { font-size: 22px; }
  .record-sub { font-size: 12px; }
  .record-meta { margin-bottom: 16px; font-size: 11px; }
  .record-actions { margin-top: 18px; }
  .record-actions .primary-button, .record-actions .secondary-button { min-height: 46px; }
}

@media (max-width: 430px) {
  .hero-card h2 { font-size: 38px; }
  .steps { display: grid; grid-template-columns: 1fr 1fr; }
  .home-panel { padding: 22px; }
  .bar { font-size: 15px; }
  .bar-sep { flex-basis: 18px; font-size: 13px; }
}
