/* ============================================================
   Queens — LinkedIn Queens clone
   ============================================================ */

:root {
  --bg: #eef1f6;
  --bg-glow: rgba(10, 102, 194, 0.10);
  --card: #ffffff;
  --ink: #1b2432;
  --muted: #6b7684;
  --line: #e3e7ee;
  --accent: #0a66c2;
  --accent-soft: rgba(10, 102, 194, 0.12);
  --boundary: rgba(27, 36, 50, 0.55);
  --cell-line: rgba(27, 36, 50, 0.09);
  --x-color: #5a6474;
  --bad: #d93025;
  --cal-solved: #cfeccd;
  --cal-solved-ink: #1f5b2b;
  --cal-progress: #fbeaa8;
  --cal-progress-ink: #6d5100;
  --shadow: 0 18px 44px -28px rgba(15, 23, 42, 0.55);
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --bg-glow: rgba(80, 160, 255, 0.12);
    --card: #171d26;
    --ink: #e8edf5;
    --muted: #93a0b1;
    --line: #26303d;
    --accent: #6fb2ff;
    --accent-soft: rgba(111, 178, 255, 0.16);
    --boundary: rgba(10, 14, 20, 0.75);
    --cell-line: rgba(10, 14, 20, 0.16);
    --x-color: #4a5566;
    --cal-solved: rgba(96, 200, 122, 0.24);
    --cal-solved-ink: #a6e2b3;
    --cal-progress: rgba(240, 200, 82, 0.22);
    --cal-progress-ink: #f0d489;
    --shadow: 0 18px 44px -28px rgba(0, 0, 0, 0.9);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 50% -220px, var(--bg-glow), transparent 70%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding: max(10px, env(safe-area-inset-top)) 0 max(10px, env(safe-area-inset-bottom));
}

.app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px 18px;
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 20px);
}

/* ---------------------------------------------------------- top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo {
  width: 30px;
  height: 30px;
  flex: none;
  fill: var(--ink);
  padding: 5px;
  background: var(--card);
  border-radius: 9px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset, 0 2px 8px -4px rgba(15, 23, 42, 0.4);
}

.titles { min-width: 0; }

.titles h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1.15;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn:hover { background: var(--accent-soft); border-color: transparent; }
.icon-btn:active { transform: scale(0.94); }

/* --------------------------------------------------------- board */

.stage { flex: 1; display: flex; flex-direction: column; gap: 12px; }

.board-shell { position: relative; }

.board {
  --n: 8;
  width: min(100%, 520px, calc(100dvh - 290px));
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  border-radius: 13px;
  overflow: hidden;
  background: var(--card);
  box-shadow: 0 0 0 2px var(--boundary), var(--shadow);
  touch-action: none;
  outline: none;
  user-select: none;
}

.board:focus,
.board:focus-visible { outline: none; }

.cell {
  position: relative;
  display: grid;
  place-items: center;
  background: var(--cell-bg, #dfe5ee);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.12s;
}

.cell:hover { filter: brightness(1.04); }

/* Edges are drawn once per shared side: top + left always, right/bottom only
   on the last row or column. */
.cell.bt-strong { border-top: 2px solid var(--boundary); }
.cell.bl-strong { border-left: 2px solid var(--boundary); }
.cell.br-strong { border-right: 2px solid var(--boundary); }
.cell.bb-strong { border-bottom: 2px solid var(--boundary); }
.cell.bt-thin { border-top: 1px solid var(--cell-line); }
.cell.bl-thin { border-left: 1px solid var(--cell-line); }

.cell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

/* conflict stripes, mirrors LinkedIn's red stripes */
.cell.is-bad::after {
  opacity: 1;
  background: repeating-linear-gradient(
    -45deg,
    rgba(217, 48, 37, 0.42) 0 5px,
    rgba(217, 48, 37, 0) 5px 10px
  );
  box-shadow: inset 0 0 0 2px var(--bad);
}

.cell.is-hint::after {
  opacity: 1;
  box-shadow: inset 0 0 0 3px var(--accent);
  animation: hintPulse 1.3s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { box-shadow: inset 0 0 0 3px rgba(10, 102, 194, 0.95); }
  50% { box-shadow: inset 0 0 0 3px rgba(10, 102, 194, 0.25); }
}

.ico {
  position: absolute;
  width: 66%;
  height: 66%;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.7);
  transition: opacity 0.13s ease, transform 0.16s cubic-bezier(0.2, 1.5, 0.5, 1);
}

.x {
  width: 50%;
  height: 50%;
  fill: none;
  stroke: var(--x-color);
  stroke-width: 2.7;
  stroke-linecap: round;
  transform: none;
}

.crown {
  fill: #1b2432;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.55));
}

.cell.is-mark .x,
.cell.is-ghost .x { opacity: 1; }
.cell.is-ghost .x { stroke-opacity: 0.3; }

.cell.is-queen .crown {
  opacity: 1;
  transform: scale(1);
  animation: crownPop 0.2s cubic-bezier(0.2, 1.5, 0.5, 1);
}

@keyframes crownPop {
  from { transform: scale(0.55); }
  to { transform: scale(1); }
}

.cell.is-focus::after {
  opacity: 1;
  box-shadow: inset 0 0 0 2px var(--accent);
  background: var(--accent-soft);
}

.board-veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  border-radius: 13px;
  background: rgba(238, 241, 246, 0.86);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(2px);
  color: var(--muted);
  font-size: 13px;
  z-index: 5;
}

.board-veil[hidden] { display: none; }

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------- meta row */

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
  min-height: 20px;
}

.timer { letter-spacing: 0.6px; }
.counter { font-weight: 600; color: var(--ink); }
.counter.is-done { color: #1a7f37; }

/* --------------------------------------------------------- toolbar */

.toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--card);
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.12s, opacity 0.15s;
}

.tool svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool:hover:not(:disabled) { background: var(--accent-soft); border-color: transparent; }
.tool:active:not(:disabled) { transform: scale(0.96); }
.tool:disabled { opacity: 0.42; cursor: not-allowed; }

/* --------------------------------------------------------- date nav */

.datenav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px;
}

.nav-btn {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}

.nav-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-btn:hover:not(:disabled) { background: var(--accent-soft); border-color: transparent; }
.nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.date-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 36px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.date-btn:hover { background: var(--accent-soft); border-color: transparent; }
.date-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.cal-icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
}

/* ------------------------------------------------------ calendar popover */

.cal-sheet { max-width: 380px; padding: 18px 16px 16px; }

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 12px;
}

.cal-head-group { display: flex; align-items: center; gap: 6px; }

/* 翻年按钮小一号，和翻月按钮区分开 */
.nav-btn.is-year { width: 32px; height: 32px; border-radius: 10px; }

.cal-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  flex: 1;
}

.cal-weekdays,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-weekdays {
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.cal-day {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s, transform 0.1s;
}

.cal-day:hover:not(:disabled) { background: var(--accent-soft); }
.cal-day:active:not(:disabled) { transform: scale(0.94); }

/* 没有题目：灰掉、不可点 */
.cal-day.is-none { color: var(--muted); opacity: 0.34; cursor: not-allowed; }

/* 当月之外的日子只做占位，不显示状态 */
.cal-day.is-out { visibility: hidden; }

/* 做了一半：浅黄 */
.cal-day.is-progress {
  background: var(--cal-progress);
  color: var(--cal-progress-ink);
}

/* 已完成：浅绿 */
.cal-day.is-solved {
  background: var(--cal-solved);
  color: var(--cal-solved-ink);
}

/* 今天：虚线描边；当前正在看的那天：实线环 */
.cal-day.is-today { box-shadow: inset 0 0 0 1.5px var(--muted); }
.cal-day.is-selected { box-shadow: inset 0 0 0 2px var(--accent); }

.cal-day:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 14px;
  font-size: 11.5px;
  color: var(--muted);
}

.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }

.cal-dot {
  width: 11px;
  height: 11px;
  border-radius: 4px;
  background: var(--line);
}

.cal-dot.is-solved { background: var(--cal-solved); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08); }
.cal-dot.is-progress { background: var(--cal-progress); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08); }
.cal-dot.is-none { background: var(--line); opacity: 0.5; }

.ghost-btn {
  height: 36px;
  padding: 0 12px;
  border: 1px dashed var(--line);
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.ghost-btn:hover { color: var(--accent); border-color: var(--accent); }

.foot {
  padding: 16px 4px 0;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* --------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  max-width: min(92vw, 420px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(27, 36, 50, 0.94);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  z-index: 40;
}

.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* --------------------------------------------------------- dialogs */

.sheet {
  border: 0;
  border-radius: var(--radius);
  padding: 22px;
  width: calc(100% - 32px);
  max-width: 420px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.6);
}

.sheet::backdrop { background: rgba(12, 18, 27, 0.5); backdrop-filter: blur(3px); }

.sheet h2 {
  margin: 0 0 8px;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.sheet h3 {
  margin: 18px 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}

.lede { margin: 0 0 12px; font-size: 13.5px; line-height: 1.6; color: var(--muted); }

.rules {
  margin: 0;
  padding-left: 20px;
  font-size: 13.5px;
  line-height: 1.75;
}

.rules.tight li { margin-bottom: 4px; }
.rules b { font-weight: 700; }

.fine {
  margin: 16px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--muted);
}

kbd {
  font: inherit;
  font-size: 11.5px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg);
}

.sheet-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

.btn {
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}

.btn:hover { background: var(--accent-soft); border-color: transparent; }
.btn:active { transform: scale(0.97); }

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }

.settings { display: flex; flex-direction: column; gap: 4px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.switch-row:last-child { border-bottom: 0; }
.switch-row span { display: flex; flex-direction: column; gap: 2px; }
.switch-row b { font-size: 13.5px; font-weight: 600; }
.switch-row small { font-size: 11.5px; color: var(--muted); }

.switch-row input[type="checkbox"] {
  appearance: none;
  width: 42px;
  height: 25px;
  flex: none;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  cursor: pointer;
  transition: background 0.18s;
}

.switch-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.35);
  transition: transform 0.18s;
}

.switch-row input[type="checkbox"]:checked { background: var(--accent); }
.switch-row input[type="checkbox"]:checked::after { transform: translateX(17px); }

.size-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.size-btn {
  padding: 14px 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}

.size-btn small { display: block; font-size: 10px; font-weight: 500; color: var(--muted); margin-top: 3px; }
.size-btn:hover { background: var(--accent-soft); border-color: transparent; }
.size-btn:active { transform: scale(0.96); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat {
  padding: 14px;
  border-radius: 12px;
  background: var(--bg);
  text-align: center;
}

.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; color: var(--muted); }

.win { text-align: center; }
.win-badge { font-size: 34px; line-height: 1; margin-bottom: 6px; }
.win .lede { margin-bottom: 14px; }

.share-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.35;
  white-space: pre;
  text-align: left;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  overflow: auto;
  max-height: 190px;
}

.win .sheet-actions { justify-content: center; }

@media (max-width: 380px) {
  .app { padding: 0 10px 14px; }
  .titles h1 { font-size: 18px; }
  .board { width: min(100%, calc(100dvh - 280px)); }
  .tool { font-size: 11px; }
  /* four date controls now share the row: keep the date field readable */
  .datenav { gap: 6px; }
  .ghost-btn { padding: 0 8px; font-size: 11px; }
}

@media (max-height: 620px) {
  .foot { display: none; }
  .board { width: min(100%, 440px, calc(100dvh - 250px)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::after, *::before { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
