/* ==========================================================================
   连连看 · 全局样式（浅色主题 / 卡片式三栏布局 / 响应式）
   布局说明：
     任何宽度都保持「左栏 | 棋盘区 | 右栏」三栏结构（绝不改成上/下工具条）：
       ≥1200px       侧栏 124px，图标 + 文字
       900 ~ 1199px  侧栏 96px，文字缩短
       700 ~ 899px   侧栏 64px，纯图标（title / aria-label 保留）
       < 700px       侧栏 56px，正方形图标按钮
     宽度不够时压缩侧栏，而不是换行；棋盘区永远吃掉剩余空间。
   ========================================================================== */

:root {
  --bg: #f2f5fa;
  --card: #ffffff;
  --text: #2c3a4f;
  --text-light: #7a8699;
  --primary: #4f7cff;
  --primary-dark: #3c63d8;
  --accent: #ff6d3b;
  --border: #e3e8f0;
  --danger: #ff5252;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(60, 90, 150, 0.10);

  /* 侧栏宽度与栏间距：集中控制，改这里即可整体调节 */
  --rail-w: 124px;
  --rail-gap: 12px;
  --rail-btn-h: 44px;
  --rail-font: 14px;
  --body-pad: 10px;
  --app-pad: 10px 12px 12px;
  --header-gap: 4px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(160deg, #eef2f9 0%, #e4ebf7 100%);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: var(--body-pad);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;            /* 任何宽度下都不出现横向 / 整页滚动 */
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 卡片容器 ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/*
 * 高度锁定为视口：舞台拿到确定高度，棋盘区在内部滚动，
 * 而不是让整页被棋盘撑高（放大到 150% 时尤其重要）。
 */
.app {
  width: 100%;
  max-width: none;
  min-width: 0;
  padding: var(--app-pad);
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: calc(100vh - var(--body-pad) * 2);
  height: calc(100dvh - var(--body-pad) * 2);
  overflow: hidden;
}

/* ---------- 顶部紧凑状态条（≤ 56px） ---------- */
.app-header {
  display: flex;
  flex-direction: column;
  gap: var(--header-gap);
  flex: 0 0 auto;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.app-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
  line-height: 1.2;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stat {
  font-size: 13px;
  color: var(--text-light);
  white-space: nowrap;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-left: 2px;
  font-variant-numeric: tabular-nums;
}

.combo-badge {
  background: linear-gradient(135deg, #ffb347, #ff6d3b);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
  animation: combo-pop 0.25s ease;
}

@keyframes combo-pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ---------- 倒计时进度条 ---------- */
.time-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.time-bar-track {
  flex: 1;
  height: 8px;
  background: #edf1f7;
  border-radius: 999px;
  overflow: hidden;
}

.time-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #58c97b, #4f7cff);
  border-radius: 999px;
  transition: width 0.25s linear, background 0.3s;
}

.time-bar.low {
  background: linear-gradient(90deg, #ff8f5e, #ff5252);
}

.time-text {
  min-width: 42px;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-light);
  font-variant-numeric: tabular-nums;
}

/* ---------- 三栏舞台 ---------- */
.stage {
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  gap: var(--rail-gap);
  min-width: 0;
  min-height: 0;
}

/* ---------- 侧栏（任何宽度都常驻左右两侧） ---------- */
.rail {
  flex: 0 0 var(--rail-w);
  width: var(--rail-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  padding-left: 2px;
}

.rail-select {
  width: 100%;
  min-height: 40px;
  font-size: 13px;
  padding: 8px 6px;
}

/* ---------- 缩放控件：−  100%  + ---------- */
.zoom-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
  width: 100%;
}

.zoom-btn {
  flex: 0 0 auto;
  width: 30px;
  min-height: 34px;
  font-size: 17px;
  line-height: 1;
}

.zoom-value {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 34px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  border-color: #c9d6ff;
  background: #f5f8ff;
}

/* 清零 .btn 的 8px/14px 内边距。
   注意：.btn 在本文件中声明于 .zoom-btn 之后，同权重下会覆盖 padding，
   而「内边距 + 边框 = 30px」又会成为按钮的固有小尺寸，把 width: 26px 顶回去，
   导致缩放行总宽 98px > 96px 侧栏、右侧被 .rail 的 overflow:hidden 裁掉。
   因此这里用 .btn.zoom-xxx 提升权重，确保窄断点下 26px 真正生效。 */
.btn.zoom-btn {
  padding: 0;
}

.btn.zoom-value {
  padding: 0 2px;
}

/* 下拉框同理：.btn 的 padding: 8px 14px 会盖掉 .rail-select，窄侧栏里浪费宽度 */
.btn.rail-select {
  padding: 6px 6px;
}

/* ---------- 棋盘区：吃掉剩余空间；放大后内部滚动 ---------- */
.board-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  overflow: auto;              /* 缩放到 >100% 时在棋盘区内部滚动 */
  overscroll-behavior: contain;
}

/* margin:auto 在「有富余空间」时居中，溢出时仍可向左上滚动（不像 justify-content 会裁边） */
.board-box {
  position: relative;
  line-height: 0;
  margin: auto;
}

#board {
  display: block;
  max-width: none;
  border-radius: 10px;
  background: #f7f9fd;
  border: 1px solid var(--border);
  touch-action: manipulation;
  cursor: pointer;
}

/* 暂停遮罩（对齐画布，而非整个棋盘区） */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  background: rgba(247, 249, 253, 0.92);
  border-radius: 10px;
  line-height: 1.5;
  z-index: 5;
}

.overlay[hidden] {
  display: none;
}

.overlay-icon {
  font-size: 42px;
}

.overlay-title {
  font-size: 20px;
  font-weight: 700;
}

.overlay-tip {
  font-size: 13px;
  color: var(--text-light);
}

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}

.btn:hover:not(:disabled) {
  background: #f0f4ff;
  border-color: #c9d6ff;
  box-shadow: 0 2px 8px rgba(79, 124, 255, 0.15);
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  padding: 10px 28px;
  font-size: 15px;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

/* 侧栏按钮：纵向排列、宽度占满、触控目标 ≥ 40px */
.rail-btn {
  position: relative;
  width: 100%;
  min-height: var(--rail-btn-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  font-size: var(--rail-font);
  white-space: nowrap;
}

.btn-glyph {
  font-size: 16px;
  line-height: 1;
}

.btn-name {
  line-height: 1;
}

.btn-count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}

.btn:disabled .btn-count {
  background: #b9c4d6;
}

/* ---------- 轻提示 toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 48px;
  transform: translateX(-50%) translateY(16px);
  background: rgba(44, 58, 79, 0.92);
  color: #fff;
  font-size: 14px;
  padding: 9px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 30;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- 结算面板 ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 42, 60, 0.45);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
  padding: 16px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 340px;
  padding: 28px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: modal-in 0.25s ease;
}

@keyframes modal-in {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-title {
  font-size: 24px;
}

.modal-detail {
  font-size: 15px;
  color: var(--text-light);
  line-height: 1.9;
  white-space: pre-line;
}

/* ==========================================================================
   响应式：三栏结构永不塌陷 —— 宽度不够就压缩侧栏（而不是换成上下工具条）
   ========================================================================== */

/* 900 ~ 1199px：侧栏 96px，文字缩短、字号收敛 */
@media (max-width: 1199px) {
  :root {
    --rail-w: 96px;
    --rail-gap: 10px;
    --rail-font: 12px;
    --body-pad: 8px;
    --app-pad: 8px 10px 10px;
  }

  .rail-select {
    font-size: 12px;
    padding: 8px 4px;
  }

  .btn.rail-select {
    padding: 6px 4px;
  }

  .btn-glyph {
    font-size: 15px;
  }

  .btn-count {
    min-width: 18px;
    padding: 1px 5px;
    font-size: 11px;
  }

  /* 缩放行必须完整放进 96px：26 + 4 + 值 + 4 + 26 = 96。
     min-width: 0 让 flex 项不再被 min-content 撑住。 */
  .zoom-btn {
    flex: 0 0 26px;
    width: 26px;
    min-width: 0;
  }

  .btn.zoom-value {
    padding: 0 1px;
    font-size: 11px;
  }
}

/* 700 ~ 899px：侧栏 64px 纯图标（title / aria-label 仍在） */
@media (max-width: 899px) {
  :root {
    --rail-w: 64px;
    --rail-gap: 8px;
    --rail-btn-h: 42px;
  }

  body {
    padding: 6px;
  }

  /* 只留图标与次数徽标 */
  .btn-name,
  .field-label {
    display: none;
  }

  .rail-select {
    font-size: 11px;
    padding: 6px 2px;
    min-height: 38px;
    text-align: center;
    text-overflow: clip;
  }

  /* 与 base 的 .btn.rail-select 同权重，靠声明顺序生效 */
  .btn.rail-select {
    padding: 6px 2px;
  }

  .rail-btn {
    padding: 6px 2px;
    gap: 3px;
  }

  .btn-glyph {
    font-size: 17px;
  }

  .btn-count {
    min-width: 16px;
    padding: 0 4px;
    font-size: 10px;
  }

  /* 缩放控件改为「+ / % / −」三段纵排，64px 也能按准 */
  .zoom-row {
    flex-direction: column;
  }

  .zoom-btn,
  .zoom-value {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
    min-height: 26px;
    font-size: 11px;
  }

  .zoom-btn {
    font-size: 16px;
  }
}

/* < 700px：侧栏 56px，正方形图标按钮 */
@media (max-width: 699px) {
  :root {
    --rail-w: 56px;
    --rail-gap: 6px;
    --rail-btn-h: 48px;
  }

  body {
    padding: 4px;
  }

  .app {
    padding: 6px 6px 8px;
    gap: 6px;
  }

  .app-title {
    font-size: 16px;
  }

  .stat {
    font-size: 12px;
  }

  .stat-value {
    font-size: 14px;
  }

  .rail {
    gap: 6px;
  }

  .rail-select {
    min-height: 36px;
    font-size: 10px;
    padding: 4px 1px;
  }

  .btn.rail-select {
    padding: 4px 1px;
  }

  /* 正方形图标按钮，次数徽标挂在右上角 */
  .rail-btn {
    width: var(--rail-btn-h);
    height: var(--rail-btn-h);
    min-height: var(--rail-btn-h);
    margin: 0 auto;
    padding: 0;
    border-radius: 12px;
  }

  .btn-glyph {
    font-size: 20px;
  }

  .btn-count {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 16px;
    padding: 0 4px;
    font-size: 10px;
    line-height: 1.5;
  }

  .zoom-btn,
  .zoom-value {
    min-height: 24px;
    font-size: 10px;
    border-radius: 8px;
  }

  .zoom-btn {
    font-size: 15px;
  }

  .toast {
    bottom: 24px;
    font-size: 13px;
  }
}

/* 高度很小的横屏（如 1280×600）：进一步压缩顶栏，把高度留给棋盘 */
@media (max-height: 640px) {
  .app-title {
    font-size: 16px;
  }

  .app-header {
    gap: 2px;
  }

  .time-bar-track {
    height: 6px;
  }

  .rail {
    gap: 6px;
  }

  .field {
    gap: 2px;
  }
}

/* ---------- 结算面板弹入动画（通关特效配套，独立 class，不改动 .modal 原有行为） ---------- */
.modal-pop {
  animation: modal-pop-in 260ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes modal-pop-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* 用户要求减少动态效果时，面板只做显隐、不做弹入 */
@media (prefers-reduced-motion: reduce) {
  .modal-pop {
    animation: none;
  }
}

/* ---------- 关卡系统（聚合玩法） ---------- */

/* 关卡下拉框：用蓝色描边与「难度」等普通设置区分，短标签在 56px 侧栏里也能读 */
#level.rail-select {
  border-color: #a9bfff;
  background: #f3f7ff;
  color: #2c4fb0;
  font-weight: 700;
}

/* 结算面板双按钮：重玩本关 / 下一关 */
.modal-actions {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-actions .btn {
  flex: 1 1 120px;
  min-width: 0;
}

.modal-actions .btn.primary {
  padding: 10px 12px;
  font-size: 14px;
}

/* ---------- 下拉框文字居中（难度 / 皮肤 / 关卡） ---------- */
/* text-align-last 让「选中后收起」的显示值也居中（Chrome/Edge/Firefox 支持） */
.rail-select {
  text-align: center;
  text-align-last: center;
}
.rail-select option {
  text-align: center; /* 展开列表的选项文字（支持的浏览器生效） */
}

/* hidden 属性全局兜底：任何元素带 hidden 都必须真正不占位，
   防止 .btn{display:flex} 这类作者样式压过 UA 的 [hidden]{display:none}，
   出现「按钮看着在、点了没反应」的假象 */
[hidden] {
  display: none !important;
}

/* ---------- 开局机器自检遮罩（关卡门禁） ---------- */

.verify-overlay {
  background: rgba(247, 249, 253, 0.96);
  cursor: default;
}

.verify-dots {
  display: flex;
  gap: 7px;
  margin-bottom: 4px;
}

.verify-dots i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--primary);
  animation: verify-pulse 0.9s ease-in-out infinite;
}

.verify-dots i:nth-child(2) { animation-delay: 0.15s; }
.verify-dots i:nth-child(3) { animation-delay: 0.30s; }

@keyframes verify-pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1); }
}

.verify-track {
  width: min(220px, 70%);
  height: 7px;
  margin-top: 6px;
  border-radius: 999px;
  background: #e6ecf8;
  overflow: hidden;
}

.verify-bar {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #58c97b, #4f7cff);
  transition: width 0.18s ease;
}

.verify-overlay.pass .verify-dots i {
  animation: none;
  opacity: 1;
  background: #3fa96b;
}

@media (prefers-reduced-motion: reduce) {
  .verify-dots i { animation: none; opacity: 1; }
  .verify-bar { transition: none; }
}

/* ------------------------------------------------------------------
   多人对战（网页版专属）
   ------------------------------------------------------------------ */

/* 多人对战切换时隐藏右栏按钮：.btn 有显式 display，hidden 需兜底 */
.rail .btn[hidden] {
  display: none;
}

/* 对战入口按钮（离线 exe / file:// 下由 JS 隐藏） */
.mp-entry .btn-glyph { font-size: 1.05em; }

.mp-modal {
  width: min(430px, 92vw);
}

.mp-tip {
  margin: 2px 0 12px;
  font-size: 12.5px;
  line-height: 1.7;
  color: #66738c;
}

.mp-entry-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

/* 固定房间（浪浪山 / 巴厘岛）一键进入 */
.mp-rooms {
  display: flex;
  gap: 8px;
  margin: 10px 0 4px;
}
.mp-room-btn {
  flex: 1;
  min-height: 44px;
  font-size: 15px;
  font-weight: 700;
  border-color: #a9bfff;
  background: #f3f7ff;
  color: #2c4fb0;
}
.mp-room-btn .btn-glyph {
  margin-right: 4px;
}
.mp-room-btn:hover {
  background: #e3edff;
}
.mp-rooms-tip {
  margin: 0 0 8px;
  font-size: 12px;
  color: #8a97ad;
  text-align: center;
}
.mp-rooms-tip b {
  color: #2c4fb0;
}

.mp-code-input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-align: center;
  text-transform: uppercase;
  color: #233047;
  background: #fff;
  border: 1.5px solid #ccd6ea;
  border-radius: 10px;
  outline: none;
}

.mp-code-input:focus {
  border-color: var(--primary);
}

.mp-pass-input {
  width: 100%;
  margin-bottom: 6px;
  padding: 8px 12px;
  font-size: 13px;
  color: #233047;
  background: #fff;
  border: 1.5px solid #ccd6ea;
  border-radius: 10px;
  outline: none;
  box-sizing: border-box;
}

.mp-pass-input:focus {
  border-color: var(--primary);
}

.mp-error {
  margin: 6px 0 0;
  font-size: 12px;
  color: #c4372f;
}

.mp-room-code {
  margin-bottom: 10px;
  font-size: 13px;
  color: #66738c;
}

.mp-room-code b {
  margin-left: 4px;
  font-size: 20px;
  letter-spacing: 0.3em;
  color: #233047;
}

/* 4 把椅子 */
.mp-chairs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.mp-chair {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  color: #66738c;
  background: #f3f6fc;
  border: 1.5px dashed #c6d2e8;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.mp-chair:hover:not(.taken) {
  border-color: var(--primary);
  background: #eef3fd;
}

.mp-chair .mp-chair-icon {
  font-size: 20px;
  line-height: 1;
}

.mp-chair .mp-chair-name {
  flex: 1;
  text-align: left;
  font-weight: 600;
}

.mp-chair.taken {
  border-style: solid;
  border-color: transparent;
  color: #fff;
  cursor: default;
}

.mp-chair.taken.mine {
  box-shadow: 0 0 0 2px #233047 inset;
}

.mp-level-field {
  margin-bottom: 8px;
}

/* 关卡 + 难度并排 */
.mp-field-row {
  display: flex;
  gap: 10px;
}

.mp-field-row .mp-level-field {
  flex: 1;
  min-width: 0;
}

.mp-field-row .select {
  width: 100%;
}

.mp-skin-tip {
  margin-top: 0;
}

.mp-status {
  margin: 0 0 10px;
  font-size: 12.5px;
  line-height: 1.6;
  color: #66738c;
  min-height: 1.6em;
}

/* 对局中的记分板（棋盘区顶部悬浮） */
.mp-hud {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #dfe7f5;
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(35, 48, 71, 0.08);
}

.mp-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  border-radius: 999px;
  white-space: nowrap;
}

.mp-chip.dim {
  opacity: 0.45;
}

.mp-chip.me {
  box-shadow: 0 0 0 2px #233047;
}

.mp-hud .mp-exit {
  padding: 2px 8px;
  font: inherit;
  font-size: 11.5px;
  color: #66738c;
  background: transparent;
  border: 1px solid #ccd6ea;
  border-radius: 999px;
  cursor: pointer;
}

.mp-hud .mp-exit:hover {
  color: #c4372f;
  border-color: #e5a09b;
}

@media (max-width: 560px) {
  .mp-hud {
    flex-wrap: wrap;
    justify-content: center;
    max-width: calc(100% - 12px);
    border-radius: 14px;
  }
}

