:root {
  /* Cores das peças, próximas às do jogo físico */
  --piece-red: #d63a4a;
  --piece-blue: #5f6fd0;
  --piece-white: #eef0ec;
  --piece-yellow: #e0c62c;
  --piece-black: #33262a;
  /* usadas só na opção de 8 cores diferentes */
  --piece-orange: #ee8a2e;
  --piece-green: #4caf6a;
  --piece-cyan: #35b6c9;
  --piece-pink: #e872a8;

  --page: #eceae6;
  --panel: #f8f7f5;
  --text: #26242a;
  --muted: #66636b;
  --frame: #77716f;
  --board: #b9b6b2;
  --peg: #cdcac6;
  --accent: #3f52b5;
  --ok: #1f9d55;
  --bad: #d62839;

  /*
   * Lado de uma casa, calculado para tabuleiro e bandeja caberem na tela sem
   * rolagem. Este é o caso da tela em pé (bandeja embaixo): 320px de cabeçalho
   * e botões, mais 8 casas do tabuleiro e cerca de 4 da bandeja na altura
   * (o suficiente mesmo com todas as peças giradas).
   */
  --cell: max(26px, min((100vw - 52px) / 8, (100dvh - 320px) / 12, 72px));
  --tray-cell: calc(var(--cell) * 0.45);
  --gap: 2px;
}

/* Tela deitada (computador): bandeja ao lado do tabuleiro. */
@media (orientation: landscape) {
  :root {
    /* na largura: 8 casas do tabuleiro e cerca de 6,4 da bandeja, mais as margens */
    --cell: max(24px, min((100dvh - 290px) / 8, (100vw - 150px) / 14.4, 72px));
    --tray-cell: calc(var(--cell) * 0.58);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 16px 24px;
  background: var(--page);
  color: var(--text);
  font: 16px/1.5 system-ui, sans-serif;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1160px;
  margin: 0 auto;
  padding: 12px 0;
}

h1 { margin: 0; font-size: 1.5rem; letter-spacing: 0.02em; white-space: nowrap; }

.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

/* precisa comportar tabuleiro e bandeja lado a lado com a casa no tamanho máximo */
main { max-width: 1160px; margin: 0 auto; }

button, .button {
  padding: 8px 18px;
  border: 1px solid #c4c1bc;
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

button:hover:not(:disabled), .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.stars { color: #c8931a; letter-spacing: 0.1em; }

/* ---------- guia e apoio ---------- */

.support-button { color: #b4213a; font-weight: 600; }

dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: min(85vh, calc(100vh - 32px));
  padding: 0;
  overflow-y: auto;
  border: 0;
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 16px 48px rgb(0 0 0 / 0.35);
}

dialog::backdrop { background: rgb(20 18 24 / 0.55); }

.dialog-body { padding: 20px 24px 24px; }
.dialog-body h2 { margin: 0 0 12px; font-size: 1.4rem; }
.dialog-body h3 { margin: 0; font-size: 1rem; }
.dialog-body li p { margin: 2px 0 12px; }

.steps { padding-left: 24px; }
.steps li::marker { color: var(--accent); font-weight: 700; }

.ok { color: var(--ok); }
.bad { color: var(--bad); }

.tip { padding: 10px 14px; border-radius: 10px; background: #eef0fb; }

.support-options {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  padding: 16px;
  border-radius: 12px;
  background: #fbeff1;
  text-align: center;
}

.support-options p { margin: 0; }
.pix { display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 100%; }
.pix-key { padding: 6px 12px; border-radius: 8px; background: #fff; overflow-wrap: anywhere; }
.pix-name, .copy-status, .fine-print { color: var(--muted); font-size: 0.85rem; }
.soon { font-weight: 600; }

/* ---------- seleção de fases ---------- */

.summary { color: var(--muted); }

#levels h2 { display: flex; align-items: baseline; gap: 12px; margin: 24px 0 8px; font-size: 1.2rem; }
#levels h2 small { color: var(--muted); font-weight: normal; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 8px;
}

.level {
  display: grid;
  place-items: center;
  position: relative;
  aspect-ratio: 1;
  border: 1px solid #c4c1bc;
  border-radius: 10px;
  background: var(--panel);
  color: inherit;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-decoration: none;
}

.level:hover { border-color: var(--accent); }
.level--done { background: var(--ok); border-color: var(--ok); color: #fff; }
.level--done::after { content: '✔'; position: absolute; top: 2px; right: 5px; font-size: 0.7rem; }

/* ---------- partida ---------- */

.level-bar { display: flex; align-items: center; justify-content: center; gap: 16px; }
.level-bar h2 { margin: 4px 0 12px; min-width: 14ch; text-align: center; font-size: 1.25rem; }
.level-bar button { margin-bottom: 8px; padding: 2px 14px; font-size: 1.3rem; }
.done-mark { color: var(--ok); font-size: 0.85rem; }

.play {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 24px;
}

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

.board-frame {
  position: relative;
  padding: 10px;
  border-radius: 16px;
  background: var(--frame);
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.22);
}

.board {
  display: grid;
  grid-template: repeat(8, var(--cell)) / repeat(8, var(--cell));
  border-radius: 8px;
  background: var(--board);
  user-select: none;
}

.peg {
  margin: 12%;
  border-radius: 50%;
  background: var(--peg);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
}

.piece {
  --size: var(--cell);
  width: calc(var(--w) * var(--size) - 2 * var(--gap));
  height: calc(var(--h) * var(--size) - 2 * var(--gap));
  margin: var(--gap);
  border-radius: 6px;
  box-shadow:
    inset 0 2px 0 rgb(255 255 255 / 0.3),
    inset 0 -3px 0 rgb(0 0 0 / 0.18),
    0 2px 4px rgb(0 0 0 / 0.3);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.piece--red { background: var(--piece-red); }
.piece--blue { background: var(--piece-blue); }
.piece--white { background: var(--piece-white); }
.piece--yellow { background: var(--piece-yellow); }
.piece--black { background: var(--piece-black); }
.piece--orange { background: var(--piece-orange); }
.piece--green { background: var(--piece-green); }
.piece--cyan { background: var(--piece-cyan); }
.piece--pink { background: var(--piece-pink); }

.board .piece { z-index: 1; }
.piece--fixed { cursor: default; }
.piece--lifted { opacity: 0.3; }
.piece--gone { visibility: hidden; }

.piece--dragging {
  position: fixed;
  z-index: 10;
  margin: 0;
  opacity: 0.85;
  pointer-events: none;
  box-shadow: 0 10px 22px rgb(0 0 0 / 0.35);
}

.preview {
  z-index: 3;
  margin: var(--gap);
  border: 3px solid;
  border-radius: 5px;
  pointer-events: none;
}

.preview--ok { border-color: var(--ok); background: rgb(31 157 85 / 0.45); }
.preview--bad { border-color: var(--bad); background: rgb(214 40 57 / 0.45); }

.hint {
  z-index: 2;
  margin: var(--gap);
  border: 4px dashed var(--text);
  border-radius: 8px;
  opacity: 0.7;
  pointer-events: none;
  animation: pulse 1.2s ease-in-out infinite alternate;
}

.hint--red { background: var(--piece-red); }
.hint--blue { background: var(--piece-blue); }
.hint--white { background: var(--piece-white); }
.hint--yellow { background: var(--piece-yellow); }
.hint--orange { background: var(--piece-orange); }
.hint--green { background: var(--piece-green); }
.hint--cyan { background: var(--piece-cyan); }
.hint--pink { background: var(--piece-pink); }

.piece--hinted { outline: 4px dashed var(--text); outline-offset: 3px; }

@keyframes pulse { to { opacity: 0.35; } }

@media (prefers-reduced-motion: reduce) {
  .hint { animation: none; }
}

.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }

.message { min-height: 1.5em; max-width: calc(8 * var(--cell)); margin: 10px 0 0; text-align: center; color: var(--muted); }

/* em pé, a bandeja usa a largura da tela para ocupar menos altura */
.tray-column { width: min(100%, max(8 * var(--cell) + 20px, 360px)); }

.tray {
  --size: var(--tray-cell);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border: 2px dashed #c4c1bc;
  border-radius: 16px;
  background: var(--panel);
}

.tray .piece { --size: var(--tray-cell); }
.tray--over { border-color: var(--accent); background: #eef0fb; }

.help { color: var(--muted); font-size: 0.9rem; }

.help-touch { display: none; }

@media (pointer: coarse) {
  .help-touch { display: inline; }
  .help-mouse { display: none; }

  /* amplia a área de toque, porque as peças finas da bandeja são pequenas */
  .tray .piece { position: relative; }
  .tray .piece::after { content: ''; position: absolute; inset: -5px; }
}

@media (orientation: landscape) {
  .play { flex-wrap: nowrap; }
  .tray-column { width: calc(11 * var(--tray-cell) + 40px); }
  .tray { min-height: calc(8 * var(--cell) + 20px); padding: 16px; gap: 12px; }
}

/* telas estreitas ou baixas (celular): cabeçalho e botões compactos */
@media (max-width: 600px), (max-height: 500px) {
  body { padding-bottom: 12px; }
  header { gap: 8px; padding: 8px 0; }
  h1 { font-size: 1.2rem; }
  .header-actions { gap: 6px; }
  .header-actions button, .header-actions .button { padding: 3px 10px; font-size: 0.85rem; }
  .level-bar h2 { margin: 0 0 6px; font-size: 1.05rem; }
  .level-bar button { margin-bottom: 6px; padding: 0 12px; font-size: 1.1rem; }
  .play { gap: 8px; }
  .actions { margin-top: 8px; }
  .actions button { padding: 5px 14px; }
  .message { margin-top: 4px; font-size: 0.85rem; line-height: 1.35; }
}

kbd { padding: 0 6px; border: 1px solid #c4c1bc; border-radius: 4px; background: var(--panel); }

.victory {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgb(20 18 24 / 0.45);
}

.victory-card {
  margin: 16px;
  padding: 20px 24px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.35);
  text-align: center;
}

.victory-card h3 { margin: 0; font-size: 1.5rem; color: var(--ok); }
.victory-card p { margin: 8px 0 0; }
