@media (max-width: 900px) {

/* =========================================================
   1. Grundlayout
   ========================================================= */

body {
  overflow-x: hidden;
  overflow-y: auto;
  height: auto;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border-radius: 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
}

.help-link {
  margin-left: auto;
  font-size: 13px;
  padding: 4px 8px;
}

.topbar-button {
  padding: 4px 8px;
  font-size: 13px;
}

.controller-config-row {
  grid-template-columns: 1fr;
  gap: 5px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

/* =========================================================
   2. Layout
   ========================================================= */

.table-layout {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Desktop-Elemente ausblenden */

.info-current,
.info-total,
.player-top,
.player-left,
.player-right {
  display: none;
}

.player {
    background: rgba(255,255,255,.08);
    border-radius: 12px;
    padding: 8px;
    margin-bottom: 10px;
}

body:not(.mobile-open-play) .player.player-local-human {
  display: flex;
}

body:not(.mobile-open-play) .player-bottom:not(.player-local-human) {
  display: none;
}

.player.active {
    background: rgba(130,140,140,.35);
    border: 2px solid #ffd400;
    box-shadow: none;
}

/* =========================================================
   3. Spielinfo
   ========================================================= */

.center-table {
  order: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: rgba(0,0,0,.18);
  border-radius: 14px;
  overflow: visible;
}

.center-table > h2 {
  display: none;
}

#mobile-game-info {
  order: -100;
  display: block;
  padding: 8px;
  border-radius: 10px;
  background: rgba(255,255,255,.10);
}

#mobile-score-line {
  text-align: center;
  font-size: 14px;
  line-height: 1.45;
  color: white;
}

.mobile-score-title {
  font-size: 15px;
  font-weight: 800;
}

.mobile-score-row {
  line-height: 1.35;
}

.mobile-score-total {
  color: #fff6a8;
}

.mobile-game-context:first-of-type,
.mobile-score-row + .mobile-game-context {
  margin-top: 4px;
}

#mobile-opponents {
    display: flex;
    justify-content: space-between;
    gap: 8px;

    width: calc(100% - 20px);
    margin: 4px auto 8px;
}

.mobile-opponent {
    flex: 1;

    background: rgba(0,0,0,.18);
    color: rgba(255,255,255,.82);

    text-align: center;
    padding: 6px 4px;

    border: 1px solid rgba(255,255,255,.18);
    border-radius: 6px;

    font-size: 12px;
    font-weight: 600;
}

.mobile-opponent.active {
  background: rgba(255,212,0,.12);
  color: #fff000;
  border-color: rgba(255,212,0,.65);
}

.ai-suggestion {
    text-align: center;
    color: #8cff8c;
    text-shadow: none;
    font-size: 11px;
    line-height: 1.3;
    margin: 6px 0;
}

.ai-suggestion-toggle {
    margin: 0 auto;
}

.ai-suggestion-details {
    max-width: 360px;
    margin: 8px auto 0;
}

/* =========================================================
   4. Tisch
   ========================================================= */

#table-area {
    position: relative;

    width: 100%;
    height: 280px;

    margin: 6px 0 8px;

    background:
        radial-gradient(circle at center,
            rgba(40,150,90,.18) 0%,
            rgba(0,0,0,.12) 100%);
    border-radius: 14px;
    border: 4px solid #5b3217;
    box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.28);
    overflow: hidden;
}

#table {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.table-card-player-0 {
  left: 50%;
  top: 68%;
}

.table-card-player-1 {
  left: 36%;
  top: 52%;
}

.table-card-player-2 {
  left: 50%;
  top: 36%;
}

.table-card-player-3 {
  left: 64%;
  top: 52%;
}

#table .played-card {
    position: absolute;

    width: 50px;
    height: auto;

    transform: translate(-50%, -50%);
}


/* =========================================================
   5. Meldungsfenster
   ========================================================= */

#table-message {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(86vw, 340px);
  padding: 12px;
  background: rgba(3, 25, 18, 0.97);
  color: white;
  border-radius: 16px;
  text-align: center;
  z-index: 100;
  min-height: 0;
  border: 1px solid rgba(180, 255, 195, 0.62);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.3);
}

#table-message:empty {
    display: none;
}

#table-message.weis-message {
  width: min(86vw, 390px);
  max-height: min(52vh, 330px);
  padding: 6px 8px;
  overflow-y: auto;
}

#table-message.weis-message .weis-meldung {
  gap: 3px;
}

#table-message.weis-message .weis-zeile {
  gap: 4px;
  padding: 2px 4px;
}

#table-message.weis-message .weis-karte {
  max-width: 36px;
}

#table-message.weis-message .weis-titel {
  font-size: 14px;
}

#table-message.weis-message .weis-total {
  font-size: 12px;
}

#table-message.weis-message #message-ok-button {
  margin-top: 2px;
  padding: 4px 14px;
}

#table-message.stoeck-message {
  width: min(78vw, 300px);
  min-height: 0;
  padding: 10px;
  flex-direction: column;
  align-items: center;
}

#table-message.stoeck-message .stoeck-karte {
  width: 48px;
}

.mobile-game-context .trumpf-status-anzeige {
  white-space: nowrap;
}

.table-message-text {
  font-size: 13px;
  line-height: 1.35;
}

#message-ok-button {
  margin-top: 10px;
  padding: 6px 16px;
  border-radius: 5px;
  background: #ffd400;
  color: #111;
  border: none;
  border-radius: 8px;
  font-weight: bold;
}

#table-message.matchende-message {
  position: fixed;
  width: min(90vw, 420px);
  min-height: 0;
  padding: 26px 18px;
  border: 3px solid #ffd700;
  background: linear-gradient(160deg, #073f2c, #021b13);
  box-shadow: 0 0 0 5px rgba(255, 215, 0, 0.14),
    0 18px 45px rgba(0, 0, 0, 0.65);
}

#table-message.matchende-message .table-message-text {
  margin-bottom: 14px;
  color: #fff6a8;
  font-size: clamp(22px, 7vw, 32px);
  font-weight: 900;
  line-height: 1.25;
  text-wrap: balance;
}

#table-message.matchende-message #message-ok-button {
  min-width: 120px;
  margin-top: 10px;
  padding: 10px 22px;
  font-size: 15px;
}

#table-message.rundenende-message {
  box-sizing: border-box;
  width: min(82vw, 300px);
  padding: 8px 10px;
}

#table-message.rundenende-message .table-message-text {
  font-size: 11px;
  line-height: 1.2;
}

#table-message.rundenende-message.matsch-message .table-message-text {
  line-height: 1.12;
}

#table-message.rundenende-message .matsch-hinweis {
  color: #ffd700;
  font-size: 12px;
}

#table-message.rundenende-message .matsch-detail {
  color: #d8ffd8;
  font-size: 9px;
}

#table-message.rundenende-message #message-ok-button {
  margin-top: 6px;
  padding: 5px 14px;
}

/* =========================================================
   6. Eigener Spieler
   ========================================================= */

.player-bottom,
.player-local-human {
  order: 3;

  position: relative;
  left: auto;
  bottom: auto;
  transform: none;

  width: 100%;
  height: auto;
  min-height: 0;

  display: flex;
  flex-direction: column;
  align-items: center;

  padding: 6px;
  margin-bottom: 4px;
  border-radius: 12px;

  overflow: visible;
}

.player-bottom h2,
.player-local-human h2 {
  position: relative;
  left: auto;
  top: auto;
  bottom: auto;
  transform: none;

  margin: 0 0 6px 0;

  color: #fff000;
  font-size: 15px;

  text-shadow: 0 2px 3px rgba(0,0,0,.35);
  white-space: nowrap;
}

.player-bottom .player-hand,
.player-local-human .player-hand {
  display: block;
  position: relative;
  height: 120px;

  left: auto;
  bottom: auto;
  transform: none;

  width: 100%;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: flex-end;

  gap: 2px;
  overflow: visible;

  z-index: 10;
}

.player-bottom .karte,
.player-local-human .karte {
  position: absolute;
  left: 50%;
  bottom: 25%;
  margin-left: 0;
  transform-origin: 50% 90%;

  transition:
    transform 0.15s ease;
}

.player-bottom .karte:first-child,
.player-local-human .karte:first-child {
  margin-left: 0;
}


/* =========================================================
   7. Button
   ========================================================= */

#play-button {
  order: 2;

  position: relative;
  left: auto;
  bottom: auto;
  transform: none;

  align-self: center;

  margin-top: 2px;
  margin-bottom: 8px;

  min-width: 220px;
  padding: 12px 22px;
  border: none;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  border-radius: 5px;
  background: #2f9d35;
  color: white;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);

  z-index: 5;
  
}

/* =========================================================
   8. Karten
   ========================================================= */

.karte,
.played-card {
  width: 50px;
  border-radius: 8px;
  padding: 2px;
  border-width: 1px;
}

.karten-ecke,
.karten-symbol {
  width: 10px;
  height: 10px;
}

.karten-ecke {
  top: 2px;
  right: 2px;
}

.karten-wert-mitte {
  font-size: 10px;
  padding-top: 2px;
}


/* =========================================================
   9. Trumpfwahl
   ========================================================= */

#trumpf-modal {
    position: absolute !important;
    inset: 0;

    display: flex;
    justify-content: center;
    align-items: flex-start;

    background: rgba(0,0,0,.35);

    z-index: 200;
}

#trumpf-modal.modal-hidden {
    display: none !important;
}

   .trumpfwahl-spieler {
  gap: 4px;
  margin-top: 4px;
}


#trumpf-modal .modal-content {
  box-sizing: border-box;
  width: min(80vw, 280px);
  min-width: 0;
  max-width: 280px;

  padding: 8px;
  border-width: 2px;
  border-radius: 10px;
}

#trumpf-modal .modal-content h2 {
  margin-bottom: 6px;
  font-size: 18px;
}

#trumpf-modal .ai-suggestion {
  margin-bottom: 6px;
  font-size: 10px;
  line-height: 1.15;
}

#trumpf-modal .trumpf-row-top,
#trumpf-modal .trumpf-row-bottom {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  box-sizing: border-box;
  width: 100%;
  gap: 4px;
  margin: 4px 0;
}

#trumpf-modal .trumpf-row-top .trumpf-btn,
#trumpf-modal .trumpf-row-bottom .trumpf-btn,
#trumpf-modal .trumpf-row-schieben .schieben-btn {
  width: 100%;
  height: 30px;

  font-size: 12px;

  display: flex;
  align-items: center;
  justify-content: center;
}

#trumpf-modal .trumpf-row-bottom .trumpf-btn:nth-child(3) {
  grid-column: 1 / -1;
  width: 100%;
  justify-self: center;
}

#trumpf-modal .trumpf-row-schieben {
  display: flex;
  justify-content: center;
  margin-top: 5px;
}

#trumpf-modal .trumpf-row-schieben .schieben-btn {
  width: 90px;
  height: 28px;
  flex: 0 0 auto;
}

#trumpf-modal #trumpf-close {
  margin-top: 8px;
  padding: 5px 12px;
  font-size: 11px;
}

#trumpf-modal .trumpf-status-symbol {
  width: 22px;
  height: 22px;
}

#table-message .trumpf-bestaetigungs-symbol .trumpf-status-symbol {
  width: 46px;
  height: 46px;
}

/* =========================================================
   10. Open Play
   ========================================================= */

body.mobile-open-play #mobile-opponents {
  display: none;
}

body.mobile-open-play #trumpf-modal .trumpf-title {
  margin-bottom: 3px;
  font-size: 17px;
  line-height: 1.1;
}

body.mobile-open-play .player-top,
body.mobile-open-play .player-left,
body.mobile-open-play .player-right {

  display: flex;
  flex-direction: column;
  align-items: center;

  width: 100%;
  padding: 8px 0;

  position: relative;
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
  transform: none;

  order: 4;
}

body.mobile-open-play .player-left {
  order: 4;
}

body.mobile-open-play .player-top {
  order: 5;
}

body.mobile-open-play .player-right {
  order: 6;
}

body.mobile-open-play .player-top h2,
body.mobile-open-play .player-left h2,
body.mobile-open-play .player-right h2 {

  position: relative;
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
  transform: none;

  writing-mode: horizontal-tb;

  color: #fff000;
  font-size: 15px;

  margin-bottom: 4px;
}

body.mobile-open-play .player-top .player-hand,
body.mobile-open-play .player-left .player-hand,
body.mobile-open-play .player-right .player-hand {

    display: block;
    position: relative;
    width: 100%;
    height: 120px;

    overflow: visible;
}
}

body.mobile-open-play .player-top .karte,
body.mobile-open-play .player-left .karte,
body.mobile-open-play .player-right .karte {

    position: absolute;
    left: 50%;
    bottom: 25%;

    margin-left: 0;

    transform-origin: 50% 90%;
}

body.mobile-open-play .player-top .karte:first-child,
body.mobile-open-play .player-left .karte:first-child,
body.mobile-open-play .player-right .karte:first-child {
  margin-left: 0;
}

.player-bottom .karte:hover,
.player-bottom .karte:focus-visible,
.player-local-human .karte:hover,
.player-local-human .karte:focus-visible {
  filter: none;
  box-shadow: none;
}
