@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Oswald:wght@500;600;700&display=swap');

:root {
  --ink: #f7f0df;
  --muted: #b9c6bc;
  --night: #091812;
  --panel: #10291f;
  --felt: #174936;
  --felt-light: #1d5942;
  --gold: #e4aa3c;
  --gold-soft: #f3ce7c;
  --red: #d65b47;
  --paper: #fffaf0;
  --paper-shadow: #d8ccb5;
  --line: rgba(255, 255, 255, 0.12);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--night);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--night); }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% -10%, rgba(35, 116, 81, 0.36), transparent 38rem),
    linear-gradient(160deg, #0c2119 0%, #07130f 58%, #0c1913 100%);
}

button { font: inherit; }
button:focus-visible, .playing-card:focus-visible, summary:focus-visible {
  outline: 3px solid var(--gold-soft);
  outline-offset: 3px;
}

.ambient {
  position: fixed;
  z-index: 0;
  width: 34rem;
  height: 34rem;
  border-radius: 999px;
  filter: blur(110px);
  opacity: 0.16;
  pointer-events: none;
}

.ambient-one { top: -18rem; right: -9rem; background: #d89a2c; }
.ambient-two { bottom: -20rem; left: -14rem; background: #2fa97a; }

.game-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 26px;
}

.topbar {
  min-height: 78px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
}

.brand {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(228, 170, 60, 0.65);
  border-radius: 50%;
  color: var(--gold);
  transform: rotate(45deg);
}

.brand-mark span { font-size: 20px; transform: rotate(-45deg); }
.brand strong, .brand small { display: block; font-family: "Oswald", sans-serif; line-height: 1; letter-spacing: 0.16em; }
.brand strong { font-size: 22px; }
.brand small { margin-top: 5px; color: var(--gold-soft); font-size: 8px; }

.scoreboard {
  min-width: 330px;
  display: grid;
  grid-template-columns: 76px 1fr 76px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(5, 17, 12, 0.48);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(14px);
}

.score { display: flex; align-items: center; justify-content: center; gap: 8px; }
.score span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 0.13em; }
.score strong { font: 600 28px/1 "Oswald", sans-serif; }
.score-you strong { color: var(--gold-soft); }

.score-center { text-align: center; }
.score-center small { display: block; margin-bottom: 7px; color: #8fa598; font-size: 8px; font-weight: 700; letter-spacing: 0.13em; }
.score-track { position: relative; height: 4px; border-radius: 5px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.score-track span { position: absolute; top: 0; bottom: 0; width: 0; transition: width 500ms ease; }
#humanProgress { left: 50%; background: var(--gold); transform: translateX(-100%); }
#aiProgress { left: 50%; background: #b7c6bd; }

.top-actions { justify-self: end; display: flex; gap: 9px; }
.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.055);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: 180ms ease;
}
.icon-button:hover { border-color: rgba(228, 170, 60, 0.7); background: rgba(228, 170, 60, 0.12); transform: translateY(-1px); }
.multiplayer-link { width: 66px; color: var(--gold-soft); font-size: 8px; letter-spacing: .08em; }

.table-wrap {
  position: relative;
  padding: 7px;
  border-radius: 42px;
  background: linear-gradient(135deg, #9c622d, #e2ad58 22%, #75431f 62%, #c0833e);
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(255, 240, 195, 0.18);
}

.wood-edge {
  position: absolute;
  inset: 2px;
  border: 2px solid rgba(59, 31, 10, 0.35);
  border-radius: 40px;
  pointer-events: none;
}

.game-table {
  position: relative;
  height: min(650px, calc(100vh - 254px));
  min-height: 510px;
  overflow: hidden;
  border: 2px solid #143e2f;
  border-radius: 36px;
  background:
    radial-gradient(ellipse at center, rgba(54, 135, 94, 0.46), transparent 64%),
    linear-gradient(135deg, var(--felt-light), var(--felt));
  box-shadow: inset 0 0 75px rgba(0, 0, 0, 0.28), inset 0 0 0 2px rgba(255, 255, 255, 0.05);
}

.table-pattern {
  position: absolute;
  inset: 0;
  opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cpath d='M40 4l7 13 14 7-14 7-7 13-7-13-14-7 14-7z' fill='none' stroke='%23fff'/%3E%3C/svg%3E");
  background-size: 74px 74px;
  pointer-events: none;
}

.player-area { position: absolute; left: 0; right: 0; z-index: 3; display: flex; align-items: center; justify-content: center; }
.opponent-area { top: 18px; }
.human-area { bottom: 14px; }

.player-badge {
  position: absolute;
  left: 25px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px 7px 7px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(6, 25, 17, 0.38);
}

.player-badge strong, .player-badge small { display: block; line-height: 1.15; }
.player-badge strong { font-size: 12px; }
.player-badge small { margin-top: 3px; color: #aac0b2; font-size: 9px; text-transform: uppercase; letter-spacing: 0.12em; }
.avatar { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 50%; font-size: 10px; font-weight: 800; }
.avatar-rival { color: #d7e1da; background: #345748; }
.avatar-you { color: #231602; background: var(--gold); }

.hand { display: flex; align-items: center; justify-content: center; }
.opponent-hand { height: 104px; }
.human-hand { height: 154px; }

.playing-card {
  --suit-color: #35483f;
  position: relative;
  width: 98px;
  height: 142px;
  margin: 0 -7px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 11px;
  color: var(--suit-color);
  background: linear-gradient(145deg, #fffdf7 0%, var(--paper) 60%, #efe6d4 100%);
  box-shadow: 0 9px 18px rgba(0, 0, 0, 0.28), inset 0 0 0 1px rgba(84, 55, 20, 0.22);
  transform-origin: 50% 100%;
  transition: transform 180ms ease, filter 180ms ease, opacity 180ms ease;
}

.playing-card::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid color-mix(in srgb, var(--suit-color) 48%, transparent);
  border-radius: 7px;
  pointer-events: none;
}

.playing-card.suit-oros { --suit-color: #b27a0c; }
.playing-card.suit-copas { --suit-color: #b34638; }
.playing-card.suit-espadas { --suit-color: #285b76; }
.playing-card.suit-bastos { --suit-color: #47763a; }
.playing-card .corner { position: absolute; left: 11px; top: 9px; display: grid; justify-items: center; z-index: 1; font: 700 18px/1 "Oswald", sans-serif; }
.playing-card .corner.bottom { left: auto; top: auto; right: 11px; bottom: 9px; transform: rotate(180deg); }
.playing-card .corner .tiny-suit { margin-top: 4px; font-size: 13px; }
.playing-card .main-suit { position: absolute; inset: 0; display: grid; place-items: center; font-size: 47px; text-shadow: 0 2px 0 rgba(255,255,255,.6); }
.playing-card .face-name { position: absolute; left: 0; right: 0; bottom: 17px; text-align: center; font: 600 8px/1 "Oswald", sans-serif; letter-spacing: 0.12em; text-transform: uppercase; }
.playing-card .piece-banner { position: absolute; top: 8px; right: 8px; padding: 3px 5px; border-radius: 4px; color: #2b1c05; background: var(--gold); font: 700 7px/1 "DM Sans"; letter-spacing: .04em; }

.human-hand .playing-card { cursor: pointer; }
.human-hand .playing-card:nth-child(1) { transform: rotate(-5deg) translateY(3px); }
.human-hand .playing-card:nth-child(2) { transform: translateY(-4px); z-index: 2; }
.human-hand .playing-card:nth-child(3) { transform: rotate(5deg) translateY(3px); }
.human-hand .playing-card:not(:disabled):hover { transform: translateY(-16px) rotate(0); z-index: 5; filter: brightness(1.04); }
.human-hand .playing-card:disabled { cursor: default; filter: saturate(.74); }

.card-back {
  width: 70px;
  height: 101px;
  margin: 0 -12px;
  border: 5px solid #efe6cf;
  border-radius: 8px;
  background:
    radial-gradient(circle, transparent 20%, #b97827 21%, #b97827 23%, transparent 24%) 0 0 / 14px 14px,
    linear-gradient(135deg, #173d30, #245942);
  box-shadow: 0 7px 15px rgba(0,0,0,.28), inset 0 0 0 2px #d8a44e;
}
.opponent-hand .card-back:nth-child(1) { transform: rotate(5deg); }
.opponent-hand .card-back:nth-child(3) { transform: rotate(-5deg); }

.playfield { position: absolute; inset: 120px 0 166px; display: grid; grid-template-columns: 150px 1fr 150px; align-items: center; z-index: 2; }
.center-stage { position: relative; height: 100%; min-height: 230px; }
.vira-panel, .hand-info {
  width: 122px;
  justify-self: center;
  padding: 13px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px;
  background: rgba(4, 24, 16, 0.24);
  backdrop-filter: blur(4px);
}
.micro-label { display: block; margin-bottom: 10px; color: #b4c7ba; font-size: 8px; font-weight: 700; letter-spacing: .16em; }
.mini-card-placeholder { min-height: 104px; display: grid; place-items: center; }
.mini-card-placeholder .playing-card { width: 67px; height: 98px; margin: 0; border-radius: 8px; }
.mini-card-placeholder .playing-card::before { inset: 4px; }
.mini-card-placeholder .playing-card .corner { left: 7px; top: 6px; font-size: 12px; }
.mini-card-placeholder .playing-card .corner.bottom { left: auto; top: auto; right: 7px; bottom: 6px; }
.mini-card-placeholder .playing-card .corner .tiny-suit { margin-top: 2px; font-size: 8px; }
.mini-card-placeholder .playing-card .main-suit { font-size: 29px; }
.mini-card-placeholder .playing-card .face-name, .mini-card-placeholder .playing-card .piece-banner { display: none; }
.pieces-label { display: block; min-height: 22px; margin-top: 8px; color: var(--gold-soft); font-size: 8px; line-height: 1.35; text-align: center; }

.hand-info { align-self: center; }
.info-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid rgba(255,255,255,.08); font-size: 10px; }
.info-row span { color: #a8bcaf; }
.info-row strong { color: var(--gold-soft); font-size: 12px; }

.status-pill {
  position: absolute;
  z-index: 8;
  top: -3px;
  left: 50%;
  min-width: 170px;
  padding: 7px 14px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 999px;
  color: #dce7df;
  background: rgba(5, 25, 17, 0.48);
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  transform: translateX(-50%);
}

.call-ribbon {
  position: absolute;
  z-index: 9;
  top: 34px;
  left: 50%;
  opacity: 0;
  color: var(--gold-soft);
  font: 600 20px/1 "Oswald", sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
  transform: translate(-50%, -5px) scale(.96);
  transition: 220ms ease;
}
.call-ribbon.visible { opacity: 1; transform: translate(-50%, 0) scale(1); }

.played-zone { position: absolute; left: 50%; width: 110px; height: 145px; transform: translateX(-50%); display: grid; place-items: center; }
.played-zone .playing-card { width: 82px; height: 119px; margin: 0; cursor: default; }
.played-zone .playing-card .corner { font-size: 15px; }
.played-zone .playing-card .main-suit { font-size: 38px; }
.played-zone .playing-card .face-name { font-size: 7px; bottom: 14px; }
.ai-played { top: 52px; transform: translateX(-92%) rotate(-2deg); }
.human-played { bottom: 13px; transform: translateX(-8%) rotate(2deg); }

.table-seal {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 105px;
  height: 105px;
  display: grid;
  place-content: center;
  border: 1px solid rgba(238, 208, 141, 0.12);
  border-radius: 50%;
  color: rgba(248, 226, 179, .09);
  text-align: center;
  transform: translate(-50%, -50%);
}
.table-seal::before, .table-seal::after { content: ""; position: absolute; inset: 7px; border: 1px solid currentColor; border-radius: 50%; }
.table-seal::after { inset: -8px; border-style: dashed; }
.table-seal span { font: 700 42px/1 "Oswald", sans-serif; }
.table-seal small { font: 600 7px/1 "DM Sans"; letter-spacing: .16em; }

.trick-dots { position: absolute; left: 50%; bottom: -1px; display: flex; gap: 7px; transform: translateX(-50%); }
.trick-dot { width: 8px; height: 8px; border: 1px solid rgba(255,255,255,.32); border-radius: 50%; background: rgba(0,0,0,.14); }
.trick-dot.human { border-color: var(--gold); background: var(--gold); }
.trick-dot.ai { border-color: #d9e1dc; background: #d9e1dc; }
.trick-dot.tie { border-color: #b6c8bc; background: linear-gradient(90deg, var(--gold) 50%, #d9e1dc 50%); }

.control-deck {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: center;
  min-height: 86px;
  padding: 12px 10px 2px;
}
.action-copy span, .action-copy strong, .action-copy small { display: block; }
.eyebrow { color: var(--gold); font-size: 9px; font-weight: 800; letter-spacing: .18em; }
.action-copy strong { margin: 3px 0 2px; font: 600 18px/1.25 "Oswald", sans-serif; }
.action-copy small { color: #93a79a; font-size: 10px; }
.action-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.game-button, .primary-button {
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 12px;
  color: var(--ink);
  background: rgba(255,255,255,.07);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: 160ms ease;
}
.game-button { min-height: 42px; padding: 0 17px; }
.game-button:hover:not(:disabled) { border-color: rgba(255,255,255,.34); background: rgba(255,255,255,.12); transform: translateY(-2px); }
.game-button:disabled { opacity: .3; cursor: not-allowed; }
.game-button.accent { border-color: #d49a2c; color: #251805; background: linear-gradient(180deg, #f0bd59, #d79725); box-shadow: 0 7px 18px rgba(215,151,37,.18); }
.game-button.warm { border-color: rgba(236, 184, 101, .38); color: #f3d79d; background: rgba(192, 119, 46, .16); }
.game-button.ghost { color: #9fb0a5; background: transparent; }
.game-button.hidden { display: none; }

.game-log { margin: 10px 10px 0; border-top: 1px solid var(--line); color: #9aada1; font-size: 10px; }
.game-log summary { display: flex; justify-content: space-between; padding: 13px 2px; cursor: pointer; list-style: none; }
.game-log summary::-webkit-details-marker { display: none; }
.game-log ol { max-height: 140px; margin: 0 0 12px; padding-left: 24px; overflow: auto; }
.game-log li { padding: 3px 0; }

footer { display: flex; justify-content: space-between; padding: 12px 10px 0; color: #63796b; font-size: 8px; letter-spacing: .05em; }

.modal-layer {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 12, 8, .74);
  backdrop-filter: blur(8px);
  animation: fadeIn 180ms ease both;
}
.modal-layer.hidden { display: none; }
.modal-card {
  position: relative;
  width: min(430px, 100%);
  padding: 34px;
  overflow: hidden;
  border: 1px solid rgba(245, 209, 137, .24);
  border-radius: 25px;
  background:
    radial-gradient(circle at 100% 0, rgba(222, 164, 60, .16), transparent 13rem),
    linear-gradient(150deg, #17382b, #0e241b);
  box-shadow: 0 30px 100px rgba(0,0,0,.52);
  text-align: center;
  animation: modalUp 220ms ease both;
}
.modal-card h2 { margin: 8px 0 9px; font: 600 34px/1.1 "Oswald", sans-serif; }
.modal-card p { margin: 0; color: #adbbb2; font-size: 13px; line-height: 1.6; }
.modal-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; margin-top: 25px; }
.modal-actions .primary-button:first-child { grid-column: 1 / -1; }
.primary-button { min-height: 48px; padding: 0 20px; border-color: var(--gold); color: #271a05; background: linear-gradient(180deg, #f2c362, #d99b2d); }
.primary-button:hover { filter: brightness(1.08); transform: translateY(-1px); }
.primary-button.secondary { border-color: rgba(255,255,255,.15); color: var(--ink); background: rgba(255,255,255,.06); }
.primary-button.danger { border-color: rgba(210,94,72,.4); color: #ffd3ca; background: rgba(171,63,44,.18); }

.result-icon { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 18px; border: 1px solid var(--gold); border-radius: 50%; color: var(--gold-soft); font-size: 27px; }
.result-icon.loss { border-color: #9caea3; color: #c5d0c9; }
.point-breakdown { margin: 23px 0; border-top: 1px solid var(--line); }
.point-row { display: flex; justify-content: space-between; padding: 10px 3px; border-bottom: 1px solid var(--line); color: #bac8bf; font-size: 12px; text-align: left; }
.point-row strong { color: var(--ink); }
.result-card > .primary-button { width: 100%; }
.confetti { margin: -10px 0 14px; color: var(--gold); font-size: 23px; letter-spacing: .25em; }
.final-score { margin: 24px 0; color: var(--gold-soft); font: 600 42px/1 "Oswald", sans-serif; }

.rules-card { width: min(780px, 100%); max-height: calc(100vh - 36px); overflow-y: auto; text-align: left; }
.rules-card > h2 { margin-bottom: 25px; }
.rules-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.rules-grid article { padding: 17px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,255,255,.035); }
.rule-number { color: var(--gold); font: 600 11px/1 "Oswald", sans-serif; }
.rules-grid h3 { margin: 8px 0 5px; font: 600 16px/1.2 "Oswald", sans-serif; }
.rules-grid p { font-size: 11px; line-height: 1.5; }
.rules-card > .primary-button { display: block; min-width: 150px; margin: 22px auto 0; }
.modal-close { position: absolute; top: 16px; right: 18px; width: 36px; height: 36px; border: 0; color: #aebcb3; background: transparent; font-size: 25px; cursor: pointer; }

.toast-region { position: fixed; z-index: 80; top: 92px; left: 50%; display: grid; gap: 8px; transform: translateX(-50%); pointer-events: none; }
.toast { min-width: 220px; padding: 11px 16px; border: 1px solid rgba(228,170,60,.36); border-radius: 12px; color: #f9e7bc; background: rgba(13, 40, 29, .94); box-shadow: 0 12px 30px rgba(0,0,0,.3); font-size: 11px; text-align: center; animation: toastIn 250ms ease both; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalUp { from { opacity: 0; transform: translateY(14px) scale(.98); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } }

@media (max-width: 780px) {
  .game-shell { width: min(100% - 16px, 620px); padding-top: 8px; }
  .topbar { grid-template-columns: 1fr auto; min-height: 63px; }
  .brand-mark { width: 36px; height: 36px; }
  .brand strong { font-size: 18px; }
  .scoreboard { grid-row: 2; grid-column: 1 / -1; width: 100%; min-width: 0; margin-bottom: 10px; }
  .top-actions { grid-column: 2; grid-row: 1; }
  .game-table { height: 525px; min-height: 525px; border-radius: 26px; }
  .table-wrap { border-radius: 31px; }
  .playfield { inset: 112px 0 158px; grid-template-columns: 90px 1fr 90px; }
  .vira-panel, .hand-info { width: 76px; padding: 8px; }
  .hand-info .micro-label { text-align: center; }
  .info-row { display: grid; justify-items: center; gap: 2px; }
  .mini-card-placeholder .playing-card { width: 54px; height: 79px; }
  .mini-card-placeholder { min-height: 84px; }
  .pieces-label { font-size: 7px; }
  .player-badge { left: 10px; padding-right: 8px; }
  .player-badge > span:last-child { display: none; }
  .playing-card { width: 88px; height: 128px; }
  .human-hand { height: 139px; }
  .control-deck { grid-template-columns: 1fr; gap: 10px; }
  .action-copy { text-align: center; }
  .action-buttons { justify-content: center; }
  .game-button { min-height: 40px; padding: 0 13px; }
  .rules-grid { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .brand small { display: none; }
  .table-wrap { padding: 5px; }
  .game-table { height: 500px; min-height: 500px; }
  .opponent-area { top: 10px; }
  .human-area { bottom: 8px; }
  .playfield { inset: 102px 0 145px; grid-template-columns: 72px 1fr 72px; }
  .vira-panel, .hand-info { width: 64px; padding: 6px; border-radius: 11px; }
  .mini-card-placeholder .playing-card { width: 48px; height: 70px; }
  .mini-card-placeholder { min-height: 73px; }
  .pieces-label { min-height: 0; font-size: 0; }
  .playing-card { width: 80px; height: 117px; margin: 0 -9px; }
  .playing-card .main-suit { font-size: 40px; }
  .playing-card .corner { font-size: 16px; }
  .human-hand { height: 126px; }
  .played-zone .playing-card { width: 69px; height: 101px; }
  .played-zone { height: 120px; }
  .ai-played { top: 53px; }
  .human-played { bottom: 15px; }
  .table-seal { width: 78px; height: 78px; }
  .table-seal span { font-size: 31px; }
  .status-pill { top: 0; min-width: 140px; font-size: 9px; }
  .call-ribbon { top: 36px; font-size: 16px; }
  .action-buttons { display: grid; grid-template-columns: repeat(2, 1fr); }
  .game-button { width: 100%; }
  footer { display: none; }
  .modal-card { padding: 28px 21px; }
  .modal-actions { grid-template-columns: 1fr; }
  .modal-actions .primary-button:first-child { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
