:root {
  color-scheme: dark;
  --bg: #15110f;
  --panel: #241f1b;
  --panel-2: #302821;
  --line: rgba(255, 255, 255, .16);
  --text: #fff8f0;
  --muted: #d8cabc;
  --red: #ff4b55;
  --teal: #2dd4bf;
  --amber: #f6c343;
  --green: #8bd450;
  --ink: #11100f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 0, rgba(255, 75, 85, .20), transparent 20rem),
    radial-gradient(circle at 86% 8%, rgba(45, 212, 191, .14), transparent 18rem),
    linear-gradient(135deg, #15110f 0%, #211a16 58%, #171916 100%);
  color: var(--text);
}

.pr-bar {
  background: #fef3c7;
  border-bottom: 1px solid #fcd34d;
  color: #78350f;
  font-family: system-ui, sans-serif;
  font-size: .75rem;
  line-height: 1.4;
  padding: 6px 12px;
  text-align: center;
}

.app {
  width: min(940px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 3.2rem;
  line-height: 1;
  letter-spacing: 0;
}

.lead {
  margin: 10px 0 0;
  max-width: 680px;
  color: var(--muted);
  line-height: 1.6;
}

.hub-link,
button,
.support-strip a {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, .08);
  text-decoration: none;
  font-weight: 800;
}

.hub-link {
  display: inline-flex;
  align-items: center;
  padding: 0 16px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stats div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(36, 31, 27, .82);
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
}

.stats strong {
  display: block;
  margin-top: 2px;
  font-size: 1.5rem;
}

.game-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 17, 15, .78);
  padding: 14px;
}

.puzzle-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 30px;
  color: var(--muted);
  font-weight: 800;
}

#patternName {
  color: var(--amber);
}

#message {
  text-align: right;
}

.nonogram-shell {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  grid-template-rows: 76px minmax(0, 1fr);
  gap: 8px;
  width: min(560px, 100%);
  margin: 12px auto 0;
}

.corner,
.top-clues,
.row-clues,
.board {
  border-radius: 8px;
}

.corner {
  border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(255, 75, 85, .24), rgba(45, 212, 191, .18));
}

.top-clues {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
}

.top-clues div,
.row-clues div {
  border: 1px solid var(--line);
  background: rgba(48, 40, 33, .92);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 4px;
  text-align: center;
  font-size: .82rem;
  font-weight: 900;
  line-height: 1.1;
}

.top-clues div {
  min-height: 76px;
  align-items: flex-end;
  padding-bottom: 8px;
}

.row-clues {
  display: grid;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 4px;
}

.board {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 4px;
  aspect-ratio: 1;
}

.cell {
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 6px;
  background: #fff8f0;
  color: var(--ink);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 900;
  transition: transform .08s ease, background .12s ease, border-color .12s ease;
}

.cell:hover,
.cell:focus-visible {
  transform: translateY(-2px);
  border-color: var(--amber);
  outline: none;
}

.cell.filled {
  background: linear-gradient(135deg, var(--red), #ff884d);
  border-color: rgba(255, 255, 255, .40);
  color: #fff;
}

.cell.marked {
  background: #2d3631;
  color: var(--teal);
}

.cell.miss {
  background: #312022;
  color: #ffb4b8;
  border-color: rgba(255, 75, 85, .62);
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 10px;
  margin: 14px 0;
}

button {
  padding: 0 14px;
  cursor: pointer;
}

button.primary,
.mode-toggle .active {
  color: var(--ink);
  background: var(--amber);
  border-color: transparent;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.support-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.support-strip a {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
}

.result {
  position: fixed;
  inset: auto 16px 16px 16px;
  max-width: 520px;
  margin: 0 auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 17, 15, .96);
  box-shadow: 0 16px 44px rgba(0, 0, 0, .38);
  text-align: center;
  z-index: 10;
}

.result-label {
  margin: 0;
  color: var(--teal);
  font-size: .78rem;
  font-weight: 900;
}

.result strong {
  display: block;
  margin: 6px 0;
  color: var(--amber);
  font-size: 2.4rem;
}

.result p:last-of-type {
  margin: 0 0 12px;
  color: var(--muted);
}

.result button {
  margin: 4px;
}

#viewportState {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

@media (max-width: 720px) {
  .app {
    padding: 14px;
  }

  .hero {
    display: block;
  }

  h1 {
    font-size: 2.35rem;
  }

  .hub-link {
    margin-top: 12px;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .nonogram-shell {
    grid-template-columns: 70px minmax(0, 1fr);
    grid-template-rows: 64px minmax(0, 1fr);
    gap: 6px;
  }

  .top-clues div {
    min-height: 64px;
  }
}

@media (max-width: 480px) {
  .app {
    padding: 10px;
  }

  h1 {
    font-size: 1.95rem;
  }

  .stats {
    gap: 6px;
  }

  .stats div,
  .game-panel {
    padding: 10px;
  }

  .nonogram-shell {
    grid-template-columns: 56px minmax(0, 1fr);
    grid-template-rows: 56px minmax(0, 1fr);
    gap: 4px;
  }

  .top-clues,
  .row-clues,
  .board {
    gap: 3px;
  }

  .top-clues div,
  .row-clues div {
    font-size: .68rem;
    padding: 2px;
  }

  .top-clues div {
    min-height: 56px;
  }

  .cell {
    border-radius: 4px;
    font-size: .82rem;
  }

  .controls {
    grid-template-columns: 1fr;
  }
}
