*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #1a2e1a 0%, #111 55%, #000 100%);
  color: #f0f0f0;
  margin: 0;
  padding: 12px;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.wrapper {
  max-width: 1100px;
  margin: 0 auto;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.back-link {
  color: #9ee89e;
  text-decoration: none;
  font-size: 0.85rem;
  opacity: 0.9;
}

.back-link:hover {
  text-decoration: underline;
}

.lang-switch button {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ccc;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}

.lang-switch button.active {
  background: #6fdc6f;
  color: #111;
  border-color: #6fdc6f;
}

.container {
  display: flex;
  gap: 20px;
  background: rgba(40, 40, 40, 0.85);
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 200px;
  max-width: 260px;
  flex: 0 0 auto;
}

h1 {
  margin: 0;
  color: #6fdc6f;
  text-align: center;
  letter-spacing: 2px;
  font-size: 1.4rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.panel {
  background: #3a3a3a;
  padding: 10px;
  border-radius: 6px;
}

.panel-label {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: #aaa;
}

.panel p {
  margin: 4px 0;
  font-size: 0.9rem;
}

.difficulty-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.diff-btn {
  flex: 1 1 calc(50% - 6px);
  min-width: 0;
  padding: 6px 8px;
  font-size: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: #ddd;
  cursor: pointer;
}

.diff-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

.diff-btn.active {
  background: #6fdc6f;
  color: #111;
  border-color: #6fdc6f;
}

.diff-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.daily-info,
.daily-puzzle {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: #9ee89e;
}

.hidden {
  display: none !important;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px !important;
  font-size: 1rem !important;
}

#statusEmoji {
  font-size: 1.4rem;
  line-height: 1;
}

.restart-btn {
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  background: #6fdc6f;
  color: #111;
  cursor: pointer;
}

.restart-btn:hover {
  filter: brightness(1.08);
}

.diff-btn.diff-disabled,
.diff-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hint {
  margin: 0;
  font-size: 0.75rem;
  color: #888;
  line-height: 1.4;
}

.board-wrap {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: auto;
  max-width: 100%;
  padding: 4px;
}

#board {
  --cols: 9;
  --rows: 9;
  --tile-size: min(36px, calc((100vw - 48px) / var(--cols)));
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile-size));
  grid-template-rows: repeat(var(--rows), var(--tile-size));
  gap: 0;
  border: 4px solid #555;
  background: #2a2a2a;
  box-shadow: inset 0 0 0 2px #1a1a1a;
  user-select: none;
  touch-action: manipulation;
}

#board[data-diff="expert"] {
  --tile-size: min(28px, calc((100vw - 32px) / var(--cols)));
}

#board[data-diff="intermediate"] {
  --tile-size: min(30px, calc((100vw - 40px) / var(--cols)));
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  padding: 0;
  margin: 0;
  border: 1px solid #4a4a4a;
  background: linear-gradient(145deg, #5a5a5a, #4a4a4a);
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.15);
  font-size: calc(var(--tile-size) * 0.55);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile:hover:not(.revealed):not(:disabled) {
  background: linear-gradient(145deg, #666, #555);
}

.tile.revealed {
  background: #bdbdbd;
  box-shadow: none;
  border-color: #999;
  cursor: default;
}

.tile.flagged {
  background: linear-gradient(145deg, #5a5a5a, #4a4a4a);
}

.tile.long-press {
  background: #6a6a6a;
}

.tile.mine {
  background: #c44;
}

.tile.mine-hit {
  background: #f33;
  animation: pulse 0.4s ease;
}

.tile.wrong-flag {
  background: #a55;
}

.tile.empty.revealed {
  background: #bdbdbd;
}

.tile.n1 { color: #0000ff; }
.tile.n2 { color: #008000; }
.tile.n3 { color: #ff0000; }
.tile.n4 { color: #000080; }
.tile.n5 { color: #800000; }
.tile.n6 { color: #008080; }
.tile.n7 { color: #000000; }
.tile.n8 { color: #808080; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay-card {
  background: #3a3a3a;
  padding: 24px 32px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.overlay-card p {
  margin: 0 0 16px;
  font-size: 1.25rem;
  font-weight: 600;
}

@media (max-width: 720px) {
  .container {
    flex-direction: column;
    align-items: stretch;
  }

  .sidebar {
    max-width: none;
  }

  #board {
    --tile-size: min(34px, calc((100vw - 56px) / var(--cols)));
  }

  #board[data-diff="expert"] {
    --tile-size: min(34px, calc((100vw - 24px) / var(--cols)));
  }

  #board[data-diff="intermediate"] {
    --tile-size: min(26px, calc((100vw - 40px) / var(--cols)));
  }
}

@media (min-width: 900px) {
  #board {
    --tile-size: 32px;
  }

  #board[data-diff="beginner"],
  #board[data-diff="daily"] {
    --tile-size: 36px;
  }

  #board[data-diff="intermediate"] {
    --tile-size: 28px;
  }

  #board[data-diff="expert"] {
    --tile-size: 24px;
  }
}
