/* ============================================================
   apps/pegsolitaire.html 样式 · 紫罗兰柔雾磨砂
   - 主题：浅紫渐变背景 / 紫罗兰主色 / 钉色 #7c3aed / 空孔 #ede9fe
   - 与 hanoi 紫罗兰主题共享"明亮轻量"差异化定位
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body { min-height: 100%; }

:root {
  /* 紫罗兰主色 + 辅助 */
  --primary:        #6d28d9;
  --primary-soft:   #a78bfa;
  --primary-deep:   #4c1d95;
  --primary-fade:   rgba(109, 40, 217, 0.10);

  /* 钉 + 空孔颜色 */
  --peg:            #7c3aed;
  --peg-deep:       #5b21b6;
  --peg-glow:       rgba(124, 58, 237, 0.45);
  --hole:           #ede9fe;
  --hole-border:    rgba(109, 40, 217, 0.18);

  /* 选中态黄色环 */
  --select-ring:    #f59e0b;
  --select-glow:    rgba(245, 158, 11, 0.55);

  /* 提示高亮 */
  --hint-from:      #fbbf24;
  --hint-to:        #34d399;

  /* 背景 / 浅紫灰台面 */
  --bg-page-1:      #f8f5ff;
  --bg-page-2:      #f0e9ff;
  --surface:        #ffffff;
  --surface-soft:   rgba(255, 255, 255, 0.78);
  --surface-border: rgba(109, 40, 217, 0.10);
  --board-bg:       #f5f3ff;
  --board-border:   rgba(109, 40, 217, 0.16);

  /* 文字 */
  --text:           #2b2440;
  --text-soft:      #5b5478;
  --text-mute:      #8b85a3;
  --text-hint:      #b8b3cf;

  /* 状态 */
  --success:        #10b981;
  --warn:           #f59e0b;
  --danger:         #ef4444;

  /* 阴影 */
  --shadow-card:    0 8px 24px rgba(109, 40, 217, 0.10);
  --shadow-soft:    0 2px 6px rgba(76, 29, 149, 0.08);
  --shadow-deep:    0 12px 32px rgba(76, 29, 149, 0.16);

  /* 字体 */
  --font-body:      'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC',
                    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

body {
  background:
    radial-gradient(ellipse 70% 50% at 50% -5%, rgba(167, 139, 250, 0.18) 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-page-1) 0%, var(--bg-page-2) 100%);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }

/* ============================================================
   布局
   ============================================================ */

.back-link-wrap {
  max-width: 1200px;
  width: 100%;
  margin: 12px auto 0;
  padding: 0 16px;
}
.back-link {
  display: inline-block;
  color: var(--text-soft);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background-color 0.18s ease;
}
.back-link:hover { background-color: var(--primary-fade); color: var(--primary); }

main {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 16px 32px;
  flex: 1;
}

/* HERO */
.head { text-align: center; margin: 16px 0 20px; }
.head .eyebrow {
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--primary);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.head h1 {
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}
.head .sub {
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.6;
  max-width: 640px;
  margin: 0 auto;
}

/* ============================================================
   游戏区
   ============================================================ */

.game-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  align-items: start;
}

@media (max-width: 880px) {
  .game-area { grid-template-columns: 1fr; }
}

.board-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow-card);
}

.board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-soft);
  letter-spacing: 0.04em;
}
.board-head .l {
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--primary);
  text-transform: uppercase;
}
.board-head .info { font-size: 12px; }
.board-head .info b {
  color: var(--primary-deep);
  font-weight: 700;
  margin: 0 2px;
}

/* ============================================================
   棋盘（English Cross 33 孔，CSS Grid 7×7）
   ============================================================ */

.board {
  --cell-size: clamp(46px, 8.5vw, 76px);
  display: grid;
  grid-template-columns: repeat(7, var(--cell-size));
  grid-template-rows: repeat(7, var(--cell-size));
  gap: 4px;
  padding: 16px;
  background: var(--board-bg);
  border-radius: 14px;
  border: 1px solid var(--board-border);
  margin: 0 auto;
  width: fit-content;
  max-width: 100%;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: default;
  transition: transform 0.15s ease;
}
.cell:focus-visible {
  outline: 2px solid var(--primary-soft);
  outline-offset: 2px;
  border-radius: 6px;
}

/* 钉 */
.peg {
  width: 76%;
  height: 76%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #a78bfa 0%, var(--peg) 55%, var(--peg-deep) 100%);
  box-shadow:
    0 2px 6px rgba(76, 29, 149, 0.35),
    inset 0 -2px 4px rgba(91, 33, 182, 0.4),
    inset 0 2px 4px rgba(255, 255, 255, 0.25);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.peg:hover {
  transform: scale(1.08);
  box-shadow:
    0 4px 12px var(--peg-glow),
    inset 0 -2px 4px rgba(91, 33, 182, 0.4),
    inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

/* 选中态：黄色环 + box-shadow 加深 */
.peg.is-selected {
  transform: scale(1.1);
  box-shadow:
    0 0 0 2px var(--select-ring),
    0 0 14px var(--select-glow),
    0 4px 12px var(--peg-glow),
    inset 0 -2px 4px rgba(91, 33, 182, 0.4);
  animation: peg-pulse 1.5s ease-in-out infinite;
}

@keyframes peg-pulse {
  0%, 100% {
    box-shadow:
      0 0 0 2px var(--select-ring),
      0 0 14px var(--select-glow),
      0 4px 12px var(--peg-glow),
      inset 0 -2px 4px rgba(91, 33, 182, 0.4);
  }
  50% {
    box-shadow:
      0 0 0 2px var(--select-ring),
      0 0 22px var(--select-glow),
      0 4px 14px var(--peg-glow),
      inset 0 -2px 4px rgba(91, 33, 182, 0.4);
  }
}

/* 提示起点：金色环 */
.peg.is-hint-source {
  box-shadow:
    0 0 0 3px var(--hint-from),
    0 0 18px rgba(251, 191, 36, 0.55),
    inset 0 -2px 4px rgba(91, 33, 182, 0.4);
  animation: hint-source-pulse 1.2s ease-in-out infinite;
}

@keyframes hint-source-pulse {
  0%, 100% { transform: scale(1.05); }
  50% { transform: scale(1.15); }
}

/* 空孔 */
.hole {
  width: 56%;
  height: 56%;
  border-radius: 50%;
  background: var(--hole);
  border: 1px solid var(--hole-border);
  cursor: pointer;
  transition: all 0.18s ease;
  position: relative;
}
.hole.is-target {
  background: rgba(167, 139, 250, 0.45);
  border: 1px solid var(--primary-soft);
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.35);
  animation: target-pulse 1.2s ease-in-out infinite;
}

@keyframes target-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 12px rgba(124, 58, 237, 0.35);
  }
  50% {
    transform: scale(1.18);
    box-shadow: 0 0 20px rgba(124, 58, 237, 0.55);
  }
}

/* 提示目标空孔 */
.hole.is-hint-target {
  background: rgba(52, 211, 153, 0.55);
  border: 2px solid var(--hint-to);
  box-shadow: 0 0 18px rgba(52, 211, 153, 0.55);
  animation: hint-target-pulse 1s ease-in-out infinite;
}

@keyframes hint-target-pulse {
  0%, 100% {
    transform: scale(1.1);
    box-shadow: 0 0 18px rgba(52, 211, 153, 0.55);
  }
  50% {
    transform: scale(1.25);
    box-shadow: 0 0 24px rgba(52, 211, 153, 0.75);
  }
}

/* 中心孔强调 */
.cell.is-center .hole {
  border: 1px dashed rgba(109, 40, 217, 0.35);
}
.cell.is-center .hole::after {
  content: '✦';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(109, 40, 217, 0.35);
  font-size: 14px;
  font-weight: 700;
}

/* 抖动 */
.cell.cell-shake { animation: shake 0.4s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ============================================================
   HUD 紧凑条（移动端）
   ============================================================ */

.hud-strip {
  display: none;
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface-soft);
  border-radius: 10px;
  gap: 8px;
  justify-content: space-between;
}
.hs-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.hs-l { font-size: 10px; color: var(--text-mute); letter-spacing: 0.08em; }
.hs-item b { font-size: 14px; color: var(--primary-deep); font-weight: 700; }

@media (max-width: 880px) {
  .hud-strip { display: flex; }
}

/* ============================================================
   工作台
   ============================================================ */

.workbench {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.workbench-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--primary);
  text-transform: uppercase;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--surface-border);
}
.workbench-head .gear { color: var(--text-mute); font-size: 14px; }

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat {
  background: var(--surface-soft);
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat .l {
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--text-mute);
  text-transform: uppercase;
}
.stat .v {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.stat .v small {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-mute);
  margin-left: 2px;
}
.stat.is-time .v { color: var(--primary); }
.stat.is-best .v { color: var(--success); }

/* 按钮 */
.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.btn {
  flex: 1;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--primary-fade);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
}
.btn:hover:not(:disabled) {
  background: var(--primary-fade);
  border-color: var(--primary-soft);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff;
  border: none;
}
.btn.primary:hover:not(:disabled) {
  box-shadow: 0 4px 12px rgba(109, 40, 217, 0.35);
  transform: translateY(-1px);
}

/* 状态条 */
.status-info {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface-soft);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.6;
  border-left: 3px solid var(--primary-soft);
}
.status-info.is-hint { border-left-color: var(--hint-from); background: rgba(251, 191, 36, 0.08); }
.status-info.is-win { border-left-color: var(--success); background: rgba(16, 185, 129, 0.08); }
.status-info.is-fail { border-left-color: var(--danger); background: rgba(239, 68, 68, 0.08); }
.status-info.is-demo { border-left-color: var(--hint-to); background: rgba(52, 211, 153, 0.08); }

/* ============================================================
   玩法说明
   ============================================================ */

.legend {
  margin-top: 16px;
}
.legend-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: var(--shadow-soft);
}
.legend-card .l {
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--primary);
  text-transform: uppercase;
  margin-bottom: 12px;
}
.legend-card ol {
  list-style: decimal;
  padding-left: 24px;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.8;
}
.legend-card strong { color: var(--primary-deep); }

/* ============================================================
   Modal
   ============================================================ */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 41, 0.55);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal-mask.is-open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 18px;
  padding: 28px 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-deep);
  animation: modal-in 0.3s ease;
}
.modal.fail { border-top: 3px solid var(--danger); }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.modal.fail h2 { color: var(--danger); }
.modal .sub {
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 16px;
}
.modal .rating {
  display: inline-block;
  padding: 4px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.rating.optimal { background: rgba(16, 185, 129, 0.12); color: var(--success); }
.rating.good    { background: rgba(245, 158, 11, 0.12); color: var(--warn); }
.rating.normal  { background: rgba(139, 132, 163, 0.12); color: var(--text-mute); }

.stars-big {
  font-size: 28px;
  letter-spacing: 0.1em;
  color: var(--select-ring);
  margin-bottom: 16px;
}

.result {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.result .r {
  background: var(--surface-soft);
  border-radius: 10px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.result .r .l { font-size: 10px; color: var(--text-mute); letter-spacing: 0.08em; }
.result .r .v { font-size: 18px; font-weight: 700; color: var(--text); }
.result .r.is-opt .v { color: var(--primary); }

.modal .actions {
  display: flex;
  gap: 8px;
}

/* ============================================================
   Toast
   ============================================================ */

.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-deep);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 999;
  border: 1px solid var(--surface-border);
  max-width: 90%;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.warn  { border-color: var(--warn);   color: var(--warn); }

/* ============================================================
   响应式
   ============================================================ */

@media (max-width: 480px) {
  .board { --cell-size: clamp(36px, 11vw, 56px); gap: 2px; padding: 8px; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .stat .v { font-size: 16px; }
  .modal { padding: 22px 18px; }
  .modal h2 { font-size: 20px; }
  .result { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .result .r .v { font-size: 14px; }
}