* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--primary-color);
  font-family: 'Roboto', sans-serif;
  user-select: none;
  touch-action: none;

  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--footer-h);
}

/* HEADER */
.topbar {
  height: var(--header-h);

  display: grid;
  grid-template-columns: 48px auto 48px;
  align-items: center;

  width: min(calc(100vw - (var(--side-space) * 2)),
      calc((100vh - var(--header-h) - var(--footer-h) - 16px) * var(--img-ratio)));

  margin: 0 auto;
  color: var(--line-color);
}

.topbar__title {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  /* text-transform: lowercase; */
}

.topbar__btn {
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--line-color);
  font-size: 1.4rem;
  cursor: pointer;
  border-radius: 10px;
}

/* ÁREA CENTRAL */
.game-area {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px var(--side-space);
}

/*
  O board usa o menor valor entre:
  - largura disponível
  - altura disponível convertida pela proporção
*/
.board {
  width: min(calc(100vw - (var(--side-space) * 2)),
      calc((100vh - var(--header-h) - var(--footer-h) - 16px) * var(--img-ratio)));

  aspect-ratio: var(--img-ratio);

  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: var(--gap);
  padding: var(--board-pad);

  background: rgba(0, 0, 0, .10);
  position: relative;
}

/* FOOTER */
.bottombar {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  /* gap: 18px; */
  padding: 0 12px 30px 12px;
  /* sobe os ícones */
}

.bottombar__btn {
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--line-color);
  font-size: 1.3rem;
  cursor: pointer;
  border-radius: 10px;
}

.bottombar__like-count {
  color: var(--line-color);
  font-size: 1rem;
  font-weight: 600;
  min-width: 40px;
  text-align: left;
}

/* restante do puzzle */
.board.debug {
  --gap: 10px;
  --tile-radius: 10px;
  --tile-border: 2px solid rgba(255, 255, 255, .55);
  --sep: 0px;
}

.tile {
  border-radius: var(--tile-radius);
  border: var(--tile-border);
  background: transparent;
  overflow: hidden;

  cursor: grab;
  position: relative;
  transform: translateZ(0);
  will-change: transform;
}

.tile:active {
  cursor: grabbing;
}

.tile__inner {
  width: 100%;
  height: 100%;
  padding: 0;
}

.tile__img {
  width: 100%;
  height: 100%;
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
  border-radius: 0;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;

  --sep-l: var(--sep);
  --sep-r: var(--sep);
  --sep-t: var(--sep);
  --sep-b: var(--sep);

  background:
    linear-gradient(to right,
      var(--sep-color) 0 var(--sep-l),
      transparent var(--sep-l) calc(100% - var(--sep-r)),
      var(--sep-color) calc(100% - var(--sep-r)) 100%),
    linear-gradient(to bottom,
      var(--sep-color) 0 var(--sep-t),
      transparent var(--sep-t) calc(100% - var(--sep-b)),
      var(--sep-color) calc(100% - var(--sep-b)) 100%);
}

.join-right::after {
  --sep-r: 0px;
}

.join-left::after {
  --sep-l: 0px;
}

.join-top::after {
  --sep-t: 0px;
}

.join-bot::after {
  --sep-b: 0px;
}

.dragging-hidden {
  opacity: 0;
  pointer-events: none;
}

.ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9999;
  pointer-events: none;
  filter: drop-shadow(0 18px 40px rgba(0, 0, 0, .35));
}

.ghost .tile {
  position: absolute;
  box-shadow: none;
  cursor: grabbing;
}

#dropPreview {
  position: absolute;
  left: var(--board-pad);
  top: var(--board-pad);
  right: var(--board-pad);
  bottom: var(--board-pad);

  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: var(--gap);

  pointer-events: none;
  z-index: 50;
}

#dropPreview .cell {
  opacity: 0;
  transform: scale(.98);
  transition: opacity .08s ease, transform .08s ease;
}

#dropPreview .cell.on {
  opacity: 1;
  transform: scale(1);
  outline: 3px solid var(--primary-color);
  outline-offset: -3px;
  background: rgba(255, 255, 255, .10);
}

#dropPreview .cell.bad {
  opacity: 1;
  transform: scale(1);
  outline: 3px solid rgba(255, 80, 80, .80);
  outline-offset: -3px;
  background: rgba(255, 80, 80, .12);
}


.theme-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
}

.theme-modal.is-open {
  display: block;
}

.theme-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.28);
}

.theme-modal__panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 520px);
  max-height: 80vh;
  overflow-y: auto;

  background: var(--primary-color);
  border: 2px solid var(--line-color);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
}

.theme-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.theme-modal__title {
  margin: 0;
  color: var(--line-color);
  font-size: 1.1rem;
  font-weight: 700;
}

.theme-modal__close {
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--line-color);
  border-radius: 10px;
  background: transparent;
  color: var(--line-color);
  cursor: pointer;
  font-size: 1.1rem;
}

.theme-modal__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.theme-card-form {
  margin: 0;
}

.theme-card {
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.theme-card__preview {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--line-color);
  border-radius: 12px;
  display: block;
}

.theme-card__label {
  color: var(--line-color);
  font-size: 0.95rem;
  font-weight: 500;
}

.theme-card:hover,
.theme-modal__close:hover {
  background: rgba(255, 255, 255, 0.08);
}

.status-modal__content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.status-card {
  border: 2px solid var(--line-color);
  border-radius: 14px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.06);

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-card__label {
  color: var(--line-color);
  font-size: 1rem;
  font-weight: 600;
}

.status-card__value {
  color: var(--line-color);
  font-size: 1.15rem;
  font-weight: 700;
}

.status-share {
  display: flex;
  justify-content: center;
  gap: 12px;
  /* margin-top: 20px; */
}

.status-share__btn {
  width: 50px;
  height: 50px;
  border: none;
  background: transparent;
  color: var(--line-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  text-decoration: none;
  /* transition: transform 0.15s ease, opacity 0.15s ease; */
}

.status-share__btn:hover {
  transform: scale(1.3);
  opacity: 0.9;
}

.status-share__btn.copied {
  animation: flash 0.4s ease;
}

.status-share-title {
  text-align: center;
  font-weight: 500;
  font-size: 20px;
  /* margin: 36px 0 0; */
  color: var(--line-color);
}

.how-to-play-p {
  color: var(--line-color);
  text-align: justify;
  margin-bottom: 30px;
  margin-top: 30px;
}

.status-support-link {
  display: none;
  text-align: center;
  margin: 30px 0 25px;
  color: var(--line-color);
  font-size: 0.98rem;
  font-weight: 600;
  opacity: 0.92;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.status-support-link:hover {
  transform: scale(1.03);
  opacity: 1;
  text-decoration: underline;
}

@keyframes flash {
  0%   { transform: scale(1); opacity: 1; }
  50%  { transform: scale(1.3); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}

@media (min-width: 900px) {

  /* HEADER */
  .topbar {
    height: 72px;
  }

  .topbar__title {
    font-size: 1.8rem;
  }

  .topbar__btn {
    font-size: 1.9rem;
    width: 48px;
    height: 48px;
  }

  /* FOOTER */

  .bottombar {
    height: 72px;
    /* gap: 28px; */
  }

  .bottombar__btn {
    font-size: 1.8rem;
    width: 48px;
    height: 48px;
  }

  .theme-modal__panel {
    width: min(90vw, 640px);
    padding: 22px;
  }

  .theme-modal__title {
    font-size: 1.35rem;
  }

  .theme-modal__grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
  }

  .theme-card {
    padding: 14px;
  }

  .theme-card__label {
    font-size: 1rem;
  }

}


/* ===== SIDE MENU ===== */

.side-menu {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.side-menu.is-open {
  pointer-events: all;
}

/* backdrop */
.side-menu__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  transition: 0.25s ease;
}

.side-menu.is-open .side-menu__backdrop {
  opacity: 1;
}

/* panel */
.side-menu__panel {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 260px;

  background: var(--primary-color);
  color: var(--line-color);

  transform: translateX(-100%);
  transition: 0.25s ease;

  display: flex;
  flex-direction: column;
  padding: 16px;
  backdrop-filter: blur(6px);
}

.side-menu.is-open .side-menu__panel {
  transform: translateX(0);
}

/* header */
.side-menu__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 18px;
  margin-bottom: 20px;
}

.side-menu__close {
  background: none;
  border: none;
  color: var(--line-color);
  font-size: 20px;
  cursor: pointer;
}

/* items */
.side-menu__content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-menu__item {
  color: var(--line-color);
  text-decoration: none;
  font-size: 16px;
  padding: 10px;
  border-radius: 8px;
  transition: 0.2s;
}

.side-menu__item:hover {
  background: rgba(255,255,255,0.1);
}