:root {
  color-scheme: dark;
  --bg: #071013;
  --panel: #0d171b;
  --panel-2: #121f24;
  --line: rgba(255, 255, 255, 0.12);
  --muted: #8ea1a5;
  --text: #eff7f4;
  --green: #0f5a38;
  --green-deep: #073c27;
  --gold: #d9aa4e;
  --red: #dd2d3d;
  --black-card: #101418;
  --card: #fbfbf7;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 18% 18%, rgba(15, 90, 56, 0.28), transparent 28rem),
    linear-gradient(135deg, #061014 0%, #10171c 52%, #171511 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  font: inherit;
}

select {
  font: inherit;
}

.app-shell {
  width: min(1800px, calc(100vw - 16px));
  height: calc(100vh - 16px);
  min-height: 680px;
  margin: 8px auto;
  display: grid;
  grid-template-columns: minmax(300px, 34%) minmax(0, 1fr);
  gap: 10px;
}

.table-panel,
.ranking-panel {
  background: rgba(13, 23, 27, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.table-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto auto;
  overflow: hidden;
}

.top-bar,
.ranking-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 2.2vw, 2.5rem);
}

h2 {
  font-size: 1.35rem;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  flex-shrink: 0;
}

.opponent-control {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.opponent-control select {
  height: 38px;
  min-width: 66px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #1b2b31;
  color: var(--text);
  padding: 0 10px;
  font-weight: 900;
}

.primary-button,
.icon-button {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  background: #1b2b31;
  cursor: pointer;
}

.primary-button {
  padding: 0 16px;
  border-color: rgba(217, 170, 78, 0.7);
  background: linear-gradient(180deg, #d8a84d 0%, #9b6b24 100%);
  color: #10100d;
  font-weight: 900;
}

.icon-button {
  width: 40px;
  font-size: 1.45rem;
  display: grid;
  place-items: center;
}

.primary-button:hover,
.icon-button:hover {
  filter: brightness(1.08);
}

.icon-button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.felt {
  margin: 12px;
  min-height: 0;
  border: 10px solid #2a2017;
  outline: 4px solid rgba(255, 255, 255, 0.06);
  background:
    radial-gradient(ellipse at center, rgba(255, 255, 255, 0.08), transparent 45%),
    linear-gradient(135deg, var(--green) 0%, var(--green-deep) 100%);
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  align-items: start;
  gap: 16px;
  padding: 18px;
  overflow: auto;
  max-height: 430px;
}

.board-zone,
.nut-readout {
  min-width: 0;
}

.zone-label,
.readout-kicker {
  display: block;
  margin: 0 0 8px;
  color: rgba(239, 247, 244, 0.72);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card-row,
.hole-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.board-cards {
  flex-wrap: wrap;
}

.board-card-button,
.card-option {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.board-card-button {
  display: block;
  position: relative;
}

.board-card-button::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 2px solid transparent;
  pointer-events: none;
}

.board-card-button:hover:not(:disabled)::after,
.board-card-button.selected::after,
.board-card-button:focus-visible::after {
  border-color: var(--gold);
}

.board-card-button:focus-visible,
.card-option:focus-visible,
.picker-close:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.board-card-button:disabled {
  cursor: not-allowed;
}

.board-card-placeholder {
  width: clamp(52px, 5vw, 72px);
  aspect-ratio: 0.72;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.24);
  background: rgba(0, 0, 0, 0.18);
  color: rgba(239, 247, 244, 0.78);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.board-card-placeholder:disabled {
  opacity: 0.35;
}

.card {
  width: clamp(52px, 5vw, 72px);
  aspect-ratio: 0.72;
  border: 1px solid rgba(0, 0, 0, 0.22);
  background: var(--card);
  color: var(--black-card);
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 6px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.22);
  user-select: none;
}

.card.small {
  width: 30px;
  min-width: 30px;
  padding: 3px;
  border-radius: 4px;
  box-shadow: none;
}

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

.rank {
  font-size: clamp(1.15rem, 1.8vw, 1.65rem);
  line-height: 0.92;
  font-weight: 950;
}

.card.small .rank {
  font-size: 0.78rem;
}

.suit {
  align-self: center;
  justify-self: center;
  font-size: clamp(1.2rem, 2.2vw, 1.8rem);
  line-height: 1;
}

.card.small .suit {
  font-size: 0.72rem;
}

.rank-bottom {
  justify-self: end;
  transform: rotate(180deg);
}

.card-picker {
  margin-top: 12px;
  border: 1px solid rgba(217, 170, 78, 0.45);
  background: rgba(5, 16, 18, 0.84);
}

.card-picker-head {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 9px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.card-picker-head strong {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card-picker-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.picker-close,
.picker-remove {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #1b2b31;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.picker-remove {
  width: auto;
  padding: 0 9px;
  color: #111;
  background: var(--gold);
  font-size: 0.68rem;
  font-weight: 900;
}

.card-picker-grid {
  display: grid;
  grid-template-columns: repeat(13, minmax(30px, 1fr));
  gap: 4px;
  padding: 8px;
}

.card-option {
  display: grid;
  place-items: center;
  min-width: 30px;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.18);
}

.card-option:hover:not(:disabled),
.card-option.selected {
  border-color: var(--gold);
  background: rgba(217, 170, 78, 0.16);
}

.card-option:disabled {
  opacity: 0.24;
  cursor: not-allowed;
}

.nut-readout {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  border-left: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  padding: 14px 0 0;
}

.nut-combo {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.nut-readout strong {
  font-size: clamp(1.15rem, 2.2vw, 1.65rem);
  line-height: 1.08;
}

.nut-meta {
  margin-top: 8px;
  color: rgba(239, 247, 244, 0.78);
  font-size: 0.82rem;
  font-weight: 800;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
}

.stats-grid div {
  min-width: 0;
  padding: 12px 14px;
  border-right: 1px solid var(--line);
}

.stats-grid div:last-child {
  border-right: 0;
}

.stats-grid span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stats-grid strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
}

.ranking-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 100%;
}

.flop-code {
  flex-shrink: 0;
  color: #111;
  background: var(--gold);
  padding: 6px 9px;
  font-weight: 950;
  font-size: 0.9rem;
}

.ranking-list {
  overflow: auto;
  padding: 10px;
}

.tier-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  margin-bottom: 7px;
  padding: 8px;
}

.tier-card:first-child {
  border-color: rgba(217, 170, 78, 0.75);
  background: linear-gradient(180deg, rgba(217, 170, 78, 0.12), rgba(18, 31, 36, 0.96));
}

.tier-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  margin-bottom: 7px;
}

.tier-rank {
  min-width: 40px;
  color: #111;
  background: var(--gold);
  padding: 4px 6px;
  text-align: center;
  font-weight: 950;
  font-size: 0.74rem;
}

.tier-title {
  min-width: 0;
}

.tier-title strong,
.tier-title span {
  display: block;
}

.tier-title strong {
  font-size: 0.92rem;
  line-height: 1.18;
}

.tier-title span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
}

.tier-metrics {
  min-width: 106px;
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 4px 10px;
  justify-content: end;
  text-align: right;
}

.metric-block strong,
.metric-block span,
.combo-count {
  display: block;
}

.metric-block strong {
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.1;
}

.metric-block span,
.combo-count {
  color: var(--muted);
  font-size: 0.68rem;
  white-space: nowrap;
}

.combo-count {
  grid-column: 1 / -1;
}

.combo-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 54px;
  overflow: hidden;
}

.combo-list.expanded {
  max-height: none;
}

.combo-pill {
  min-width: 0;
  width: auto;
  max-width: 162px;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(30px, 1fr);
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.combo-pill.extra-combo {
  display: none;
}

.combo-list.expanded .combo-pill.extra-combo {
  display: flex;
}

.combo-cards {
  display: flex;
  gap: 3px;
}

.redraw-tags {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.redraw-tags span {
  display: block;
  min-width: 0;
  color: #111;
  background: var(--gold);
  padding: 1px 3px;
  font-size: 0.5rem;
  line-height: 1;
  font-weight: 950;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.more-combos {
  display: grid;
  place-items: center;
  min-height: 42px;
  min-width: 70px;
  flex: 0 0 auto;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.16);
  font-size: 0.74rem;
  font-weight: 800;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  cursor: pointer;
}

.more-combos:hover {
  color: var(--text);
  border-color: rgba(217, 170, 78, 0.55);
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .ranking-panel {
    max-height: none;
  }

  .table-panel {
    overflow: visible;
  }

  .felt {
    max-height: none;
    grid-template-columns: minmax(140px, 0.8fr) minmax(170px, 1fr);
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 20px, 720px);
    margin: 10px auto;
  }

  .top-bar,
  .ranking-header {
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
  }

  h1 {
    font-size: 1.55rem;
  }

  .eyebrow {
    font-size: 0.62rem;
  }

  .felt {
    margin: 10px;
    grid-template-columns: minmax(130px, 0.8fr) minmax(150px, 1fr);
    padding: 14px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stats-grid div:last-child {
    border-bottom: 0;
  }

  .card {
    width: clamp(42px, 14vw, 58px);
  }

  .board-card-placeholder {
    width: clamp(42px, 14vw, 58px);
  }

  .card-picker-grid {
    grid-template-columns: repeat(8, minmax(30px, 1fr));
  }

  .tier-head {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .tier-metrics {
    grid-column: 1 / -1;
    justify-content: start;
    text-align: left;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100vw - 12px, 520px);
    margin: 6px auto;
  }

  .controls {
    justify-content: flex-start;
  }

  .felt {
    grid-template-columns: 1fr;
  }

  .card-picker-grid {
    grid-template-columns: repeat(6, minmax(30px, 1fr));
  }
}
