:root {
  --bg: #f6f3ee;
  --ink: #2b2a33;
  --muted: #7a7684;
  --line: #2b2a33;
  --thin: rgba(43, 42, 51, 0.18);
  --accent: #e8a33d;
  --danger: #d6455d;
  --btn: #ffffff;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

.app {
  width: min(560px, 100vw);
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.01em; }

button {
  font: inherit;
  font-weight: 600;
  border: 1.5px solid var(--thin);
  background: var(--btn);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.4; cursor: default; }

.difficulty { display: flex; gap: 4px; background: #ebe6de; padding: 3px; border-radius: 12px; }
.difficulty button { border: none; background: transparent; padding: 6px 12px; font-size: 0.9rem; color: var(--muted); }
.difficulty button[aria-checked="true"] { background: var(--btn); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

.status { display: flex; justify-content: space-between; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }
#timer { color: var(--ink); font-size: 1.1rem; }

.board {
  --n: 8;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  grid-template-rows: repeat(var(--n), minmax(0, 1fr));
  aspect-ratio: 1;
  width: 100%;
  border: 3px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-right: 1px solid var(--thin);
  border-bottom: 1px solid var(--thin);
}
.cell.edge-r { border-right: 2.5px solid var(--line); }
.cell.edge-b { border-bottom: 2.5px solid var(--line); }
.cell.last-c { border-right: none; }
.cell.last-r { border-bottom: none; }

.cell svg { flex: none; aspect-ratio: 1; height: auto; }
.cell .mark {
  width: 28%;
  opacity: 0.55;
}
.cell .star {
  width: 88%;
  color: var(--accent);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.25));
  animation: pop 0.15s ease-out;
}
.cell.conflict { background-image: repeating-linear-gradient(45deg, rgba(214,69,93,0.22) 0 6px, transparent 6px 12px); }
.cell.conflict .star { color: var(--danger); }

.cell.given { cursor: default; }
.cell.given .star { color: #c47d12; animation: none; }

.cell.hint-focus { box-shadow: inset 0 0 0 3px rgba(43, 42, 51, 0.55); }
.cell.hint-target::before {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 3px solid #2b6fd6;
  animation: pulse 1.2s ease-in-out infinite;
  pointer-events: none;
}
.cell.hint-star::before { border-color: #c47d12; }
@keyframes pulse { 50% { transform: scale(0.8); opacity: 0.5; } }

.hint-text {
  margin: 0;
  padding: 10px 14px;
  background: #fff;
  border-left: 4px solid #2b6fd6;
  border-radius: 8px;
  line-height: 1.4;
}
.hint-text[hidden] { display: none; }

@keyframes pop { from { transform: scale(0.5); } to { transform: scale(1); } }

.board.solved .star { animation: bounce 0.5s ease-out both; }
@keyframes bounce { 0% { transform: scale(1); } 40% { transform: scale(1.25) rotate(12deg); } 100% { transform: scale(1); } }

.controls { display: flex; gap: 8px; justify-content: center; }

.rules { color: var(--muted); font-size: 0.95rem; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ul { padding-left: 20px; margin: 8px 0 0; line-height: 1.5; }

.win {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(246, 243, 238, 0.6);
  backdrop-filter: blur(2px);
}
.win[hidden] { display: none; }
.win-card {
  background: var(--btn);
  padding: 24px 32px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}
.win-card h2 { margin: 0 0 6px; }
.win-card p { margin: 0 0 16px; color: var(--muted); }
