:root {
  --bg: #0b1f16;
  --bg-alt: #123026;
  --card: #fffefe;
  --ink: #14201b;
  --text: #e8f5ea;
  --muted: #b7cfbc;
  --accent: #efbd4a;
  --danger: #df5151;
  --ok: #63d189;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 20%, #1b493b, var(--bg) 48%);
  min-height: 100vh;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 1rem;
  margin-bottom: 0.42rem;
}

.brand {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 1.05rem;
}

.brand h1 {
  margin: 0;
  line-height: 1;
  font-family: "Snell Roundhand", "Brush Script MT", "Lucida Handwriting", cursive;
  letter-spacing: 0.02em;
  font-size: 3.4rem;
  font-weight: 700;
  color: #f8e8c3;
  text-shadow: 0 1px 0 #67231e, 0 2px 8px rgba(0, 0, 0, 0.35);
}

.brand p {
  margin: 0.14rem 0 0;
  color: var(--muted);
}

.brand-logo {
  width: 110px;
  height: 110px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(255, 244, 213, 0.45);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

.header-action .btn {
  width: 12.8rem;
  min-height: 46px;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  line-height: 1.1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.header-action {
  align-self: center;
  padding-top: 0.45rem;
}

.tagline-portrait {
  display: none;
}

.btn {
  border: 1px solid #6d8652;
  background: #25381d;
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.12);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}

.btn.primary {
  background: linear-gradient(180deg, #a9791b, #8a5d15);
  border-color: #cc9f44;
  color: #fff6db;
}

.btn.secondary {
  background: #243b33;
  border-color: #3d6355;
}

.btn.small {
  padding: 0.2rem 0.65rem;
}

.table-area {
  display: grid;
  grid-template-columns: minmax(0, 2.45fr) minmax(210px, 1fr);
  gap: 0.7rem;
  align-items: stretch;
}

.cards {
  border: 1px solid #2a5745;
  border-radius: 12px;
  background: linear-gradient(180deg, #0e2f23 0%, #123f2f 100%);
  padding: 0.62rem;
  display: grid;
  gap: 0.5rem;
  height: 100%;
}

.right-rail {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 0.5rem;
  align-content: stretch;
  height: 100%;
}

.hand-row {
  border: 1px solid rgba(190, 220, 205, 0.16);
  border-radius: 10px;
  padding: 0.34rem 0.45rem 0.42rem;
  background: rgba(7, 24, 17, 0.2);
}

.hand-main {
  display: grid;
  grid-template-columns: minmax(82px, 96px) minmax(0, 1fr);
  gap: 0.4rem;
  align-items: start;
}

.hand-info-box {
  min-height: 0;
  align-self: start;
  border: 1px solid rgba(194, 224, 208, 0.2);
  border-radius: 8px;
  padding: 0.3rem 0.34rem;
  background: rgba(9, 31, 22, 0.34);
  display: grid;
  align-content: start;
  gap: 0.14rem;
}

.hand-info-box h2 {
  margin: 0;
  font-size: 0.82rem;
  letter-spacing: 0.07em;
  text-transform: none;
  color: #dcefe3;
}

.hand-total {
  color: var(--muted);
  font-size: 0.78rem;
}

.hand-cards {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  overflow: hidden;
  gap: 0.42rem;
  min-height: 190px;
}

.player-hands {
  display: grid;
  gap: 0.44rem;
}

.player-hand {
  display: grid;
  grid-template-columns: minmax(104px, 122px) minmax(0, 1fr);
  gap: 0.35rem;
  border: 1px solid rgba(194, 224, 208, 0.18);
  border-radius: 8px;
  padding: 0.28rem;
}

.player-hand.single-hand {
  grid-template-columns: 1fr;
  border: 1px solid transparent;
  padding: 0.18rem;
  background: transparent;
}

.player-hand.is-active {
  border-color: rgba(239, 189, 74, 0.86);
  box-shadow: 0 0 0 1px rgba(239, 189, 74, 0.28) inset;
}

.player-hand.single-hand.is-active {
  border-color: rgba(239, 189, 74, 0.45);
}

.player-hand-label {
  display: grid;
  align-content: start;
  height: 100%;
  border: 1px solid rgba(194, 224, 208, 0.16);
  border-radius: 7px;
  background: rgba(10, 29, 22, 0.32);
  padding: 0.22rem 0.28rem;
  font-size: 0.74rem;
  color: #cee2d7;
  letter-spacing: 0.03em;
  white-space: pre-line;
}

.card-slot {
  width: 128px;
  min-height: 190px;
  background: var(--card);
  color: var(--ink);
  border-radius: 10px;
  border: 2px solid #dbd8ce;
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
}

.hand-cards.is-fanned > .card-slot + .card-slot {
  margin-left: -64px;
}

.card-slot.red {
  color: #bc2430;
}

.card-corner {
  position: absolute;
  font-weight: 800;
  line-height: 1.05;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 2;
}

.card-corner.top {
  top: 8px;
  left: 8px;
}

.card-corner.bottom {
  right: 8px;
  bottom: 8px;
  transform: rotate(180deg);
}

.card-corner .rank {
  font-size: 1.35rem;
  margin-bottom: 0.18rem;
}

.card-corner .suit {
  font-size: 1.15rem;
}

.card-body {
  position: absolute;
  inset: 10% 10% 10% 10%;
  display: grid;
  place-items: center;
}

.pip-field {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(5, 1fr);
  align-items: center;
  justify-items: center;
}

.pip {
  font-size: 1.4rem;
  line-height: 1;
}

.pip.invert {
  transform: rotate(180deg);
}

.court-wrap {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: #fffefe;
}

.court-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.ace-art {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background: radial-gradient(circle at center, #ffffff 0%, #fffefe 62%, #fbfbfb 100%);
  display: grid;
  place-items: center;
}

.ace-logo-center {
  width: 50px;
  height: 50px;
  border-radius: 10px;
}

.card-back {
  position: absolute;
  inset: 8px;
  border-radius: 8px;
  background-image: url("./assets/tahoe-21-back.jpg");
  background-size: cover;
  background-position: center;
  border: 1px solid #274f87;
}

.empty-hand {
  min-height: 190px;
  border: 1px dashed rgba(201, 228, 213, 0.35);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #aac4b2;
  width: 100%;
}

.paytable {
  border: 1px solid #3f6655;
  border-radius: 12px;
  padding: 0.56rem;
  background: rgba(9, 27, 19, 0.72);
  display: grid;
  gap: 0.4rem;
  height: 100%;
  align-content: start;
}

.paytable h2 {
  margin: 0;
  font-size: 1.08rem;
}

.paytable ul {
  margin: 0.02rem 0 0;
  padding-left: 0.82rem;
}

.paytable li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.08rem 0;
  font-size: 1.02rem;
  color: var(--muted);
}

.side-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.34rem;
  align-content: start;
  align-self: start;
}

.side-actions .btn {
  padding: 0.36rem 0.44rem;
  min-height: 37px;
  font-size: 0.8rem;
}

#splitBtn.is-split-ready {
  background: linear-gradient(180deg, #9f7a1a, #7b5b13);
  border-color: #be9440;
  color: #fff6db;
}

.status-row {
  display: flex;
  gap: 0.85rem;
  align-items: stretch;
  margin-top: 0.32rem;
}

.status-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(118px, 160px));
  gap: 0.75rem;
  width: fit-content;
}

.status-item {
  background: linear-gradient(180deg, #0d2a1f, var(--bg-alt));
  border: 1px solid #2f5b4b;
  border-radius: 10px;
  padding: 0.2rem 0.32rem;
}

.bet-item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 0.5rem;
  align-items: center;
}

.bet-item span {
  grid-column: 1;
  grid-row: 1;
}

.bet-item strong {
  grid-column: 1;
  grid-row: 2;
}

.bet-item .bet-controls {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.status-item span {
  display: block;
  color: var(--muted);
  font-size: 1rem;
}

.status-item strong {
  font-size: 1.42rem;
  line-height: 1;
}

.bet-controls {
  display: flex;
  flex-direction: row;
  gap: 0.22rem;
  margin-top: 0;
}

.bet-controls .btn.small {
  min-width: 28px;
  min-height: 28px;
  padding: 0.2rem;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
}

.result {
  border: 1px solid #315a4b;
  border-radius: 10px;
  padding: 0.22rem 0.42rem;
  background: rgba(9, 30, 21, 0.7);
  flex: 1 1 auto;
  min-width: 0;
}

.result p {
  margin: 0.08rem 0;
  font-size: 0.92rem;
}

#resultLine.is-win {
  color: var(--ok);
}

#resultLine.is-loss {
  color: var(--danger);
}

#resultLine.is-neutral {
  color: #d8e9df;
}

#resultLine.is-split {
  color: #f2cc6d;
}

.utility-panel {
  margin-top: 0.16rem;
  align-self: flex-end;
}

.controls {
  display: grid;
  justify-items: end;
  gap: 0.3rem;
}

.control-buttons {
  display: flex;
  gap: 0.5rem;
}

.utility-meta {
  width: calc(100% + 2rem);
  margin-left: -1rem;
  padding: 0 1rem;
  display: flex;
  justify-content: flex-start;
  align-items: baseline;
  gap: 0;
}

.header-promo {
  margin: 0.12rem 0 0;
  color: #efbd4a;
  font-size: 0.88rem;
}

.header-promo a {
  color: #efbd4a;
  text-decoration: underline;
}

.source-link {
  color: #4ea4ff;
  text-decoration: underline;
}

.header-version {
  margin: 0.12rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  margin-left: auto;
}

.header-copyright {
  margin: 0.12rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.header-version::after {
  content: "  ";
  white-space: pre;
}

#helpDialog,
#aboutDialog {
  border: 1px solid #2d4a3f;
  border-radius: 12px;
  max-width: 640px;
}

#aboutDialog {
  width: min(50vw, 640px);
  position: relative;
  padding-top: 1rem;
}

.about-logo {
  width: 74px;
  height: 74px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(255, 244, 213, 0.5);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
  position: absolute;
  top: 1.2rem;
  right: 1rem;
}

#helpDialog::backdrop,
#aboutDialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

@media (max-width: 980px) {
  .table-area {
    grid-template-columns: 1fr;
  }

  .right-rail {
    grid-template-rows: auto auto;
    height: auto;
  }
}

@media (max-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.24rem;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 0.3rem;
    order: 1;
  }

  .header-action {
    justify-self: end;
    align-self: start;
    order: 0;
    padding-top: 0;
  }

  .header-action .btn {
    width: 10.4rem;
  }

  .brand-logo {
    width: 76px;
    height: 76px;
  }

  .brand h1 {
    font-size: 2.35rem;
  }

  .brand p {
    font-size: 0.86rem;
  }

  .table-area {
    display: contents;
  }

  .right-rail {
    display: contents;
  }

  .side-actions {
    order: 2;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    margin-top: 0.04rem;
  }

  .cards {
    order: 3;
  }

  .status-row {
    order: 4;
    flex-direction: row;
    align-items: stretch;
    margin-top: 0.14rem;
  }

  .hand-main {
    grid-template-columns: minmax(82px, 96px) minmax(0, 1fr);
    gap: 0.28rem;
  }

  .player-hand {
    grid-template-columns: minmax(96px, 112px) minmax(0, 1fr);
  }

  .card-slot {
    width: 96px;
    min-height: 142px;
  }

  .hand-cards.is-fanned > .card-slot + .card-slot {
    margin-left: -48px;
  }

  .hand-cards,
  .empty-hand {
    min-height: 142px;
  }

  .status-panel {
    grid-template-columns: repeat(2, minmax(76px, 96px));
    gap: 0.34rem;
    width: auto;
    flex: 0 0 auto;
  }

  .status-item {
    padding: 0.2rem 0.3rem;
  }

  .status-item span {
    font-size: 0.74rem;
  }

  .status-item strong {
    font-size: 0.96rem;
  }

  .result {
    padding: 0.28rem 0.42rem;
  }

  .result p {
    margin: 0.03rem 0;
    font-size: 0.8rem;
  }

  .paytable {
    order: 5;
    margin-top: 0.08rem;
  }

  .utility-panel {
    order: 6;
    align-self: stretch;
    margin-top: 0.12rem;
  }

  .controls {
    justify-items: stretch;
  }

  .control-buttons {
    width: 100%;
    justify-content: space-between;
  }

  .control-buttons .btn {
    flex: 1;
  }

  .header-copyright,
  .header-version,
  .header-promo {
    font-size: 0.74rem;
  }

  .utility-meta {
    justify-content: flex-start;
    margin-left: -1rem;
    width: calc(100% + 2rem);
    padding: 0 1rem;
  }

  .side-actions .btn {
    min-height: 34px;
    font-size: 0.76rem;
  }
}

@media (max-width: 900px) and (orientation: portrait) {
  .tagline-desktop {
    display: none;
  }

  .tagline-portrait {
    display: inline;
  }

  #aboutDialog {
    width: min(96vw, 640px);
  }

  #helpDialog,
  #aboutDialog {
    max-width: 96vw;
  }

  .app {
    padding-top: 0.5rem;
  }

  .brand h1 {
    font-size: 2.1rem;
  }

  .brand-logo {
    width: 59px;
    height: 59px;
  }

  .header-action .btn {
    width: 6.8rem;
    min-height: 39px;
    font-size: 0.9rem;
    margin-top: 0;
  }

  .hand-cards {
    gap: 0.35rem;
    min-height: 120px;
  }

  .card-slot {
    width: 80px;
    min-height: 120px;
  }

  .hand-cards.is-fanned > .card-slot + .card-slot {
    margin-left: -40px;
  }

  .card-corner.top {
    top: 5px;
    left: 5px;
  }

  .card-corner.bottom {
    right: 5px;
    bottom: 5px;
  }

  .card-corner .rank {
    font-size: 0.95rem;
  }

  .card-corner .suit {
    font-size: 0.82rem;
  }

  .card-body {
    inset: 20% 12% 18% 12%;
  }

  .pip {
    font-size: 0.9rem;
  }

  .ace-logo-center {
    width: 34px;
    height: 34px;
    border-radius: 7px;
  }

  .result p {
    font-size: 0.76rem;
    line-height: 1.1;
  }

  .paytable h2 {
    font-size: 0.8rem;
  }

  .paytable li {
    font-size: 0.8rem;
  }

  .hand-main,
  .player-hand {
    grid-template-columns: minmax(48px, 58px) minmax(0, 1fr);
    gap: 0.24rem;
  }

  .status-row {
    gap: 0.42rem;
    margin-top: 0.08rem;
    display: grid;
    grid-template-columns: 168px minmax(0, 1fr);
  }

  .status-panel {
    grid-template-columns: minmax(98px, 114px) minmax(58px, 66px);
    gap: 0.12rem;
    min-width: 0;
    max-width: none;
  }

  .status-item {
    padding: 0.16rem 0.24rem;
  }

  .status-item span {
    font-size: 0.68rem;
    line-height: 1;
  }

  .status-item strong {
    font-size: 0.9rem;
    line-height: 1;
  }

  .bet-controls .btn.small {
    min-width: 26px;
    min-height: 26px;
    padding: 0.1rem;
    font-size: 0.84rem;
  }

  .result {
    padding: 0.2rem 0.32rem;
  }

  .player-hands.is-split .player-hand {
    grid-template-columns: 1fr;
    gap: 0.18rem;
  }

  .hand-info-box,
  .player-hand-label {
    font-size: 0.66rem;
    padding: 0.18rem 0.22rem;
  }

  .header-copyright,
  .header-version,
  .header-promo {
    font-size: 0.66rem;
  }

  .utility-meta {
    justify-content: flex-start;
    margin-left: -1rem;
    width: calc(100% + 2rem);
    padding: 0 1rem;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  .card-corner {
    line-height: 0.96;
  }

  .card-corner .rank {
    font-size: 0.86rem;
    margin-bottom: 0.08rem;
  }

  .card-corner .suit {
    font-size: 0.62rem;
  }
}
