:root {
  --bg: #fafaf9;
  --panel: #ffffff;
  --ink: #1c1917;
  --muted: #78716c;
  --black: #1c1917;
  --white: #ffffff;
  --line: #e7e5e4;
  --border: #d6d3d1;
  --select: #44403c;
  --peer: #f5f5f4;
  --error: #b91c1c;
  --error-bg: #fef2f2;
  --ok: #15803d;
  --notes: #a8a29e;
  --link: #1c1917;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --cols: 5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

#game-container {
  max-width: 720px;
  margin: 52px auto 20px;
  padding: 12px 12px 8px;
  text-align: center;
}

h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.tagline {
  margin: 2px 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
}

.diff-label {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
}

#difficulty {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

#timer {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.88rem;
}

.board-wrap {
  overflow: visible;
  margin: 0;
  padding: 0 0 2px;
}

#board {
  display: grid;
  gap: 1px;
  background: var(--border);
  border: 1px solid #a8a29e;
  margin: 0 auto;
  width: 100%;
  max-width: min(100%, calc(var(--cols) * 68px));
}

.cell {
  width: 100%;
  aspect-ratio: 1;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-weight: 700;
  user-select: none;
  touch-action: manipulation;
}

.cell.block {
  background: var(--black);
}

.cell.clue {
  background: var(--black);
  color: #fafaf9;
  font-size: clamp(0.55rem, 2.6vw, 0.78rem);
  font-weight: 600;
}

.cell.clue::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top right, transparent 49%, #78716c 49%, #78716c 51%, transparent 51%);
  pointer-events: none;
}

.clue-down {
  position: absolute;
  left: 3px;
  bottom: 2px;
}

.clue-across {
  position: absolute;
  right: 3px;
  top: 2px;
}

.cell.empty {
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  font-size: clamp(1.1rem, 4.5vw, 1.5rem);
}

.cell.empty.selected {
  outline: 2px solid var(--select);
  outline-offset: -2px;
  background: #e7e5e4;
}

.cell.empty.peer {
  background: var(--peer);
}

.cell.empty.same {
  outline: 2px solid rgba(68, 64, 60, 0.35);
  outline-offset: -2px;
}

.cell.empty.error {
  background: var(--error-bg);
  color: var(--error);
}

.cell.empty.ok-sum {
  box-shadow: inset 0 0 0 2px rgba(21, 128, 61, 0.45);
}

.notes {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: clamp(0.48rem, 2.2vw, 0.7rem);
  font-weight: 600;
  color: var(--notes);
  line-height: 1;
  pointer-events: none;
}

.notes span {
  display: flex;
  align-items: center;
  justify-content: center;
}

#status {
  min-height: 1.25em;
  margin: 8px 0;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.92rem;
}

#numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  max-width: min(520px, 100%);
  margin: 0 auto 10px;
}

#numpad button {
  aspect-ratio: 1;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

#numpad button:active {
  background: #f5f5f4;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.actions button {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.actions button:active {
  background: #f5f5f4;
}

.actions button.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.actions button[aria-pressed="true"] {
  background: #44403c;
  border-color: #44403c;
  color: #fff;
}

.pro-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px auto 6px;
  max-width: 520px;
  padding: 14px 16px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  text-align: left;
}

.pro-link:hover,
.pro-link:focus-visible {
  background: #292524;
  border-color: #292524;
}

.pro-link__label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.85;
}

.pro-link__host {
  display: block;
  margin-top: 2px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.pro-link__go {
  flex-shrink: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.geo-seo {
  max-width: 720px;
  margin: 28px auto 40px;
  padding: 20px 12px 8px;
  border-top: 1px solid var(--line);
  font-family: var(--font);
  line-height: 1.55;
  color: var(--ink);
}

.geo-seo h2,
.geo-seo h3,
.geo-seo h4 {
  color: var(--ink);
}

.geo-seo a {
  color: var(--ink);
  font-weight: 600;
}

.geo-seo .pro-inline {
  margin-top: 16px;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
  font-size: 1rem;
}

.geo-seo .pro-inline a {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (min-width: 640px) {
  #board {
    max-width: min(100%, calc(var(--cols) * 66px));
  }

  #numpad button {
    min-height: 48px;
  }
}

@media (max-width: 480px) {
  #game-container {
    margin-top: 44px;
    padding: 6px 6px 4px;
  }

  h1 { font-size: 1.4rem; }

  #board {
    max-width: 100%;
  }

  #numpad {
    gap: 5px;
  }

  #numpad button {
    min-height: 48px;
    font-size: 1.2rem;
  }

  .actions button {
    flex: 1 1 calc(33.33% - 6px);
    min-height: 44px;
  }
}
