/* Chrome 61 兼容：不使用 gap / :is / inset / aspect-ratio；间距用 margin 实现。 */
:root {
  --ink: #241c15;
  --ink-soft: #5b4a38;
  --paper: #f5ecdc;
  --paper-deep: #eadcc2;
  --seal: #b3241c;
  --line: rgba(36, 28, 21, 0.14);
  --content-top: 8px;
}

* { box-sizing: border-box; }

/* .btn/.link 自带 display，会盖掉浏览器默认的 [hidden] 规则——
   没有这一条，能力不可用的按钮仍然会显示出来。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: #e9dcc4;
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  background-image: radial-gradient(rgba(36,28,21,0.05) 1px, transparent 1px);
  background-size: 12px 12px;
}

/* H5 单列：手机宽度铺满，桌面预览保持 430px 的手机画布。 */
.app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  padding-top: var(--content-top);
  background: var(--paper);
  box-shadow: 0 0 0 1px rgba(36, 28, 21, 0.08), 0 12px 48px rgba(36, 28, 21, 0.12);
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  padding: 10px 16px 6px;
}

.emblem { width: 34px; height: 34px; margin-right: 10px; flex: 0 0 auto; }

.topbar-text { display: flex; flex-direction: column; min-width: 0; }

.brand { font-size: 16px; letter-spacing: 1px; }

.case-no {
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* ---------- 主体 ---------- */
.main { flex: 1 1 auto; position: relative; overflow: hidden; }

.screen {
  display: none;
  padding: 6px 16px 120px;
  animation: fade 0.28s ease both;
}

.screen.is-active { display: block; }

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

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

.block { margin-bottom: 18px; }

.block-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--ink);
}

.counter { font-size: 11px; font-weight: 400; color: var(--ink-soft); }

/* ---------- 人设 ---------- */
.personas { display: flex; flex-wrap: wrap; margin: -4px; }

.persona {
  flex: 1 1 0;
  min-width: 0;
  margin: 4px;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  text-align: left;
  font: inherit;
  color: var(--ink);
  transition: border-color 0.16s, background 0.16s;
}

.persona.is-active {
  border-color: var(--seal);
  background: rgba(179, 36, 28, 0.07);
}

.persona-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.persona-desc {
  display: block;
  margin-top: 3px;
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 标签墙 ---------- */
.group { margin-bottom: 10px; }

.group-name {
  margin: 0 0 6px;
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.5px;
}

.tags { display: flex; flex-wrap: wrap; margin: -3px; }

.tag {
  margin: 3px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  transition: border-color 0.16s, background 0.16s, color 0.16s;
}

.tag.is-active {
  border-color: var(--seal);
  background: var(--seal);
  color: #fff;
}

.tag[disabled] { opacity: 0.42; }

/* ---------- 语录 ---------- */
.quote {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  resize: none;
}

.quote:focus { outline: none; border-color: var(--seal); }

.quote-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
}

.quote-tip { font-size: 11px; color: var(--ink-soft); line-height: 1.5; }

.warn {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(179, 36, 28, 0.08);
  color: var(--seal);
  font-size: 11.5px;
  line-height: 1.5;
}

.chips { display: flex; flex-wrap: wrap; margin: 8px -3px 0; }

.chip {
  margin: 3px;
  padding: 4px 9px;
  border: 1px dashed var(--line);
  border-radius: 999px;
  background: transparent;
  font: inherit;
  font-size: 11.5px;
  color: var(--ink-soft);
}

/* ---------- 处刑模式 ---------- */
.modes { display: flex; }

.mode {
  flex: 1 1 0;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  font: inherit;
  font-size: 13px;
  color: var(--ink);
}

.mode + .mode { margin-left: 8px; }

.mode.is-active {
  border-color: var(--seal);
  background: rgba(179, 36, 28, 0.07);
  font-weight: 600;
}

/* ---------- 第二屏 ---------- */
.trial-stage {
  position: relative;
  margin: 40px 0 0;
  padding: 0 4px;
}

.fx-canvas {
  display: block;
  width: 100%;
  height: 320px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid var(--line);
}

.trial-status {
  margin: 14px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
  letter-spacing: 0.5px;
  min-height: 20px;
}

.gavel {
  margin-top: 26px;
  text-align: center;
  font-size: 46px;
  opacity: 0.16;
}

/* ---------- 第三屏 ---------- */
.poster-wrap {
  margin: 6px 0 0;
  padding: 8px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(36, 28, 21, 0.16);
}

.poster { display: block; width: 100%; border-radius: 8px; }

.source-note {
  margin: 8px 0 0;
  text-align: center;
  font-size: 11px;
  color: var(--ink-soft);
  min-height: 16px;
}

.actions { margin: 14px 0 0; }

.btn {
  display: block;
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
  transition: transform 0.12s, opacity 0.12s;
}

.btn + .btn { margin-top: 9px; }

.btn:active { transform: scale(0.985); }

.btn[disabled] { opacity: 0.45; }

.btn-primary {
  border-color: var(--seal);
  background: var(--seal);
  color: #fff;
  font-weight: 600;
  letter-spacing: 1px;
}

.btn-ghost {
  border-style: dashed;
  color: var(--ink-soft);
}

.btn-block { width: 100%; }

.links { margin: 16px 0 0; text-align: center; }

.link {
  display: inline-block;
  margin: 4px 8px;
  padding: 4px 2px;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 12px;
  color: var(--ink-soft);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
}

.link-danger { color: var(--seal); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 60;
  width: auto;
  max-width: 320px;
  margin: 0 0 0 -160px;
  padding: 9px 14px;
  border-radius: 10px;
  background: rgba(36, 28, 21, 0.9);
  color: #fff;
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
}

.toast[hidden] { display: none; }

.save-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------- 底部固定按钮 ---------- */
.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  padding: 10px 16px;
  /* env() 是增强项：Chrome 61 不认识时保留上面的基础内边距 */
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper) 72%, rgba(245, 236, 220, 0));
  z-index: 20;
}

.footer[hidden] { display: none; }

/* ---------- 抽屉 ---------- */
.drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  max-height: 76vh;
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: #fffdf8;
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -12px 30px rgba(36, 28, 21, 0.18);
  z-index: 30;
}

.drawer[hidden] { display: none; }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  font-size: 14px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(36, 28, 21, 0.06);
  font: inherit;
  font-size: 13px;
  color: var(--ink-soft);
}

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px 0;
  max-height: 48vh;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 86%;
  margin: 0 0 10px;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble-user {
  margin-left: auto;
  background: var(--seal);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble-ai {
  background: rgba(36, 28, 21, 0.06);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}

.bubble-note {
  margin: 0 auto;
  background: transparent;
  color: var(--ink-soft);
  font-size: 11.5px;
  text-align: center;
}

.drawer-foot { display: flex; align-items: center; padding-top: 6px; }

.chat-input {
  flex: 1 1 auto;
  min-width: 0;
  margin-right: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
}

.chat-input:focus { outline: none; border-color: var(--seal); }

.drawer-foot .btn { width: auto; padding: 10px 16px; font-size: 13.5px; }

@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; }
  .btn:active { transform: none; }
}
