/* AI 小镇 — "世界窗口" 视觉系统
   设计原则：canvas 是绝对主角，HUD 与字幕条悬浮其上，
   面板平时收进抽屉。暖橙 accent = 黄昏路灯色。 */

* { box-sizing: border-box; }

:root {
  /* 暮色小镇调色板（见 DESIGN.md） */
  --sky-night:  #0d1330;
  --sky-dusk:   #1c2a55;
  --grass:      #2f4a2a;
  --panel:      #151a2e;
  --panel-2:    #1d2440;
  --ink:        #e8ecff;
  --ink-dim:    #8b94c2;
  --ink-faint:  #5a6391;
  --accent:     #ffb347;   /* 黄昏路灯 */
  --accent-dim: #cc8524;
  --money:      #7ee0a0;
  --speech:     #ffd97a;
  --line:       #2a3358;
  --radius:     14px;
  --font-hud:   "Space Grotesk", "Noto Sans SC", system-ui, sans-serif;
  --font-body:  "Noto Sans SC", system-ui, -apple-system, sans-serif;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--sky-night);
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
}

button { font-family: inherit; }

/* ---------- 世界舞台 ---------- */
#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--sky-night);
}

#town {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* 夜间蒙层覆盖全视口（z 低于 HUD） */
#nightveil {
  position: absolute;
  inset: 0;
  background: #0a1030;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
  transition: opacity 1.2s ease;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

.hud-time {
  display: flex;
  align-items: baseline;
  gap: 10px;
  background: rgba(13, 19, 48, 0.8);
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

#clock {
  font-family: var(--font-hud);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  letter-spacing: 0.5px;
}

.hud-day {
  font-size: 12px;
  color: var(--ink-dim);
}

.hud-controls {
  display: flex;
  gap: 6px;
}

.hud-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border-radius: 50%;
  background: rgba(13, 19, 48, 0.55);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.hud-btn:hover { background: var(--panel-2); border-color: var(--accent-dim); }
.hud-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hud-btn#speedBtn {
  padding: 0 12px;
  border-radius: 999px;
  font-family: var(--font-hud);
  font-size: 13px;
  font-weight: 500;
}

/* 角落小镇名标 */
.town-mark {
  position: absolute;
  top: 20px;
  right: 24px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-hud);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 1px;
  color: var(--ink-dim);
}

.town-mark-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

@media (prefers-reduced-motion: reduce) {
  .town-mark-dot { animation: none; }
  .drawer { transition: none; }
}

/* ---------- 气泡（跟随说话者头顶） ---------- */
.speech {
  position: absolute;
  z-index: 6;
  transform: translateX(-50%);
  background: rgba(248, 244, 230, 0.95);
  color: #1a1f3a;
  padding: 9px 16px;
  border-radius: 12px;
  font-size: 14px;
  max-width: min(70vw, 520px);
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 179, 71, 0.35);
  /* 小三角指向说话者 */
}
.speech::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid rgba(248, 244, 230, 0.95);
}

/* 底部"小镇播报"字幕条 */
.ticker {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(13, 19, 48, 0.85);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.ticker-track {
  display: flex;
  gap: 20px;
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
}

.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--ink-dim);
  animation: slide-in 0.5s ease both;
}

.ticker-item .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ticker-item.money .dot { background: var(--money); }
.ticker-item.speak .dot { background: var(--speech); }
.ticker-item.move  .dot { background: var(--ink-faint); }
.ticker-item.day   .dot { background: var(--accent); }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .ticker-item { animation: none; }
}

.ticker-expand {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 13px;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
.ticker-expand:hover { color: var(--accent); border-color: var(--accent-dim); }

/* 展开的全日志 */
.ticker-log {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 64px;
  z-index: 4;
  max-height: 0;
  overflow: hidden;
  background: rgba(13, 19, 48, 0.92);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: max-height 0.35s ease;
  list-style: none;
  margin: 0;
  padding: 0;
}
.ticker-log.open { max-height: 40vh; }
.ticker-log.open .log-body { padding: 12px 14px; }

.ticker-log .log-body {
  max-height: 40vh;
  overflow-y: auto;
}

.ticker-log li {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
  color: var(--ink-dim);
  border-bottom: 1px solid var(--line);
}
.ticker-log li:last-child { border-bottom: none; }
.ticker-log li .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.ticker-log li.money .dot { background: var(--money); }
.ticker-log li.speak .dot { background: var(--speech); }
.ticker-log li.move  .dot { background: var(--ink-faint); }
.ticker-log li.day   .dot { background: var(--accent); }
.ticker-log .log-time {
  font-family: var(--font-hud);
  font-variant-numeric: tabular-nums;
  color: var(--ink-faint);
  min-width: 44px;
}

/* ---------- 抽屉把手 ---------- */
.drawer-tab {
  position: absolute;
  right: 18px;
  bottom: 76px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(13, 19, 48, 0.85);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.drawer-tab:hover { border-color: var(--accent-dim); background: var(--panel-2); }
.drawer-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.drawer-tab-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.drawer-tab-label {
  font-size: 12px;
  color: var(--ink-dim);
  letter-spacing: 0.5px;
}

body.drawer-open .drawer-tab { opacity: 0; pointer-events: none; }

/* ---------- 抽屉 ---------- */
.drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 86vw);
  z-index: 10;
  background: var(--panel);
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.4);
}

body.drawer-open .drawer { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 0;
}

.drawer-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 16px;
}
.drawer-close:hover { color: var(--ink); border-color: var(--accent-dim); }

.drawer-tabs {
  display: flex;
  gap: 18px;
  margin-left: auto;
}

.tab {
  background: none;
  border: none;
  padding: 8px 2px 10px;
  font-size: 14px;
  color: var(--ink-dim);
  cursor: pointer;
  position: relative;
  font-weight: 500;
}
.tab::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: transparent;
  transition: background 0.2s;
}
.tab.is-active { color: var(--ink); }
.tab.is-active::after { background: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tab-pane {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 12px 16px 16px;
  overflow: auto;
}
.tab-pane.is-active { display: flex; }

.pane-hint {
  margin: 4px 0 12px;
  font-size: 12.5px;
  color: var(--ink-faint);
}

/* 居民名册 */
.roster {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.roster li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.roster li:hover { border-color: var(--line); }
.roster li:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.roster li.is-chatted { border-color: var(--accent-dim); }

.roster .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 15px;
  flex-shrink: 0;
  border: 2px solid var(--panel);
}

.roster .r-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.roster .r-type {
  font-size: 11.5px;
  color: var(--ink-faint);
  margin-top: 1px;
}

.roster .r-gold {
  margin-left: auto;
  font-family: var(--font-hud);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--money);
}

/* 聊天 */
.chat-meta {
  font-size: 13px;
  color: var(--ink-dim);
  min-height: 18px;
  margin-bottom: 8px;
}

.chat-log {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}

.msg {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  max-width: 82%;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent-dim);
  color: #1a1408;
  border-bottom-right-radius: 4px;
}
.msg.npc {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

#chatForm {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
#chatForm.hidden { display: none !important; }
#chatForm input {
  flex: 1;
  padding: 9px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-size: 13.5px;
  font-family: var(--font-body);
}
#chatForm input:focus {
  outline: none;
  border-color: var(--accent);
}
#chatForm button {
  padding: 0 16px;
  background: var(--accent);
  color: #1a1408;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
#chatForm button:hover { background: var(--accent-dim); }
#chatForm button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 今日目标 */
.goal-form {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.goal-label {
  display: block;
  font-size: 12px;
  color: var(--ink-dim);
  margin-bottom: 6px;
}
.goal-row {
  display: flex;
  gap: 8px;
}
.goal-row input {
  flex: 1;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 13px;
}
.goal-row input::placeholder { color: var(--ink-faint); }
.goal-row input:focus { outline: none; border-color: var(--accent); }
.goal-row button {
  padding: 0 14px;
  background: transparent;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
}
.goal-row button:hover { background: var(--accent-dim); color: #1a1408; }
.goal-row button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 经济 */
.economy {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.economy > div {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
.economy dt {
  font-size: 12px;
  color: var(--ink-faint);
  margin-bottom: 4px;
}
.economy dd {
  margin: 0;
  font-family: var(--font-hud);
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.economy dd.gold { color: var(--money); font-size: 24px; }
.economy .stock-line {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-dim);
  margin-top: 2px;
  font-family: var(--font-body);
}

/* 名人榜 */
.rank-title {
  margin: 18px 0 4px;
  font-size: 13px;
  color: var(--ink-dim);
}
.rank-meta {
  font-size: 12px;
  color: var(--accent);
  margin: 0 0 8px;
}
.leaderboard {
  list-style: none;
  counter-reset: lb;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.leaderboard .lb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.leaderboard .lb-item:hover { border-color: var(--accent-dim); }
.leaderboard .lb-rank {
  width: 20px;
  font-family: var(--font-hud);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.leaderboard .lb-item:nth-child(1) .lb-rank { color: var(--accent); }
.leaderboard .lb-item:nth-child(2) .lb-rank { color: var(--money); }
.leaderboard .lb-item:nth-child(3) .lb-rank { color: var(--speech); }
.leaderboard .lb-name {
  flex: 1;
  font-size: 13px;
  color: var(--ink);
}
.leaderboard .lb-score {
  font-family: var(--font-hud);
  font-size: 12px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

/* ---------- 移动端 ---------- */
@media (max-width: 720px) {
  .hud { top: 12px; left: 12px; }
  .town-mark { display: none; }
  .ticker { left: 12px; right: 12px; bottom: 12px; }
  .ticker-log { left: 12px; right: 12px; bottom: 56px; }
  .drawer-tab { right: 12px; bottom: 64px; }
}
