/* 微光小鎮：樣式。淺色與深色各一組變數，所有互動狀態（含 focus）都用變數上色。 */
:root {
  --bg: #f6f1e4; --surface: #fffdf6; --surface-2: #f1ead9; --ink: #2f2921; --ink-2: #6b6253; --line: #d9cfb9;
  --accent: #3f8f5b; --accent-ink: #ffffff; --accent-soft: #dff1e0; --warn: #b7791f; --danger: #c0443a; --danger-soft: #fbe3e0;
  --focus: #1f6fd1; --shadow: 0 2px 0 rgba(60, 48, 30, 0.12), 0 6px 18px rgba(60, 48, 30, 0.08);
  --input-bg: #ffffff; --input-ink: #2f2921; --tag-bg: #ece3cf; --tag-ink: #5b5142; --ghost: rgba(63, 143, 91, 0.16);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1b1920; --surface: #27242e; --surface-2: #322e3b; --ink: #f0eadc; --ink-2: #b6ad9d; --line: #484355;
  --accent: #6fcf8e; --accent-ink: #10231a; --accent-soft: #254233; --warn: #f0c267; --danger: #ff8a7d; --danger-soft: #4a2826;
  --focus: #8fc4ff; --shadow: 0 2px 0 rgba(0, 0, 0, 0.35), 0 8px 22px rgba(0, 0, 0, 0.35);
  --input-bg: #1b1920; --input-ink: #f0eadc; --tag-bg: #3c3747; --tag-ink: #ddd5c5; --ghost: rgba(111, 207, 142, 0.2);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; display: flex; flex-direction: column; min-height: 100dvh; -webkit-text-size-adjust: 100%; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }

/* 頁首 */
.top { display: flex; align-items: center; gap: 12px 18px; flex-wrap: wrap; padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right)); background: var(--surface); border-bottom: 2px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { image-rendering: pixelated; border-radius: 8px; }
.brand h1 { font-size: 19px; letter-spacing: 0.04em; line-height: 1.2; }
.brand p { font-size: 12px; color: var(--ink-2); }
.clock { font-weight: 700; font-variant-numeric: tabular-nums; background: var(--surface-2); border: 2px solid var(--line); border-radius: 999px; padding: 4px 14px; white-space: nowrap; }
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.speed { display: inline-flex; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.speed button { border: 0; background: transparent; padding: 6px 11px; min-width: 40px; min-height: 36px; cursor: pointer; font-weight: 700; color: var(--ink-2); }
.speed button + button { border-left: 2px solid var(--line); }
.speed button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.speed button:focus-visible { outline-offset: -3px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--tag-bg); color: var(--tag-ink); white-space: nowrap; border: 1px solid var(--line); }
.pill[data-state="ok"] { background: var(--accent-soft); color: var(--ink); border-color: var(--accent); }
.pill[data-state="warn"] { border-color: var(--warn); }

/* 按鈕 */
.btn { border: 2px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 10px; padding: 8px 14px; min-height: 40px; cursor: pointer; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--accent); }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.icon-btn { border: 0; background: transparent; color: var(--ink-2); cursor: pointer; border-radius: 8px; min-width: 30px; min-height: 30px; padding: 2px 6px; font-size: 14px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.big { font-size: 18px; min-width: 40px; min-height: 40px; }
.icon-btn.danger { color: var(--danger); background: var(--danger-soft); font-size: 12px; font-weight: 700; }
.tag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--tag-bg); color: var(--tag-ink); white-space: nowrap; }
.tag.ai { background: var(--accent-soft); color: var(--ink); }

/* 版面 */
.layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 400px; min-height: 0; }
.stage { position: relative; min-height: 0; background: var(--surface-2); border-right: 2px solid var(--line); }
#town { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; image-rendering: pixelated; }
#town:active { cursor: grabbing; }
#town:focus-visible { outline-offset: -4px; border-radius: 0; }
.stage-tools { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 6px; }
.stage-tools button { min-width: 42px; min-height: 42px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 700; cursor: pointer; box-shadow: var(--shadow); font-size: 13px; }
.stage-tools button:hover { border-color: var(--accent); }
.wake-hint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); max-width: min(520px, calc(100% - 130px)); background: var(--surface); color: var(--ink); border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 12.5px; box-shadow: var(--shadow); }
.inspector { position: absolute; left: 12px; bottom: 12px; width: min(320px, calc(100% - 24px)); background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); display: grid; gap: 8px; }
.ins-head { display: flex; align-items: center; gap: 10px; }
.ins-head > div { flex: 1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ins-act { font-weight: 600; }
.ins-think { font-size: 13px; color: var(--ink-2); }
.meters { display: grid; gap: 4px; }
.meter { display: grid; grid-template-columns: 3.4em 1fr; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-2); }
progress { width: 100%; height: 9px; appearance: none; -webkit-appearance: none; border: 0; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--accent); }
.avatar { image-rendering: pixelated; flex: none; background: var(--surface-2); border-radius: 10px; border: 2px solid var(--line); }

/* 側欄 */
.panel { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-bottom: 2px solid var(--line); }
.tabs button { border: 0; background: transparent; padding: 11px 4px; min-height: 44px; font-weight: 700; color: var(--ink-2); cursor: pointer; border-bottom: 3px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs button:focus-visible { outline-offset: -3px; }
.panel-scroll { flex: 1; overflow-y: auto; padding: 12px 14px 28px; overscroll-behavior: contain; }
.tip { font-size: 12.5px; color: var(--ink-2); margin-bottom: 10px; }
.note { font-size: 13px; color: var(--danger); min-height: 1.4em; }
.muted { color: var(--ink-2); }

/* 卡片看板 */
.board-bar { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 2px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 3px 12px; min-height: 32px; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.group { margin-bottom: 12px; border-radius: 14px; border: 2px dashed transparent; padding: 2px; }
.is-dragging .group { border-color: var(--line); }
.group.drop { border-color: var(--accent); background: var(--ghost); }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 36px; }
.group-toggle { border: 0; background: transparent; cursor: pointer; font-weight: 700; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 8px; min-height: 34px; }
.group-toggle .count { font-size: 12px; font-weight: 600; background: var(--tag-bg); color: var(--tag-ink); padding: 0 8px; border-radius: 999px; }
.group-tools { display: flex; gap: 2px; }
.group-input, input[type="text"], select { background: var(--input-bg); color: var(--input-ink); border: 2px solid var(--line); border-radius: 10px; padding: 7px 10px; min-height: 40px; width: 100%; }
.group-input { max-width: 220px; min-height: 34px; padding: 3px 10px; }
input[type="text"]:focus, select:focus, .group-input:focus { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--focus); background: var(--input-bg); color: var(--input-ink); }
input::placeholder { color: var(--ink-2); opacity: 0.8; }
.zone { display: grid; gap: 8px; min-height: 12px; }
.zone-empty { display: none; border: 2px dashed var(--line); border-radius: 12px; padding: 14px; text-align: center; font-size: 13px; color: var(--ink-2); }
.zone.is-empty .zone-empty { display: block; }
.card { background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); display: grid; gap: 8px; cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: pan-y; position: relative; }
.card:hover { border-color: var(--accent); }
.card.is-selected { border-color: #e0a92b; }
.card.dragging { opacity: 0.35; border-style: dashed; border-color: var(--accent); background: var(--ghost); box-shadow: none; }
.card.lifted { border-color: var(--focus); box-shadow: 0 0 0 3px var(--focus), var(--shadow); transform: scale(1.015); }
.card-ghost { position: fixed; z-index: 1000; pointer-events: none; margin: 0; transform: rotate(-1.5deg) scale(1.03); border-color: var(--accent); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.35); opacity: 0.96; }
.dragging-card, .dragging-card * { cursor: grabbing !important; }
.card-move { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); cursor: default; }
.card-move select { min-height: 32px; padding: 2px 8px; font-size: 13px; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.rc, .nc { display: grid; gap: 6px; }
.rc-top, .nc-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rc-who { flex: 1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.rc-who strong, .nc-top strong { font-size: 15.5px; }
.rc-emoji { font-size: 22px; line-height: 1; }
.rc-line, .nc-line { font-size: 13.5px; }
.rc-line.sub, .nc-line.go, .nc-line.when { color: var(--ink-2); font-size: 12.5px; }
.nc-line:empty { display: none; }
details summary { cursor: pointer; font-size: 12.5px; color: var(--ink-2); padding: 4px 0; min-height: 28px; }
.details-body { margin: 4px 0 0; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; font-size: 13px; max-height: 220px; overflow: auto; user-select: text; -webkit-user-select: text; }
ol.details-body { padding-left: 28px; }
.line { margin: 2px 0; }

/* 動態 */
.feed { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.feed-row { background: var(--surface); border: 2px solid var(--line); border-left-width: 6px; border-radius: 12px; padding: 8px 12px; }
.feed-row.kind-chat { border-left-color: #5a9bd8; } .feed-row.kind-news { border-left-color: #e0a92b; } .feed-row.kind-event { border-left-color: #d9607a; }
.feed-row.kind-reflect { border-left-color: #9a7fd0; } .feed-row.kind-player { border-left-color: var(--accent); }
.feed-head { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--ink-2); }
.feed-text { font-size: 14px; }
.feed-empty { color: var(--ink-2); text-align: center; padding: 20px; }

/* 表單 */
.form-card { background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 14px; display: grid; gap: 10px; margin-bottom: 14px; box-shadow: var(--shadow); }
.form-card h2 { font-size: 16px; }
.form-card label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.form-card .tip { margin: 0; }

/* 對話框 */
dialog { border: 2px solid var(--line); border-radius: 18px; padding: 0; background: var(--surface); color: var(--ink); width: min(560px, calc(100vw - 24px)); max-height: min(86dvh, 760px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(20, 16, 28, 0.55); }
.dialog-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 2px solid var(--line); }
.dialog-head h2 { font-size: 18px; flex: 1; }
.dialog-head .rc-who { flex: 1; }
.dialog-body { padding: 14px 16px 20px; overflow-y: auto; display: grid; gap: 12px; }
.dialog-body h3 { font-size: 14px; color: var(--ink-2); margin-bottom: 6px; }
.persona { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.plain, .plan { margin: 0; padding-left: 20px; display: grid; gap: 3px; font-size: 13.5px; }
.plan { list-style: none; padding-left: 0; font-variant-numeric: tabular-nums; }
.plan li { padding: 2px 8px; border-radius: 8px; }
.plan li.now { background: var(--accent-soft); font-weight: 700; }
.rels { display: grid; gap: 5px; }
.help-list { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.downloads { display: flex; gap: 8px; flex-wrap: wrap; }
.fine { font-size: 12px; color: var(--ink-2); }
.toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: min(520px, calc(100vw - 32px)); z-index: 1100; box-shadow: var(--shadow); }
.noscript { padding: 24px; text-align: center; }

/* 手機與平板：地圖在上、資訊在下 */
@media (max-width: 900px) {
  body { display: block; }
  .layout { display: block; }
  .stage { height: 46dvh; min-height: 260px; border-right: 0; border-bottom: 2px solid var(--line); position: sticky; top: 0; z-index: 5; }
  .panel-scroll { overflow: visible; padding-bottom: 60px; }
  .tabs { position: sticky; top: 46dvh; z-index: 6; }
  .top { padding-top: 8px; padding-bottom: 8px; gap: 8px 10px; }
  .brand p { display: none; }
  .controls { margin-left: 0; width: 100%; justify-content: space-between; }
  .inspector { padding: 9px; gap: 5px; bottom: 8px; left: 8px; width: min(280px, calc(100% - 70px)); }
  .inspector .meters { display: none; }
  .wake-hint { top: auto; bottom: 8px; max-width: calc(100% - 16px); width: calc(100% - 16px); }
}
@media (max-width: 420px) {
  .pill { font-size: 11px; padding: 3px 8px; }
  .speed button { padding: 6px 8px; min-width: 36px; }
}
@media (prefers-reduced-motion: reduce) { .card.lifted, .card-ghost { transform: none; } }
