:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #596678;
  --line: #d7dee8;
  --soft-line: #edf1f6;
  --accent: #d51f2a;
  --accent-dark: #a91520;
  --blue: #1d6fb8;
  --green: #11865b;
  --yellow: #f0b429;
  --focus: #f2bd35;
  --cell: #fbfdff;
  --cell-active: #fff7d8;
  --cell-correct: #e7f6ed;
  --cell-wrong: #fde8e8;
  --shadow: 0 12px 30px rgba(28, 39, 55, 0.08);
  --tight-shadow: 0 8px 18px rgba(28, 39, 55, 0.07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(213, 31, 42, 0.08) 0 6px, transparent 6px),
    linear-gradient(180deg, #ffffff 0, var(--bg) 260px);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 44px;
}

.topbar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 0.98;
  letter-spacing: 0;
}

.puzzle-date {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.scorecard {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 520px;
}

.score-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(84px, auto));
  min-height: 44px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--tight-shadow);
}

#score {
  display: grid;
  align-content: center;
  padding: 7px 12px;
  border-right: 1px solid var(--soft-line);
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

#score::before {
  margin-bottom: 3px;
  color: var(--muted);
  content: "Найдено";
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

#mistakes {
  display: grid;
  align-content: center;
  padding: 7px 12px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.12;
}

button {
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 750;
}

button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

button:disabled {
  border-color: var(--line);
  background: #e7ebf1;
  color: var(--muted);
  cursor: not-allowed;
}

.secondary-button {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}

.secondary-button:hover {
  border-color: var(--blue);
  background: #edf6ff;
  color: var(--ink);
}

.contact-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 750;
}

.contact-button:hover {
  border-color: var(--blue);
  background: #edf6ff;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.grid {
  display: grid;
  grid-template-columns: minmax(96px, 0.65fr) repeat(3, minmax(128px, 1fr));
  grid-template-rows: minmax(96px, auto) repeat(3, minmax(118px, 1fr));
  border: 2px solid #cbd3df;
  background: #cbd3df;
  gap: 1px;
  min-width: 0;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.grid-cell,
.clue-cell,
.corner-cell {
  min-width: 0;
  padding: 14px;
  background: var(--panel);
}

.corner-cell {
  position: relative;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.72)),
    repeating-linear-gradient(
      135deg,
      var(--accent) 0 9px,
      var(--blue) 9px 18px,
      var(--green) 18px 27px,
      var(--yellow) 27px 36px
    );
}

.corner-cell::after {
  position: absolute;
  inset: 16px;
  border: 2px solid rgba(17, 24, 39, 0.18);
  border-radius: 999px;
  content: "";
}

.clue-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 96px;
  border: 0;
  border-radius: 0;
  background: #f9fbfd;
  color: var(--ink);
  font-weight: 800;
  text-align: center;
  line-height: 1.16;
  overflow-wrap: normal;
  word-break: normal;
}

.clue-cell.column {
  border-top: 6px solid var(--blue);
  box-shadow: inset 0 1px 0 rgba(29, 111, 184, 0.12);
}

.clue-cell.row {
  border-left: 6px solid var(--green);
  box-shadow: inset 1px 0 0 rgba(17, 134, 91, 0.12);
}

.line-clue {
  font-size: 14px;
  line-height: 1.12;
}

.line-clue-text {
  display: inline;
  max-width: 100%;
}

.metro-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35em;
  height: 1.35em;
  min-width: 1.35em;
  border-radius: 50%;
  color: white;
  font-size: 0.78em;
  font-weight: 700;
  line-height: 1;
  margin: 0 0.12em;
  vertical-align: -0.15em;
  text-decoration: none;
  white-space: nowrap;
}

.metro-line-1 {
  background-color: #e42313;
}

.metro-line-2 {
  background-color: #4fb04f;
}

.metro-line-3 {
  background-color: #0072bc;
}

.metro-line-4 {
  background-color: #00a2df;
}

.metro-line-5 {
  background-color: #8d5b2d;
}

.metro-line-6 {
  background-color: #ef7c00;
}

.metro-line-7 {
  background-color: #943e90;
}

.metro-line-8 {
  background-color: #ffcd1c;
  color: black;
}

.metro-line-9 {
  background-color: #a1a2a3;
}

.metro-line-10 {
  background-color: #b3d445;
  color: black;
}

.metro-line-11 {
  background-color: #82c0c0;
  color: black;
}

.metro-line-12 {
  background-color: #acbfe1;
  color: black;
}

.metro-line-14 {
  background-color: #f2a900;
  color: black;
}

.metro-line-15 {
  background-color: #de64a1;
}

.metro-line-16 {
  background-color: #ed6f35;
}

.metro-line-d1 {
  background-color: #f6a800;
  color: black;
}

.metro-line-d2 {
  background-color: #e74280;
}

.metro-line-d3 {
  background-color: #ed6f35;
}

.metro-line-d4 {
  background-color: #45b97c;
}

.metro-line-bkl {
  background-color: #8d5b2d;
}

.metro-line-f {
  background-color: #00a2df;
}

.grid-cell {
  min-height: 118px;
  background: var(--cell);
  border: 0;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  position: relative;
}

.grid-cell::after {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  max-width: calc(100% - 16px);
  padding: 5px 7px;
  border: 1px solid rgba(17, 24, 39, 0.12);
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.88);
  color: white;
  content: attr(data-variant-label);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  text-overflow: ellipsis;
  transform: translateY(-4px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
  white-space: nowrap;
}

.grid-cell:hover::after,
.grid-cell:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.grid-cell:hover,
.grid-cell.active {
  background: var(--cell-active);
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

.grid-cell.correct {
  background: var(--cell-correct);
  box-shadow: inset 0 0 0 2px rgba(17, 134, 91, 0.18);
}

.grid-cell.revealed {
  background: #f8fafc;
}

.grid-cell.wrong {
  background: var(--cell-wrong);
}

.answer-name {
  display: block;
  font-weight: 850;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.answer-line {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

.cell-placeholder {
  color: #9da9b8;
  font-weight: 800;
}

.side-panel {
  position: sticky;
  top: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
  border-radius: 8px;
  box-shadow: var(--tight-shadow);
}

.active-cell {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--soft-line);
}

.label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0;
}

.active-cell h2 {
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 1.1;
}

.muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.search-box {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  font-weight: 750;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 12px;
  background: #fbfcff;
  color: var(--ink);
}

.search-box input:focus {
  outline: 3px solid var(--focus);
  border-color: #b78020;
}

.search-box input:disabled {
  background: #f1f4f8;
  color: var(--muted);
}

.suggestions {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.suggestion {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcff;
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
}

.suggestion:hover {
  border-color: var(--blue);
  background: #eef6ff;
}

.suggestion small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-weight: 500;
}

.message {
  min-height: 24px;
  margin: 14px 0 0;
  color: var(--accent-dark);
  font-weight: 750;
  line-height: 1.35;
}

.result-panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.result-panel h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.result-panel p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.35;
}

.perfect-badge {
  display: inline-flex;
  width: fit-content;
  margin: 0 0 10px;
  border: 1px solid #bfe8cd;
  border-radius: 999px;
  padding: 5px 9px;
  background: #e8f7ee;
  color: var(--green);
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
}

.result-panel dl {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.result-panel div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.result-panel dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.result-panel dd {
  margin: 0;
  font-weight: 850;
}

.share-button {
  width: 100%;
}

.possible-answers {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--soft-line);
}

.possible-answers h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.possible-answers ul {
  display: grid;
  gap: 8px;
  max-height: 260px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.possible-answers li {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
  border: 1px solid var(--soft-line);
  border-radius: 6px;
  background: #fbfcff;
  font-weight: 750;
}

.possible-answers span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 550;
}

.rules-dialog {
  width: min(560px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 28px 90px rgba(18, 27, 40, 0.28);
}

.rules-dialog::backdrop {
  background: rgba(19, 28, 42, 0.42);
}

.rules-card {
  position: relative;
  padding: 28px;
  background: var(--panel);
}

.rules-card h2 {
  margin: 0 0 14px;
  font-size: 34px;
  line-height: 1;
}

.rules-card ul {
  display: grid;
  gap: 10px;
  margin: 0 0 22px;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.42;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--accent);
  background: #fff1f2;
  color: var(--accent-dark);
}

.close-button {
  position: absolute;
  top: 16px;
  right: 16px;
}

.rules-start {
  width: 100%;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px;
  margin-top: 30px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.info-grid article {
  min-width: 0;
}

.info-grid h2 {
  margin: 0 0 12px;
  font-size: 22px;
  line-height: 1.1;
}

.archive-panel {
  grid-column: 1 / -1;
}

.archive-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.archive-button {
  padding: 8px 10px;
  font-size: 14px;
}

details {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

details:last-of-type {
  border-bottom: 1px solid var(--line);
}

summary {
  cursor: pointer;
  font-weight: 800;
}

details p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.changelog-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  line-height: 1.4;
}

.changelog-list > li {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.changelog-list time {
  color: var(--ink);
  font-weight: 850;
}

.changelog-list ul {
  display: grid;
  gap: 6px;
  margin: 8px 0 0;
  padding-left: 18px;
  list-style: disc;
}

.changelog-list ul li {
  padding: 0;
  border: 0;
}

@media (max-width: 900px) {
  .topbar,
  .game-layout {
    display: grid;
  }

  .topbar {
    align-items: start;
  }

  .scorecard {
    justify-content: start;
    max-width: none;
    width: 100%;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

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

  .side-panel {
    position: static;
  }

  .grid {
    grid-template-columns: minmax(78px, 0.58fr) repeat(3, minmax(92px, 1fr));
    grid-template-rows: minmax(86px, auto) repeat(3, minmax(96px, auto));
  }

  .grid-cell,
  .clue-cell,
  .corner-cell {
    padding: 10px;
  }

  .clue-cell {
    font-size: 13px;
  }

  .line-clue {
    font-size: 12px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 18px, 1180px);
    padding-top: 18px;
  }

  .scorecard {
    display: grid;
    grid-template-columns: 1fr 1fr;
    justify-content: space-between;
  }

  .score-stack {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    text-align: left;
    width: 100%;
  }

  .grid {
    grid-template-columns: minmax(92px, 1.15fr) repeat(3, minmax(64px, 1fr));
  }

  .grid-cell {
    min-height: 88px;
  }

  .answer-name {
    font-size: 13px;
  }

  .answer-line {
    font-size: 11px;
  }

  button {
    padding: 9px 11px;
  }

  .rules-card {
    padding: 24px 18px 18px;
  }
}
