:root {
  --bg: #ffe4f0;
  --bg2: #ffd6ea;
  --card: #ffffff;
  --ink: #3b2348;
  --muted: #9b7aad;
  --line: #93c5fd;
  --grid-line: #7dd3fc;
  --pink: #f472b6;
  --pink-deep: #ec4899;
  --purple: #a855f7;
  --soft: #fce7f3;
  --obstacle: #9ca3af;
  --obstacle-edge: #6b7280;
  --shadow: 0 12px 32px rgba(236, 72, 153, 0.18);
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 10%, #ffc2e0 0%, transparent 50%),
    radial-gradient(ellipse at 80% 90%, #fbcfe8 0%, transparent 45%),
    linear-gradient(165deg, var(--bg), var(--bg2));
}

body {
  display: flex;
  justify-content: center;
  padding: 20px 12px 40px;
}

.app {
  width: min(960px, 100%);
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  border: 2px solid #f9a8d4;
  overflow: hidden;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 8px;
  background: linear-gradient(180deg, #fff5fb, #fff);
  border-bottom: 1px solid #fce7f3;
  position: relative;
}

.header img {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
}

.header h1 {
  margin: 0;
  font-size: clamp(18px, 3.2vw, 26px);
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #2563eb;
  text-align: center;
}


.score-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 6px 16px 12px;
}

.btn-op-log {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #ec4899, #a855f7);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: filter 0.15s, transform 0.1s, box-shadow 0.15s;
}

.btn-op-log:hover { filter: brightness(1.05); }
.btn-op-log:active { transform: scale(0.98); }
.btn-op-log[aria-expanded="true"] {
  box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.28);
}

.op-log-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #1e1b4b;
  color: #fde047;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

/* 文档流抽屉：在操作按钮下方展开，绝不盖住左侧选块 / 中间棋盘 */
.op-log-drawer {
  margin: 0 18px 4px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transform: translateY(-6px);
  pointer-events: none;
  transition:
    max-height 0.28s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.2s ease,
    transform 0.22s ease,
    margin-bottom 0.2s ease;
}

.op-log-drawer.open {
  max-height: 280px;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  margin-bottom: 10px;
}

.op-log-panel-inner {
  background: #fff7fb;
  border: 2px solid #f9a8d4;
  border-radius: 14px;
  padding: 10px 10px 8px;
  box-shadow: 0 8px 20px rgba(236, 72, 153, 0.12);
}

.place-log-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  padding: 0 4px;
}

.place-log-head h2 {
  margin: 0;
  font-size: 14px;
  color: var(--pink-deep);
}

.place-log-sub {
  font-size: 11px;
  color: var(--muted);
}

.op-log-table-wrap {
  max-height: 200px;
  overflow-y: auto;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.65);
}

.op-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.op-log-table th,
.op-log-table td {
  padding: 6px 10px;
  text-align: left;
}

.op-log-table thead th {
  position: sticky;
  top: 0;
  background: #fce7f3;
  color: #9d174d;
  font-size: 12px;
  font-weight: 700;
  z-index: 1;
}

.op-log-table tbody tr:nth-child(odd) {
  background: rgba(255, 255, 255, 0.75);
}

.op-log-table .pl-time {
  font-variant-numeric: tabular-nums;
  color: #6b21a8;
  font-weight: 600;
  white-space: nowrap;
  width: 1%;
}

.op-log-table .pl-cells { color: #be185d; font-weight: 700; }
.op-log-table .pl-restart { color: #64748b; font-weight: 700; }
.op-log-table .pl-undo { color: #db2777; font-weight: 700; }
.op-log-table .pl-mode { color: #7c3aed; font-weight: 700; }

.op-log-table .pl-empty td {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 14px 8px;
}

.score {
  background: #1e1b4b;
  color: #fde047;
  font-weight: 700;
  font-size: 16px;
  padding: 8px 22px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 2px #fbbf24;
}

.main {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 16px;
  padding: 8px 18px 8px;
}

@media (max-width: 640px) {
  .main {
    grid-template-columns: 1fr;
  }
  .shapes {
    max-height: 140px;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
  }
}

.panel {
  background: #fff7fb;
  border: 1px solid #fbcfe8;
  border-radius: 14px;
  padding: 10px;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--pink-deep);
  text-align: center;
}

.shapes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 460px;
  overflow-y: auto;
  padding-right: 4px;
}

.shape-btn {
  appearance: none;
  border: 2px solid transparent;
  background: #fff;
  border-radius: 10px;
  padding: 8px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.shape-btn:hover { transform: translateY(-1px); }
.shape-btn.active {
  border-color: var(--pink-deep);
  box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.2);
}

.shape-preview {
  display: grid;
  gap: 2px;
}

.shape-preview span {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12);
}

.shape-btn .label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  width: min(420px, 88vw);
  aspect-ratio: 1;
  background: #fff;
  border: 3px solid var(--grid-line);
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
}

.cell {
  border: 1px solid #bae6fd;
  background: #f8fafc;
  position: relative;
}

.cell.filled {
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.12);
}

.cell.obstacle {
  background: linear-gradient(145deg, #d1d5db, #9ca3af);
  border-color: #6b7280;
}

.cell.ghost-ok {
  outline: 2px solid rgba(59, 130, 246, 0.85);
  outline-offset: -2px;
  background: color-mix(in srgb, var(--ghost-color, #60a5fa) 45%, white);
  opacity: 0.9;
}

.cell.ghost-bad {
  outline: 2px solid rgba(239, 68, 68, 0.7);
  outline-offset: -2px;
  background: rgba(254, 202, 202, 0.55);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  min-height: 18px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 12px 18px 18px;
}

.actions button {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  color: #fff;
  transition: filter 0.15s, transform 0.1s;
}

.actions button:hover { filter: brightness(1.05); }
.actions button:active { transform: scale(0.98); }

.btn-restart { background: #94a3b8; }

.btn-undo { background: #f472b6; }
.btn-export { background: #fb923c; }
.btn-import { background: #38bdf8; }
.btn-shot { background: #34d399; }



.footer {
  text-align: center;
  font-size: 12px;
  color: #c4b5d4;
  padding: 0 16px 14px;
}

/* Win overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(59, 35, 72, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.overlay.show { display: flex; }

.overlay-card {
  background: #fff;
  border-radius: 18px;
  padding: 28px 32px;
  text-align: center;
  max-width: 360px;
  box-shadow: var(--shadow);
  border: 3px solid #f9a8d4;
}

.overlay-card h3 {
  margin: 0 0 8px;
  font-size: 24px;
  color: var(--pink-deep);
}

.overlay-card p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
}

.overlay-card button {
  appearance: none;
  border: none;
  background: linear-gradient(135deg, #ec4899, #a855f7);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  padding: 10px 22px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
}

.confirm-overlay {
  z-index: 60;
}

.confirm-card .confirm-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.confirm-card .btn-confirm-cancel {
  background: #e2e8f0 !important;
  color: #64748b !important;
}

.confirm-card .btn-confirm-ok {
  background: linear-gradient(135deg, #ec4899, #a855f7) !important;
  color: #fff !important;
  min-width: 96px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: #1e1b4b;
  color: #fde047;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
}

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

#fileImport { display: none; }

/* Room sync bar */
.roombar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin: 0 18px 10px;
  padding: 10px 14px;
  border: 1px solid #f9a8d4;
  background: #fff7fb;
  border-radius: 12px;
}
.roombar .rk {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.roombar .rcd {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: #db2777;
  font-variant-numeric: tabular-nums;
}
.roombar .rst {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid #e9d5ff;
  color: #7c3aed;
  background: #faf5ff;
}
.roombar .rst.ok {
  border-color: #86efac;
  color: #15803d;
  background: #f0fdf4;
}
.roombar .rst.sync {
  border-color: #c4b5fd;
  color: #6d28d9;
  background: #f5f3ff;
}
.roombar .rst.off {
  border-color: #fca5a5;
  color: #b91c1c;
  background: #fef2f2;
}
.roombar .rbtns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}
.roombar .rbtns button {
  appearance: none;
  border: 1px solid #f9a8d4;
  background: #fff;
  color: #be185d;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}
.roombar .rbtns button:hover {
  background: #fce7f3;
}
@media (max-width: 640px) {
  .roombar .rbtns { margin-left: 0; width: 100%; }
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}
.header-left h1 {
  margin: 0;
  font-size: clamp(15px, 2.8vw, 24px);
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #2563eb;
  text-align: left;
}
.mode-switch {
  display: inline-flex;
  flex-shrink: 0;
  gap: 0;
  border: 2px solid #f9a8d4;
  border-radius: 999px;
  overflow: hidden;
  background: #fff;
  margin-left: auto;
}
.mode-btn {
  appearance: none;
  border: none;
  background: transparent;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #9d174d;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.mode-btn.active {
  background: linear-gradient(135deg, #ec4899, #a855f7);
  color: #fff;
}
.board.hard-board {
  width: min(540px, 94vw);
}
@media (max-width: 560px) {
  .header { flex-wrap: wrap; }
  .mode-switch { margin-left: 0; }
}
