/* Layout und Komponenten kommen von Bootstrap (static/vendor/bootstrap.min.css);
   hier nur Ergänzungen. Kein Inline-Style wegen CSP. */
.app-container {
  max-width: 40rem;
}

/* Läuft ein Spiel, darf es die volle Breite nutzen (Spiele können darauf aufsetzen). */
body.game-started .app-container {
  max-width: none;
}

.passphrase {
  font-family: ui-monospace, monospace;
  font-size: 1.8rem;
  letter-spacing: 0.1em;
  font-weight: bold;
}

.flag {
  display: block;
  border-radius: 2px;
}

/* Ersatz für die von htmx sonst inline eingefügten Indicator-Styles
   (htmx.config.includeIndicatorStyles = false wegen CSP). */
.htmx-indicator {
  opacity: 0;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
  transition: opacity 200ms ease-in;
}

/* Bootstrap bettet Icons als data:-URI ein, das verbietet die CSP (img-src 'self').
   Daher Pfeil des Select aus einer statischen Datei. */
.form-select {
  --bs-form-select-bg-img: url("chevron.f5bcc9e39db4.svg");
  background-image: url("chevron.f5bcc9e39db4.svg");
}

/* Version im Footer: dezent, gedämpft. */
.app-version {
  font-size: 0.7rem;
  color: var(--bs-tertiary-color);
  opacity: 0.7;
}

/* Tic-Tac-Toe */
.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 5rem);
  gap: 0.5rem;
}

.ttt-cell {
  height: 5rem;
  font-size: 2rem;
  font-weight: bold;
}

/* Kartenbaustein (games/cards/static/cards/table.js). Positionen kommen als Custom-Properties
   (--x/--y in Kartenbreiten, --r in Grad, --z, --delay in ms) per style.setProperty. */
/* --cw (Kartenbreite) setzt table.js aus der Größe des Behälters; der Tisch füllt ihn. */
.table-cards {
  --cw: 40px;
  position: relative;
  /* Kartenebenen (--z) bleiben im Tisch und überdecken keine Hinweise der Leiste. */
  isolation: isolate;
  width: 100%;
  max-width: 40rem;
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 1rem;
  background: #2f6b4a;
  overflow: hidden;
  touch-action: manipulation;
}

.tcard {
  position: absolute;
  left: calc(50% - var(--cw) / 2);
  /* Seitenverhältnis der Karten-SVGs (189,5 × 318) */
  top: calc(50% - var(--cw) * 0.839);
  width: var(--cw);
  height: calc(var(--cw) * 1.678);
  padding: 0;
  border: 0;
  background: none;
  perspective: calc(var(--cw) * 12);
  z-index: var(--z, 0);
  transform: translate(calc(var(--x, 0) * var(--cw)), calc(var(--y, 0) * var(--cw)))
    rotate(calc(var(--r, 0) * 1deg));
  transition: transform 450ms ease;
  transition-delay: calc(var(--delay, 0) * 1ms);
  cursor: default;
}

.tcard.selectable {
  cursor: pointer;
}

.tcard.selected {
  filter: drop-shadow(0 0 0.3rem #ffd54f);
}

.tcard-inner {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 350ms ease;
  transition-delay: calc(var(--delay, 0) * 1ms);
}

.tcard.face-down .tcard-inner {
  transform: rotateY(180deg);
}

.tcard-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 6%;
  box-shadow: 0 1px 2px rgb(0 0 0 / 40%);
}

.tcard-back {
  transform: rotateY(180deg);
}

.table-cards.no-anim .tcard,
.table-cards.no-anim .tcard-inner,
.tcard.no-anim,
.tcard.no-anim .tcard-inner {
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  .tcard,
  .tcard-inner {
    transition-duration: 1ms;
  }
}

/* Vollbild-Tisch: nach dem Start entfällt alles außer Leiste (Bedienung) und Spielfläche. */
body.game-started {
  overflow: hidden;
}

body.game-started .navbar,
body.game-started footer,
body.game-started .game-players {
  display: none;
}

body.game-started main.app-container {
  padding: 0 !important;
}

body.game-started #game {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--bs-tertiary-bg);
}

/* Material Design Icons (core/static/vendor/mdi/mdi.svg) */
.icon {
  width: 1.25em;
  height: 1.25em;
  fill: currentcolor;
  vertical-align: -0.25em;
}

.btn .icon + .btn-label {
  margin-left: 0.4em;
}

/* Leiste mit Titel, Spielinfos und Knöpfen (vor dem Start Karte, danach dunkle Leiste am Tisch). */
.game-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  background: var(--bs-body-bg);
}

.game-title {
  margin: 0;
  font-size: 1.25rem;
}

.game-buttons {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}

.game-icon-btn {
  border: 1px solid var(--bs-border-color);
}

.game-error {
  flex-basis: 100%;
  margin: 0;
}

.game-error:empty {
  display: none;
}

/* Spiel-spezifische Infos (Runde, Status, Punkte) sitzen in der Leiste zwischen Titel und Knöpfen. */
.game-bar-info {
  flex: 1 1 auto;
  min-width: 0;
}

.game-bar-info .scopa-hud {
  padding: 0;
}

body.game-started .game-panel {
  order: -1;
  flex-wrap: nowrap;
  gap: 0.75rem;
  margin: 0;
  padding: 0.25rem 0.5rem 0.25rem 0.875rem;
  border: 0;
  border-radius: 0;
  background: #153828;
  color: #fff;
  box-shadow: 0 1px 0 rgb(0 0 0 / 35%);
  position: relative;
  z-index: 2;
}

body.game-started .game-title {
  flex: none;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
}

/* Knöpfe in der Leiste: nur Icons, ohne Rahmen; Beschriftung steht im Tooltip. */
body.game-started .game-buttons .btn-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

body.game-started .game-buttons .btn .icon + .btn-label {
  margin-left: 0;
}

body.game-started .game-icon-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem;
  border: 0;
  border-radius: 50%;
  color: rgb(255 255 255 / 80%);
}

body.game-started .game-icon-btn.d-none {
  display: none;
}

body.game-started .game-icon-btn .icon {
  width: 1.5rem;
  height: 1.5rem;
  vertical-align: baseline;
}

body.game-started .game-icon-btn:hover,
body.game-started .game-icon-btn:focus-visible {
  background: rgb(255 255 255 / 15%);
  color: #fff;
}

body.game-started .game-error {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  padding: 0.25rem 0.875rem;
  background: rgb(0 0 0 / 70%);
  color: #ffb4a9 !important;
  font-size: 0.85rem;
}

.game-lobby-open,
.lobby-close {
  display: none;
}

body.game-started .game-lobby-open {
  display: inline-block;
}

/* Lobby: nach dem Start verborgen, über die Leiste als Overlay erreichbar. */
body.game-started #lobby {
  display: none;
}

body.game-started.lobby-open #lobby {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow: auto;
  padding: 1rem;
  background: var(--bs-body-bg);
}

body.game-started.lobby-open .lobby-close {
  display: inline-block;
  margin-bottom: 1rem;
}

body.game-started .game-panel .text-danger {
  margin: 0 !important;
}

body.game-started .game-board {
  flex: 1;
  min-height: 0;
  margin: 0 !important;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

/* Scopa */
.scopa {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #1f4a33;
  color: #fff;
}

.scopa-hud {
  padding: 0.25rem 0.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
  font-size: 0.9rem;
}

.scopa-hud p {
  margin: 0;
  color: inherit;
}

.scopa-table.table-cards {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
  aspect-ratio: auto;
  border-radius: 0;
}

.scopa-active {
  outline: 2px solid #ffc107;
  font-weight: bold;
}

.scopa-summary-overlay {
  position: absolute;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  background: rgb(0 0 0 / 45%);
}

.scopa-banner {
  position: absolute;
  top: 40%;
  left: 50%;
  z-index: 1500;
  transform: translate(-50%, -50%);
  padding: 0.5rem 1.5rem;
  border-radius: 0.75rem;
  background: #ffc107;
  color: #3a2a00;
  font-size: clamp(1.5rem, 6vmin, 3rem);
  font-weight: 800;
  pointer-events: none;
  box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 45%);
  animation: scopa-pop 1.6s ease both;
}

@keyframes scopa-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.6);
  }
  15%,
  80% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1);
  }
}

.scopa-summary-table {
  --bs-table-bg: transparent;
  font-size: clamp(1rem, 2.6vmin, 1.4rem);
  border-collapse: separate;
  border-spacing: 0 0.25rem;
}

.scopa-summary-table th,
.scopa-summary-table td {
  padding: 0.6rem 1.25rem;
  border-bottom: 0;
}

.scopa-summary-table td.scopa-win {
  border-radius: 0.4rem;
  background: #0d6efd;
  color: #fff;
  font-weight: 600;
}

/* Summenstriche: über „Runde“ einfach, über „Summe“ doppelt. */
.scopa-summary-table tr.scopa-sum-line > * {
  border-top: 3px solid currentcolor;
}

.scopa-summary-table tr.scopa-total > * {
  border-top: 6px double currentcolor;
}

.scopa-summary-card {
  max-height: 100%;
  overflow: auto;
  padding: clamp(1rem, 4vmin, 2.5rem);
  border-radius: 0.5rem;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 40%);
}

/* Schmale Bildschirme: kompaktere Kopfzeile. */
@media (max-width: 575.98px) {
  .scopa-hud {
    font-size: 0.8rem;
  }

  body.game-started .game-title {
    display: none;
  }
}

/* Karten lassen sich nicht wie Text markieren (blaue Auswahlfläche). */
.table-cards,
.table-cards * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.tcard-face {
  -webkit-user-drag: none;
}

/* Aktueller Spieler: ganze Pille gefüllt. */
.scopa-player.scopa-active {
  border-color: #ffc107 !important;
  background: #ffc107 !important;
  color: #3a2a00 !important;
}

.scopa-sizes {
  display: inline-flex;
  gap: 0.25rem;
}

.scopa-size {
  padding: 0 0.4rem;
  border: 1px solid rgb(255 255 255 / 40%);
  color: inherit;
  line-height: 1.4;
}

.scopa-size:hover {
  background: rgb(255 255 255 / 15%);
  color: #fff;
}

.scopa-fuori {
  font-weight: 700;
}

/* Hinweis bei abgelehntem Zug: mitten auf dem Tisch, über den Karten. */
.scopa-notice {
  position: absolute;
  top: 35%;
  left: 50%;
  z-index: 1600;
  max-width: min(90%, 32rem);
  transform: translate(-50%, -50%);
  padding: 0.75rem 1.25rem;
  border-radius: 0.75rem;
  background: #b02a37;
  color: #fff;
  font-size: clamp(1rem, 2.4vmin, 1.4rem);
  font-weight: 600;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 45%);
}

.scopa-summary-card {
  width: min(100%, 64rem);
}

.scopa-winner {
  margin: 0 0 0.25rem;
  color: #0d6efd;
  font-size: clamp(1.5rem, 4.5vmin, 2.5rem);
  font-weight: 800;
  text-align: center;
}

.scopa-fuori-note {
  margin: 0 0 1rem;
  text-align: center;
  font-weight: 600;
}
