.minesweeper-page {
  --ms-cell: clamp(14px, min(28px, calc((100vw - 620px) / 30), calc((100dvh - 202px) / 16)), 28px);
  --ms-mode: 38px;
  --ms-status: 64px;
  --ms-height: calc((var(--ms-cell) * 16) + var(--ms-status) + var(--ms-mode));
  min-height: 100dvh;
  width: 100%;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 18px;
  overflow: hidden;
}

.minesweeper-page::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-color: #050505;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 34px 34px;
}

.minesweeper-header {
  width: min(1420px, 100%);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.minesweeper-title {
  font-size: 21px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.minesweeper-subtitle {
  color: #666;
  font-size: 11px;
  letter-spacing: 0.14em;
  margin-top: 6px;
}

.minesweeper-layout {
  display: grid;
  grid-template-columns: minmax(190px, 245px) auto minmax(225px, 275px);
  justify-content: center;
  align-items: center;
  gap: clamp(10px, 1.15vw, 18px);
  width: 100%;
}

.minesweeper-side {
  height: var(--ms-height);
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: rgba(5, 5, 5, 0.82);
  padding: 0 6px;
}

.minesweeper-stats-panel {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.minesweeper-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex: 0 0 auto;
  margin-bottom: 7px;
}

.minesweeper-side h2 {
  color: #ededed;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
}

.minesweeper-online {
  color: #79a68f;
  font-size: 11px;
}

.minesweeper-panel-note {
  color: #575757;
  font-size: 10px;
  margin-bottom: 11px;
}

.minesweeper-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.minesweeper-chat-messages::-webkit-scrollbar,
.minesweeper-leaderboard::-webkit-scrollbar {
  width: 7px;
}

.minesweeper-chat-messages::-webkit-scrollbar-track,
.minesweeper-leaderboard::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

.minesweeper-chat-messages::-webkit-scrollbar-thumb,
.minesweeper-leaderboard::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 9px;
  border: 1px solid var(--scrollbar-track);
}

.minesweeper-chat-message {
  color: #c9c9c9;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  transition: opacity 480ms ease;
}

.minesweeper-chat-message.expiring {
  opacity: 0;
}

.minesweeper-chat-time {
  color: #555;
  margin-right: 5px;
}

.minesweeper-chat-user {
  color: #f1f1f1;
  font-weight: 600;
  margin-right: 4px;
}

.minesweeper-empty {
  color: #666;
  font-size: 12px;
}

.minesweeper-error {
  color: #ff7187;
  font-size: 11px;
  padding-top: 8px;
}

.minesweeper-chat-form {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.minesweeper-chat-form .input-field {
  padding: 9px 10px;
  font-size: 12px;
  min-width: 0;
}

.minesweeper-chat-form .btn {
  padding: 9px 12px;
  font-size: 12px;
}

.minesweeper-game {
  height: var(--ms-height);
  position: relative;
  display: flex;
  flex-direction: column;
  background: #050505;
  overflow: hidden;
}

.minesweeper-mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  width: min(260px, 54%);
  height: calc(var(--ms-mode) - 8px);
  margin: 0 auto 8px;
  background: #070707;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-sizing: border-box;
}

.minesweeper-mode-btn {
  border: 0;
  border-radius: 0;
  background: #0b0b0b;
  color: var(--text-muted);
  padding: 7px 10px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  cursor: pointer;
}

.minesweeper-mode-btn:hover,
.minesweeper-mode-btn.active {
  background: var(--scrollbar-thumb);
  color: #fff;
}

.minesweeper-no-flag-notice {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 12px 18px;
  background: rgba(0, 0, 0, 0.72);
  color: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
  pointer-events: none;
  opacity: 0;
}

.minesweeper-no-flag-notice.visible {
  animation: minesweeper-notice-fade 950ms ease both;
}

@keyframes minesweeper-notice-fade {
  0% { opacity: 0; transform: translate(-50%, -45%); }
  18% { opacity: 1; transform: translate(-50%, -50%); }
  78% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -55%); }
}

.minesweeper-status {
  height: var(--ms-status);
  flex: 0 0 var(--ms-status);
  position: relative;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  background: #080808;
  border-bottom: 1px solid #181818;
}

.counter-display {
  min-width: 68px;
  padding: 5px 9px;
  color: #ececec;
  font: 600 25px/1 "Consolas", monospace;
  letter-spacing: 0.11em;
  background: #030303;
  text-align: center;
}

.minesweeper-counter-group {
  min-width: 135px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.minesweeper-counter-group--time {
  justify-content: flex-end;
}

.minesweeper-counter-label {
  color: #646464;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.minesweeper-game-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.minesweeper-music-control {
  height: 48px;
  padding: 3px 7px;
  border: 1px solid #191919;
  background: #090909;
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  z-index: 8;
  pointer-events: auto;
}

.minesweeper-volume-stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
  pointer-events: auto;
}

.minesweeper-volume-row {
  display: grid;
  grid-template-columns: 17px 34px 82px 28px;
  align-items: center;
  gap: 4px;
  color: #777;
  font-size: 8px;
  letter-spacing: .08em;
  text-transform: uppercase;
  pointer-events: auto;
  user-select: none;
}

.minesweeper-music-toggle {
  width: 17px;
  height: 18px;
  border: 0;
  padding: 1px;
  background: transparent;
  color: #676767;
  cursor: pointer;
}

.minesweeper-music-toggle:hover,
.minesweeper-music-toggle.is-enabled {
  color: #ededed;
}

.minesweeper-music-toggle svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.minesweeper-music-toggle .sound-wave,
.minesweeper-music-toggle .mute-line {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.65;
}

.minesweeper-music-toggle.is-enabled .mute-line {
  display: none;
}

.minesweeper-music-toggle:not(.is-enabled) .sound-wave {
  display: none;
}

.minesweeper-music-volume {
  width: 82px;
  height: 16px;
  appearance: none;
  background: transparent;
  outline: none;
  cursor: pointer;
  position: relative;
  display: block;
  margin: 0;
  z-index: 9;
  pointer-events: auto;
  touch-action: none;
}

.minesweeper-music-volume::-webkit-slider-runnable-track {
  height: 3px;
  background: #242424;
}

.minesweeper-music-volume::-moz-range-track {
  height: 3px;
  background: #242424;
}

.minesweeper-music-volume::-webkit-slider-thumb {
  width: 11px;
  height: 11px;
  margin-top: -4px;
  appearance: none;
  border-radius: 50%;
  background: #eaeaea;
  cursor: pointer;
}

.minesweeper-music-volume::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border: 0;
  border-radius: 50%;
  background: #eaeaea;
  cursor: pointer;
}

.minesweeper-volume-row output {
  color: #9b9b9b;
  font: 9px/1 "Consolas", monospace;
  letter-spacing: 0;
  text-align: right;
}

#reset-button {
  width: 36px;
  height: 36px;
  border: 1px solid #262626;
  background: #111;
  cursor: pointer;
  position: relative;
}

#reset-button::before {
  content: "";
  display: block;
  width: 9px;
  height: 9px;
  margin: auto;
  border-radius: 50%;
  background: #00ffae;
}

#reset-button.status-waiting::before {
  background: #398bff;
}

#reset-button.status-lost::before {
  background: #ff1a1a;
}

#reset-button.status-win::before {
  background: #aa00ff;
}

#reset-button.loading::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid transparent;
  border-top-color: #eee;
  border-radius: 50%;
  animation: minesweeper-spin 600ms linear infinite;
}

@keyframes minesweeper-spin {
  to { transform: rotate(360deg); }
}

.minesweeper-view-btn {
  border: 1px solid #191919;
  background: #090909;
  color: #777;
  height: 30px;
  padding: 0 8px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.minesweeper-view-btn:hover {
  border-color: #333;
  color: #ddd;
}

#board {
  display: grid;
  grid-template-columns: repeat(30, var(--ms-cell));
  grid-template-rows: repeat(16, var(--ms-cell));
  background: #050505;
}

#board .cell {
  width: var(--ms-cell);
  height: var(--ms-cell);
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  cursor: pointer;
  background: #242424;
  border-right: 1px solid #050505;
  border-bottom: 1px solid #050505;
  font-size: calc(var(--ms-cell) * 0.63);
  line-height: 1;
  font-weight: 700;
}

#board .cell:hover:not(.revealed) {
  background: #303030;
}

#board .revealed {
  background: #050505;
  border-right-color: #343434;
  border-bottom-color: #343434;
  cursor: default;
}

#board .cell.revealed:empty {
  background: #050505;
}

#board .num-1 { color: #2684ff; }
#board .num-2 { color: #16a34a; }
#board .num-3 { color: #ed2939; }
#board .num-4 { color: #1d3fbd; }
#board .num-5 { color: #991d31; }
#board .num-6 { color: #18b4bc; }
#board .num-7 { color: #ffd447; text-shadow: none; }
#board .num-8 { color: #b452df; }
#board .mine { background: #ff1a1a !important; color: #050505; }
#board .flag { color: #b032f5; font-family: "Segoe UI Symbol", sans-serif; }
#board .incorrect-flag { background: #39101b !important; color: #ff7187; }
#board .safe-start::after {
  content: "";
  width: 5px;
  height: 5px;
  background: #00ffae;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0, 255, 174, 0.68);
}

#board .cell.safe-start.shake-hint {
  animation: minesweeper-start-wiggle 310ms ease-in-out;
}

@keyframes minesweeper-start-wiggle {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

#result-screen {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 7;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  background: rgba(3, 3, 3, 0.87);
}

#result-screen.visible {
  display: flex;
}

#result-screen h2 {
  font-size: 25px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
}

#result-details {
  text-align: center;
  color: #aaa;
  font-size: 13px;
}

.minesweeper-personal-improved,
.minesweeper-personal-slower {
  display: block;
  margin-top: 7px;
  font-weight: 600;
}

.minesweeper-personal-improved {
  color: #00d98b;
}

.minesweeper-personal-slower {
  color: #ff5169;
}

#game-message {
  display: none;
}

.minesweeper-fs-hint {
  opacity: 0;
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #090909;
  padding: 8px 12px;
  z-index: 12;
  font-size: 11px;
  transition: opacity 180ms;
  pointer-events: none;
  user-select: none;
}

.minesweeper-fs-hint.visible {
  opacity: 1;
}

.minesweeper-stats-section {
  flex: 0 0 auto;
  margin-bottom: 13px;
}

.minesweeper-stats-section h2,
.minesweeper-leaderboard-section h2 {
  border-bottom: 1px solid #151515;
  padding-bottom: 6px;
  margin-bottom: 7px;
}

.minesweeper-stats-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  font-size: 11px;
}

.minesweeper-stats-grid dt {
  color: #727272;
}

.minesweeper-stats-grid dd {
  color: #e4e4e4;
  text-align: right;
  max-width: 165px;
}

.minesweeper-leaderboard-section {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.minesweeper-leaderboard {
  flex: 0 0 184px;
  height: 184px;
  max-height: 184px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 5px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.minesweeper-friend-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #f1f1f1;
  color: #070707;
  cursor: default;
  opacity: 1;
}

.minesweeper-friend-chip::before {
  content: "";
  width: 8px;
  height: 4px;
  border-left: 2px solid #070707;
  border-bottom: 2px solid #070707;
  transform: rotate(-45deg);
}

.minesweeper-rank-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  column-gap: 6px;
  row-gap: 2px;
  align-items: start;
  font-size: 11px;
  padding: 6px 0 7px;
  border-bottom: 1px solid #111;
  min-height: 46px;
}

.minesweeper-rank-row button {
  grid-column: 2;
  grid-row: 1;
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.minesweeper-rank-number {
  grid-column: 1;
  grid-row: 1 / 3;
  padding-top: 1px;
  color: #666;
}

.minesweeper-rank-time-group {
  grid-column: 3;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  font-variant-numeric: tabular-nums;
}

.minesweeper-rank-time {
  text-align: right;
  color: #00d98b;
  line-height: 1.1;
}

.minesweeper-rank-delta {
  color: #6a6a6a;
  font-size: 9px;
  font-style: italic;
  line-height: 1;
}

.minesweeper-rank-date {
  grid-column: 2;
  grid-row: 2;
  color: #555;
  font-size: 9px;
  line-height: 1.1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.minesweeper-guest-notice,
.minesweeper-popup-hint {
  display: block;
  margin-top: 8px;
  color: #8f8f8f;
  font-size: 11px;
}

.minesweeper-chat-form--disabled {
  opacity: 0.65;
}

#minesweeper-chat-error a {
  color: #d8d8d8;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.minesweeper-user-popup {
  position: fixed;
  z-index: 100;
  background: #090909;
  border: 1px solid #252525;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 150px;
}

.minesweeper-user-popup span {
  font-size: 12px;
}

.minesweeper-user-popup .btn {
  padding: 9px;
  font-size: 11px;
}

.minesweeper-game:fullscreen,
.minesweeper-game.theater-mode {
  --ms-cell: min(calc((100dvh - var(--ms-status) - var(--ms-mode) - 20px) / 16), calc((100vw - 20px) / 30));
  --ms-status: 64px;
  position: fixed;
  inset: 0;
  height: 100dvh;
  width: 100vw;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  background: #050505;
}

.minesweeper-game:fullscreen .minesweeper-status,
.minesweeper-game.theater-mode .minesweeper-status {
  width: calc(var(--ms-cell) * 30);
}

body.theater-active .minesweeper-header,
body.theater-active .minesweeper-side {
  visibility: hidden;
}

@media (max-width: 1320px), (max-height: 820px) {
  .minesweeper-page {
    overflow-y: auto;
    justify-content: flex-start;
    --ms-cell: clamp(13px, min(28px, calc((100vw - 44px) / 30), calc((100dvh - 304px) / 16)), 28px);
    padding-bottom: 132px;
  }

  .minesweeper-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .minesweeper-side {
    width: calc(var(--ms-cell) * 30);
    max-width: calc(100vw - 44px);
    height: 280px;
  }
}
