:root {
  --bg-page: #f5efe6;
  --bg-card: #fffdf9;
  --text-main: #2d2319;
  --text-muted: #786655;
  --board-frame: #8b5a2b;
  --board-frame-shadow: #5c3a1a;
  --board-surface: #e6ccb2;
  --cell-bg: #f3e1ce;
  --cell-border: #d2b494;
  --cell-text: #4a3525;
  --target-bg: #ffefb8;
  --target-border: #f59e0b;
  --target-text: #b45309;
  --accent: #d97706;
  --accent-hover: #b45309;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --cell-size: 56px;
  --cell-gap: 4px;
  --board-pad: 8px;
  --radius-lg: 16px;
  --radius-md: 10px;
}

body[data-theme="modern"] {
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --board-frame: #1e293b;
  --board-frame-shadow: #0f172a;
  --board-surface: #334155;
  --cell-bg: #475569;
  --cell-border: #64748b;
  --cell-text: #f8fafc;
  --target-bg: #fef08a;
  --target-border: #eab308;
  --target-text: #854d0e;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior-y: contain;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.app-container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mobile-only-btn {
  display: none !important;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  padding: 14px 20px;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  flex-wrap: wrap;
  gap: 12px;
}

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

.brand-icon {
  font-size: 32px;
  line-height: 1;
}

.brand h1 {
  font-size: 20px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge {
  font-size: 12px;
  font-weight: 600;
  background: rgba(217, 119, 6, 0.14);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 999px;
}

.subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Control Bar */
.control-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  padding: 12px 18px;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  flex-wrap: wrap;
  gap: 14px;
}

.date-selector-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}

.target-display {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 10px;
  border-right: 1px solid rgba(120, 102, 85, 0.2);
}

.target-label {
  font-size: 14px;
  font-weight: 700;
}

.target-pill {
  padding: 4px 11px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 14px;
  background: var(--target-bg);
  border: 2px solid var(--target-border);
  color: var(--target-text);
  box-shadow: 0 2px 4px rgba(245, 158, 11, 0.2);
}

.date-pickers {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.picker-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.divider {
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 2px;
}

input[type="date"],
select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(120, 102, 85, 0.3);
  background: var(--bg-page);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.stats-and-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-page);
  padding: 5px 12px;
  border-radius: 10px;
  min-width: 72px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
}

.stat-value {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.status-tag {
  font-size: 13px;
  color: var(--accent);
}

.status-tag.valid {
  color: var(--success);
}

.status-tag.deadend {
  color: var(--danger);
}

/* Buttons */
.btn {
  border: none;
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.95);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

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

.btn-accent {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.3);
}

.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: rgba(120, 102, 85, 0.13);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(120, 102, 85, 0.22);
}

.btn-danger {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(220, 38, 38, 0.22);
}

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(120, 102, 85, 0.25);
  color: var(--text-main);
}

.btn-ghost:hover {
  background: rgba(120, 102, 85, 0.1);
}

/* Workspace Layout */
.game-workspace {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 20px;
  align-items: start;
}

/* Board Section */
.board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.board-frame {
  background: var(--board-frame);
  padding: 14px;
  border-radius: 20px;
  box-shadow:
    0 8px 0 var(--board-frame-shadow),
    0 14px 28px rgba(0, 0, 0, 0.22),
    inset 0 2px 4px rgba(255, 255, 255, 0.25);
}

.puzzle-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, var(--cell-size));
  grid-template-rows: repeat(8, var(--cell-size));
  gap: var(--cell-gap);
  background: var(--board-surface);
  padding: var(--board-pad);
  border-radius: 12px;
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.28);
  touch-action: manipulation;
}

.board-cell {
  position: relative;
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 8px;
  background: var(--cell-bg);
  border: 1px solid var(--cell-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--cell-text);
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.5);
}

.board-cell:active:not(.cell-wall):not(.is-target) {
  transform: scale(0.93);
  background: rgba(37, 99, 235, 0.15);
}

.board-cell.cell-wall {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  pointer-events: none;
}

.board-cell .cell-main {
  font-size: 13px;
  line-height: 1.1;
}

.board-cell .cell-sub {
  font-size: 10px;
  opacity: 0.65;
  margin-top: 1px;
}

/* Target Date Cell Highlight */
.board-cell.is-target {
  background: var(--target-bg);
  border: 2.5px solid var(--target-border);
  color: var(--target-text);
  box-shadow:
    0 0 12px rgba(245, 158, 11, 0.55),
    inset 0 0 6px rgba(245, 158, 11, 0.25);
  z-index: 2;
  animation: pulse-target 2.2s infinite ease-in-out;
}

.board-cell.is-target::after {
  content: "🎯";
  position: absolute;
  top: 1px;
  right: 1px;
  font-size: 10px;
  line-height: 1;
}

@keyframes pulse-target {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
}

/* Placed Piece Cell Overlay on Board */
.placed-cell {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 7px;
  z-index: 5;
  cursor: grab;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, 0.45),
    inset 0 -3px 4px rgba(0, 0, 0, 0.22),
    0 3px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.placed-cell:hover {
  filter: brightness(1.08);
}

.placed-cell.selected-on-board {
  outline: 3px solid #ffffff;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.45);
  z-index: 7;
}

/* Ghost Preview on Board */
.preview-cell {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 7px;
  z-index: 8;
  pointer-events: none;
  transition: all 0.06s ease;
}

.preview-cell.valid {
  background: rgba(34, 197, 94, 0.55);
  border: 2px dashed #15803d;
}

.preview-cell.invalid {
  background: rgba(239, 68, 68, 0.5);
  border: 2px dashed #b91c1c;
}

.board-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  width: 100%;
}

/* Solutions Explorer Bar */
.solutions-bar {
  width: 100%;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.1), rgba(217, 119, 6, 0.12));
  border: 1px solid rgba(37, 99, 235, 0.28);
  padding: 8px 12px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.solutions-info {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.solutions-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Right Dock Section */
.dock-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.inspector-card,
.pieces-dock-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

.inspector-header,
.dock-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 6px;
}

.inspector-header h3,
.dock-header h3 {
  font-size: 15px;
  font-weight: 800;
}

.shortcut-tip,
.dock-subtip {
  font-size: 12px;
  color: var(--text-muted);
}

kbd {
  background: var(--bg-page);
  border: 1px solid rgba(120, 102, 85, 0.35);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 700;
}

.inspector-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.selected-preview {
  min-width: 120px;
  min-height: 92px;
  background: var(--bg-page);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  flex: 1;
  cursor: pointer;
}

.empty-tip {
  font-size: 12px;
  color: var(--text-muted);
}

.transform-buttons {
  display: flex;
  gap: 8px;
}

/* Pieces Dock Grid */
.pieces-dock {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 10px;
}

.dock-piece-item {
  background: var(--bg-page);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 8px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: grab;
  position: relative;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  touch-action: none;
}

.dock-piece-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.08);
}

.dock-piece-item.selected {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.09);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.dock-piece-item.is-placed {
  opacity: 0.35;
  cursor: pointer;
}

.dock-piece-item .piece-tag {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
}

.dock-piece-item .placed-badge {
  position: absolute;
  bottom: 4px;
  font-size: 10px;
  color: var(--success);
  font-weight: 700;
}

/* Mini Polyomino Grid inside Dock / Preview */
.mini-polyomino {
  display: grid;
  gap: 2px;
  pointer-events: none;
}

.mini-cell {
  width: 20px;
  height: 20px;
  border-radius: 4px;
}

.mini-cell.filled {
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.4),
    inset 0 -2px 2px rgba(0, 0, 0, 0.2);
}

/* Drag Ghost Floating Layer */
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 9999;
  display: grid;
  gap: var(--cell-gap);
  opacity: 0.92;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.38));
}

.drag-ghost-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 7px;
}

.drag-ghost-cell.filled {
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, 0.5),
    inset 0 -3px 4px rgba(0, 0, 0, 0.25);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-card {
  background: var(--bg-card);
  color: var(--text-main);
  max-width: 500px;
  width: 100%;
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  animation: modal-pop 0.22s ease-out;
  max-height: 90dvh;
  overflow-y: auto;
}

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

.victory-card {
  text-align: center;
}

.confetti-icon {
  font-size: 48px;
  margin-bottom: 6px;
}

.victory-stats {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin: 16px 0;
  padding: 12px;
  background: var(--bg-page);
  border-radius: 12px;
}

.victory-stats div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.victory-stats span {
  font-size: 12px;
  color: var(--text-muted);
}

.victory-stats strong {
  font-size: 20px;
  color: var(--accent);
}

.help-list {
  margin: 14px 0 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13.5px;
  line-height: 1.55;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.hidden {
  display: none !important;
}

/* ==================== 手机端与平板响应式深度适配 ==================== */
@media (max-width: 960px) {
  .game-workspace {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 10px;
  }
  .dock-section {
    width: 100%;
    gap: 10px;
  }
}

@media (max-width: 768px) {
  :root {
    /* 自适应手机屏幕宽度：7列棋盘自动撑满且绝不横向溢出 */
    --cell-size: clamp(36px, calc((100vw - 52px) / 7), 46px);
    --cell-gap: 3px;
    --board-pad: 6px;
  }

  .app-container {
    padding: 8px 8px 20px;
    gap: 8px;
  }

  .mobile-only-btn {
    display: inline-flex !important;
  }

  /* 精简手机端顶部栏 */
  .app-header {
    padding: 8px 12px;
    border-radius: 12px;
    gap: 8px;
  }

  .brand-icon {
    font-size: 22px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .badge,
  .subtitle {
    display: none;
  }

  .header-actions .btn {
    padding: 5px 9px;
    font-size: 12px;
  }

  /* 精简目标日期与状态栏 */
  .control-bar {
    padding: 8px 12px;
    border-radius: 12px;
    gap: 8px;
  }

  .target-display {
    border-right: none;
    padding-right: 0;
  }

  .target-label {
    font-size: 12px;
  }

  .target-pill {
    padding: 2px 8px;
    font-size: 12px;
  }

  /* 手机端默认收起复杂的日期下拉框，点击“📅 换日期”才展开 */
  .date-pickers {
    display: none;
    width: 100%;
    padding-top: 8px;
    border-top: 1px dashed rgba(120, 102, 85, 0.25);
  }

  .date-pickers.mobile-open {
    display: flex;
  }

  .stats-and-tools {
    gap: 6px;
    margin-left: auto;
  }

  .stat-box {
    padding: 3px 8px;
    min-width: 54px;
    border-radius: 8px;
  }

  .stat-label {
    font-size: 10px;
  }

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

  .board-frame {
    padding: 8px;
    border-radius: 14px;
    box-shadow:
      0 5px 0 var(--board-frame-shadow),
      0 8px 18px rgba(0, 0, 0, 0.18);
  }

  .board-cell .cell-main {
    font-size: 11.5px;
  }

  .board-cell .cell-sub {
    font-size: 8.5px;
    margin-top: 0;
  }

  .board-toolbar .btn {
    padding: 6px 10px;
    font-size: 12px;
    flex: 1 1 auto;
  }

  /* 手机端紧凑型旋转操作条 */
  .inspector-card {
    padding: 8px 12px;
    border-radius: 12px;
  }

  .inspector-header {
    margin-bottom: 6px;
  }

  .inspector-header h3 {
    font-size: 13px;
  }

  .shortcut-tip {
    font-size: 11px;
  }

  .inspector-body {
    flex-wrap: nowrap;
    gap: 8px;
  }

  .selected-preview {
    min-width: 80px;
    min-height: 62px;
    padding: 6px;
  }

  .transform-buttons {
    display: flex;
    flex-direction: row;
    gap: 6px;
  }

  .transform-buttons .btn {
    padding: 10px 12px;
    font-size: 12.5px;
  }

  /* 手机端 10 个拼图块采用 5列×2行 紧凑网格，一屏尽收眼底 */
  .pieces-dock-card {
    padding: 8px 10px;
    border-radius: 12px;
  }

  .dock-header {
    margin-bottom: 6px;
  }

  .dock-header h3 {
    font-size: 13px;
  }

  .dock-subtip {
    font-size: 11px;
  }

  .pieces-dock {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }

  .dock-piece-item {
    min-height: 68px;
    padding: 4px;
    border-radius: 9px;
  }

  .dock-piece-item .piece-tag {
    top: 2px;
    left: 4px;
    font-size: 9px;
  }

  .dock-piece-item .placed-badge {
    bottom: 2px;
    font-size: 9px;
  }
}
