/* 《烈火烹油 · 金瓶梅》视觉系统：朱金墨功能语法 + 账房美学 */

:root {
  --zhu: #a8322a;        /* 朱：罪业/官文/判词 */
  --zhu-deep: #7c1f19;
  --jin: #c9a227;        /* 金：银两/收益 */
  --jin-light: #e8cd6a;
  --ink: #2b2620;        /* 墨：常规文本 */
  --ink-soft: #5a4f42;
  --paper: #f4ecdc;      /* 绢本纸色 */
  --paper-deep: #e8dcc2;
  --wood: #3d2f23;
  --wood-deep: #2a2018;
  --grey-cool: #8a8f94;  /* 青灰：未解锁 */
  --shadow: rgba(20, 14, 8, 0.45);
  --font-song: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: var(--font-song);
  color: var(--ink);
  background: var(--wood-deep);
  font-size: 16px;
}

.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.hidden { display: none !important; }

/* ── 资产层（皮肤层：图未加载回退灰盒）── */
[data-asset] {
  background-color: #4a3d2f;
  background-size: cover;
  background-position: center;
  position: relative;
}
[data-asset]::after {
  content: attr(data-asset);
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.25); font-size: 11px; letter-spacing: 1px;
  opacity: 0; transition: opacity .3s;
  pointer-events: none;
}
[data-asset].asset-missing::after { opacity: 1; }
[data-asset].asset-missing { background-color: #4a3d2f; }
[data-asset].asset-loaded::after { display: none; }

/* ── 标题屏 ── */
#title-screen { align-items: center; justify-content: center; }
.title-bg { position: absolute; inset: 0; filter: brightness(0.75); }
.title-content {
  position: relative; text-align: center; color: var(--paper);
  padding: 40px 24px; max-width: 640px;
  animation: titleIn 1.2s ease-out;
}
@keyframes titleIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.game-title {
  font-size: clamp(56px, 10vw, 96px); font-weight: 700; letter-spacing: 12px;
  color: var(--jin-light);
  text-shadow: 0 2px 12px rgba(0,0,0,0.7), 0 0 40px rgba(200,162,39,0.35);
}
.game-subtitle { font-size: clamp(18px, 3vw, 26px); letter-spacing: 20px; margin: 8px 0 24px; color: var(--paper); opacity: .9; }
.title-quote { font-size: 15px; line-height: 1.9; opacity: .92; margin-bottom: 36px; text-shadow: 0 1px 6px rgba(0,0,0,0.9), 0 0 18px rgba(0,0,0,0.6); }
.title-note { margin-top: 22px; font-size: 12.5px; opacity: .75; text-shadow: 0 1px 4px rgba(0,0,0,0.9); }

.btn-seal {
  font-family: var(--font-song); font-size: 22px; letter-spacing: 8px;
  color: var(--paper); background: var(--zhu);
  border: 2px solid var(--jin); border-radius: 4px;
  padding: 14px 44px; cursor: pointer;
  box-shadow: 0 4px 18px rgba(168,50,42,0.5);
  transition: transform .15s, box-shadow .15s;
  animation: sealBreathe 2.4s ease-in-out infinite;
}
@keyframes sealBreathe { 0%,100% { box-shadow: 0 4px 18px rgba(168,50,42,0.5);} 50% { box-shadow: 0 4px 30px rgba(200,162,39,0.65);} }
.btn-seal:hover { transform: scale(1.05); background: var(--zhu-deep); }

/* ── 顶栏 ── */
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 18px;
  background: linear-gradient(180deg, var(--wood) 0%, var(--wood-deep) 100%);
  color: var(--paper); border-bottom: 2px solid var(--jin);
  flex-wrap: wrap; gap: 8px;
  z-index: 10;
}
.tb-act { font-size: 16px; letter-spacing: 2px; color: var(--jin-light); }
.tb-countdown {
  margin-left: 16px; font-size: 14px; color: var(--zhu);
  background: rgba(168,50,42,0.12); border: 1px solid var(--zhu);
  padding: 2px 10px; border-radius: 3px;
}
.tb-countdown b { font-size: 17px; }
.tb-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.tb-res { font-size: 15px; display: flex; align-items: center; gap: 5px; }
.tb-res b { color: var(--jin-light); font-size: 17px; }
.tb-res.phy-danger b { color: #ff7a6a !important; animation: phyPulse 1.2s ease-in-out infinite; }
@keyframes phyPulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.tb-ap b { color: #9fd08a; }
.ic { display: inline-block; width: 14px; height: 14px; border-radius: 2px; }
.ic-silver { background: linear-gradient(135deg, var(--jin-light), var(--jin)); }
.ic-body { background: linear-gradient(135deg, #d47a6a, var(--zhu)); border-radius: 50%; }
.btn-ghost {
  font-family: var(--font-song); background: none; border: 1px solid #9a8a70;
  color: #c9b99a; padding: 3px 12px; border-radius: 3px; cursor: pointer; font-size: 13px;
}
.btn-ghost:hover { color: var(--paper); border-color: var(--paper); }

/* ── 主网格 ── */
#main-grid {
  flex: 1; display: grid;
  grid-template-columns: 300px 1fr 280px;
  gap: 10px; padding: 10px;
  min-height: 0; overflow: hidden;
}

/* ── 面板通用 ── */
.panel {
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-deep) 100%);
  border: 1px solid #b8a988; border-radius: 4px;
  margin-bottom: 10px; overflow: hidden;
  box-shadow: 0 2px 8px var(--shadow);
}
.panel h3 {
  font-size: 14px; letter-spacing: 4px; color: var(--paper);
  background: var(--wood); padding: 7px 12px;
  border-bottom: 1px solid var(--jin);
  display: flex; justify-content: space-between; align-items: center;
}
.panel h3[data-toggle] { cursor: pointer; user-select: none; }
.chev { transition: transform .2s; font-size: 12px; }
.panel .collapsed { display: none; }

#rail-left, #rail-right { overflow-y: auto; min-height: 0; }

/* ── 铺面 ── */
.shop-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-bottom: 1px dashed #c9b996; font-size: 14px;
}
.shop-item.locked { color: var(--grey-cool); }
.shop-item .shop-income { color: #7a6a2c; font-size: 13px; }
.shop-item .shop-buy {
  font-size: 13px; color: var(--zhu); cursor: pointer;
  border: 1px solid var(--zhu); padding: 2px 8px; border-radius: 3px;
}
.shop-item .shop-buy:hover { background: var(--zhu); color: var(--paper); }
.shop-price-tier { display: flex; gap: 3px; }
.tier-btn {
  font-size: 12px; padding: 1px 6px; cursor: pointer;
  border: 1px solid #b8a988; background: none; border-radius: 2px; color: var(--ink-soft);
}
.tier-btn.active { background: var(--wood); color: var(--jin-light); border-color: var(--wood); }

/* ── 动作区 ── */
#action-tabs { display: flex; flex-wrap: wrap; background: var(--paper-deep); border-bottom: 1px solid #b8a988; }
.tab-btn {
  flex: 1; min-width: 54px; padding: 7px 4px; font-size: 13.5px; text-align: center;
  background: none; border: none; border-right: 1px solid #c9b996; cursor: pointer;
  font-family: var(--font-song); color: var(--ink-soft); letter-spacing: 1px;
}
.tab-btn.active { background: var(--wood); color: var(--jin-light); }
.action-item {
  padding: 9px 12px; border-bottom: 1px dashed #c9b996;
}
.action-item .a-head { display: flex; justify-content: space-between; font-size: 14px; }
.action-item .a-cost { color: var(--zhu); font-size: 12.5px; white-space: nowrap; margin-left: 8px; }
.action-item .a-desc { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; line-height: 1.55; }
.action-item .a-btn {
  margin-top: 6px; width: 100%; padding: 6px;
  font-family: var(--font-song); font-size: 14px; letter-spacing: 2px;
  background: var(--wood); color: var(--paper); border: 1px solid var(--jin);
  border-radius: 3px; cursor: pointer; transition: background .15s;
}
.action-item .a-btn:hover:not(:disabled) { background: var(--zhu); }
.action-item .a-btn:disabled { opacity: .38; cursor: not-allowed; }
.action-item.unavailable { opacity: .55; }

/* ── 中央舞台 ── */
#stage {
  position: relative; border-radius: 4px; overflow: hidden;
  border: 1px solid var(--jin);
  box-shadow: 0 4px 20px var(--shadow);
  display: flex; flex-direction: column;
  min-height: 0;
}
#stage-bg { position: absolute; inset: 0; transition: opacity .8s; }
#stage-caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px 16px; font-size: 14px; color: var(--paper);
  background: linear-gradient(0deg, rgba(20,14,8,0.82), transparent);
  text-shadow: 0 1px 4px #000; line-height: 1.6;
}
#btn-endturn {
  position: absolute; top: 12px; right: 12px; z-index: 5;
}
.btn-primary {
  font-family: var(--font-song); font-size: 16px; letter-spacing: 3px;
  background: var(--zhu); color: var(--paper);
  border: 1px solid var(--jin); border-radius: 3px;
  padding: 8px 20px; cursor: pointer;
  box-shadow: 0 2px 10px rgba(168,50,42,0.45);
}
.btn-primary:hover { background: var(--zhu-deep); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

/* ── 事件层 ── */
#event-layer {
  position: absolute; inset: 0; z-index: 8;
  background: rgba(20, 14, 8, 0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  animation: eventIn .3s ease-out;
}
@keyframes eventIn { from { opacity: 0; } to { opacity: 1; } }
#event-card {
  width: 100%; max-width: 720px; max-height: 100%;
  background: var(--paper); border: 2px solid var(--jin);
  border-radius: 5px; overflow: hidden auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  display: flex; flex-direction: column;
}
#event-cg { height: clamp(200px, 42vh, 380px); flex-shrink: 0; }
#event-title {
  padding: 12px 18px 4px; font-size: 19px; letter-spacing: 3px;
  color: var(--zhu-deep); font-weight: 700;
}
#event-title::before { content: "卍 "; color: var(--jin); }
#event-text {
  padding: 8px 18px 12px; font-size: 15px; line-height: 1.85;
  color: var(--ink); white-space: pre-line;
}
#event-choices { padding: 0 18px 16px; display: flex; flex-direction: column; gap: 8px; }
.choice-btn {
  font-family: var(--font-song); text-align: left;
  padding: 10px 14px; font-size: 15px; line-height: 1.5;
  background: #fffdf6; color: var(--ink);
  border: 1px solid #b8a988; border-radius: 3px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.choice-btn:hover:not(:disabled) { border-color: var(--zhu); background: #fdf3e8; }
.choice-btn:disabled { opacity: .45; cursor: not-allowed; }
.choice-btn .c-sub { display: block; font-size: 12.5px; color: var(--zhu); margin-top: 2px; }
.choice-btn.sin-choice { border-left: 4px solid var(--zhu); }

/* ── 账目飘字 ── */
#float-log { padding: 8px 12px; min-height: 60px; max-height: 220px; overflow-y: auto; font-size: 13.5px; }
.float-line { padding: 3px 0; line-height: 1.5; animation: floatIn .5s ease-out; border-bottom: 1px dotted #d8c9a8; }
@keyframes floatIn { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
.float-line .fl-num { font-weight: 700; }
.fl-gain .fl-num { color: #8a6d00; }
.fl-cost .fl-num { color: var(--zhu); }
.fl-sin { color: var(--zhu); font-weight: 700; }
.fl-note { color: var(--ink-soft); }

/* ── 关节/妻妾/罪业列表 ── */
.joint-item, .wife-item, .sin-item {
  padding: 7px 12px; font-size: 13.5px; border-bottom: 1px dashed #c9b996;
  display: flex; align-items: center; gap: 8px; line-height: 1.5;
}
.joint-item .j-status { margin-left: auto; font-size: 12px; }
.j-open { color: #4a7a2c; }
.j-cold { color: var(--grey-cool); }
.j-colder { color: var(--zhu); }
.wife-item .w-rank { color: var(--jin); font-weight: 700; min-width: 20px; }
.wife-item .w-temp { margin-left: auto; font-size: 12px; }
.sin-item { color: var(--zhu-deep); }
.sin-item::before { content: "⛓"; margin-right: 4px; color: var(--zhu); }

/* ── 幕扉页 ── */
#act-interlude { align-items: center; justify-content: center; }
.interlude-bg { position: absolute; inset: 0; filter: brightness(0.55) saturate(0.85); }
.interlude-content {
  position: relative; text-align: center; color: var(--paper);
  max-width: 620px; padding: 32px;
  animation: titleIn .9s ease-out;
}
.interlude-huashuo { font-size: 16px; letter-spacing: 6px; opacity: .8; margin-bottom: 18px; }
#interlude-title { font-size: clamp(30px, 6vw, 46px); letter-spacing: 8px; color: var(--jin-light); margin-bottom: 20px; text-shadow: 0 2px 10px #000; }
#interlude-text { font-size: 15.5px; line-height: 2; margin-bottom: 34px; opacity: .92; text-align: justify; }

/* ── 结算屏 ── */
#ending-screen { overflow-y: auto; }
.ending-bg { position: fixed; inset: 0; filter: brightness(0.5); }
#ending-content {
  position: relative; margin: 0 auto; max-width: 760px;
  padding: 48px 22px 60px; color: var(--paper);
}
.ending-title { font-size: clamp(34px, 7vw, 54px); letter-spacing: 10px; text-align: center; color: var(--jin-light); text-shadow: 0 2px 14px #000; margin-bottom: 8px; }
.ending-sub { text-align: center; font-size: 15px; opacity: .85; margin-bottom: 34px; line-height: 1.8; }
.ending-section {
  background: rgba(20, 14, 8, 0.72); border: 1px solid var(--jin);
  border-radius: 5px; padding: 18px 22px; margin-bottom: 18px;
  backdrop-filter: blur(3px);
}
.ending-section h3 { color: var(--jin-light); letter-spacing: 4px; font-size: 17px; margin-bottom: 12px; }
.ending-section p, .ending-section li { font-size: 14.5px; line-height: 1.9; }
.ending-ghost { padding: 5px 0; border-bottom: 1px dotted rgba(200,162,39,0.25); font-size: 14.5px; line-height: 1.7; }
.ending-ghost::before { content: "⛓ "; color: var(--zhu); }
.ending-ghost.pure::before { content: "❀ "; }
.ending-bill { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.bill-cell { background: rgba(200,162,39,0.08); border: 1px solid rgba(200,162,39,0.4); padding: 14px 8px; border-radius: 4px; }
.bill-cell .b-num { font-size: 26px; color: var(--jin-light); font-weight: 700; }
.bill-cell .b-label { font-size: 12.5px; opacity: .8; margin-top: 4px; }
.atlas-row { display: flex; gap: 10px; flex-wrap: wrap; }
.atlas-row img { height: 92px; border: 1px solid var(--jin); border-radius: 4px; opacity: .92; background: #2a2018; }
#btn-ending-restart { display: block; margin: 30px auto 0; }

/* ── 提示 toast ── */
#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(20,14,8,0.88); color: var(--paper);
  padding: 9px 20px; border-radius: 3px; font-size: 14px;
  border: 1px solid var(--jin); z-index: 50;
  animation: toastIn .25s ease-out; pointer-events: none;
  max-width: 86vw; text-align: center; line-height: 1.6;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px);} to { opacity: 1; transform: translate(-50%, 0);} }

/* ── 双端自适应 ── */
@media (max-width: 900px) {
  #main-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 44vh) auto auto;
    overflow-y: auto;
  }
  #stage { order: -1; min-height: 300px; }
  #rail-left, #rail-right { overflow: visible; }
  .tb-act { font-size: 13.5px; }
  #event-layer { padding: 10px; }
  #event-cg { height: clamp(160px, 30vh, 260px); }
  .ending-bill { grid-template-columns: 1fr; }
  .game-title { letter-spacing: 8px; }
}

/* ── reduce-motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01s !important; transition-duration: 0.01s !important; }
}
body.no-motion *, body.no-motion *::before, body.no-motion *::after {
  animation-duration: 0.01s !important; transition-duration: 0.01s !important;
}
