/* 全局样式 + 工具类。每个页面再引一份自己的页面级 CSS。 */

:root {
  --bg: #f4ecd8;
  --ink: #3e2c1a;
  --ink-soft: #7a5a3c;
  --brand: #a0522d;
  --brand-soft: #c98864;
  --line: rgba(160, 82, 45, 0.25);
  --card-bg: #fff8ec;
  --green: #6da26c;
  --yellow: #d9a44e;
  --gray: #cdbfa6;
  --danger: #c0392b;
  --shadow: 0 2px 12px rgba(91, 50, 18, 0.08);
}

* { box-sizing: border-box; }

/* hidden 属性必须能覆盖任何显式 display (例如 .modal-mask 的 display:flex),
   否则页面一加载所有 modal 都会同时弹出 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "STKaiti", "Kaiti SC", "KaiTi", "楷体", "Songti SC", "STSong",
    "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* 顶部导航条 (对应小程序的 navigationBar) */
.nav {
  background: var(--brand);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 17px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.nav .nav-title { font-weight: 600; letter-spacing: 1px; }
.nav .nav-back, .nav .nav-action {
  color: #fff;
  background: transparent;
  border: none;
  font: inherit;
  cursor: pointer;
  padding: 4px 8px;
}

/* 页面容器 */
.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

/* 卡片 */
.card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

/* 按钮 */
.btn {
  font: inherit;
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 120ms, opacity 120ms;
  font-size: 16px;
}
.btn:hover { background: #8c441f; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--brand);
}
.btn-ghost:hover { background: rgba(160, 82, 45, 0.08); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #962419; }
/* ghost + danger 复合: 透明底 + 红描边 + 红字, 与"跳过本题"等普通 ghost 区分,
   又比实心 danger 噪音小,适合「结束本局」这种需提示但不该夸张的破坏性操作 */
.btn-ghost.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-ghost.btn-danger:hover { background: rgba(178, 42, 31, 0.08); }
.btn-block { width: 100%; }

/* 输入 */
.input {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}
.input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(160, 82, 45, 0.15);
}
.input.error { border-color: var(--danger); animation: shake 0.32s; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-6px); }
  40%,80% { transform: translateX(6px); }
}

/* 全屏 modal 遮罩 */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(31, 16, 4, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 22px 20px;
  max-width: 92vw;
  width: 420px;
  max-height: 86vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 12px;
  color: var(--brand);
  text-align: center;
}
.modal-body { flex: 1; overflow-y: auto; }
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.modal-actions .btn { flex: 1; }

/* toast (脚本动态创建) */
.toast {
  position: fixed;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  background: rgba(31, 16, 4, 0.88);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 1000;
  animation: toast-in 200ms;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* 通用文本工具 */
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.spacer-12 { height: 12px; }
.spacer-20 { height: 20px; }
.spacer-32 { height: 32px; }

/* poem-grid 组件用 (components/poem-grid.js) */
poem-grid { display: block; }
.pg-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin: 4px 0;
  flex-wrap: nowrap;
}
.pg-cell {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 20px;
  font-weight: 500;
  color: #fff;
  flex-shrink: 0;
}
.pg-cell.green  { background: #6aaa64; }
.pg-cell.yellow { background: #c9b458; }
.pg-cell.gray   { background: #a89e8a; }
.pg-cell.empty {
  background: transparent;
  border: 1px solid #c8b89a;
  color: transparent;
}
/* 顶部答案区字格放大,从 page 通过类覆盖 */
.pg-row.lg .pg-cell { width: 44px; height: 44px; font-size: 24px; }
