/* ==================================================================
   Seahaven Towers — estilo
   Fiel ao original "Towers v1.0" (I. Heath, 1991):
     feltro verde RGB(0,128,0), cartas 70x90 com borda preta,
     passo horizontal de 80px, 10 colunas, Helvetica.
   Diferenca crucial: aqui o tabuleiro AJUSTA-SE a janela real,
   em vez de travar em 800px como o original.
   ================================================================== */

:root {
  --felt: #008000;
  --ink: #000000;
  --ui-bg: #e9e9e9;
  --ui-line: #8a8a8a;
  --card-face: #ffffff;
  --red: #cc0000;
  --black: #101010;
  --white: #ffffff;

  /* geometria — sobrescrita por JS para ajustar a janela */
  --card-w: 70px;
  --card-h: 90px;
  --gap-h: 10px;
  --fan: 26px;
  --row-gap: 5px;
  --radius: 4px;
}

html[data-theme='dark'] {
  --felt: #06301a;
  --card-face: #f5f5f0;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--felt);
  color: var(--white);
  font-family: Helvetica, 'Helvetica Neue', Arial, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.noscript {
  max-width: 34rem;
  margin: 4rem auto;
  padding: 1rem 1.25rem;
  background: #fff;
  color: #000;
  border: 2px solid #000;
  border-radius: 6px;
  font-size: 15px;
}

/* ------------------------------------------------------------------
   Estrutura
   ------------------------------------------------------------------ */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ------------------------------------------------------------------
   Barra de menus — o original tinha Game / Move / Help
   ------------------------------------------------------------------ */
.menubar {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 3px 6px;
  background: var(--ui-bg);
  border-bottom: 2px solid var(--ink);
  color: #000;
  font-size: 14px;
  flex: 0 0 auto;
  flex-wrap: wrap;
  position: relative;
  z-index: 60;
}

.menubar__brand {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  margin-right: 8px;
  white-space: nowrap;
}

.menubar__brand svg {
  display: block;
}

.menubar__spacer {
  flex: 1 1 auto;
}

.menu {
  position: relative;
}

.menu__btn {
  font: inherit;
  color: #000;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 4px 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.menu__btn:hover,
.menu__btn[aria-expanded='true'] {
  background: #fff;
  border-color: var(--ui-line);
}

.menu__panel {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  min-width: 244px;
  background: #fff;
  border: 2px solid #000;
  border-radius: 4px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
  padding: 4px;
  z-index: 70;
}

.menu__panel--right {
  left: auto;
  right: 0;
}

.menu__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  font: inherit;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 3px;
  padding: 7px 9px;
  cursor: pointer;
  color: #000;
}

.menu__item:hover:not(:disabled) {
  background: #0a5bd3;
  color: #fff;
}

.menu__item:disabled {
  color: #9a9a9a;
  cursor: default;
}

.menu__item > span:first-child {
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu__item kbd {
  font: 11px/1.4 ui-monospace, Menlo, Consolas, monospace;
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 1px 5px;
  opacity: 0.75;
  white-space: nowrap;
}

.menu__sep {
  height: 1px;
  background: #b9b9b9;
  margin: 4px 6px;
}

.menu__check {
  width: 14px;
  display: inline-block;
  color: inherit;
}

/* ------------------------------------------------------------------
   Barra de status (placar, como no original)
   ------------------------------------------------------------------ */
.statusbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 4px 10px;
  background: #cfcfcf;
  border-bottom: 2px solid var(--ink);
  color: #000;
  font-size: 13px;
  flex: 0 0 auto;
  z-index: 50;
}

.statusbar__item {
  display: flex;
  align-items: baseline;
  gap: 5px;
  white-space: nowrap;
}

.statusbar__label {
  color: #4a4a4a;
}

.statusbar__value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.statusbar__value--win {
  color: #006b00;
}

.statusbar__value--loss {
  color: #a80000;
}

.statusbar__spacer {
  flex: 1 1 auto;
}

.statusbar__msg {
  font-style: italic;
  color: #333;
  text-align: right;
}

/* ------------------------------------------------------------------
   Tabuleiro
   ------------------------------------------------------------------ */
.board {
  flex: 1 1 auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10px;
  overflow: hidden;
  min-height: 0;
}

.board__inner {
  position: relative;
}

.rowgrid {
  display: grid;
  grid-template-columns: repeat(10, var(--card-w));
  gap: var(--gap-h);
  justify-content: center;
}

.rowgrid--top {
  margin-bottom: var(--row-gap);
}

.slot {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
}

.slot__frame {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(0, 0, 0, 0.75);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.05);
  pointer-events: none;
}

.slot.is-target .slot__frame {
  border: 2px solid #ffd400;
  background: rgba(255, 212, 0, 0.18);
  box-shadow: 0 0 8px rgba(255, 212, 0, 0.6);
}

.slot.is-target-bad .slot__frame {
  border-color: #ff5c5c;
  background: rgba(255, 92, 92, 0.16);
}

.col {
  position: relative;
  width: var(--card-w);
  height: calc(var(--card-h) + var(--fan) * 4);
}

.col__frame {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--card-w);
  height: var(--card-h);
  border: 1px solid rgba(0, 0, 0, 0.55);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.04);
  pointer-events: none;
}

.col.is-target .col__frame {
  border: 2px solid #ffd400;
  background: rgba(255, 212, 0, 0.18);
  box-shadow: 0 0 8px rgba(255, 212, 0, 0.6);
}

.col.is-target-bad .col__frame {
  border-color: #ff5c5c;
  background: rgba(255, 92, 92, 0.16);
}

/* ------------------------------------------------------------------
   Cartas
   ------------------------------------------------------------------ */
.card {
  position: absolute;
  left: 0;
  top: calc(var(--fan) * var(--i, 0));
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--radius);
  border: 1px solid rgba(0, 0, 0, 0.9);
  background: var(--card-face);
  color: var(--black);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  z-index: calc(var(--i, 0) + 1);
  user-select: none;
  touch-action: manipulation;
  -webkit-user-drag: none;
}

.card--red {
  color: var(--red);
}

.card--movable {
  cursor: pointer;
}

.card--movable:hover::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.85);
  border-radius: var(--radius);
  pointer-events: none;
}

.card--selected {
  box-shadow: inset 0 0 0 3px #ffd400, 0 6px 14px rgba(0, 0, 0, 0.45);
  z-index: 800;
}

.card--dragging {
  opacity: 0.35;
}

.card--hint {
  box-shadow: inset 0 0 0 3px #5cff8f, 0 3px 10px rgba(0, 0, 0, 0.4);
}

.card__idx {
  position: absolute;
  top: 2px;
  left: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 700;
  font-size: calc(var(--card-w) * 0.26);
  letter-spacing: -0.5px;
}

.card__idx b {
  font-size: calc(var(--card-w) * 0.21);
  font-weight: 700;
}

/* leque de simbolos (2..10) */
.card__pips {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--card-h) * 0.13);
  bottom: calc(var(--card-h) * 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  font-size: calc(var(--card-w) * 0.22);
  line-height: 1;
  padding-left: calc(var(--card-w) * 0.2);
}

.card__row {
  display: flex;
  gap: calc(var(--card-w) * 0.16);
  align-items: center;
  justify-content: center;
}

/* simbolo unico grande (As) */
.card__big {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w) * 0.62);
  padding-top: calc(var(--card-h) * 0.1);
  padding-left: calc(var(--card-w) * 0.14);
}

/* figuras (J/Q/K) */
.card__court {
  position: absolute;
  inset: 0;
  padding: calc(var(--card-h) * 0.12) calc(var(--card-w) * 0.2) 3px
    calc(var(--card-w) * 0.2);
}

.card__court svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* verso: cena tropical com palmeira
   (o original usava fundo estilo sol/ceu/mar/areia) */
.card--back {
  background: #00ffff;
}

.card--back svg {
  display: block;
  width: 100%;
  height: 100%;
}

.card--back::after {
  content: '';
  position: absolute;
  inset: 2px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: calc(var(--radius) - 1px);
  pointer-events: none;
}

/* carta arrastada sob o cursor */
.drag {
  position: absolute;
  pointer-events: none;
  z-index: 950;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.5));
}

.drag .card {
  position: absolute;
  left: 0;
}

/* ------------------------------------------------------------------
   Animacoes
   ------------------------------------------------------------------ */
.card--dealt {
  animation: deal-in 0.3s ease-out both;
}

@keyframes deal-in {
  from {
    opacity: 0;
    transform: translateY(-22px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card--glide {
  transition: top 0.24s cubic-bezier(0.22, 0.7, 0.3, 1),
    left 0.24s cubic-bezier(0.22, 0.7, 0.3, 1);
}

.card--pulse {
  animation: pulse 0.55s ease-out 1;
}

@keyframes pulse {
  from {
    box-shadow: inset 0 0 0 0 rgba(92, 255, 143, 0.95);
  }
  to {
    box-shadow: inset 0 0 0 14px rgba(92, 255, 143, 0);
  }
}

/* ------------------------------------------------------------------
   Dialogos (vitoria, derrota, ajuda, sobre)
   ------------------------------------------------------------------ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
}

.dialog {
  width: min(540px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: #fff;
  color: #000;
  border: 2px solid #000;
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}

.dialog__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 2px solid #000;
  font-weight: 700;
  font-size: 17px;
}

.dialog__body {
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.55;
}

.dialog__body h3 {
  margin: 15px 0 6px;
  font-size: 14px;
}

.dialog__body h3:first-child {
  margin-top: 0;
}

.dialog__body ul {
  margin: 6px 0;
  padding-left: 20px;
}

.dialog__body li {
  margin: 3px 0;
}

.dialog__body p:first-child {
  margin-top: 0;
}

.dialog__body p:last-child {
  margin-bottom: 0;
}

.dialog__stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 9px;
  margin: 14px 0 4px;
}

.stat {
  border: 1px solid #c4c4c4;
  border-radius: 6px;
  padding: 8px 10px;
  background: #f7f7f7;
}

.stat__label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #5c5c5c;
}

.stat__value {
  display: block;
  font-size: 21px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dialog__foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 2px solid #000;
  background: #efefef;
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 6px;
}

.tbl th,
.tbl td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid #d8d8d8;
}

.tbl th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #5c5c5c;
}

.tbl td:not(:first-child),
.tbl th:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.btn {
  font: inherit;
  font-size: 14px;
  padding: 8px 15px;
  border: 2px solid #000;
  border-radius: 5px;
  background: #fff;
  color: #000;
  cursor: pointer;
  box-shadow: 0 1px 0 #000;
}

.btn:hover {
  background: #f0f0f0;
}

.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.btn--primary {
  background: #0a5bd3;
  color: #fff;
  border-color: #053a86;
}

.btn--primary:hover {
  background: #0d66ea;
}

.btn--danger {
  background: #c62828;
  color: #fff;
  border-color: #7f1d1d;
}

.btn--danger:hover {
  background: #e03a3a;
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.field input {
  font: inherit;
  padding: 6px 9px;
  border: 2px solid #000;
  border-radius: 5px;
  width: 8rem;
}

/* Acessibilidade */
:focus-visible {
  outline: 2px solid #ffd400;
  outline-offset: 2px;
}

.card--flash {
  animation: flash 0.9s ease-in-out 2;
}

@keyframes flash {
  50% {
    box-shadow: inset 0 0 0 4px #ffd400;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card--dealt,
  .card--pulse,
  .card--glide,
  .card--flash {
    animation: none !important;
    transition: none !important;
  }
}

/* Barra de menu estreita */
@media (max-width: 720px) {
  .menubar {
    font-size: 13px;
    padding: 3px 4px;
  }
  .menubar__brand span {
    display: none;
  }
  .statusbar {
    font-size: 12px;
    gap: 10px;
  }
  .statusbar__msg {
    display: none;
  }
}
