/* ================= 画给你看 · 样式 ================= */
:root {
  --bg: #f6f3ff;
  --bg2: #eef4ff;
  --ink: #1f2233;
  --ink-soft: #5b5f78;
  --line: #e3e0f2;
  --card: #ffffff;
  --primary: #6c5ce7;
  --primary-dark: #5546c9;
  --accent: #ff7a59;
  --accent-dark: #ef5a36;
  --ok: #12b886;
  --warn: #f5a524;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(76, 63, 153, 0.12);
  --shadow-sm: 0 2px 10px rgba(76, 63, 153, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1100px 600px at 10% -10%, #ede6ff 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #e2f0ff 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { overflow: hidden; }

#app { position: relative; width: 100%; height: 100dvh; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  overflow-y: auto;
  animation: fade 0.22s ease;
}
.screen.active { display: flex; }

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

.hidden { display: none !important; }

.undercover-inner { width: min(100%, 520px); margin: 0 auto; padding: 14px 16px 32px; display: grid; gap: 12px; }
.undercover-inner .lobby-head { justify-content: space-between; }
.undercover-card { background: var(--card); color: var(--ink); border-radius: 18px; padding: 16px; box-shadow: var(--shadow-sm); }
.undercover-card h3, .undercover-card h4 { margin: 0 0 8px; }
.undercover-phase { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
#undercoverTimer { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--primary-dark); }
#undercoverWordWrap { border-radius: 10px; padding: 10px; background: #f5f0ff; }
#undercoverWord { margin-left: 8px; font-size: 20px; }
.undercover-players { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; }
.undercover-players li { background: #f6f5fb; padding: 8px; border-radius: 8px; overflow-wrap: anywhere; }
.undercover-players .speaking { outline: 2px solid var(--primary); }
.undercover-votes { display: flex; flex-wrap: wrap; gap: 8px; }
#undercoverMessages { padding-left: 22px; margin-bottom: 0; overflow-wrap: anywhere; }
#undercoverMessages li + li { margin-top: 6px; }
#undercoverDetails h4 { margin-top: 16px; }

/* ---------------- 通用组件 ---------------- */
.btn {
  border: 0;
  border-radius: 14px;
  padding: 13px 18px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  background: #eeeaff;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease, background 0.15s ease;
  font-family: inherit;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, #7b6cf6, #5b46d8); color: #fff; box-shadow: 0 8px 18px rgba(108, 92, 231, 0.32); }
.btn.accent { background: linear-gradient(135deg, #ff8f6b, #f9613a); color: #fff; box-shadow: 0 8px 18px rgba(249, 97, 58, 0.28); }
.btn.soft { background: #f0ecff; color: var(--primary-dark); box-shadow: none; }
.btn.ghost { background: transparent; color: var(--ink-soft); }
.btn.block { width: 100%; }
.btn.small { padding: 9px 14px; font-size: 14px; border-radius: 12px; }
.btn.tiny { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn:disabled:active { transform: none; }

.card {
  background: var(--card);
  border-radius: 24px;
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.field { display: flex; flex-direction: column; gap: 7px; font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.field input, .field select {
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  padding: 12px 14px;
  border-radius: 13px;
  border: 1.5px solid var(--line);
  background: #fbfaff;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus, .field select:focus { border-color: var(--primary); background: #fff; }
.field select { background-image: linear-gradient(45deg, transparent 50%, #948ccc 50%), linear-gradient(135deg, #948ccc 50%, transparent 50%); background-position: calc(100% - 18px) 21px, calc(100% - 13px) 21px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.settings-grid .span2 { grid-column: span 2; }

.micro { font-size: 12px; color: #8b8fa8; line-height: 1.5; margin: 0; }
.center { text-align: center; }
.spacer { flex: 1; }

/* ---------------- 首页 ---------------- */
.home-inner { width: 100%; max-width: 480px; margin: 0 auto; padding: 28px 18px 40px; }
.brand { text-align: center; margin: 12px 0 22px; }
.logo { width: 74px; height: 74px; margin: 0 auto 12px; filter: drop-shadow(0 10px 20px rgba(108, 92, 231, 0.35)); }
.logo svg { width: 100%; height: 100%; display: block; border-radius: 18px; }
.brand h1 { font-size: 30px; margin: 0 0 6px; letter-spacing: 2px; }
.tagline { margin: 0; color: var(--ink-soft); font-size: 14px; }

.tabs { display: flex; gap: 6px; background: #f2effc; padding: 5px; border-radius: 14px; margin: 18px 0 16px; }
.tab { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 10px; font-size: 15px; font-weight: 700; color: var(--ink-soft); cursor: pointer; font-family: inherit; }
.tab.active { background: #fff; color: var(--primary-dark); box-shadow: var(--shadow-sm); }
.tabpanel { display: none; }
.tabpanel.active { display: block; }

.howto { margin-top: 22px; padding: 0 6px; }
.howto h2 { font-size: 15px; color: var(--ink-soft); margin: 0 0 8px; letter-spacing: 1px; }
.howto ol { margin: 0 0 8px; padding-left: 20px; color: var(--ink-soft); font-size: 14px; line-height: 1.9; }

/* ---------------- 大厅 ---------------- */
.lobby-inner { width: 100%; max-width: 520px; margin: 0 auto; padding: 14px 16px 32px; display: flex; flex-direction: column; gap: 14px; }
.lobby-head { display: flex; align-items: center; gap: 8px; }
.lobby-title { font-weight: 700; font-size: 17px; }

.roomcode-card {
  background: linear-gradient(140deg, #7b6cf6, #5b46d8 60%, #4a37bd);
  color: #fff;
  border-radius: 22px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 16px 30px rgba(91, 70, 216, 0.28);
  position: relative;
  overflow: hidden;
}
.roomcode-card::after {
  content: ""; position: absolute; inset: auto -30px -60px auto; width: 180px; height: 180px;
  background: rgba(255, 255, 255, 0.12); border-radius: 50%;
}
.roomcode-label { font-size: 12px; letter-spacing: 4px; opacity: 0.82; margin-bottom: 6px; }
.roomcode { font-size: 40px; font-weight: 800; letter-spacing: 8px; margin-bottom: 14px; font-variant-numeric: tabular-nums; }
.roomcode-card .btn { background: rgba(255, 255, 255, 0.18); color: #fff; margin: 0 4px; backdrop-filter: blur(6px); }

.players { display: flex; flex-direction: column; gap: 10px; }
.player-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.avatar {
  width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center;
  font-weight: 800; font-size: 18px; color: #fff; background: linear-gradient(135deg, #a99bff, #7b6cf6); flex: none;
}
.avatar.p2 { background: linear-gradient(135deg, #ffb36b, #ff7a59); }
.player-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 8px; background: #f0ecff; color: var(--primary-dark); font-weight: 700; }
.badge.ready { background: #e6fbf2; color: #0f9d76; }
.badge.offline { background: #f4f4f8; color: #9a9db2; }
.player-sub { font-size: 12px; color: #9296ad; margin-top: 2px; }
.player-empty .avatar { background: #f1eefc; color: #b3aadf; }
.player-empty { opacity: 0.75; border: 1.5px dashed #ded8f7; background: transparent; box-shadow: none; }

.lobby-settings { background: var(--card); border-radius: 18px; padding: 16px; box-shadow: var(--shadow-sm); }
.lobby-settings h3 { margin: 0 0 12px; font-size: 14px; color: var(--ink-soft); display: flex; justify-content: space-between; align-items: baseline; }
.lobby-settings .settings-grid { margin-bottom: 0; }
.lobby-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 2px; }

/* ---------------- 对局 ---------------- */
#screen-game { overflow: hidden; padding: 0; }

.game-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
  flex: none;
}
.round-chip { display: flex; align-items: baseline; gap: 3px; font-size: 13px; color: var(--ink-soft); }
.round-chip b { font-size: 18px; color: var(--primary-dark); }

.timer { position: relative; width: 44px; height: 44px; display: grid; place-items: center; flex: none; }
.timer svg { position: absolute; inset: 0; width: 44px; height: 44px; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 4; }
.timer .track { stroke: #eae6f8; }
.timer .bar { stroke: var(--primary); stroke-linecap: round; stroke-dasharray: 119.4; stroke-dashoffset: 0; transition: stroke-dashoffset 0.25s linear, stroke 0.3s ease; }
.timer.low .bar { stroke: var(--accent); }
.timer span { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }

.scoreboard { display: flex; gap: 6px; flex: 1; justify-content: flex-end; min-width: 0; }
.score-item {
  display: flex; align-items: center; gap: 5px; background: #fff; border-radius: 12px;
  padding: 5px 8px; box-shadow: var(--shadow-sm); max-width: 50%; min-width: 0;
}
.score-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); flex: none; }
.score-item.p2 .dot { background: var(--accent); }
.score-item .nm { font-size: 11px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-item .sc { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score-item.drawer { outline: 2px solid rgba(108, 92, 231, 0.35); }

.stage { position: relative; flex: 1 1 0; min-height: 0; display: grid; place-items: center; padding: 8px; }
.board-wrap {
  position: relative; flex: none;
  border-radius: 18px; overflow: hidden; background: #fff;
  box-shadow: 0 12px 28px rgba(76, 63, 153, 0.14); border: 1px solid #ece8fa;
}
#board { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#board.eraser { cursor: cell; }
#board.readonly { cursor: default; }

/* 提示横幅（第二次提示） */
.hint-banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  max-width: calc(100% - 28px); padding: 7px 14px; border-radius: 12px;
  background: rgba(255, 238, 200, 0.97); color: #8a5b00; font-size: 13px; font-weight: 700;
  box-shadow: 0 6px 16px rgba(138, 91, 0, 0.18); z-index: 4; text-align: center; line-height: 1.45;
  animation: toastIn 0.2s ease;
}

/* 结算里的作品快照 */
.artwork {
  display: none; height: 130px; width: auto; max-width: 100%;
  border-radius: 12px; background: #fff; border: 1px solid #ece8fa; margin: 0 auto 12px;
}

/* 大厅模式行 */
.mode-row { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 12px; background: #f8f6ff; margin-bottom: 12px; }
.mode-name { font-weight: 800; color: var(--primary-dark); font-size: 14px; }

/* 覆盖层 */
.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(31, 34, 51, 0.38); backdrop-filter: blur(3px); z-index: 5;
  animation: fade 0.18s ease;
}
.panel {
  background: #fff; border-radius: 22px; padding: 22px; width: min(100%, 420px);
  box-shadow: 0 20px 50px rgba(31, 34, 51, 0.25); text-align: center;
}
.panel.slim { padding: 26px; }
.panel h2 { margin: 6px 0 10px; font-size: 20px; }
.word-options { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.word-option {
  border: 2px solid #ece8fa; background: #fbfaff; border-radius: 16px; padding: 16px;
  font-size: 22px; font-weight: 800; letter-spacing: 2px; cursor: pointer; color: var(--ink);
  font-family: inherit; transition: all 0.12s ease;
}
.word-option:active { transform: scale(0.98); }
.word-option:hover { border-color: var(--primary); background: #f4f1ff; }
.reveal-word { font-size: 34px; letter-spacing: 6px; color: var(--primary-dark); margin: 10px 0 16px; }
.deltas { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.delta-row { display: flex; justify-content: space-between; align-items: center; background: #f8f6ff; border-radius: 12px; padding: 10px 14px; font-size: 14px; }
.delta-row b { font-size: 16px; }
.delta-row .plus { color: var(--ok); }

.spinner {
  width: 34px; height: 34px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid #eae6f8; border-top-color: var(--primary); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.final-list { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 18px; }
.overlay .panel { max-height: 100%; overflow-y: auto; }
.art-grid { display: flex; justify-content: center; gap: 8px; }
.saved-art { flex: 1 1 0; min-width: 0; margin: 0; }
.saved-art canvas { display: block; width: 100%; height: auto; border: 1px solid #dce1e9; border-radius: 8px; }
.saved-art figcaption { overflow-wrap: anywhere; }
@media (prefers-reduced-motion: no-preference) {
  #roundOverlay:not(.hidden) .panel,
  #endOverlay:not(.hidden) .panel { animation: result-enter 180ms ease-out; }
  @keyframes result-enter {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }
}
.final-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; background: #f8f6ff; }
.final-row.win { background: linear-gradient(135deg, #fff4e5, #ffe9d1); }
.final-row .rank { font-weight: 800; color: var(--primary-dark); width: 22px; }
.final-row .nm { flex: 1; text-align: left; font-weight: 700; }
.final-row .sc { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 10px; }
.row-actions .btn { flex: 1; }

/* 词条栏 */
.wordbar {
  display: flex; align-items: center; gap: 10px; padding: 6px 14px; flex: none;
  background: rgba(255, 255, 255, 0.9); border-top: 1px solid var(--line); min-height: 44px;
}
.role-chip {
  font-size: 12px; font-weight: 800; padding: 4px 9px; border-radius: 9px;
  background: #f0ecff; color: var(--primary-dark); flex: none;
}
.role-chip.guesser { background: #fff0ea; color: var(--accent-dark); }
.wordbar .word { display: flex; align-items: flex-end; gap: 7px; font-size: 22px; font-weight: 800; }
.wordbar .word.plain { display: block; font-size: 22px; letter-spacing: 2px; color: var(--ink); }
.wordbar .wchar { font-size: 22px; line-height: 1.1; }
.wordbar .wblank {
  display: inline-block; width: 15px; height: 15px; border-radius: 4px; margin-bottom: 3px;
  background: #ddd6f8; border-bottom: 3px solid #b6a9ee;
}
.wordbar .micro { margin-left: auto; }

/* 工具栏 */
.toolbar {
  display: flex; flex-direction: column; gap: 8px; padding: 8px 12px; flex: none;
  background: #fff; border-top: 1px solid var(--line);
}
.tool-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tool-sep { width: 1px; height: 20px; background: var(--line); margin: 0 2px; flex: none; }
.colors { display: flex; gap: 7px; flex: none; }
.color-dot {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1.5px #e6e2f5;
  cursor: pointer; padding: 0; flex: none; transition: transform 0.1s ease;
}
.color-dot.active { box-shadow: 0 0 0 2.5px var(--primary); transform: scale(1.08); }
.sizes { display: flex; gap: 6px; flex: none; }
.size-dot {
  width: 30px; height: 30px; border-radius: 10px; border: 1.5px solid #ece8fa; background: #fbfaff;
  display: grid; place-items: center; cursor: pointer; padding: 0; flex: none;
}
.size-dot i { display: block; border-radius: 50%; background: #4a4664; }
.size-dot.active { border-color: var(--primary); background: #f4f1ff; }
.tool {
  border: 1.5px solid #ece8fa; background: #fbfaff; border-radius: 11px; padding: 7px 11px;
  font-size: 13px; font-weight: 700; color: var(--ink-soft); cursor: pointer; flex: none; font-family: inherit;
}
.tool.active { border-color: var(--accent); color: var(--accent-dark); background: #fff4f0; }

/* 底部聊天与输入 */
.bottom { display: flex; flex-direction: column; flex: 0 0 auto; min-height: 0; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
.chat {
  flex: 0 0 auto; height: 112px; min-height: 0; overflow-y: auto; padding: 8px 14px 4px; display: flex; flex-direction: column; gap: 4px;
  font-size: 13px; line-height: 1.45; scroll-behavior: smooth;
}
.chat > :first-child { margin-top: auto; }
.chat .msg { display: flex; gap: 6px; align-items: baseline; }
.chat .who { color: var(--primary-dark); font-weight: 700; flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat .txt { color: var(--ink); word-break: break-word; }
.chat .sys { color: #979bb2; font-size: 12px; }
.chat .correct .txt { color: var(--ok); font-weight: 800; }
.chat .hintline { color: var(--warn); font-weight: 700; }

.guessbar { display: flex; gap: 8px; padding: 8px 12px 10px; flex: none; }
.guessbar input {
  flex: 1; font-family: inherit; font-size: 16px; padding: 12px 14px; border-radius: 13px;
  border: 1.5px solid var(--line); background: #fbfaff; outline: none; min-width: 0;
}
.guessbar input:focus { border-color: var(--primary); background: #fff; }
.guessbar .btn { padding: 12px 18px; flex: none; }
.guessbar .btn:disabled { opacity: 0.4; }

/* 提示条 */
.toast-wrap { position: fixed; left: 50%; top: calc(70px + var(--safe-top)); transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 420px); }
.toast {
  background: rgba(31, 34, 51, 0.92); color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
  animation: toastIn 0.2s ease;
}
.toast.hot { background: linear-gradient(135deg, #ff8f6b, #f9613a); }
.toast.ok { background: linear-gradient(135deg, #22c99b, #0f9d76); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.net-banner {
  position: fixed; left: 0; right: 0; top: 0; z-index: 70; text-align: center;
  background: var(--warn); color: #fff; font-size: 13px; font-weight: 700; padding: 6px;
  padding-top: calc(6px + var(--safe-top));
}

/* ---------------- 响应式 ---------------- */
@media (max-width: 380px) {
  .roomcode { font-size: 34px; letter-spacing: 6px; }
  .wordbar .word { font-size: 18px; letter-spacing: 3px; }
  .chat { height: 66px; }
}

@media (min-width: 760px) {
  .home-inner { padding-top: 48px; }
  .brand h1 { font-size: 36px; }
  .stage { padding: 14px; }
  .chat { height: 150px; }
  .game-head { padding: 10px 20px; }
}

/* 横屏手机：把工具栏压扁，画布优先 */
@media (orientation: landscape) and (max-height: 560px) {
  .game-head { padding: 4px 10px; }
  .chat { flex: 0 0 auto; height: 52px; min-height: 0; }
  .bottom { flex: 0 0 auto; min-height: 0; }
  .toolbar { flex-direction: row; flex-wrap: wrap; gap: 6px; padding: 5px 10px; }
  .wordbar { padding: 4px 12px; min-height: 38px; }
  .guessbar { padding: 6px 10px; }
  .stage { padding: 4px; }
}
