:root {
  color-scheme: light;
  font-family: "MS Sans Serif", Tahoma, Arial, sans-serif;
  font-synthesis: none;
  --desktop-blue: #008080;
  --window-gray: #c0c0c0;
  --window-light: #ffffff;
  --window-mid: #dfdfdf;
  --window-dark: #808080;
  --window-black: #000000;
  --title-blue: #000080;
  --counter-red: #ff2a2a;
  --cell-size: 30px;
  --outer-shadow:
    inset -1px -1px var(--window-black),
    inset 1px 1px var(--window-light),
    inset -2px -2px var(--window-dark),
    inset 2px 2px var(--window-mid);
  --pressed-shadow:
    inset 1px 1px var(--window-black),
    inset 2px 2px var(--window-dark);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background:
    linear-gradient(135deg, rgb(255 255 255 / 5%) 25%, transparent 25%) 0 0 / 8px 8px,
    linear-gradient(315deg, rgb(0 0 0 / 5%) 25%, transparent 25%) 0 0 / 8px 8px,
    var(--desktop-blue);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  color: #000;
  background: transparent;
}

button,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.page-shell {
  width: min(100%, 1040px);
  margin: 0 auto;
}

.window {
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 3px;
  background: var(--window-gray);
  box-shadow: var(--outer-shadow), 4px 5px 0 rgb(0 0 0 / 28%);
}

.title-bar {
  display: flex;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 4px 3px 7px;
  color: #fff;
  background: linear-gradient(90deg, var(--title-blue), #1084d0);
  user-select: none;
}

.title-bar__caption {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
}

.title-bar__icon {
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  color: #fff;
  font-size: 17px;
  line-height: 1;
}

.title-bar h1 {
  overflow: hidden;
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-bar__buttons {
  display: flex;
  gap: 2px;
}

.title-bar__buttons span {
  display: grid;
  width: 20px;
  height: 19px;
  place-items: center;
  color: #000;
  background: var(--window-gray);
  box-shadow: var(--outer-shadow);
  font-family: Arial, sans-serif;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}

.menu-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 7px 6px;
  border-bottom: 1px solid var(--window-dark);
  background: var(--window-gray);
}

.control-label {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.classic-select,
.classic-button {
  min-height: 32px;
  color: #000;
  border: 0;
  border-radius: 0;
  background: var(--window-gray);
  box-shadow: var(--outer-shadow);
}

.classic-select {
  min-width: 215px;
  padding: 4px 28px 4px 8px;
  border: 1px solid #000;
  background: #fff;
  box-shadow:
    inset 1px 1px var(--window-black),
    inset -1px -1px var(--window-light);
  font-size: 13px;
}

.classic-button {
  padding: 5px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  touch-action: manipulation;
}

.classic-button:active,
.classic-button[aria-pressed="true"],
.face-button--pressed {
  padding-top: 6px;
  padding-right: 11px;
  padding-bottom: 4px;
  padding-left: 13px;
  box-shadow: var(--pressed-shadow);
}

.classic-button:focus-visible,
.classic-select:focus-visible,
.cell:focus-visible,
.help-panel summary:focus-visible {
  outline: 2px dotted #000;
  outline-offset: -5px;
}

.menu-button {
  white-space: nowrap;
}

.flag-mode {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.flag-mode > span:first-child {
  color: #d40000;
  font-size: 18px;
  line-height: 1;
  text-shadow: 1px 1px #fff;
}

.flag-mode--active {
  background: #b8d4ff;
}

.game-panel {
  padding: 7px;
  background: var(--window-gray);
}

.score-panel {
  display: grid;
  min-height: 74px;
  grid-template-columns: minmax(92px, 1fr) auto minmax(92px, 1fr);
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  padding: 8px 10px;
  box-shadow:
    inset 1px 1px var(--window-dark),
    inset -1px -1px var(--window-light),
    inset 2px 2px var(--window-black),
    inset -2px -2px var(--window-mid);
}

.counter-block {
  display: grid;
  justify-items: start;
  gap: 2px;
}

.counter-block--right {
  justify-items: end;
}

.counter-label {
  font-size: 11px;
  font-weight: 700;
}

.digital-counter {
  display: inline-block;
  min-width: 74px;
  padding: 2px 5px 1px;
  color: var(--counter-red);
  border: 2px inset var(--window-gray);
  background:
    repeating-linear-gradient(
      to bottom,
      rgb(255 255 255 / 3%) 0,
      rgb(255 255 255 / 3%) 1px,
      transparent 1px,
      transparent 3px
    ),
    #130000;
  font-family: "Courier New", Consolas, monospace;
  font-size: 33px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -3px;
  text-align: right;
  text-shadow: 0 0 5px #f00;
}

.face-button {
  display: grid;
  width: 50px;
  min-height: 50px;
  padding: 0;
  place-items: center;
}

.face-button:active,
.face-button--pressed {
  padding: 2px 0 0 2px;
}

#face-icon {
  font-family: "Arial Black", Arial, sans-serif;
  font-size: 31px;
  font-weight: 900;
  line-height: 1;
}

.board-frame {
  width: max-content;
  max-width: 100%;
  margin-inline: auto;
  padding: 3px;
  background: var(--window-gray);
  box-shadow:
    inset 1px 1px var(--window-dark),
    inset -1px -1px var(--window-light),
    inset 2px 2px var(--window-black),
    inset -2px -2px var(--window-mid);
}

.board-scroller {
  width: max-content;
  max-width: calc(100vw - 50px);
  max-height: min(68dvh, 650px);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--window-dark) var(--window-gray);
  scrollbar-width: auto;
  touch-action: pan-x pan-y;
}

.board[data-preset="beginner"] {
  --cell-size: clamp(30px, calc((100vw - 72px) / 9), 34px);
}

.board {
  display: grid;
  width: max-content;
  grid-template-columns: repeat(var(--columns), var(--cell-size));
  grid-auto-rows: var(--cell-size);
  background: var(--window-dark);
  border: 1px solid var(--window-dark);
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  position: relative;
  display: grid;
  width: var(--cell-size);
  height: var(--cell-size);
  min-width: 0;
  min-height: 0;
  padding: 0;
  place-items: center;
  overflow: hidden;
  color: #000;
  border: 0;
  border-radius: 0;
  background: var(--window-gray);
  box-shadow:
    inset -2px -2px var(--window-dark),
    inset 2px 2px var(--window-light),
    inset -3px -3px #404040,
    inset 3px 3px var(--window-mid);
  cursor: pointer;
  font-family: "Arial Black", Arial, sans-serif;
  font-size: calc(var(--cell-size) * 0.62);
  font-weight: 900;
  line-height: 1;
  touch-action: manipulation;
}

.cell:not(.cell--revealed):active {
  padding: 2px 0 0 2px;
  background: #b8b8b8;
  box-shadow:
    inset 1px 1px #404040,
    inset 2px 2px var(--window-dark);
}

.cell--revealed {
  border-top: 1px solid var(--window-dark);
  border-left: 1px solid var(--window-dark);
  background: var(--window-gray);
  box-shadow: none;
  cursor: default;
}

.cell--revealed:not(.cell--mine):not(:empty) {
  cursor: pointer;
}

.cell--flagged {
  color: #d00000;
}

.cell__symbol {
  display: block;
  line-height: 1;
  text-shadow: 1px 1px #fff;
}

.cell__symbol--flag {
  transform: translateY(-1px);
}

.cell--mine .cell__symbol {
  color: #000;
  font-size: calc(var(--cell-size) * 0.72);
}

.cell--exploded {
  background: #f00;
}

.cell--wrong-flag {
  color: #d00000;
}

.cell__wrong {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #f00;
  font-family: Arial, sans-serif;
  font-size: calc(var(--cell-size) * 0.95);
  font-weight: 900;
  line-height: 1;
  text-shadow: 1px 1px #fff;
}

.cell--number-1 {
  color: #0000ff;
}

.cell--number-2 {
  color: #008000;
}

.cell--number-3 {
  color: #ff0000;
}

.cell--number-4 {
  color: #000080;
}

.cell--number-5 {
  color: #800000;
}

.cell--number-6 {
  color: #008080;
}

.cell--number-7 {
  color: #000000;
}

.cell--number-8 {
  color: #666666;
}

.board--finished .cell {
  cursor: default;
}

.status-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  padding: 0 4px 4px;
  background: var(--window-gray);
}

.status-bar__field {
  min-height: 25px;
  margin: 0;
  padding: 5px 7px 3px;
  overflow: hidden;
  border-top: 1px solid var(--window-dark);
  border-left: 1px solid var(--window-dark);
  box-shadow:
    inset -1px -1px var(--window-light),
    inset 1px 1px #404040;
  font-size: 12px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-bar__field--compact {
  min-width: 145px;
  text-align: right;
}

.help-panel {
  width: min(100%, 760px);
  margin: 18px auto 0;
  color: #000;
  background: var(--window-gray);
  box-shadow: var(--outer-shadow), 3px 4px 0 rgb(0 0 0 / 22%);
}

.help-panel summary {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  user-select: none;
}

.help-panel__content {
  padding: 0 14px 13px;
  border-top: 1px solid var(--window-dark);
  font-size: 14px;
  line-height: 1.65;
}

.help-panel__content p {
  margin: 10px 0 0;
}

kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: 1px 5px;
  border: 1px solid #555;
  border-radius: 2px;
  background: #eee;
  box-shadow: 0 1px 0 #555;
  font-family: Consolas, monospace;
  font-size: 0.9em;
  text-align: center;
}

@media (max-width: 720px) {
  :root {
    --cell-size: 29px;
  }

  body {
    padding-inline: max(7px, env(safe-area-inset-left));
  }

  .menu-bar {
    flex-wrap: wrap;
  }

  .classic-select {
    min-width: min(100%, 230px);
    flex: 1 1 220px;
  }

  .menu-button {
    flex: 1 1 auto;
  }

  .game-panel {
    padding: 5px;
  }

  .score-panel {
    gap: 8px;
    padding-inline: 7px;
  }

  .board-scroller {
    max-width: calc(100vw - 28px);
    max-height: 64dvh;
  }

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

  .status-bar__field--compact {
    text-align: left;
  }
}

@media (max-width: 420px) {
  :root {
    --cell-size: 28px;
  }

  .title-bar__buttons span {
    width: 18px;
  }

  .control-label {
    display: none;
  }

  .classic-select {
    flex-basis: 100%;
  }

  .score-panel {
    min-height: 67px;
    grid-template-columns: minmax(78px, 1fr) auto minmax(78px, 1fr);
  }

  .counter-label {
    font-size: 10px;
  }

  .digital-counter {
    min-width: 63px;
    font-size: 28px;
  }

  .face-button {
    width: 46px;
    min-height: 46px;
  }

  #face-icon {
    font-size: 28px;
  }

  .flag-mode__label {
    display: none;
  }
}

@media (pointer: coarse) {
  .classic-button {
    min-height: 38px;
  }

  .cell {
    font-size: calc(var(--cell-size) * 0.6);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .flag-mode--active {
    animation: flag-mode-pulse 240ms ease-out;
  }

  @keyframes flag-mode-pulse {
    from {
      filter: brightness(1.25);
    }
    to {
      filter: brightness(1);
    }
  }
}
