:root {
  color-scheme: light;
  --bg: #f8faf7;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: #ffffff;
  --ink: #2e3652;
  --muted: #5f6f8d;
  --mint: #4fcebc;
  --mint-deep: #149989;
  --sky: #88c8ff;
  --peach: #ffd6c2;
  --coral: #ff7d85;
  --butter: #ffd96d;
  --line: rgba(96, 118, 149, 0.16);
  --shadow: 0 24px 68px rgba(84, 123, 130, 0.14);
  --radius-xl: 34px;
  --radius-lg: 26px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --cell-size: 48px;
  --font-display: "Avenir Next", "Trebuchet MS", "Gill Sans", sans-serif;
  --font-body: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(circle at top left, rgba(142, 203, 255, 0.5), transparent 24%),
    radial-gradient(circle at right 18% top 16%, rgba(255, 214, 194, 0.65), transparent 22%),
    radial-gradient(circle at bottom left, rgba(79, 206, 188, 0.2), transparent 28%),
    linear-gradient(180deg, #fbfbf7 0%, #f3f8f6 100%);
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  width: 24rem;
  height: 24rem;
  border-radius: 999px;
  filter: blur(10px);
  pointer-events: none;
}

body::before {
  left: -5rem;
  bottom: 3rem;
  background: rgba(136, 200, 255, 0.16);
}

body::after {
  right: -5rem;
  top: 4rem;
  background: rgba(255, 214, 194, 0.16);
}

button,
input,
summary {
  font: inherit;
}

.page-shell {
  width: min(1320px, calc(100% - 28px));
  margin: 20px auto 36px;
}

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.8));
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.game-header {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 20px;
  align-items: start;
  padding: 26px 28px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(112, 135, 169, 0.14);
  color: var(--mint-deep);
  font-weight: 800;
}

.title-wrap h1 {
  margin: 4px 0 10px;
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 6vw, 4.8rem);
  line-height: 1.02;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.kicker,
.tip-label {
  margin: 0;
  color: var(--mint-deep);
  font-weight: 800;
  letter-spacing: 0.04em;
}

.subtitle {
  margin: 0;
  max-width: 42rem;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.7;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.82fr);
  gap: 22px;
  margin-top: 22px;
}

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

.main-column,
.side-column {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.preset-panel,
.status-bar {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.preset-panel {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.preset-button {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px;
  border: 1px solid rgba(128, 152, 183, 0.16);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(248, 252, 255, 0.9));
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.preset-button:hover,
.preset-button:focus-visible,
.mode-button:hover,
.mode-button:focus-visible,
.restart-button:hover,
.restart-button:focus-visible,
.cell:hover,
.cell:focus-visible {
  transform: translateY(-1px);
}

.preset-button.is-active {
  border-color: rgba(20, 153, 137, 0.48);
  box-shadow: 0 14px 30px rgba(79, 206, 188, 0.18);
}

.preset-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 62px;
  width: 62px;
  height: 62px;
  border-radius: 20px;
  background: linear-gradient(145deg, #ffffff, #ecf8ff);
  font-size: 1.7rem;
}

.preset-button strong,
.status-chip strong,
.tip-card h3,
.board-head h2 {
  font-family: var(--font-display);
}

.preset-button strong {
  display: block;
  font-size: 1.65rem;
}

.preset-button small {
  color: var(--muted);
  font-weight: 700;
}

.status-bar {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 96px;
  min-width: 0;
  padding: 0 18px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(127, 150, 180, 0.12);
}

.status-chip p,
.mode-toggle p,
.legend span,
.info-body p {
  margin: 0;
  color: var(--muted);
}

.status-icon {
  font-size: 2rem;
}

.status-chip strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
}

.restart-button {
  width: 100%;
  min-height: 64px;
  padding: 0 28px;
  border: 0;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--coral), #ff9683);
  color: white;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 18px 28px rgba(255, 125, 133, 0.24);
}

.mode-toggle {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  min-width: 0;
  justify-self: stretch;
}

.toggle-buttons {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 6px;
  border-radius: 18px;
  background: rgba(247, 251, 255, 0.92);
  border: 1px solid rgba(127, 150, 180, 0.14);
}

.mode-button {
  min-width: 0;
  width: 100%;
  min-height: 46px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.mode-button.is-active {
  background: linear-gradient(180deg, #ffffff, #ebfff7);
  color: var(--mint-deep);
  box-shadow: 0 10px 18px rgba(110, 143, 148, 0.12);
}

.board-card {
  padding: 22px;
  overflow: hidden;
}

.board-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.board-head h2 {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
}

.board-head p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: flex-end;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.legend-cell {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 8px;
  font-style: normal;
}

.hidden-cell {
  background: linear-gradient(180deg, #eef7ff, #dfefff);
  box-shadow: inset 0 0 0 1px rgba(118, 144, 176, 0.16);
}

.revealed-cell {
  background: linear-gradient(180deg, #fffefb, #fff5e8);
  box-shadow: inset 0 0 0 1px rgba(118, 144, 176, 0.12);
}

.flag-cell {
  background: linear-gradient(180deg, #fff3f3, #ffe3e6);
  color: #ff6572;
}

.board-scroll {
  overflow: auto;
  padding-bottom: 6px;
  overscroll-behavior-x: contain;
}

.board {
  display: grid;
  gap: 6px;
  width: max-content;
  min-width: 100%;
  margin-inline: auto;
  padding: 10px;
  border-radius: 24px;
  background:
    radial-gradient(circle at left bottom, rgba(79, 206, 188, 0.16), transparent 30%),
    linear-gradient(180deg, #f5fbff, #f9fffb);
  border: 1px solid rgba(112, 136, 168, 0.12);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #eef7ff, #dfefff);
  box-shadow:
    inset 0 0 0 1px rgba(118, 144, 176, 0.16),
    0 6px 12px rgba(112, 140, 170, 0.08);
  font-family: var(--font-display);
  font-size: clamp(1rem, 2.3vw, 1.3rem);
  font-weight: 900;
  color: var(--ink);
  cursor: pointer;
  transition: transform 140ms ease, background 180ms ease, box-shadow 180ms ease;
  user-select: none;
}

.cell.revealed {
  background: linear-gradient(180deg, #fffefb, #fff5e8);
  box-shadow: inset 0 0 0 1px rgba(118, 144, 176, 0.12);
}

.cell.empty {
  color: transparent;
}

.cell.flagged {
  color: #ff6070;
  background: linear-gradient(180deg, #fff6f7, #ffe5e9);
}

.cell.mine {
  background: linear-gradient(180deg, #ffd7da, #ffc4ca);
  color: #30405e;
}

.cell.exploded {
  background: linear-gradient(180deg, #ffb6bd, #ff8e98);
}

.cell.wrong-flag {
  background: linear-gradient(180deg, #fff7dd, #ffe9b8);
  color: #8a6b1a;
}

.board.is-disabled .cell {
  cursor: default;
}

.board.is-portrait .cell {
  border-radius: 12px;
}

.n1 { color: #2b86ed; }
.n2 { color: #27a05a; }
.n3 { color: #eb5e5e; }
.n4 { color: #6b4fd9; }
.n5 { color: #d57a17; }
.n6 { color: #1797a5; }
.n7 { color: #50577d; }
.n8 { color: #7c5d51; }

.info-card,
.tip-card {
  padding: 18px 20px;
}

.info-card summary {
  list-style: none;
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 800;
}

.info-card summary::-webkit-details-marker {
  display: none;
}

.info-body {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.rule-item {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: start;
}

.rule-item span,
.steps strong {
  font-family: var(--font-display);
}

.rule-item span {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff, #edf6ff);
  color: var(--mint-deep);
  font-size: 1.3rem;
  font-weight: 900;
}

.steps .step-item {
  padding-bottom: 14px;
  border-bottom: 1px dashed rgba(127, 150, 180, 0.24);
}

.steps .step-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.steps strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1.2rem;
  color: var(--mint-deep);
}

.tip-card h3 {
  margin: 10px 0 8px;
  font-size: 1.65rem;
}

.tip-card p:last-child {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

@media (min-width: 1181px) {
  .layout.board-priority .side-column {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: start;
  }
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .status-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .restart-button,
  .mode-toggle {
    justify-self: stretch;
  }
}

@media (max-width: 840px) {
  .game-header {
    grid-template-columns: 1fr;
  }

  .preset-panel {
    grid-template-columns: 1fr;
  }

  .status-bar {
    grid-template-columns: 1fr;
  }

  .board-head {
    flex-direction: column;
  }

  .legend {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  :root {
    --cell-size: 40px;
  }

  .page-shell {
    width: min(1320px, calc(100% - 18px));
    margin-top: 12px;
  }

  .card {
    border-radius: 26px;
  }

  .title-wrap h1 {
    font-size: clamp(2.2rem, 13vw, 3.5rem);
  }

  .game-header,
  .board-card,
  .info-card,
  .tip-card,
  .preset-panel,
  .status-bar {
    padding: 18px;
  }

  .preset-button strong {
    font-size: 1.35rem;
  }

  .status-chip {
    min-height: 84px;
  }

  .toggle-buttons {
    width: 100%;
  }

  .board {
    gap: 4px;
    padding: 8px;
  }

  .cell {
    border-radius: 10px;
  }
}
