/* =====================================================
   GAME SHELL — integrated with civic-tool aesthetic
   ===================================================== */

body.ms-no-scroll { overflow: hidden; }

.ms-game-shell {
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

/* Top stats bar */
.ms-game-topbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  background: var(--c-blue-deep);
  color: #fff;
}
.ms-stat {
  padding: 1rem 0.85rem;
  text-align: center;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
}
.ms-stat:last-child { border-right: none; }
.ms-stat__label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 0.35rem;
}
.ms-stat strong {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 3vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1;
  color: #fff;
}

/* Toolbar */
.ms-game-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem clamp(0.85rem, 2vw, 1.25rem);
  background: var(--c-surface-alt);
  border-bottom: 1px solid var(--c-line);
  justify-content: center;
}

.ms-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.7rem 1rem;
  font-family: var(--font-body);
  font-size: 0.93rem;
  font-weight: 700;
  letter-spacing: -0.005em;
  border-radius: var(--r-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  background: var(--c-surface);
  color: var(--c-ink);
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.12s ease;
  min-height: 42px;
  white-space: nowrap;
}
.ms-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.ms-btn:active { transform: translateY(1px); }
.ms-btn:focus-visible {
  outline: 3px solid rgba(26, 77, 122, 0.3);
  outline-offset: 2px;
}

.ms-btn--primary {
  background: var(--c-blue);
  color: #fff;
  border-color: var(--c-blue);
}
.ms-btn--primary:hover {
  background: var(--c-blue-dark);
  border-color: var(--c-blue-dark);
}

.ms-btn--ghost {
  background: var(--c-surface);
  color: var(--c-ink-2);
  border-color: var(--c-line);
}
.ms-btn--ghost:hover {
  background: var(--c-blue-tint);
  border-color: var(--c-blue);
  color: var(--c-blue-deep);
}

/* Message strip */
.ms-message {
  padding: 0.75rem 1rem;
  background: var(--c-bg-soft);
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--c-ink-2);
  border-bottom: 1px solid var(--c-line);
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ms-message.is-warning {
  background: var(--c-amber-soft);
  color: var(--c-warning);
}
.ms-message.is-success {
  background: #e7f5ee;
  color: var(--c-success);
}

/* The board */
.ms-board {
  position: relative;
  width: min(100%, 1080px);
  min-height: 580px;
  margin: 0 auto;
  background:
    radial-gradient(circle at 50% 0%, rgba(26, 77, 122, 0.08) 0%, transparent 65%),
    linear-gradient(180deg, #ede5d4 0%, #e6dbc5 100%);
  overflow: auto;
  touch-action: manipulation;
  padding: 0.5rem;
}

.ms-tile {
  position: absolute;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--c-ink);
  font-weight: 900;
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease, filter 0.12s ease, opacity 0.18s ease;
  overflow: visible;
}
.ms-tile:hover { transform: translateY(-2px); filter: brightness(1.04); }
.ms-tile:focus-visible {
  outline: 3px solid rgba(194, 65, 12, 0.45);
  outline-offset: 3px;
}
.ms-tile-image {
  position: absolute;
  inset: -3px;
  width: calc(100% + 6px);
  height: calc(100% + 6px);
  object-fit: contain;
  opacity: 1;
  pointer-events: none;
  filter: drop-shadow(0 4px 2px rgba(15, 33, 46, 0.18));
}
.ms-tile.is-selected .ms-tile-image {
  filter:
    drop-shadow(0 0 9px rgba(194, 65, 12, 0.85))
    drop-shadow(0 4px 2px rgba(15, 33, 46, 0.18));
}
.ms-tile.is-hint {
  animation: msHintPulse 1.1s ease-in-out 2;
}
.ms-tile.is-hint .ms-tile-image {
  filter:
    drop-shadow(0 0 12px rgba(26, 77, 122, 0.85))
    drop-shadow(0 4px 2px rgba(15, 33, 46, 0.18));
}
.ms-tile.is-blocked { cursor: not-allowed; }
.ms-tile.is-blocked .ms-tile-image {
  filter:
    grayscale(0.22) brightness(0.85)
    drop-shadow(0 4px 2px rgba(15, 33, 46, 0.14));
}
.ms-tile.is-removed {
  pointer-events: none;
  opacity: 0;
  transform: scale(0.82);
}
.ms-tile-symbol,
.ms-tile-label { display: none; }

@keyframes msHintPulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-4px) scale(1.04); }
}

/* Fullscreen */
.game-wrapper:fullscreen {
  background: var(--c-bg);
  padding: 1rem;
  overflow: auto;
}
.game-wrapper:fullscreen .ms-game-shell {
  min-height: calc(100vh - 2rem);
  height: 100%;
}
.game-wrapper:fullscreen .ms-board {
  min-height: calc(100vh - 240px);
}

/* Responsive game adjustments */
@media (max-width: 720px) {
  .ms-game-topbar { grid-template-columns: repeat(2, 1fr); }
  .ms-stat:nth-child(2) { border-right: none; }
  .ms-stat:nth-child(1),
  .ms-stat:nth-child(2) { border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
  .ms-board { min-height: 440px; }
}

@media (max-width: 520px) {
  .ms-game-toolbar { padding: 0.85rem; }
  .ms-btn {
    flex: 1 1 calc(50% - 0.25rem);
    justify-content: center;
    font-size: 0.88rem;
    padding: 0.65rem 0.8rem;
  }
  .ms-board { min-height: 360px; }
}


/* =====================================================
   RESPONSIVE GAME FIX — fit board to narrow phones
   ===================================================== */
.ms-game-shell,
.ms-board {
  max-width: 100%;
}

.ms-board {
  overflow: hidden;
  overscroll-behavior: contain;
}

@media (hover: none) {
  .ms-tile:hover {
    transform: none;
    filter: none;
  }
}

@media (max-width: 720px) {
  .ms-game-topbar {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .ms-stat {
    padding: 0.72rem 0.35rem;
    border-bottom: none !important;
  }

  .ms-stat__label {
    font-size: 0.62rem;
    letter-spacing: 0.08em;
  }

  .ms-stat strong {
    font-size: clamp(1rem, 4vw, 1.35rem);
  }

  .ms-message {
    font-size: 0.9rem;
    line-height: 1.35;
    padding: 0.65rem 0.75rem;
  }
}

@media (max-width: 560px) {
  .ms-game-shell {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    margin-inline: -0.85rem;
  }

  .ms-game-toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    padding: 0.75rem;
  }

  .ms-btn {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 0.62rem 0.55rem;
    font-size: 0.83rem;
    line-height: 1.1;
    white-space: normal;
  }

  .ms-btn svg {
    width: 14px;
    height: 14px;
  }

  .ms-board {
    width: 100%;
    min-height: 300px;
    padding: 0.35rem;
  }

  .ms-tile-image {
    inset: -2px;
    width: calc(100% + 4px);
    height: calc(100% + 4px);
    filter: drop-shadow(0 2px 1px rgba(15, 33, 46, 0.18));
  }
}

@media (max-width: 380px) {
  .ms-game-topbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ms-stat:nth-child(odd) {
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }

  .ms-stat:nth-child(1),
  .ms-stat:nth-child(2) {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
  }

  .ms-game-toolbar {
    grid-template-columns: 1fr;
  }
}
