:root {
  color-scheme: dark;
  --bg: #000;
  --surface: #080808;
  --ink: #f5f5f5;
  --muted: #8b8b8b;
  --line: #242424;
  --tile: #080808;
  --tile-fill: #171717;
  --exact: #48c8b3;
  --near: #f2b36b;
  --no: #555;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #000;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  background: #000;
}

button {
  font: inherit;
}

main {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 14px;
}

.game {
  width: min(100%, 620px);
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* CABEÇALHO */

.game-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-height: 40px;
  margin: 0 0 14px;
}

.game-header h1 {
  margin: 0;
  font-size: clamp(17px, 3vw, 22px);
  font-weight: 650;
  letter-spacing: .01em;
  color: #f5f5f5;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  width: 100%;
}

.how-to-button {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  background: #111;
  color: #f3f3f3;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.how-to-button:hover,
.how-to-button:focus-visible,
.icon-button:hover,
.icon-button:focus-visible {
  border-color: #8b8b8b;
  background: #1b1b1b;
  outline: 2px solid #777;
  outline-offset: 2px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid #3a3a3a;
  border-radius: 7px;
  background: #111;
  color: #f3f3f3;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.menu-button {
  font-size: 19px;
}

.menu-panel {
  position: absolute;
  z-index: 20;
  top: 43px;
  right: 0;
  width: min(250px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid #414141;
  border-radius: 9px;
  background: #111;
  box-shadow: 0 12px 35px #000a;
}

.menu-panel p {
  margin: 0 0 5px;
  font-size: 14px;
  font-weight: 700;
}

.menu-panel span {
  color: #aaa;
  font-size: 12px;
}

/* CONTADOR DE TENTATIVAS */

.attempt-counter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 0 17px;
  padding: 10px 14px;
  border: 1px solid #303030;
  border-radius: 8px;
  background: #101010;
  color: #ddd;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .01em;
}

.attempt-counter strong {
  color: #fff;
  font: 700 25px var(--mono);
  line-height: 1;
}

.rules,
.progress-track,
.target-meta {
  display: none !important;
}

/* TABULEIRO
   Cada palavra fica numa linha.
   As letras de cada palavra permanecem na horizontal.
*/

#board.board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 15px;
  padding: 4px 2px 8px;
  overflow-x: hidden;
  overflow-y: visible;
  scrollbar-width: thin;
  scrollbar-color: #383838 transparent;
}

#board .guess-attempt-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 3px 0;
}

#board .guess-attempt-row > .word-group {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: max-content;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  flex: 0 0 auto;
}

#board .guess-attempt-row > .word-group > .tile {
  display: grid;
  place-items: center;
  flex: 0 0 clamp(21px, 3.7vw, 35px);
  width: clamp(21px, 3.7vw, 35px);
  min-width: 0;
  max-width: none;
  height: 41px;
  padding: 0;
  border: 1px solid #393939;
  border-radius: 3px;
  background: var(--tile);
  color: var(--ink);
  font: 600 13px var(--mono);
  transition: border-color .12s, background .12s;
}

.tile.filled {
  background: var(--tile-fill);
  border-color: #666;
}

.tile.exact {
  background: var(--exact);
  border-color: var(--exact);
  color: #061a17;
}

.tile.near {
  background: var(--near);
  border-color: var(--near);
  color: #171025;
}

.tile.no {
  background: #303030;
  border-color: #303030;
  color: #a5a5a5;
}

.tile.current {
  cursor: pointer;
}

.tile.selected {
  outline: 2px solid #f5f5f5;
  outline-offset: 2px;
  border-color: #f5f5f5;
}

.tile:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

/* MENSAGENS NO TOPO */

.status {
  position: fixed;
  z-index: 1000;
  top: 12px;
  left: 50%;
  width: min(calc(100% - 24px), 560px);
  min-height: 0;
  margin: 0;
  padding: 12px 16px;
  border: 1px solid #454545;
  border-radius: 8px;
  background: #171717;
  color: #f2f2f2;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .65);
  transform: translate(-50%, -150%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform .22s ease, opacity .22s ease, visibility .22s ease;
}

.status.visible {
  transform: translate(-50%, 0);
  opacity: 1;
  visibility: visible;
}

.status.error {
  border-color: #a74343;
  color: #ffb4b4;
  background: #251111;
}

.status.success {
  border-color: #258b7b;
  color: #d2fff7;
  background: #10221f;
}

/* TECLADO VIRTUAL */

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  max-width: 510px;
  margin: 0 auto;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  min-width: 0;
  flex: 1;
  height: 43px;
  padding: 0 3px;
  border: 1px solid #262626;
  border-radius: 4px;
  background: #191919;
  color: #eee;
  font: 500 13px var(--mono);
  cursor: pointer;
  box-shadow: none;
  transition: background .12s, border-color .12s;
}

.key:active {
  background: #303030;
}

.key.wide {
  flex: 1.55;
  font: 600 9px var(--sans);
  letter-spacing: 0;
}

.key.space {
  flex: 1.8;
  font: 500 10px var(--sans);
}

.key:disabled {
  cursor: default;
  opacity: .4;
}

.key.exact {
  background: var(--exact);
  border-color: var(--exact);
  color: #061a17;
}

.key.near {
  background: var(--near);
  border-color: var(--near);
  color: #171025;
}

.key.no {
  background: #303030;
  border-color: #303030;
  color: #888;
}

.key.erase-key {
  flex: 1.35;
  min-width: 39px;
  background: #4a2024;
  border: 2px solid #e05a63;
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 0 0 1px #e05a6333;
}

.key.erase-key:hover,
.key.erase-key:focus-visible {
  background: #69262c;
  border-color: #ff858c;
  outline: 2px solid #ff858c;
  outline-offset: 1px;
}

.key.confirm-key {
  width: 82px;
  min-width: 82px;
  padding: 0 3px;
  font: 700 10px var(--sans);
  letter-spacing: -0.5px;
  white-space: nowrap;
  overflow: hidden;
}

.key.confirm-key:hover,
.key.confirm-key:focus-visible {
  background: #218779;
  border-color: #6de0ce;
  outline: 2px solid #6de0ce;
  outline-offset: 1px;
}

/* COMO JOGAR */

.how-to-dialog {
  width: min(560px, calc(100% - 28px));
  max-height: min(82dvh, 720px);
  padding: 0;
  border: 1px solid #454545;
  border-radius: 12px;
  background: #101010;
  color: #eee;
  box-shadow: 0 20px 70px #000b;
}

.how-to-dialog::backdrop,
.settings-dialog::backdrop,
.result-dialog::backdrop {
  background: rgba(0, 0, 0, .78);
  backdrop-filter: blur(3px);
}

.how-to-content {
  padding: 20px 22px 22px;
  overflow-y: auto;
}

.how-to-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.how-to-heading h2 {
  margin: 0;
  font-size: 21px;
}

.close-how-to {
  width: 34px;
  height: 34px;
  border: 1px solid #393939;
  border-radius: 6px;
  background: #1b1b1b;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.how-to-content p {
  margin: 10px 0;
  color: #d0d0d0;
  font-size: 13px;
  line-height: 1.6;
}

.how-to-content h3 {
  margin: 18px 0 8px;
  font-size: 14px;
  color: #fff;
}

.color-explanations {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.color-explanations li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: #d0d0d0;
  font-size: 13px;
  line-height: 1.5;
}

.color-explanations i {
  flex: 0 0 13px;
  width: 13px;
  height: 13px;
  margin-top: 3px;
  border-radius: 3px;
}

.color-explanations i.exact {
  background: var(--exact);
}

.color-explanations i.near {
  background: var(--near);
}

.color-explanations i.no {
  background: #555;
}

.how-to-tip {
  padding: 10px 12px;
  border-left: 3px solid #555;
  background: #191919;
  border-radius: 0 5px 5px 0;
}

/* RESULTADO: VITÓRIA OU DERROTA */

.result-dialog {
  width: min(390px, calc(100% - 28px));
  max-height: 80dvh;
  padding: 0;
  border: 1px solid #454545;
  border-radius: 11px;
  background: #101010;
  color: #eee;
  box-shadow: 0 20px 70px #000b;
}

.result-dialog::backdrop {
  background: rgba(0, 0, 0, .82);
  backdrop-filter: blur(3px);
}

.result-content {
  padding: 16px 17px 17px;
}

.result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.result-heading h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
}

.result-content > p {
  margin: 8px 0 12px;
  color: #d0d0d0;
  font-size: 13px;
  line-height: 1.55;
}

.share-result {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #39b8a6;
  border-radius: 6px;
  background: #176b61;
  color: #fff;
  font: 650 13px var(--sans);
  cursor: pointer;
}

.share-result:hover,
.share-result:focus-visible {
  background: #218779;
  outline: 2px solid #6de0ce;
  outline-offset: 2px;
}

.share-result[hidden] {
  display: none;
}

.result-content .share-feedback {
  margin: 8px 0 0;
  color: var(--exact);
  font-size: 11px;
}

/* CONFIGURAÇÕES E TEMA */

.settings-dialog {
  width: min(380px, calc(100% - 28px));
  padding: 0;
  border: 1px solid #454545;
  border-radius: 12px;
  background: #101010;
  color: #eee;
  box-shadow: 0 20px 70px #000b;
}

.settings-content {
  padding: 18px;
}

.theme-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  cursor: pointer;
}

.theme-setting > span:first-child {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.theme-setting strong {
  font-size: 14px;
}

.theme-setting small {
  color: #aaa;
  font-size: 12px;
}

.theme-control {
  position: relative;
  flex: 0 0 46px;
  width: 46px;
  height: 26px;
}

.theme-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  border: 1px solid #555;
  border-radius: 99px;
  background: #292929;
  transition: background .15s;
}

.toggle-track:after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #eee;
  transition: transform .15s;
}

.theme-control input:checked + .toggle-track {
  background: #168477;
  border-color: #42cdb8;
}

.theme-control input:checked + .toggle-track:after {
  transform: translateX(20px);
}

.theme-control input:focus-visible + .toggle-track {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

/* HISTÓRICO DE DESEMPENHO */

.performance-dialog {
  width: min(620px, calc(100% - 28px));
}

.performance-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 18px;
}

.performance-stat {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px 8px;
  border: 1px solid #303030;
  border-radius: 8px;
  background: #171717;
  text-align: center;
}

.performance-stat strong {
  color: #65e6d2;
  font-size: 22px;
  line-height: 1.2;
}

.performance-stat span {
  color: #bdbdbd;
  font-size: 11px;
}

.performance-history {
  max-width: 100%;
  overflow-x: auto;
}

.performance-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
}

.performance-table th,
.performance-table td {
  padding: 9px 8px;
  border-bottom: 1px solid #303030;
  text-align: left;
}

.performance-table th {
  color: #aaa;
  font-weight: 600;
}

.performance-table td {
  color: #eee;
}

.performance-table .performance-win {
  color: #65e6d2;
  font-weight: 700;
}

.performance-table .performance-loss {
  color: #ff9999;
}

.performance-empty,
.performance-note {
  color: #aaa !important;
  font-size: 12px !important;
}

.performance-note {
  margin-top: 16px !important;
}

/* TEMA CLARO */

body.light,
body.light main {
  background: #f4f4f4;
  color: #191919;
}

body.light .attempt-counter {
  background: #fff;
  border-color: #d0d0d0;
  color: #333;
}

body.light .attempt-counter strong {
  color: #111;
}

body.light .tile {
  background: #fff;
  border-color: #b8b8b8;
  color: #171717;
}

body.light .tile.filled {
  background: #e8e8e8;
  border-color: #777;
}

body.light .tile.exact {
  background: var(--exact);
  border-color: var(--exact);
  color: #061a17;
}

body.light .tile.near {
  background: var(--near);
  border-color: var(--near);
  color: #171025;
}

body.light .tile.no {
  background: #d0d0d0;
  border-color: #d0d0d0;
  color: #555;
}

body.light .key {
  background: #e5e5e5;
  border-color: #c6c6c6;
  color: #161616;
}

body.light .key.exact {
  background: var(--exact);
  border-color: var(--exact);
}

body.light .key.near {
  background: var(--near);
  border-color: var(--near);
}

body.light .key.no {
  background: #d0d0d0;
  border-color: #d0d0d0;
  color: #555;
}

body.light .how-to-button,
body.light .icon-button {
  background: #fff;
  border-color: #ccc;
  color: #222;
}

body.light .game-header h1 {
  color: #191919;
}

body.light .status {
  background: #fff;
  color: #222;
  border-color: #ccc;
  box-shadow: 0 8px 28px #0002;
}

body.light .status.error {
  background: #fff0f0;
  color: #8d2020;
  border-color: #d88;
}

body.light .status.success {
  background: #edfffa;
  color: #125d52;
  border-color: #72b9ae;
}

body.light .how-to-dialog,
body.light .settings-dialog,
body.light .result-dialog {
  background: #fff;
  color: #222;
  border-color: #ccc;
  box-shadow: 0 20px 70px #0003;
}

body.light .how-to-content p,
body.light .color-explanations li,
body.light .result-content > p {
  color: #444;
}

body.light .close-how-to {
  background: #f2f2f2;
  border-color: #ccc;
  color: #222;
}

body.light .menu-panel {
  background: #fff;
  border-color: #ccc;
  box-shadow: 0 12px 35px #0002;
}

body.light .menu-panel span,
body.light .theme-setting small {
  color: #555;
}

/* AJUSTES PARA TELAS MAIORES */

@media (min-width: 700px) {
  #board .guess-attempt-row {
    gap: 8px;
  }

  #board .guess-attempt-row > .word-group > .tile {
    height: 41px;
  }

  .keyboard {
    gap: 8px;
  }

  .key {
    height: 45px;
  }
}

/* AJUSTES PARA CELULARES */

@media (max-width: 520px) {
  main {
    padding: 18px 8px;
  }

  .game-header {
    margin-bottom: 12px;
  }

  .header-actions {
    gap: 5px;
  }

  .how-to-button {
    padding: 7px 8px;
    font-size: 11px;
  }

  .icon-button {
    width: 35px;
    height: 35px;
  }

  .attempt-counter {
    gap: 8px;
    margin-bottom: 14px;
    padding: 9px 11px;
    font-size: 15px;
  }

  .attempt-counter strong {
    font-size: 23px;
  }

  #board.board {
    gap: 5px;
    margin-bottom: 12px;
    padding: 4px 0 8px;
  }

  #board .guess-attempt-row {
    gap: 3px;
    padding: 2px 0;
  }

  #board .guess-attempt-row > .word-group {
    gap: 2px;
  }

  #board .guess-attempt-row > .word-group > .tile {
    flex-basis: clamp(30px, 8.25vw, 42px);
    width: clamp(30px, 8.25vw, 42px);
    height: 46px;
    border-radius: 4px;
    font-size: 19px;
  }

  .keyboard {
    gap: 7px;
  }

  .key-row {
    gap: 4px;
  }

  .key {
    height: 54px;
    font-size: 18px;
    border-radius: 5px;
  }

  .key.wide {
    font-size: 12px;
  }

  .key.space {
    font-size: 12px;
  }

  .key.erase-key {
    font-size: 17px;
  }

  .key.confirm-key {
    font-size: 12px;
  }

  .status {
    top: 8px;
    width: calc(100% - 16px);
    padding: 10px 12px;
    font-size: 13px;
  }

  .how-to-content {
    padding: 17px 16px 18px;
  }

  .how-to-heading h2 {
    font-size: 19px;
  }

  .how-to-content p,
  .color-explanations li {
    font-size: 12px;
  }

  .result-content {
    padding: 14px;
  }

  .result-heading h2 {
    font-size: 16px;
  }

  .result-content > p {
    font-size: 12px;
  }

  .performance-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }

  .performance-stat {
    padding: 10px 4px;
  }

  .performance-stat strong {
    font-size: 19px;
  }

  .performance-stat span {
    font-size: 10px;
  }

  .performance-table {
    font-size: 11px;
  }

  .performance-table th,
  .performance-table td {
    padding: 8px 6px;
  }
}