:root {
  --ink: #3a2a1c;
  --ink-soft: #6b5640;
  --paper: #fffaf1;
  --paper-2: #f7ecda;
  --line: #e2cdb0;
  --brand: #b93b2f;
  --brand-soft: #f3d9d1;
  --gold: #c08a3e;
  --wood: #d8a86c;
  --shadow: 0 10px 28px rgba(90, 62, 34, 0.16);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 15% -10%, #fff8ea 0%, rgba(255, 248, 234, 0) 60%),
    radial-gradient(900px 500px at 110% 10%, #fbe6d2 0%, rgba(251, 230, 210, 0) 55%),
    linear-gradient(180deg, #f6eddd 0%, #efe0c9 100%);
  min-height: 100vh;
  padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
}

.app {
  width: min(560px, 100%);
  margin: 0 auto;
}

/* ---------------- 顶部 ---------------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 2px 12px;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  background: linear-gradient(160deg, #cf4a38, #96281f);
  color: #fff6e8;
  font-weight: 800;
  font-size: 22px;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 14px rgba(150, 40, 31, 0.28);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: 0.5px; }
.brand-text span { font-size: 11px; color: var(--ink-soft); letter-spacing: 2px; }

/* 这条链接的账本主人：玩之前先看是不是自己 */
.who {
  max-width: 46%;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.who.warn { border-color: #d08a2e; background: #fdf0d8; color: #8a5310; }

/* 任务页简笔画说明卡 */
.mission-guide { margin: 4px 0 10px; }
.mission-guide img {
  width: 100%;
  max-width: 300px;
  display: block;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.mission-guide figcaption {
  margin-top: 6px;
  font-size: 10.5px;
  color: var(--ink-soft);
  line-height: 1.6;
  text-align: center;
}

/* ---------------- 标签 ---------------- */

.tabs {
  display: flex;
  gap: 8px;
  background: rgba(255, 250, 241, 0.72);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 5px;
  margin-bottom: 12px;
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 6px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.16s, color 0.16s;
}

.tab.active {
  background: linear-gradient(180deg, #ffffff, #fff3e3);
  color: var(--brand);
  box-shadow: 0 4px 12px rgba(120, 80, 40, 0.12);
}

.notice {
  margin: -4px 2px 12px;
  padding: 8px 10px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  background: var(--paper-2);
  border: 1px dashed var(--line);
  border-radius: 12px;
}

.notice b {
  color: var(--brand);
  font-weight: 700;
}

/* ---------------- 面板 ---------------- */

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.levels { display: flex; gap: 6px; }

.level {
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink-soft);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 11px;
  border-radius: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.level em {
  font-style: normal;
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  background: #fdf3e2;
  border-radius: 7px;
  padding: 1px 5px;
}

.level.active {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}
.level.active em { background: #fff; }

.ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 12px;
  padding: 7px 11px;
  border-radius: 10px;
  cursor: pointer;
}

.hud {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--paper-2);
  border-radius: 11px;
  padding: 8px 10px;
  margin-bottom: 10px;
}

.hud-inline { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-soft); }

.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.black { background: radial-gradient(circle at 32% 28%, #6d6a67, #17161a 70%); margin-left: 2px; }
.dot.white { background: radial-gradient(circle at 32% 28%, #ffffff, #cfc6b8 75%); margin-left: 8px; border: 1px solid #b9ad9b; }

.board-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}

/* ---------------- 扫雷 ---------------- */

.mines {
  display: grid;
  grid-template-columns: repeat(var(--cols, 9), minmax(0, 1fr));
  gap: 3px;
  width: max(100%, calc(var(--cols, 9) * 26px));
  margin: 0 auto;
  touch-action: manipulation;
  user-select: none;
}

.cell {
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 7px;
  background: linear-gradient(160deg, #e9cfa5, #d3ad78);
  box-shadow: inset 0 -2px 0 rgba(120, 82, 42, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  color: var(--ink);
  font: inherit;
  font-size: clamp(11px, 3.6vw, 17px);
  font-weight: 800;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}

.cell:active { transform: translateY(1px); }

.cell.open {
  background: #fdf6e8;
  box-shadow: inset 0 0 0 1px rgba(190, 160, 120, 0.35);
  cursor: default;
}

.cell.flag { color: #b93b2f; font-size: clamp(10px, 3.2vw, 15px); }
.cell.mine { background: #f6d3cb; color: #8f1f16; }
.cell.boom { background: #b93b2f; color: #fff; }

.cell.n1 { color: #2f6fbf; }
.cell.n2 { color: #2f8a53; }
.cell.n3 { color: #b93b2f; }
.cell.n4 { color: #6a3fa0; }
.cell.n5 { color: #9a5a1e; }
.cell.n6, .cell.n7, .cell.n8 { color: #4b3a2a; }

.hint {
  margin: 10px 2px 0;
  font-size: 11.5px;
  color: var(--ink-soft);
  line-height: 1.6;
}

/* ---------------- 五子棋 ---------------- */

.gomoku {
  width: min(100%, 470px);
  margin: 2px auto 0;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  background: linear-gradient(150deg, #e3b981, #cf9a5b);
  border: 2px solid #a9793f;
  border-radius: 12px;
  padding: 4px;
  box-shadow: inset 0 0 24px rgba(120, 76, 32, 0.25);
  touch-action: manipulation;
}

.gcell {
  position: relative;
  border: 0;
  background: transparent;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.gcell::before,
.gcell::after {
  content: "";
  position: absolute;
  background: rgba(94, 62, 28, 0.45);
}

.gcell::before { left: 50%; top: 0; bottom: 0; width: 1px; }
.gcell::after { top: 50%; left: 0; right: 0; height: 1px; }

.stone {
  width: 84%;
  height: 84%;
  border-radius: 50%;
  position: relative;
  z-index: 2;
  animation: pop 0.14s ease-out;
}

.stone.black { background: radial-gradient(circle at 32% 28%, #6f6b68, #191818 68%); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); }
.stone.white { background: radial-gradient(circle at 32% 28%, #ffffff, #d3c9b8 78%); border: 1px solid #b4a795; }
.stone.last::after {
  content: "";
  position: absolute;
  inset: 36%;
  border-radius: 50%;
  background: #c0392b;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6);
}

@keyframes pop { from { transform: scale(0.6); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }

/* ---------------- 提示与遮罩 ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  max-width: min(520px, 92vw);
  background: rgba(46, 31, 18, 0.94);
  color: #fff3e1;
  font-size: 13px;
  line-height: 1.5;
  padding: 11px 15px;
  border-radius: 13px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 9;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.good { background: linear-gradient(135deg, #b93b2f, #8f2419); }
.toast.bad { background: rgba(60, 60, 60, 0.95); }

.blocked {
  position: fixed;
  inset: 0;
  background: rgba(40, 27, 15, 0.55);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
}

/* hidden 属性要能压过上面的 display:grid，不然遮罩永远盖在页面上 */
.blocked[hidden] { display: none; }

.blocked-card {
  background: var(--paper);
  border-radius: 18px;
  padding: 22px;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow);
}

.blocked-card h2 { margin: 0 0 8px; font-size: 17px; color: var(--brand); }
.blocked-card p { margin: 0; font-size: 13px; color: var(--ink-soft); line-height: 1.7; }

.foot {
  margin: 12px 4px 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 10.5px;
  color: rgba(90, 68, 46, 0.72);
}

/* ---------------- 狙击训练 ---------------- */

.sniper-scene {
  background: linear-gradient(180deg, #dceaf5 0%, #eef3e4 62%, #dcc79b 62%, #c9a96e 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  line-height: 0;
}

.sniper-scene svg { width: 100%; height: auto; display: block; }

.sniper-idle {
  padding: 14px 12px;
  line-height: 1.7;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.sniper-idle p { margin: 4px 0; line-height: 1.7; }

.sniper-idle .grade-line { color: var(--brand); font-weight: 700; font-size: 12px; }

.guns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.guns button {
  flex: 1 1 44%;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 6px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.16s, color 0.16s;
}

.guns button small { display: block; font-weight: 500; font-size: 10.5px; color: var(--ink-soft); }

.guns button.active {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}

/* 底部装表条（竖屏：距离 / 密位 / 刻镜 + 开枪） */
.sniper-form {
  position: sticky;
  bottom: 8px;
  margin-top: 10px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--shadow);
}

.sniper-form label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10.5px;
  color: var(--ink-soft);
  font-weight: 700;
}

.sniper-form input,
.sniper-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf7;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 8px 6px;
  text-align: center;
}

.sniper-form .fire {
  flex: 1.2;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, #cf4a3b, #b93b2f);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 4px;
  padding: 12px 6px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(140, 40, 28, 0.28);
}

.sniper-form .fire:active { transform: translateY(1px); }

/* ---------------- 执行任务 ---------------- */

.mission-log {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  max-height: 300px;
  overflow-y: auto;
  font-size: 12.5px;
  color: var(--ink);
  line-height: 1.7;
}

.mission-log p { margin: 6px 0; line-height: 1.7; }

.mission-log .mission-idle { color: var(--ink-soft); }

.choices { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.choices button {
  border: 1px solid var(--line);
  background: #fffdf7;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.16s, color 0.16s;
}

.choices button:active { border-color: var(--brand); color: var(--brand); }

.choices button small { display: block; font-size: 10.5px; color: var(--ink-soft); margin-top: 2px; }

.choices button.med { flex: 1 1 30%; text-align: center; font-weight: 700; }

/* 任务选项：简报卡（可滚动长列表） */
.choices.scrollable {
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 4px;
}

.choices .choice-card {
  display: block;
}

.choices .choice-card .choice-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.choices .choice-card .choice-head b {
  font-size: 13px;
  line-height: 1.5;
}

.choices .choice-card .choice-head .tag {
  flex-shrink: 0;
  font-style: normal;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  background: #efe7d6;
  color: #6b5a3e;
}

.choices .choice-card small {
  display: block;
  font-size: 10.5px;
  color: var(--ink-soft);
  line-height: 1.55;
  margin-top: 3px;
}

.choices .choice-card.g-perfect { border-left: 4px solid #4c9e63; }
.choices .choice-card.g-perfect .tag { background: #e2f2e6; color: #2f7a44; }
.choices .choice-card.g-good { border-left: 4px solid #4a7fb5; }
.choices .choice-card.g-good .tag { background: #e3edf7; color: #33618f; }
.choices .choice-card.g-fair { border-left: 4px solid #c98a2e; }
.choices .choice-card.g-fair .tag { background: #f9ecd7; color: #9a6a1e; }
.choices .choice-card.g-risky { border-left: 4px solid #c25a34; }
.choices .choice-card.g-risky .tag { background: #f8e5db; color: #9c4322; }
.choices .choice-card.g-death { border-left: 4px solid #8c2b23; background: #f7e8e5; }
.choices .choice-card.g-death .tag { background: #8c2b23; color: #fff; }
