/* ============================================================
   apps/nonogram.html 样式 · 数织像素工坊
   - 主题：深夜工作台 · 像素网格 · 紫罗兰 + 琥珀强调
   - 与 sokoban 同色温（暖暗），但用紫罗兰 + 琥珀双色锚点强调「逻辑」感
   ============================================================ */

*, *::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:    #0f0a23;
  --bg-floor:   #14102a;
  --bg-card:    #1c1740;
  --bg-card-hi: #251e54;
  --bg-elev:    #2a2360;

  /* —— 文字 —— */
  --ink:        #f1edff;
  --ink-soft:   #b9b1e8;
  --ink-mute:   #7a73a8;
  --ink-faint:  #4d4880;

  /* —— 紫罗兰（数织主色 / 数字线索 / 网格线） —— */
  --violet:     #a78bfa;
  --violet-hi:  #c4b5fd;
  --violet-deep:#7c3aed;
  --violet-soft:rgba(167,139,250,0.18);

  /* —— 琥珀（提示/强调） —— */
  --amber:      #f59e0b;
  --amber-glow: #fbbf24;
  --amber-soft: rgba(251,191,36,0.18);

  /* —— 状态 —— */
  --ok:         #84cc16;
  --bad:        #ef4444;
  --bad-soft:   rgba(239,68,68,0.22);

  /* —— 网格 —— */
  --cell-bg:    #1a1540;
  --cell-fill:  #c4b5fd;
  --cell-mark:  #4b4576;
  --cell-grid:  rgba(167,139,250,0.18);
  --cell-grid-hi: rgba(167,139,250,0.36);

  /* —— 字体 —— */
  --font-display: 'Cormorant Garamond', 'Playfair Display', Georgia, serif;
  --font-mono:    'JetBrains Mono', 'IBM Plex Mono', 'SF Mono', Consolas, monospace;
  --font-body:    'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI',
                  'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse 60% 50% at 85% -10%, rgba(167,139,250,0.10) 0%, transparent 55%),
    radial-gradient(ellipse 50% 40% at 10% 100%, rgba(245,158,11,0.05) 0%, transparent 60%),
    var(--bg-floor);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex; flex-direction: column;
  user-select: none; -webkit-user-select: none;
  position: relative;
}
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    /* 像素点阵 */
    radial-gradient(circle at 1px 1px, rgba(167,139,250,0.10) 1px, transparent 0);
  background-size: 14px 14px;
  opacity: 0.45;
}
body > * { position: relative; z-index: 1; }

a { color: inherit; text-decoration: none; }

/* —— 主布局 —— */
main {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 60px;
}

/* ============================================================
   HERO · 像素工坊
   ============================================================ */
.head {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 18px 24px; margin-bottom: 22px;
  background: linear-gradient(135deg, rgba(167,139,250,0.10) 0%, rgba(245,158,11,0.06) 100%);
  border: 1px solid rgba(167,139,250,0.18);
  border-radius: 14px;
  position: relative;
  overflow: hidden;
}
.head::after {
  content: ''; position: absolute; inset: 0;
  background:
    repeating-linear-gradient(0deg, transparent 0 7px, rgba(167,139,250,0.04) 7px 8px),
    repeating-linear-gradient(90deg, transparent 0 7px, rgba(167,139,250,0.04) 7px 8px);
  pointer-events: none;
}
.head .left .eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--amber);
  margin-bottom: 6px;
}
.head .left h1 {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.1;
  color: var(--ink);
}
.head .left h1 .sub-floor {
  margin-left: 12px;
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
  vertical-align: middle;
}
.head .left .sub {
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}
.head .right {
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
.stars { display: inline-flex; gap: 4px; font-size: 18px; color: var(--ink-faint); }
.stars .lit { color: var(--amber); text-shadow: 0 0 8px rgba(251,191,36,0.4); }
.hero-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: 0.2em;
}

/* ============================================================
   GAME AREA · 棋盘 + 工作台
   ============================================================ */
.game-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  margin-bottom: 32px;
}

/* —— 棋盘卡片 —— */
.board-card {
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-deep) 100%);
  border: 1px solid rgba(167,139,250,0.18);
  border-radius: 14px;
  padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
}
.board-head {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.25em;
  color: var(--ink-mute);
  padding-bottom: 10px;
  border-bottom: 1px dashed rgba(167,139,250,0.18);
}
.board-head .l { color: var(--amber); }
.board-head .info b { color: var(--ink); font-weight: 700; }

.board {
  --cell-size: 36px;
  display: grid;
  gap: 0;
  padding: 6px;
  margin: 0 auto;
  background: var(--bg-card-hi);
  border-radius: 6px;
  position: relative;
}
.board.size-5  { --cell-size: 64px; }
.board.size-10 { --cell-size: 44px; }
.board.size-15 { --cell-size: 32px; }
.board.size-20 { --cell-size: 26px; }
.board.size-25 { --cell-size: 22px; }
/* 线索容器也用同样的 cell-size：行/列线索的 cell 高度/宽度需要与 board 单元对齐 */
.clues-area.size-5  { --cell-size: 64px; }
.clues-area.size-10 { --cell-size: 44px; }
.clues-area.size-15 { --cell-size: 32px; }
.clues-area.size-20 { --cell-size: 26px; }
.clues-area.size-25 { --cell-size: 22px; }

/* —— 棋盘格子 —— */
.cell {
  width: var(--cell-size); height: var(--cell-size);
  background: var(--cell-bg);
  border-right: 1px solid var(--cell-grid);
  border-bottom: 1px solid var(--cell-grid);
  position: relative;
  cursor: pointer;
  transition: background-color 0.08s ease;
}
.cell.size-5-col, .cell.size-5-row { border-color: var(--cell-grid-hi); }
.cell.thick-right { border-right: 2px solid var(--violet); }
.cell.thick-bottom { border-bottom: 2px solid var(--violet); }
.cell.filled { background: var(--cell-fill); }
.cell.filled::after {
  content: ''; position: absolute; inset: 2px;
  background: linear-gradient(135deg, rgba(255,255,255,0.18) 0%, transparent 60%);
  border-radius: 1px;
}
.cell.marked {
  background: var(--cell-bg);
}
.cell.marked::before {
  content: '×';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 800;
}
.cell.wrong { background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad); }
/* 错填格的红色样式优先级最高，避免被其他状态覆盖 */
.cell.wrong.satisfied { background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad); }
.cell.satisfied {
  background: rgba(132,204,22,0.10);
}

/* —— 线索区 —— */
.clues {
  display: grid;
  position: relative;
}
.clues-col {
  grid-row: 1 / -1;
  display: grid;
  align-items: end;
}
.clues-row {
  grid-column: 1 / -1;
  display: grid;
  align-items: end;
}
.clue-cell {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
  user-select: none;
}
.clue-cell.col { height: var(--cell-size); }
.clue-cell.row { width: var(--cell-size); }
.clue-cell .v { color: var(--violet); font-weight: 700; }
.clue-cell.done { color: var(--ink-faint); }

/* ============================================================
   RIGHT COL · 工作台
   ============================================================ */
.right-col { display: flex; flex-direction: column; gap: 14px; }

.workbench {
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-deep) 100%);
  border: 1px solid rgba(167,139,250,0.18);
  border-radius: 14px;
  overflow: hidden;
}
.workbench-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  background: rgba(167,139,250,0.06);
  border-bottom: 1px dashed rgba(167,139,250,0.18);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.25em;
  color: var(--ink-mute);
}
.workbench-head .l { color: var(--amber); }
.workbench-head .gear { color: var(--violet); cursor: pointer; }
.workbench-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.stat-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.stat {
  background: var(--bg-elev);
  border: 1px solid rgba(167,139,250,0.14);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat .l { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.2em; color: var(--ink-mute); }
.stat .v { font-size: 18px; font-weight: 700; color: var(--ink); font-family: var(--font-mono); }
.stat.timer .v { color: var(--amber); }
.stat.status.idle .v { color: var(--ink-mute); }
.stat.status.playing .v { color: var(--violet); }
.stat.status.won .v { color: var(--ok); }

.lvl-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.btn {
  background: var(--bg-elev);
  border: 1px solid rgba(167,139,250,0.20);
  color: var(--ink);
  padding: 9px 12px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover:not(:disabled) { border-color: var(--violet); background: rgba(167,139,250,0.10); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--violet) 0%, var(--violet-deep) 100%); border-color: transparent; color: #fff; }
.btn.primary:hover:not(:disabled) { box-shadow: 0 0 16px rgba(167,139,250,0.45); }

.actions { display: flex; flex-direction: column; gap: 8px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.status-info {
  background: rgba(167,139,250,0.05);
  border: 1px dashed rgba(167,139,250,0.18);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.status-info b { color: var(--ink); }
.status-info a { color: var(--amber); }
.status-info .guest { color: var(--amber); }

.keys {
  background: rgba(167,139,250,0.04);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 11px;
  color: var(--ink-mute);
  line-height: 1.8;
}
.keys kbd {
  display: inline-block;
  background: var(--bg-elev);
  border: 1px solid rgba(167,139,250,0.30);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
  margin: 0 2px;
}

/* —— 跳关横幅 —— */
.resume-banner {
  background: linear-gradient(135deg, rgba(245,158,11,0.10) 0%, rgba(167,139,250,0.10) 100%);
  border: 1px solid rgba(245,158,11,0.30);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  color: var(--ink);
}
.resume-banner .rb-icon { font-size: 16px; }
.resume-banner .rb-text { flex: 1; }
.resume-banner .rb-close {
  background: none; border: none; color: var(--ink-mute); cursor: pointer; font-size: 16px;
}

/* ============================================================
   CHAPTER · 楼层进度
   ============================================================ */
.chapter-bar {
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-deep) 100%);
  border: 1px solid rgba(167,139,250,0.18);
  border-radius: 14px;
  padding: 16px 18px;
}
.chapter-head {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.25em;
  color: var(--ink-mute);
  margin-bottom: 12px;
}
.chapter-head .l { color: var(--amber); }
.chapter-head .progress b { color: var(--ink); }

.chapter-track {
  position: relative;
  height: 56px;
  background: var(--bg-elev);
  border-radius: 8px;
  overflow: hidden;
}
.chapter-seg {
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(0deg, transparent 0 6px, rgba(167,139,250,0.06) 6px 7px);
}
.chapter-seg-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, rgba(167,139,250,0.30) 0%, rgba(245,158,11,0.30) 100%);
  transition: width 0.4s ease;
}
.chapter-nodes {
  position: absolute; inset: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 6px;
}
.chapter-node {
  position: relative;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-card-hi);
  border: 1px solid rgba(167,139,250,0.30);
  border-radius: 50%;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  transition: all 0.15s ease;
  z-index: 2;
}
.chapter-node.cleared { background: var(--violet); color: #fff; border-color: var(--violet-hi); }
.chapter-node.current { box-shadow: 0 0 0 3px rgba(245,158,11,0.40); border-color: var(--amber); color: var(--ink); font-weight: 700; }
.chapter-node.locked { opacity: 0.4; cursor: not-allowed; }
.chapter-node .floor-tag {
  position: absolute; bottom: -16px;
  font-size: 9px; color: var(--ink-mute);
  font-family: var(--font-mono);
}

/* ============================================================
   MODAL · 胜利弹窗
   ============================================================ */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(15,10,35,0.78);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
}
.modal-mask.show { display: flex; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-deep) 100%);
  border: 1px solid rgba(167,139,250,0.40);
  border-radius: 14px;
  padding: 32px 36px;
  max-width: 420px;
  text-align: center;
  position: relative;
  box-shadow: 0 24px 80px rgba(167,139,250,0.30);
}
.modal::before {
  content: ''; position: absolute; inset: -1px;
  background: linear-gradient(135deg, var(--violet) 0%, transparent 50%, var(--amber) 100%);
  border-radius: 14px;
  z-index: -1;
  opacity: 0.4;
}
.modal h2 {
  font-family: var(--font-display);
  font-size: 28px;
  margin-bottom: 6px;
  color: var(--ink);
}
.modal h2.win { color: var(--amber); }
.modal .sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.25em;
  color: var(--ink-mute);
  margin-bottom: 16px;
}
.stars-big {
  font-size: 32px;
  color: var(--ink-faint);
  letter-spacing: 6px;
  margin: 12px 0 18px;
}
.stars-big .lit { color: var(--amber); text-shadow: 0 0 12px rgba(251,191,36,0.45); }
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.15em;
  background: rgba(132,204,22,0.18);
  color: var(--ok);
  border: 1px solid var(--ok);
  margin-bottom: 16px;
}
.badge.star { background: rgba(245,158,11,0.18); color: var(--amber); border-color: var(--amber); }
.badge.guest { background: rgba(167,139,250,0.10); color: var(--violet); border-color: var(--violet); }

.result {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.result .r {
  background: var(--bg-elev);
  border-radius: 8px;
  padding: 10px;
}
.result .l { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.2em; color: var(--ink-mute); margin-bottom: 4px; }
.result .v { font-size: 18px; font-weight: 700; color: var(--ink); font-family: var(--font-mono); }

.modal .actions { display: flex; flex-direction: row; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* —— TOAST —— */
.toast {
  position: fixed; left: 50%; bottom: 36px;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  border: 1px solid rgba(167,139,250,0.30);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.40);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--ok); color: var(--ok); }

/* ============================================================
   HUD STRIP（窄屏紧凑状态条）
   ============================================================ */
.hud-strip { display: none; }

@media (max-width: 900px) {
  .game-area { grid-template-columns: 1fr; }
  .head { flex-direction: column; align-items: flex-start; gap: 12px; }
  .head .right { align-items: flex-start; }
  .right-col { order: 2; }
  .stat-row { grid-template-columns: repeat(4, 1fr); }
  .hud-strip {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
    margin-top: 10px;
  }
  .hud-strip .hs-item {
    background: var(--bg-elev);
    border: 1px solid rgba(167,139,250,0.14);
    border-radius: 6px;
    padding: 6px 10px;
    display: flex; flex-direction: column;
    font-family: var(--font-mono);
  }
  .hud-strip .hs-l { font-size: 9px; color: var(--ink-mute); letter-spacing: 0.2em; }
  .hud-strip b { font-size: 14px; color: var(--ink); }
  .hud-strip .hs-item.idle b { color: var(--ink-mute); }
  .hud-strip .hs-item.playing b { color: var(--violet); }
  .hud-strip .hs-item.won b { color: var(--ok); }
}
@media (max-width: 600px) {
  main { padding: 14px 12px 40px; }
  .head { padding: 14px; }
  .head .left h1 { font-size: 26px; }
  .board.size-5 { --cell-size: 56px; }
  .board.size-10 { --cell-size: 32px; }
  .board.size-15 { --cell-size: 22px; }
  .board.size-20 { --cell-size: 16px; }
  .board.size-25 { --cell-size: 14px; }
  /* 同步线索容器 cell-size */
  .clues-area.size-5  { --cell-size: 56px; }
  .clues-area.size-10 { --cell-size: 32px; }
  .clues-area.size-15 { --cell-size: 22px; }
  .clues-area.size-20 { --cell-size: 16px; }
  .clues-area.size-25 { --cell-size: 14px; }
}