:root {
  color-scheme: light;
  font-family: "Be Vietnam Pro", Inter, ui-sans-serif, system-ui, sans-serif;
  --ink: #172033;
  --muted: #5b6475;
  --paper: #fffaf0;
  --panel: rgba(255, 255, 255, 0.94);
  --line: #d4d9e5;
  --accent: #f7c948;
  --accent-strong: #b7791f;
  --fill: #1f2937;
  --danger: #dc2626;
  --surface: #f8fafc;
  --shadow: 0 24px 70px rgba(31, 41, 55, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.55) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.55) 1px, transparent 1px),
    radial-gradient(circle at 14% 10%, rgba(247, 201, 72, 0.42), transparent 26%),
    radial-gradient(circle at 88% 18%, rgba(45, 212, 191, 0.22), transparent 24%),
    linear-gradient(135deg, #fff7ed 0%, #eef6ff 55%, #fef3c7 100%);
  background-size: 28px 28px, 28px 28px, auto, auto, auto;
}

button { font: inherit; }

.app { max-width: 1220px; margin: 0 auto; padding: 18px 16px 34px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  min-height: 92px;
}

.brand {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(23, 32, 51, 0.12);
  border-radius: 999px;
  padding: 10px 14px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(2.15rem, 5vw, 4.4rem); line-height: 0.95; }
h2 { font-size: clamp(1.2rem, 2vw, 1.75rem); line-height: 1.14; margin-bottom: 8px; }
p { color: var(--muted); line-height: 1.6; }

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.layout { display: grid; gap: 14px; }

.panel {
  border: 1px solid rgba(23, 32, 51, 0.12);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.intro-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(430px, 0.82fr);
  align-items: end;
  gap: 18px;
  padding: 18px;
}
.intro-panel p { max-width: 760px; margin-bottom: 0; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stats span {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(23, 32, 51, 0.1);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  color: var(--muted);
  font-weight: 700;
}
.stats strong { color: var(--ink); font-size: 1.45rem; line-height: 1; }

.game-panel { padding: 14px; overflow: hidden; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(210px, max-content) minmax(210px, max-content) 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.level-tabs, .tool-tabs { display: flex; flex-wrap: wrap; gap: 8px; }

.level-button, .tool-button, .primary-button, .secondary-button {
  min-height: 42px;
  border: 1px solid rgba(23, 32, 51, 0.12);
  border-radius: 8px;
  padding: 10px 13px;
  cursor: pointer;
  font-weight: 900;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.level-button, .tool-button, .secondary-button { background: #fff; color: var(--ink); }
.primary-button, .level-button.active, .tool-button.active {
  background: var(--fill);
  color: #fff;
  box-shadow: 0 10px 24px rgba(31, 41, 55, 0.18);
}
.secondary-button:hover, .level-button:hover, .tool-button:hover { transform: translateY(-1px); }

.board-wrap {
  overflow: auto;
  display: grid;
  justify-content: center;
  border: 1px solid rgba(23, 32, 51, 0.1);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  padding: clamp(12px, 3vw, 26px);
}

.nonogram-grid {
  display: grid;
  grid-template-columns: var(--clue-size) repeat(var(--size), var(--cell-size));
  grid-template-rows: var(--clue-size) repeat(var(--size), var(--cell-size));
  gap: 2px;
  width: max-content;
  min-width: auto;
  justify-content: center;
}

.corner, .clue, .cell {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.94);
}

.corner { grid-column: 1; grid-row: 1; }
.clue {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  color: #374151;
  background: #eef2ff;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
}
.clue.column {
  align-items: flex-end;
  writing-mode: horizontal-tb;
  white-space: pre-line;
}
.clue.solved { color: #15803d; background: #dcfce7; }

.cell {
  position: relative;
  width: var(--cell-size);
  height: var(--cell-size);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, outline 0.12s ease;
}
.cell:hover { transform: scale(1.04); z-index: 2; }
.cell:nth-child(5n) { border-color: var(--line); }
.cell.filled { background: var(--fill); border-color: #111827; }
.cell.marked::before, .cell.marked::after {
  content: "";
  position: absolute;
  top: 48%;
  left: 18%;
  width: 64%;
  height: 3px;
  border-radius: 999px;
  background: #64748b;
}
.cell.marked::before { transform: rotate(45deg); }
.cell.marked::after { transform: rotate(-45deg); }
.cell.error { outline: 3px solid var(--danger); outline-offset: -3px; }
.cell.hint { animation: pulse 1s ease-in-out 3; }

.status {
  min-height: 44px;
  margin-top: 12px;
  border-radius: 8px;
  background: #fff7ed;
  border: 1px solid rgba(183, 121, 31, 0.16);
  padding: 12px;
  color: var(--muted);
  font-weight: 800;
}

@keyframes pulse {
  50% { box-shadow: 0 0 0 6px rgba(247, 201, 72, 0.45); }
}

@media (max-width: 860px) {
  .intro-panel { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 560px) {
  .app { padding-inline: 10px; }
  .game-panel, .intro-panel { padding: 12px; }
  .stats { grid-template-columns: 1fr; }
  .toolbar { gap: 8px; }
  .level-button, .tool-button, .primary-button, .secondary-button { flex: 1 1 auto; padding-inline: 10px; }
  .toolbar { grid-template-columns: 1fr; }
  .level-tabs, .tool-tabs { display: grid; grid-template-columns: repeat(3, 1fr); }
  .board-wrap { justify-content: start; }
}
