/* ============================================================
   apps/gobang.html 样式（P0-4-T17 自动外联）
   - 顶栏统一化：原古风顶栏主题覆盖已删除，严格使用共享 topbar 样式
   ============================================================ */

  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  /* body 用 min-height（而非 height:100%）：让 body 高度随内容增长，保证 sticky 顶栏全程有效 */
  html { height: 100%; }
  body { min-height: 100%; }
  :root {
    /* 底色 — 宣纸 */
    --bg-deep:        #f3ead7;
    --bg-page:        #ede2c4;
    --bg-card:        rgba(252, 247, 232, 0.86);
    --bg-card-solid:  #faf3df;
    --bg-inner:       rgba(28, 20, 16, 0.04);
    --bg-soft:        rgba(184, 51, 47, 0.07);
    --bg-header:      rgba(243, 234, 215, 0.72);

    /* 文字 — 墨系 */
    --text-primary:   #1c1410;
    --text-secondary: #5c4a3a;
    --text-muted:     #8a7355;
    --text-hint:      #b09a78;
    --text-on-accent: #faf6e8;

    /* 边线 — 墨线 */
    --border:         rgba(28, 20, 16, 0.18);
    --border-soft:    rgba(28, 20, 16, 0.08);

    /* 主操作色 — 朱砂系 */
    --accent:         #b8332f;
    --accent-hover:   #9a2622;
    --accent-soft:    #d96b5b;
    --accent-fade:    rgba(184, 51, 47, 0.10);
    --blue-glow:      rgba(184, 51, 47, 0.35);

    /* 状态色 */
    --success:        #5b7e5a;   /* 竹青 — 胜利 */
    --warning:        #a86a3d;   /* 赭石 — 平局/警告 */
    --danger:         #7a1d18;   /* 深朱 — 失败/认输 */

    /* 金色（重命名为赭石系） */
    --gold:           #a86a3d;
    --gold-2:         #c98c5b;
    --gold-dark:      #6b3d20;
    --gold-bg:        rgba(168, 106, 61, 0.10);
    --gold-border:    rgba(168, 106, 61, 0.55);
    --gold-glow:      rgba(168, 106, 61, 0.35);

    /* 阴影 — 墨晕 */
    --shadow:         0 8px 24px rgba(28, 20, 16, 0.18);

    /* 字体 */
    --font-kai:       "Ma Shan Zheng", "ZCOOL XiaoWei", "STKaiti", "KaiTi", "华文行楷", "方正清刻本悦宋", serif;
    --font-song:      "Noto Serif SC", "Source Han Serif SC", "方正书宋", "Songti SC", serif;
    --font-sans:      "Noto Sans SC", "Source Han Sans SC", system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;

    /* 棋子 — 墨玉/白贝 */
    --stone-black:    #1a1410;
    --stone-white:    #faf6e8;
    --board-bg:       #e0bd80;
    --board-line:     #3b2415;
  }
  body {
    background:
      /* 顶层水墨晕（极淡） */
      radial-gradient(ellipse 60% 50% at 50% 0%, rgba(168, 106, 61, 0.10) 0%, transparent 55%),
      radial-gradient(ellipse 45% 40% at 100% 100%, rgba(91, 126, 90, 0.08) 0%, transparent 55%),
      radial-gradient(ellipse 40% 35% at 0% 80%, rgba(184, 51, 47, 0.05) 0%, transparent 55%),
      /* 宣纸纹理（CSS 模拟：细竖纹 + 不规则纤维） */
      repeating-linear-gradient(90deg,
        rgba(168, 130, 80, 0.04) 0px,
        rgba(168, 130, 80, 0.04) 1px,
        transparent 1px,
        transparent 3px),
      repeating-linear-gradient(0deg,
        rgba(120, 80, 40, 0.025) 0px,
        rgba(120, 80, 40, 0.025) 1px,
        transparent 1px,
        transparent 5px),
      /* 宣纸基底 */
      var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-song);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
  }

  /* ============== 漂浮棋子粒子 ============== */
  .gb-particles { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
  .gb-particles span {
    position: fixed;
    bottom: -8vh;
    font-weight: 700;
    opacity: 0;
    animation-name: gb-float;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    user-select: none;
    text-shadow: 0 0 12px currentColor;
  }
  @keyframes gb-float {
    0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
    12%  { opacity: 0.55; }
    88%  { opacity: 0.55; }
    100% { transform: translateY(-118vh) rotate(360deg); opacity: 0; }
  }
  a { color: inherit; text-decoration: none; }
  /* 返回链接古风风格 */
  .back-link-wrapper {
    background: rgba(243, 234, 215, 0.92);
  }
  .back-link {
    font-size: 12px;
    letter-spacing: 0.15em;
    font-family: "Noto Serif SC", "Source Han Serif SC", "方正书宋", "Songti SC", serif;
    color: #5c4a3a;
    transition: color 0.18s ease;
    position: relative;
  }
  .back-link::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -2px;
    height: 1px;
    background: #b8332f;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.22s ease;
  }
  .back-link:hover { color: #b8332f; }
  .back-link:hover::after { transform: scaleX(1); }

  main { position: relative; z-index: 1; flex: 1; padding: 34px 40px 72px; max-width: 1080px; width: 100%; margin: 0 auto; }
  /* ============== 标题区 — 书法题款 ============== */
  .head { text-align: center; margin-bottom: 30px; }
  .head .eyebrow {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 12px; letter-spacing: 0.32em; color: var(--text-secondary);
    font-family: var(--font-kai);
    margin-bottom: 16px;
  }
  .head .eyebrow::before, .head .eyebrow::after {
    content: ''; width: 24px; height: 1px; background: var(--text-muted);
  }
  .head h1 {
    font-size: 48px; font-weight: 400; letter-spacing: 0.08em; line-height: 1.2;
    color: var(--text-primary);
    font-family: var(--font-kai);
    text-shadow: 2px 2px 0 rgba(168, 106, 61, 0.06);
    position: relative;
    display: inline-block;
  }
  /* 题款红线 */
  .head h1::after {
    content: ''; display: block;
    width: 100px; height: 2px; margin: 14px auto 0;
    background: linear-gradient(90deg, transparent, var(--accent) 30%, var(--accent) 70%, transparent);
  }
  .head .sub {
    margin: 18px auto 0; max-width: 560px;
    font-size: 14px; color: var(--text-secondary);
    line-height: 1.9; font-family: var(--font-song); letter-spacing: 0.05em;
  }

  /* ============== 难度按钮 — 卷轴小牌 ============== */
  .diff-row {
    display: flex; justify-content: center; gap: 12px;
    margin-bottom: 28px; width: fit-content; margin-left: auto; margin-right: auto;
  }
  .diff-btn {
    padding: 10px 28px;
    font-size: 14px; font-weight: 500; letter-spacing: 0.2em;
    color: var(--text-primary);
    background: var(--bg-card-solid);
    border: 1px solid var(--border); border-radius: 4px;
    cursor: pointer; transition: all 0.22s ease;
    font-family: var(--font-kai);
  }
  .diff-btn:hover {
    color: var(--accent); border-color: var(--gold);
    box-shadow: 0 2px 8px rgba(168, 106, 61, 0.18);
  }
  .diff-btn.active {
    background: var(--accent);
    color: var(--text-on-accent);
    border-color: var(--accent);
    box-shadow: 0 4px 14px rgba(184, 51, 47, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  }
  .diff-btn.gold.active {
    background: var(--gold);
    color: var(--text-on-accent);
    border-color: var(--gold);
    box-shadow: 0 4px 14px rgba(168, 106, 61, 0.4);
  }

  .game-area { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 28px; align-items: start; }

  /* ============== 棋盘外框 — 木雕卷轴 ============== */
  .board-wrap {
    position: relative;
    background: var(--bg-card-solid);
    border: 4px solid var(--board-line);
    border-radius: 6px;
    padding: 22px;
    display: flex; flex-direction: column; align-items: center; gap: 16px;
    box-shadow: var(--shadow), inset 0 0 0 8px var(--bg-card), inset 0 0 0 9px var(--border-soft);
    transition: border-color 0.35s ease, box-shadow 0.35s ease;
  }
  .board-wrap::before {
    content: ''; position: absolute; top: 6px; left: 6px; right: 6px; bottom: 6px;
    border: 1px dashed rgba(168, 106, 61, 0.3);
    pointer-events: none;
  }
  .board-wrap canvas {
    display: block;
    background: var(--board-bg);
    border: 1px solid rgba(59, 36, 21, 0.7);
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(28, 20, 16, 0.25), inset 0 0 24px rgba(120, 70, 30, 0.15);
    cursor: crosshair;
    max-width: 100%;
    height: auto;
    transition: box-shadow 0.35s ease;
  }
  /* AI 思考：赭石脉冲光晕 */
  .board-wrap.thinking {
    border-color: var(--gold);
    animation: gb-pulse-ochre 1.5s ease-in-out infinite;
  }
  @keyframes gb-pulse-ochre {
    0%, 100% { box-shadow: var(--shadow), inset 0 0 0 8px var(--bg-card), inset 0 0 0 9px var(--border-soft), 0 0 0 rgba(168, 106, 61, 0); }
    50%      { box-shadow: var(--shadow), inset 0 0 0 8px var(--bg-card), inset 0 0 0 9px var(--border-soft), 0 0 42px rgba(168, 106, 61, 0.45); }
  }
  /* 对局结束氛围光：竹青(胜) / 深朱(负) / 赭石(和) */
  .board-wrap.stage-win  {
    border-color: var(--success);
    box-shadow: var(--shadow), inset 0 0 0 8px var(--bg-card), inset 0 0 0 9px var(--border-soft), 0 0 44px rgba(91, 126, 90, 0.30);
  }
  .board-wrap.stage-lose {
    border-color: var(--danger);
    box-shadow: var(--shadow), inset 0 0 0 8px var(--bg-card), inset 0 0 0 9px var(--border-soft), 0 0 44px rgba(122, 29, 24, 0.32);
  }
  .board-wrap.stage-draw {
    border-color: var(--gold);
    box-shadow: var(--shadow), inset 0 0 0 8px var(--bg-card), inset 0 0 0 9px var(--border-soft), 0 0 44px rgba(168, 106, 61, 0.28);
  }

  /* ============== 状态行 — 题字条 ============== */
  .status-line {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 13px; letter-spacing: 0.1em; color: var(--text-primary);
    min-height: 32px; padding: 7px 22px;
    font-family: var(--font-kai);
    background: var(--bg-card-solid);
    border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 2px;
    transition: all 0.25s ease;
  }
  .status-line.thinking {
    color: var(--gold);
    border-left-color: var(--gold);
    background: var(--gold-bg);
  }
  .status-line.thinking::after {
    content: '●'; color: var(--gold);
    animation: gb-blink 1s ease-in-out infinite;
    font-size: 10px; line-height: 1;
  }
  @keyframes gb-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
  .status-line.winner { color: var(--success); border-left-color: var(--success); background: rgba(91, 126, 90, 0.06); }
  .status-line.loser  { color: var(--danger);  border-left-color: var(--danger);  background: rgba(122, 29, 24, 0.06); }
  .status-line.draw   { color: var(--warning); border-left-color: var(--warning); background: var(--gold-bg); }

  .stats-panel { display: flex; flex-direction: column; gap: 14px; }
  .gb-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  /* ============== stat-card — 宣纸小卡 ============== */
  .stat-card {
    background: var(--bg-card-solid);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 16px 18px;
    box-shadow: 0 4px 12px rgba(28, 20, 16, 0.08);
    position: relative;
  }
  .stat-card::before {
    content: ''; position: absolute; top: 8px; right: 8px;
    width: 6px; height: 6px; background: var(--accent); border-radius: 1px;
  }
  .stat-card .l {
    font-size: 11px; letter-spacing: 0.2em; color: var(--text-secondary);
    margin-bottom: 10px; font-family: var(--font-song);
  }
  .stat-card .v {
    font-size: 26px; font-weight: 600; color: var(--text-primary);
    font-family: var(--font-song);
    line-height: 1; font-variant-numeric: tabular-nums;
  }
  .stat-card .v small { font-size: 13px; font-weight: 400; color: var(--text-muted); margin-left: 4px; font-family: var(--font-song); }
  .stat-card.is-time .v { color: var(--accent); }
  .stat-card.best {
    background: var(--bg-card-solid);
    border: 1.5px solid var(--gold);
    box-shadow: 0 4px 12px rgba(168, 106, 61, 0.12);
  }
  .stat-card.best::before { background: var(--gold); }
  .stat-card.best .l { color: var(--gold); }
  .stat-card.best .v { color: var(--text-primary); font-size: 15px; font-weight: 500; font-family: var(--font-song); }

  .actions { display: flex; flex-direction: column; gap: 10px; }
  /* ============== 按钮 — 卷轴小牌 ============== */
  .btn {
    padding: 12px 18px; font-size: 13px; font-weight: 500; letter-spacing: 0.2em;
    background: var(--bg-card-solid); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: 4px;
    cursor: pointer; transition: all 0.22s ease; font-family: var(--font-kai);
  }
  .btn:hover {
    background: var(--text-primary); color: var(--text-on-accent);
    border-color: var(--text-primary);
  }
  .btn:disabled { opacity: 0.4; cursor: not-allowed; }
  .btn:disabled:hover { background: var(--bg-card-solid); color: var(--text-primary); border-color: var(--border); }
  .btn.primary {
    background: var(--accent); color: var(--text-on-accent);
    border-color: var(--accent);
    box-shadow: 0 4px 14px rgba(184, 51, 47, 0.35);
  }
  .btn.primary:hover {
    background: var(--accent-hover); color: var(--text-on-accent);
    border-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(184, 51, 47, 0.5);
  }
  /* 认输：赭石描边 */
  .btn.danger { color: var(--danger); border-color: var(--danger); background: rgba(122, 29, 24, 0.06); }
  .btn.danger:hover { background: var(--danger); color: var(--text-on-accent); border-color: var(--danger); }
  /* 结算弹窗内：保存图片赭石钮 */
  .btn.gold-text { color: var(--gold); border-color: var(--gold); background: var(--gold-bg); }
  .btn.gold-text:hover { background: var(--gold); color: var(--text-on-accent); border-color: var(--gold); }

  /* ============== status-info — 题字小笺 ============== */
  .status-info {
    padding: 14px 16px; font-size: 13px; line-height: 1.9; letter-spacing: 0.02em;
    color: var(--text-secondary);
    background: var(--bg-card-solid);
    border: 1px solid var(--border); border-left: 3px solid var(--gold); border-radius: 2px;
    font-family: var(--font-song);
  }
  .status-info b { color: var(--text-primary); font-weight: 600; }
  .status-info .guest { color: var(--accent); font-weight: 600; }

  /* ============== 结算弹窗 — 宣纸卷轴 ============== */
  .modal-mask {
    position: fixed; inset: 0; background: rgba(28, 20, 16, 0.55);
    display: none; align-items: center; justify-content: center; z-index: 1000;
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  }
  .modal-mask.show { display: flex; animation: gb-fadein 0.22s ease; }
  @keyframes gb-fadein { from { opacity: 0; } to { opacity: 1; } }
  .modal {
    background: var(--bg-card-solid);
    border: 3px solid var(--board-line);
    border-radius: 4px;
    max-width: 460px; width: calc(100% - 40px);
    padding: 38px 32px 30px; text-align: center;
    box-shadow: var(--shadow), 0 0 0 6px var(--bg-card), 0 0 0 7px var(--border-soft);
    position: relative;
    animation: gb-pop 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  }
  /* 卷轴顶部装饰 */
  .modal::before {
    content: ''; position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
    width: 60%; height: 4px; background: linear-gradient(90deg, transparent, var(--accent) 20%, var(--accent) 80%, transparent);
  }
  /* 落款小印 */
  .modal::after {
    content: '弈'; position: absolute; bottom: 12px; right: 18px;
    width: 28px; height: 28px; background: var(--accent); color: var(--text-on-accent);
    font-family: var(--font-kai); font-size: 18px; line-height: 28px; text-align: center;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(184, 51, 47, 0.4);
    transform: rotate(-3deg);
  }
  @keyframes gb-pop {
    from { transform: scale(0.92) translateY(14px); opacity: 0; }
    to   { transform: scale(1) translateY(0); opacity: 1; }
  }
  .modal h2 {
    font-size: 56px; font-weight: 400; color: var(--text-primary);
    margin-bottom: 6px; letter-spacing: 0.2em; padding-left: 0.2em;
    font-family: var(--font-kai);
  }
  .modal h2.win  { color: var(--success); }
  .modal h2.lose { color: var(--danger); }
  .modal h2.draw { color: var(--gold); }
  .modal .sub {
    font-size: 13px; color: var(--text-secondary);
    margin-bottom: 20px; letter-spacing: 0.15em;
    font-family: var(--font-song);
  }
  .modal .result { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 22px; }
  .modal .result .r {
    padding: 14px 6px;
    background: var(--bg-card-solid);
    border: 1px solid var(--border); border-radius: 2px;
  }
  .modal .result .r .l {
    font-size: 11px; letter-spacing: 0.2em; color: var(--text-muted);
    margin-bottom: 6px; font-family: var(--font-song);
  }
  .modal .result .r .v {
    font-size: 18px; font-weight: 600; color: var(--text-primary);
    font-variant-numeric: tabular-nums; font-family: var(--font-song);
  }
  .modal .badge {
    display: inline-block; padding: 5px 16px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.18em;
    border-radius: 2px;
    background: var(--bg-card-solid);
    color: var(--accent);
    border: 1px solid var(--accent);
    margin-bottom: 18px;
    font-family: var(--font-song);
  }
  .modal .badge.guest {
    background: var(--bg-card-solid); color: var(--gold);
    border-color: var(--gold);
  }
  .modal .actions { display: flex; gap: 10px; flex-direction: row; }
  .modal .actions .btn { flex: 1; padding: 11px 10px; letter-spacing: 0.15em; font-size: 12px; }

  /* ============== toast — 题字条 ============== */
  .toast {
    position: fixed; bottom: 34px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 24px;
    background: var(--bg-card-solid); color: var(--text-primary);
    border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 2px;
    font-size: 13px; font-weight: 500; letter-spacing: 0.1em;
    font-family: var(--font-song);
    box-shadow: var(--shadow);
    opacity: 0; transition: all 0.25s ease; pointer-events: none; z-index: 1100;
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
  .toast.error   { border-left-color: var(--danger);  color: var(--danger); }
  .toast.success { border-left-color: var(--success); color: var(--success); }
  .toast.warn    { border-left-color: var(--gold);    color: var(--gold); }

  /* ============== 响应式 ============== */
  @media (max-width: 980px) {
    main { padding: 28px 24px 56px; }
    .game-area { grid-template-columns: minmax(0, 1fr) 248px; gap: 20px; }
    .board-wrap { padding: 18px; }
  }
  @media (max-width: 760px) {
    .back-link { margin-left: 0; }
    main { padding: 22px 14px 44px; }
    .head h1 { font-size: 30px; }
    .head .sub { font-size: 12px; }
    .diff-btn { padding: 8px 18px; font-size: 12px; }
    .game-area { grid-template-columns: 1fr; }
    .board-wrap { padding: 14px; border-radius: 18px; order: 1; }
    .stats-panel { order: 2; }
  }
  @media (max-width: 420px) {
    .modal { padding: 26px 18px 22px; }
    .modal .actions { flex-direction: column; }
  }
