/* ========== 基础重置 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  display: grid;
  grid-template-rows: 50px 1fr auto;
  grid-template-areas: "topbar" "main" "bottom";
  height: 100vh;
  background: #e8e0d0;
  font-family: '宋体', 'SimSun', serif;
  color: #3b352f;
}

.topbar {
  grid-area: topbar;
  display: grid;
  align-items: center;
  padding: 0 20px;
  background: linear-gradient(to bottom, #d6cbb8, #c9bea4);
  border-bottom: 1px solid #a99f8c;
  font-size: 18px;
  font-weight: bold;
}

.main {
  grid-area: main;
  display: grid;
  grid-template-columns: 340px 1fr 220px;
  grid-template-areas: "sidebar editor relation";
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: row;
  gap: 8px;
  padding: 16px 10px;
  background: #d6cbb8;
  border-right: 1px solid #a99f8c;
  overflow-y: auto;
}

.sidebar-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 0;
  min-width: 0;
}

.sidebar button {
  padding: 8px 10px;
  background: #f5eedf;
  border: 1px solid #b8a98c;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  white-space: nowrap;
  transition: all 0.2s;
}

.sidebar button:hover {
  background: #fff8e7;
  border-color: #8a6d2f;
  transform: translateY(-1px);
}

.sidebar #word-count {
  padding: 6px 10px;
  background: #ede4d3;
  border: 1px solid #b8a98c;
  border-radius: 6px;
  text-align: center;
  font-size: 13px;
  white-space: nowrap;
}

.editor {
  grid-area: editor;
  overflow-y: auto;
  padding: 32px 40px;
  background-color: #faf6ec;
  background-image: repeating-linear-gradient(to bottom, transparent, transparent 31px, #d0c6b0 31px, #d0c6b0 32px);
  background-attachment: local;
  line-height: 32px;
  outline: none;
  font-size: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  border-left: 1px solid #b8a98c;
  border-right: 1px solid #b8a98c;
}

.editor:empty::before {
  content: "在此输入正文...";
  color: #b0a48c;
}

.relation-panel {
  grid-area: relation;
  display: grid;
  place-items: center;
  overflow: auto;
  background: #e8e0d0;
  border-left: 1px solid #b8a98c;
  color: #a09480;
  font-size: 14px;
}

.bottom-panel {
  grid-area: bottom;
  display: block;
  padding: 10px 14px;
  background: #d6cbb8;
  border-top: 1px solid #a99f8c;
  min-height: 150px;
  max-height: 50vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.module-panel {
  display: none;
  width: 100%;
  min-height: 120px;
  max-height: 45vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: #faf6ec;
  border: 1px solid #c9bda4;
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
}

.module-panel.visible {
  display: block;
}

/* ========== 角色阵营区块 ========== */
.camp-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
  margin-bottom: 15px;
}

.camp-group h3 {
  grid-column: 1 / -1;
  color: #7a6230;
  border-bottom: 2px solid #c9bda4;
  padding-bottom: 6px;
  margin-bottom: 8px;
  font-size: 16px;
}

.character-card {
  background: #fffdf5;
  border: 1px solid #c9bda4;
  border-radius: 6px;
  padding: 10px;
  line-height: 1.6;
  font-size: 13px;
  box-shadow: 0 2px 3px rgba(0,0,0,0.04);
}

.character-card p { margin: 4px 0; }

/* ========== 场景信息与汇总 ========== */
.scene-summary,
.scene-info {
  background: #fffdf5;
  border: 1px solid #d5cbb8;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.6;
  box-shadow: 0 2px 3px rgba(0,0,0,0.04);
}

.scene-summary p,
.scene-info p { margin: 3px 0; }

/* ========== 场景块 ========== */
.scene-block {
  background: #fffdf5;
  border: 1px solid #d5cbb8;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
  font-size: 14px;
  line-height: 1.7;
  box-shadow: 0 2px 3px rgba(0,0,0,0.04);
}

.scene-title { font-size: 15px; color: #7a6230; margin-bottom: 2px; }

.scene-line { margin-left: 0; }

.candidate-line {
  margin-left: 20px;
  white-space: nowrap;
  overflow: visible;
}

.candidate-line.match { background: #fffbe0; border-radius: 3px; }

.candidate-meta { color: #6b5d3d; font-size: 13px; }

/* ========== 属性映射卡片 ========== */
.attr-card {
  background: #fffdf5;
  border: 1px solid #d5cbb8;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 16px;
  box-shadow: 0 2px 3px rgba(0,0,0,0.04);
}

.attr-card-header {
  border-bottom: 1px solid #c9bda4;
  padding-bottom: 6px;
  margin-bottom: 10px;
}

.attr-card-header h3 { color: #7a6230; font-size: 16px; margin: 0; }

.attr-card-info { margin-bottom: 10px; }

.attr-info-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 4px;
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.5;
}

.attr-label { font-weight: bold; color: #6b5d3d; }

.attr-value { word-break: break-word; }

.attr-output-list { display: grid; gap: 3px; }

.attr-output-item {
  white-space: normal;
  word-break: break-word;
  padding-left: 10px;
  text-indent: -10px;
}

.attr-items-section { margin-top: 10px; }

.attr-items-title {
  font-weight: bold;
  font-size: 14px;
  margin-bottom: 8px;
  color: #7a6230;
}

.attr-items-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 8px;
}

.attr-item-card {
  background: #f9f5ec;
  border: 1px solid #d5cbb8;
  border-radius: 4px;
  padding: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.attr-item-line { margin: 3px 0; }

.attr-item-name { font-weight: bold; color: #333; }

/* ========== 3-traits 模块样式 ========== */
.traits-block {
  background: #fffdf5;
  border: 1px solid #d5cbb8;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 3px rgba(0,0,0,0.04);
}

.traits-block h3 {
  color: #7a6230;
  border-bottom: 1px solid #c9bda4;
  padding-bottom: 6px;
  margin-bottom: 8px;
  font-size: 16px;
}

.traits-line { margin: 5px 0; font-size: 14px; line-height: 1.6; word-break: break-word; }

/* ========== 4-1 需求层次样式 ========== */
.needs-block {
  background: #fffdf5;
  border: 1px solid #d5cbb8;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 3px rgba(0,0,0,0.04);
}

.needs-block h3 {
  color: #7a6230;
  border-bottom: 1px solid #c9bda4;
  padding-bottom: 6px;
  margin-bottom: 8px;
  font-size: 16px;
}

.needs-block p { margin: 4px 0; font-size: 14px; line-height: 1.6; }

.needs-block ul { margin: 5px 0 5px 20px; font-size: 14px; line-height: 1.6; }

/* ========== 4-2 权力矩阵样式 ========== */
.roles-section,
.relations-section { margin-bottom: 20px; }

.roles-section h2,
.relations-section h2 {
  color: #7a6230;
  border-bottom: 2px solid #c9bda4;
  padding-bottom: 6px;
  margin-bottom: 12px;
  font-size: 17px;
}

.role-card,
.rel-block {
  background: #fffdf5;
  border: 1px solid #d5cbb8;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
  box-shadow: 0 2px 3px rgba(0,0,0,0.04);
}

.role-card h3,
.rel-block h3 { color: #7a6230; margin-bottom: 5px; font-size: 15px; }

.role-card p { margin: 3px 0; font-size: 14px; line-height: 1.6; }

.rel-item {
  border-top: 1px dashed #d5cbb8;
  padding: 6px 0;
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.6;
}

.rel-item p { margin: 2px 0; }

/* ========== 2-3 货币环节样式 ========== */
.currency-block {
  background: #fffdf5;
  border: 1px solid #d5cbb8;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 3px rgba(0,0,0,0.04);
}

.currency-block h3 {
  color: #7a6230;
  border-bottom: 1px solid #c9bda4;
  padding-bottom: 6px;
  margin-bottom: 8px;
}

/* ========== 5-1 资源环节样式 ========== */
.resource-block {
  background: #fffdf5;
  border: 1px solid #d5cbb8;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 3px rgba(0,0,0,0.04);
}

.resource-block h3 {
  color: #7a6230;
  border-bottom: 1px solid #c9bda4;
  padding-bottom: 6px;
  margin-bottom: 8px;
}

.resource-affects p { margin: 2px 0; }

/* 闭环位置高亮 */
.cycle-current {
  background: #fffbe0;
  border-left: 4px solid #8a6d2f;
  padding: 4px 8px;
  margin: 6px 0;
  font-weight: bold;
}

.cycle-full {
  background: #f9f5ec;
  padding: 6px 8px;
  border-radius: 4px;
  margin-top: 6px;
}

/* ========== 手机/平板适配 ========== */
@media (max-width: 1024px) {
  body { padding: 0; margin: 0; font-size: 16px; }

  .topbar { font-size: 1.2em; padding: 10px; text-align: center; }

  .main {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas: "sidebar" "editor" "relation";
    gap: 8px;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
  }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 6px;
    padding: 8px;
    background: transparent;
    border: none;
    box-shadow: none;
    overflow-y: visible;
  }

  .sidebar button { padding: 8px 10px; font-size: 14px; white-space: normal; }

  #word-count { grid-column: 1 / -1; text-align: center; font-size: 15px; }

  .editor { min-height: 300px; font-size: 18px; line-height: 1.6; padding: 15px; }

  .relation-panel { min-height: 150px; width: 100%; overflow-x: auto; }

  .bottom-panel { padding: 10px; width: 100%; box-sizing: border-box; max-height: 60vh; }

  .module-panel { min-height: 80px; max-height: 50vh; }

  .camp-group { grid-template-columns: 1fr; }

  .candidate-line { white-space: normal; word-break: break-word; }

  .attr-items-list { grid-template-columns: 1fr; }
}

/* 位置感知引擎 5按钮共享容器 */
#position-container {
  overflow-y: auto;
}
#position-container h3 {
  color: #7a6230;
  border-bottom: 2px solid #c9bda4;
  padding-bottom: 6px;
  margin-bottom: 10px;
}
#position-container h4 {
  color: #5a4a2a;
  margin: 12px 0 6px;
  font-size: 14px;
}
.pos-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  font-size: 12px;
}
.pos-table th {
  background: #e8dfcc;
  color: #5a4a2a;
  padding: 4px 6px;
  border: 1px solid #c9bda4;
  text-align: center;
  font-weight: bold;
}
.pos-table td {
  padding: 3px 6px;
  border: 1px solid #d5cbb8;
  text-align: center;
}
.pos-table tr:nth-child(even) {
  background: #f9f5ec;
}
.note {
  color: #6b5d3d;
  font-size: 12px;
  font-style: italic;
  background: #fffbe0;
  padding: 4px 8px;
  border-left: 3px solid #8a6d2f;
  margin-top: 10px;
}

/* ========== 6-0 被动情绪样式 ========== */
.emotion-cat-block {
  background: #fffdf5;
  border: 1px solid #d5cbb8;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 12px;
  box-shadow: 0 2px 3px rgba(0,0,0,0.04);
}

.emotion-cat-title {
  color: #7a6230;
  border-bottom: 1px solid #c9bda4;
  padding-bottom: 4px;
  margin-bottom: 8px;
  font-size: 15px;
}

.emotion-list {
  display: grid;
  gap: 3px;
}

.emotion-item {
  font-size: 13px;
  line-height: 1.6;
  padding: 2px 6px;
  border-radius: 3px;
}

.emotion-item:nth-child(even) {
  background: #f9f5ec;
}

.emotion-oid {
  color: #8a6d2f;
  font-weight: bold;
  margin-right: 4px;
}

.emotion-trigger {
  color: #5a4a2a;
}

.emotion-response {
  color: #333;
  font-weight: 500;
}

/* ================================================================
 * 手机竖屏 + 触屏优化 · 2026-10-05 修正版
 * 原则：桌面/平板保持原有布局，只对手机竖屏和触屏做优化
 * ================================================================ */

/* ========== 手机竖屏（< 600px） ========== */
@media (max-width: 599px) {
  body {
    grid-template-rows: 44px 1fr auto;
    font-size: 15px;
  }
  .topbar {
    font-size: 15px;
    padding: 0 12px;
  }

  /* 侧边栏：两列 grid，按钮均分 */
  .sidebar {
    display: block;
    padding: 8px;
    border-right: none;
    border-bottom: 1px solid #a99f8c;
    max-height: 220px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-col {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-bottom: 6px;
  }
  .sidebar button {
    padding: 9px 8px;
    font-size: 12px;
    white-space: normal;
    line-height: 1.3;
    min-height: 42px;
    text-align: center;
  }
  .sidebar #word-count {
    grid-column: 1 / -1;
    padding: 6px 10px;
    font-size: 12px;
    text-align: center;
    margin: 4px 0 6px;
  }

  /* 编辑器 */
  .editor {
    padding: 18px 20px;
    font-size: 17px;
    line-height: 30px;
    min-height: 50vh;
    background-image: repeating-linear-gradient(
      to bottom, transparent, transparent 29px,
      #d0c6b0 29px, #d0c6b0 30px
    );
  }

  /* 底部面板 */
  .bottom-panel {
    padding: 8px 10px;
    max-height: 60vh;
  }
  .module-panel {
    max-height: 55vh;
    padding: 10px;
    font-size: 12px;
  }
  #position-container h3 { font-size: 15px; }
  #position-container h4 { font-size: 13px; }
  .pos-table { font-size: 11px; }
  .pos-table th,
  .pos-table td { padding: 3px 4px; }
  .pos-table th { font-size: 10px; line-height: 1.2; }
}

/* ========== 触屏设备：去掉 hover 位移，加大触控区 ========== */
@media (hover: none) and (pointer: coarse) {
  .sidebar button:hover {
    background: #f5eedf;
    border-color: #b8a98c;
    transform: none;
  }
  .sidebar button:active {
    background: #fff8e7;
    border-color: #8a6d2f;
  }
  .sidebar button {
    min-height: 40px;
  }
}
