@font-face {
  font-family: "Massallera";
  src: url("./fonts/massallera.ttf") format("truetype");
}

@font-face {
  font-family: "PressStart2P-Regular";
  src: url("./fonts/PressStart2P-Regular.ttf") format("truetype");
}

@font-face {
  font-family: "Sans";
  src: url("./fonts/FreeSans.otf");
}

:root {
  --ink: #111;
  --paper: #e8e7e2;

  --rows: 12;
  --cols: 12;

  --max-w: calc(100vw - 80px);
  --max-h: calc(100vh - 260px);

  --board-w: min(var(--max-w), calc(var(--max-h) * var(--cols) / var(--rows)));
  --board-h: calc(var(--board-w) * var(--rows) / var(--cols));
  --cell: calc(var(--board-w) / var(--cols));
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Massallera", sans-serif;
  color: var(--ink);
  background: var(--paper);
  user-select: none;
}

header {
  position: relative;
  z-index: 6;
  font-family: "Sans", sans-serif;
  font-size: 13px;
}

header a,
.about-popup a {
  text-decoration: none;
  color: #a4a4a4;
  font-size: 13px;
}

header ul,
header li {
  margin: 0;
  padding: 0;
}

.main-menu {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background-color: white;
}

.main-menu .nav-title {
  color: black;
}

.main-menu ul {
  display: flex;
  align-items: center;
  list-style: none;
}

.main-menu ul li {
  margin-left: 1rem;
}

.menuButton {
  display: none;
  padding: 0;
  border: none;
  cursor: pointer;
  background: none;
  font-family: "Sans", sans-serif;
  font-size: 13px;
  color: #a4a4a4;
}

.hidden-menu {
  position: absolute;
  top: 100%;
  left: 0;
  flex-direction: column;
  width: 100%;
  z-index: 5;
  display: none;
}

.hidden-menu a {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 16px;
  margin-bottom: 2px;
  background-color: white;
}

@media (max-width: 1024px) {
  .main-menu ul {
    display: none;
  }
  .menuButton {
    display: block;
  }
  .hidden-menu.open {
    display: flex;
  }
}

.frame {
  margin: 12px;
  padding: 20px;
  min-height: calc(100vh - 24px - 32px);
  box-sizing: border-box;
  border: 3px solid var(--ink);
}

@media (max-width: 700px) {
  .frame {
    padding: 16px;
  }
}

.about-popup {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 320px;
  max-height: calc(100vh - 6rem);
  background: white;
  border: 1px solid #ddd;
  z-index: 100;
  display: flex;
  flex-direction: column;
  font-family: "Sans", sans-serif;
  user-select: text;
  transition:
    transform 0.3s ease,
    opacity 0.3s ease;
}

.about-popup.minimized {
  transform: translateY(150%);
  opacity: 0;
  pointer-events: none;
}

.about-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  background: #f1f3f5;
  font-size: 12px;
}

.about-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: #666;
}

.about-content {
  padding: 1rem;
  font-size: 12px;
  line-height: 1.6;
  color: #333;
  overflow-y: auto;
}

.about-content p {
  margin: 0 0 0.8rem;
}

.about-tab {
  position: fixed;
  z-index: 10000;
  right: 16px;
  bottom: 16px;
  display: none;
  color: black;
  background: #a4a4a4;
  padding: 8px;
  border: none;
  font-family: "Sans", sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.about-tab.visible {
  display: flex;
}

.about-tab:hover {
  background: #8c8c8c;
}

@media (max-width: 1024px) {
  .about-popup {
    width: 100%;
    left: 0;
    right: 0;
    top: 34px;
    bottom: auto;
    max-height: calc(100vh - 34px);
    border: none;
  }

  .about-tab,
  .about-tab.visible {
    display: none;
  }
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

main[hidden] {
  display: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.title {
  margin: 0;
  max-width: var(--board-w);
  font-size: clamp(32px, 6vw, 52px);
  font-weight: normal;
  line-height: 1.1;
  text-align: center;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.status {
  display: flex;
  justify-content: space-between;
  width: var(--board-w);
}

.status b {
  font-family: "PressStart2P-Regular", monospace;
  font-weight: normal;
  font-size: 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  width: var(--board-w);
  height: var(--board-h);
}

.board {
  border: 1px solid var(--ink);
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

.grid > button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  box-shadow: inset 0 0 0 0.5px var(--ink);
  font-size: calc(var(--cell) * 0.5);
}

.tile-covered,
.tile-number,
.tile-editor-bomb {
  background: var(--paper);
}

.tile-editor {
  background: rgba(232, 231, 226, 0.4);
}

.flag,
.bomb {
  width: 70%;
  height: 70%;
  object-fit: contain;
}

.flag-wrong {
  opacity: 0.4;
}

.num-style {
  font-family: "PressStart2P-Regular", monospace;
  font-size: calc(var(--cell) * 0.4);
}

.num-1 {
  color: #1f3fd1;
}
.num-2 {
  color: #2e9b3a;
}
.num-3 {
  color: #e50914;
}
.num-4 {
  color: #000080;
}
.num-5 {
  color: #800000;
}
.num-6 {
  color: #008080;
}
.num-7 {
  color: #000;
}
.num-8 {
  color: #808080;
}

.legend {
  position: fixed;
  left: 40px;
  bottom: 36px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 20px;
  text-align: left;
  max-width: 300px;
}

.legend li + li {
  margin-top: 0.3em;
}

.legend button {
  display: flex;
  align-items: baseline;
  gap: 0.35em;
  text-align: left;
  line-height: 1.15;
  text-wrap: pretty;
}

.legend button::before {
  flex: none;
}

.legend button.active::before {
  content: "●";
}

.legend button:not(.active)::before {
  content: "○";
}

@media (max-width: 900px) {
  .legend {
    position: static;
    align-self: flex-start;
    max-width: var(--board-w);
    font-size: 17px;
  }
}

textarea {
  width: var(--board-w);
  height: 80px;
  font-family: monospace;
  font-size: 11px;
}

input[type="number"] {
  width: 4em;
  font: inherit;
}

.mines-label {
  all: unset;
  cursor: pointer;
}

.tile-exploded {
  background: #e50914 !important;
}

.editor {
  --gap: 32px;
  --panel-w: 280px;
  --max-w: calc(100vw - 80px - var(--panel-w) - var(--gap));
  --max-h: calc(100vh - 140px);
  --board-w: min(var(--max-w), calc(var(--max-h) * var(--cols) / var(--rows)));
  --board-h: calc(var(--board-w) * var(--rows) / var(--cols));
  --cell: calc(var(--board-w) / var(--cols));
  padding: 20px 40px;
}

.editor-layout {
  display: flex;
  align-items: flex-start;
  gap: var(--gap);
}

.editor-layout > .board {
  flex: none;
}

.editor-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: var(--panel-w);
  flex: none;
  font-size: 16px;
}

.editor-controls p {
  margin: 0;
}

.editor-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.editor-controls input[type="text"],
.editor-controls input[type="number"] {
  box-sizing: border-box;
  padding: 4px 6px;
  font: inherit;
  border: 1px solid var(--ink);
  background: white;
}

.editor-controls input[type="file"] {
  max-width: 100%;
  font-family: "Sans", sans-serif;
  font-size: 13px;
}

.editor-size {
  display: flex;
  gap: 16px;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.editor-actions button {
  padding: 6px 14px;
  border: 1px solid var(--ink);
}

.editor-actions button:hover {
  color: var(--paper);
  background: var(--ink);
}

.editor-controls textarea {
  width: 100%;
  box-sizing: border-box;
}

@media (max-width: 900px) {
  .editor {
    --max-w: calc(100vw - 32px);
    --max-h: calc(100vh - 120px);
    padding: 16px;
  }

  .editor-layout {
    flex-direction: column;
    align-items: center;
    width: 100%;
  }

  .editor-controls {
    width: 100%;
  }
}