/* No text selection anywhere, also in dialogs (Safari needs the prefix). */
* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

:root {
  --terracotta-surface: radial-gradient(
    circle at 10% 5%,
    #bf7466 0%,
    #944d55 48%,
    #5d303a 100%
  );
  --felt-green: #6bd66b;
  --light-red: #ff6b6b;
  --dark-yellow: #c99a06;
  --selection-green: #315c3c;
}

html,
body,
#game-shell,
#pixiCanvas {
  width: 100%;
  height: 100%;
}

html,
body {
  margin: 0;
  overflow: hidden;
  background: #944d55;
}

#pixiCanvas {
  display: block;
  touch-action: none;
}

.game-dialog {
  position: fixed;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(
    100dvh -
    8px -
    min(env(safe-area-inset-top, 0px), 16.667dvh) -
    min(env(safe-area-inset-bottom, 0px), 16.667dvh)
  );
  overflow-y: auto;
  margin: 0;
  padding: 20px 20px 16px;
  border: 2px solid var(--felt-green);
  border-radius: 16px;
  color: #fff;
  background: var(--terracotta-surface);
  box-shadow: 0 10px 30px rgb(0 0 0 / 45%);
  font:
    16px Arial,
    sans-serif;
}

.game-dialog * {
  color: #fff;
}

/* A light scrim keeps the player's hand visible below the dialog. */
.game-dialog::backdrop {
  background: rgb(0 0 0 / 35%);
}

/* Hand text: one span per suit (handText.ts). */
.sheet-hand-suit {
  margin: 0 8px;
  white-space: nowrap;
}

.unplayed-cards-text {
  margin: 0 0 14px;
  font:
    700 20px Arial,
    sans-serif;
  text-align: center;
}

/* One row per suit; a long row may wrap. */
.unplayed-cards-text .sheet-hand-suit {
  display: block;
  margin: 0 0 6px;
  white-space: normal;
}

.unplayed-cards-text .suit-red {
  color: var(--light-red);
}

.dialog-status {
  margin: 0 0 14px;
  text-align: center;
}

.dialog-status:empty {
  display: none;
}

/* The charts scroll; the title and the close button stay in view. */
#stats[open] {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#statsContent {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 0 12px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.stats-chart {
  margin: 0 0 18px;
}

.stats-chart h3 {
  margin: 0 0 8px;
  font-size: 18px;
  text-align: center;
}

.stats-empty {
  margin: 0;
  padding: 8px 0;
  text-align: center;
}

.stats-chart-frame {
  position: relative;
  height: 220px;
}

/* The release tag, stamped into data-version by tools/build.ts. */
.stats-version {
  margin: 12px 0 0;
  opacity: 0.75;
  text-align: center;
  font:
    italic 12px Arial,
    sans-serif;
}

.dialog-buttons {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.dialog-cancel,
.dialog-confirm {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: none;
  font:
    700 18px Arial,
    sans-serif;
  cursor: pointer;
}

/* display: flex above would override the hidden attribute (dialogs and sheets). */
.dialog-cancel[hidden],
.dialog-confirm[hidden] {
  display: none;
}

.dialog-cancel:disabled,
.dialog-confirm:disabled {
  opacity: 0.45;
  cursor: default;
}

.dialog-button-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 2px 6px rgb(0 0 0 / 40%);
}

.dialog-cancel .dialog-button-icon {
  background: #e8352c;
}

.dialog-confirm .dialog-button-icon {
  background: #1414e6;
}

.dialog-cancel:focus-visible .dialog-button-icon,
.dialog-confirm:focus-visible .dialog-button-icon {
  outline: 3px solid var(--felt-green);
  outline-offset: 2px;
}

.setup-limit {
  display: flex;
  justify-content: center;
  margin: 0 0 14px;
  padding: 6px 12px 12px;
  border: 1px solid rgb(107 214 107 / 60%);
  border-radius: 10px;
}

.setup-limit legend,
.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stepper button,
.bid-option {
  border: 1px solid #caf5ce;
  border-radius: 8px;
  background: rgb(49 92 60 / 70%);
  font:
    700 18px Arial,
    sans-serif;
  cursor: pointer;
}

.stepper button {
  width: 40px;
  height: 40px;
}

.stepper output {
  min-width: 48px;
  font-size: 26px;
  font-weight: 700;
  text-align: center;
}

.setup-rules {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 10px 12px 12px;
  border: 1px solid rgb(107 214 107 / 60%);
  border-radius: 10px;
}

.setup-rules label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  cursor: pointer;
}

.setup-rules input {
  width: 20px;
  height: 20px;
  accent-color: var(--felt-green);
}

/* The six games: ♦ ♥ ♠ ♣ in a row, then Grand and Null. */
.contract-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.bid-option {
  min-height: 40px;
  padding: 4px 2px;
  white-space: nowrap;
}

.contract-grid > .bid-option:nth-child(n + 5) {
  grid-column: span 2;
}

/* Schneider, Schwarz and Ouvert under the games. */
.contract-flags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin-top: 12px;
}

.contract-flags label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  cursor: pointer;
}

.contract-flags input {
  width: 20px;
  height: 20px;
  accent-color: var(--felt-green);
}

.contract-flags label:has(input:disabled) {
  opacity: 0.4;
  cursor: default;
}

/* The ‹ value › stepper of the bidding. */
.bid-stepper {
  justify-content: center;
  /* Narrower on small phones, so the arrows stay inside the dialog. */
  gap: min(24px, 4vw);
  margin-top: 8px;
}

.bid-stepper[hidden] {
  display: none;
}

.stepper button:disabled {
  opacity: 0.3;
  cursor: default;
}

/* Wide enough for "264", so the arrows stay put while stepping. */
.bid-stepper-value {
  min-width: min(72px, 20vw);
}

/*
 * Landscape: two columns. The game setup's rules beside the number of deals
 * and Start; the games beside their announcements; the list beside the
 * summary, last trick and button. --dialog-area-height is the room above the
 * hand (BaseDialog.ts).
 */
@media (orientation: landscape) {
  #gameSetup[open] {
    display: grid;
    grid-template:
      'rules limit' auto
      'rules .' 1fr
      'rules buttons' auto
      / 1fr 1fr;
    column-gap: 20px;
    width: min(640px, calc(100vw - 32px));
  }

  #gameSetup .setup-limit {
    grid-area: limit;
  }

  #gameSetup .setup-rules {
    grid-area: rules;
    align-self: start;
  }

  #gameSetup .dialog-buttons {
    grid-area: buttons;
    margin-top: 0;
  }

  #contract[open] {
    display: grid;
    grid-template:
      'grid flags' auto
      'buttons buttons' auto
      / 1fr auto;
    column-gap: 20px;
    width: min(560px, calc(100vw - 32px));
  }

  #contract .contract-grid {
    grid-area: grid;
  }

  #contract .contract-flags {
    grid-area: flags;
    flex-direction: column;
    justify-content: center;
    margin-top: 0;
  }

  #contract .dialog-buttons {
    grid-area: buttons;
  }

  /* The list fills the room above the hand beside a 240px text column. */
  #scorecard[open] {
    display: grid;
    grid-template:
      'progress summary' auto
      'list trick' 1fr
      'seats buttons' auto
      / 1fr 240px;
    column-gap: 20px;
    width: min(760px, calc(100vw - 32px));
  }

  #scorecard .scorecard-progress {
    grid-area: progress;
  }

  #scorecardSummary {
    grid-area: summary;
  }

  #scorecard .scorecard-list {
    grid-area: list;
    /* The room minus the margin (8px), padding and border (40px), the
       progress line (24px) and the seats row (34px). */
    max-height: max(
      120px,
      calc(min(var(--dialog-area-height, 100dvh), 100dvh) - 106px)
    );
  }

  #scorecard .scorecard-seats {
    grid-area: seats;
  }

  #scorecard .dialog-buttons {
    display: contents;
  }

  #scorecard .scorecard-last-trick {
    grid-area: trick;
  }

  #scorecard .dialog-confirm {
    grid-area: buttons;
    justify-self: end;
    align-self: end;
  }
}

.bid-option .suit-red {
  color: var(--light-red);
}

.bid-option:disabled {
  opacity: 0.3;
  cursor: default;
}

.bid-option[aria-pressed='true'] {
  border-color: var(--felt-green);
  background: var(--felt-green);
  box-shadow: 0 0 0 2px #fff inset;
}

.bid-option[aria-pressed='true'],
.bid-option[aria-pressed='true'] * {
  color: #12301a;
}

/* The list: a row per deal, the latest at the bottom and in bold. */
.scorecard-progress {
  margin: 0 0 6px;
  font-size: 14px;
  opacity: 0.85;
}

.scorecard-list {
  max-height: 40dvh;
  overflow-y: auto;
}

.scorecard-table {
  width: 100%;
  border-collapse: collapse;
  font:
    15px Arial,
    sans-serif;
  text-align: right;
}

.scorecard-table th {
  position: sticky;
  top: 0;
  background: #5d303a;
  font-weight: 700;
}

.scorecard-table th,
.scorecard-table td {
  padding: 3px 6px;
  border-bottom: 1px solid rgb(202 245 206 / 25%);
}

.scorecard-table :is(th, td):nth-child(2) {
  text-align: left;
}

.scorecard-table .suit-red {
  color: var(--light-red);
}

.scorecard-table .score-positive {
  color: var(--felt-green);
}

.scorecard-table .score-negative {
  color: var(--light-red);
}

.scorecard-fresh {
  font-weight: 700;
}

/* Names and totals under their columns: left bot, you, right bot. */
.scorecard-seats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
  font-size: 17px;
}

.scorecard-seats > :first-child {
  text-align: left;
}

.scorecard-seats > :nth-child(2) {
  text-align: center;
}

.scorecard-seats > :last-child {
  text-align: right;
}

.scorecard-seat--local {
  font-weight: 700;
}

.scorecard-seats .score-positive {
  color: var(--felt-green);
}

.scorecard-seats .score-negative {
  color: var(--light-red);
}

/* Left of the button; above it in portrait. */
.scorecard-last-trick {
  font:
    700 17px Arial,
    sans-serif;
}

/* A long label wraps before the cards, never between them. */
.scorecard-last-trick-cards {
  white-space: nowrap;
}

/* Wide enough for the last trick and the button on one line. */
#scorecard {
  width: min(560px, calc(100vw - 32px));
}

.scorecard-last-trick .suit-red {
  color: var(--light-red);
}

@media (orientation: portrait) {
  /*
   * Decisions: one row per button on the right, the confirming one on top
   * (the bidding dialog has its stepper above them).
   */
  :is(#bidding, #contract, #resumeGame, #handQuestion, #kontra)
    .dialog-buttons {
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 12px;
  }

  /* Pass ✖: the caption before the icon, so all icons line up. */
  :is(#bidding, #contract, #resumeGame, #handQuestion, #kontra) .dialog-cancel {
    flex-direction: row-reverse;
  }

  #scorecard .dialog-buttons {
    flex-wrap: wrap;
  }

  #scorecard .scorecard-last-trick {
    flex-basis: 100%;
    text-align: center;
  }

  #scorecard .scorecard-last-trick:empty {
    display: none;
  }

  #scorecard .dialog-confirm {
    margin-left: auto;
  }
}

/* Its padding reports the safe-area insets to the HUD layout (safeAreaInsets.ts). */
#safeAreaProbe {
  position: fixed;
  top: 0;
  left: 0;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  visibility: hidden;
  pointer-events: none;
}
