:root {
  --felt: #1d4d36;
  --felt-dark: #143a29;
  --paper: #fbf8f0;
  --ink: #16161a;
  --red: #c4202c;
  --back-red: #b3202a;
  --back-dark: #7d1219;
  --gold: #e8c46a;

  /* Kartengröße (1em einer Karte, Breite = 5.5em): passt sich Breite UND Höhe des Bildschirms an,
     damit im Hochformat alles ohne Scrollen sichtbar bleibt. */
  --card-size: clamp(8px, min(calc((100vw - 24px) / 22.5), calc((100vh - 170px) / 37)), 16px);
}
@supports (height: 100dvh) {
  :root {
    --card-size: clamp(8px, min(calc((100vw - 24px) / 22.5), calc((100dvh - 170px) / 37)), 16px);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  background-attachment: fixed;
  color: #f3efe2;
  font-family: Georgia, "Times New Roman", serif;
  touch-action: manipulation;       /* kein Doppeltipp-Zoom auf dem Handy */
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#table {
  max-width: 980px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) ;
  padding-top: calc(10px + env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}
@supports (height: 100dvh) {
  body, #table { min-height: 100dvh; }
}

.zone { display: flex; flex-direction: column; gap: 8px; align-items: center; width: 100%; }
.empty-note { opacity: .7; padding: 2em 0; font-style: italic; text-align: center; }

.opp-block { display: flex; flex-direction: column; gap: 6px; align-items: center; width: 100%; }
.opp-name { font-size: 13px; opacity: .85; }

#center-zone {
  display: flex;
  justify-content: center;
  gap: 24px;
}
.stack-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; }
.stack-label { font-size: 13px; opacity: .85; white-space: nowrap; }

.stack {
  font-size: var(--card-size);
  width: 5.5em;
  height: 7.7em;
  position: relative;
}
.stack .card { position: absolute; inset: 0; }
.stack .card:nth-child(2) { transform: translate(.18em, -.18em); }
.stack .card:nth-child(3) { transform: translate(.36em, -.36em); }
.slot-empty {
  position: absolute; inset: 0;
  border: .15em dashed rgba(255, 255, 255, .25);
  border-radius: .5em;
}

#status {
  text-align: center;
  font-size: 16px;
  min-height: 1.4em;
}
#status.mine { color: var(--gold); }

#actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; min-height: 44px; }
button {
  font: inherit;
  font-size: 15px;
  min-height: 44px;                 /* Mindestgröße für Touch-Ziele */
  padding: .5em 1.1em;
  border-radius: 8px;
  border: 1px solid var(--gold);
  background: rgba(0, 0, 0, .3);
  color: var(--gold);
  cursor: pointer;
}
button:not(:disabled):active { background: var(--gold); color: #1a1a1a; }
@media (hover: hover) { button:not(:disabled):hover { background: var(--gold); color: #1a1a1a; } }
button:disabled {
  opacity: .4;
  cursor: not-allowed;
  border-color: #8a8a80;
  color: #b9b6a8;
}
button[hidden] { display: none; }

/* ---------- Kartenreihen ----------
   Die Karten überlappen automatisch, sobald sie nicht mehr in die Breite passen.
   --n (Anzahl der Karten) wird vom Script gesetzt. */
.card-row {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  width: 100%;
  font-size: var(--card-size);
  min-height: 7.7em;
}
.card-row:empty { min-height: 0; }
.card-row .card + .card {
  margin-left: calc(.5em - max(0px, (var(--n, 1) * 5.5em + (var(--n, 1) - 1) * .5em - 100%) / (var(--n, 2) - 1)));
}

/* ---------- Spielkarte ---------- */
.card {
  font-size: inherit;
  width: 5.5em;
  height: 7.7em;
  position: relative;
  flex: none;
  border-radius: .5em;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 .08em .25em rgba(0, 0, 0, .45);
  transition: transform .12s ease, box-shadow .12s ease;
}
.card.red { color: var(--red); }

.card.clickable { cursor: pointer; }
@media (hover: hover) { .card.clickable:hover { transform: translateY(-.4em); } }
.card.selected {
  transform: translateY(-.9em);
  box-shadow: 0 0 0 .14em var(--gold), 0 .3em .6em rgba(0, 0, 0, .5);
}

/* Eckindex: Wert + Symbol */
.index {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 700;
  width: 1.1em;
}
.index .r { font-size: 1.15em; letter-spacing: -.05em; }
.index .s { font-size: .95em; margin-top: .05em; }
.index.tl { top: .35em; left: .3em; }
.index.br { bottom: .35em; right: .3em; transform: rotate(180deg); }

/* Symbole in der Mitte */
.pips { position: absolute; top: .55em; bottom: .55em; left: 1.35em; right: 1.35em; }
.pip {
  position: absolute;
  font-size: 1.45em;
  line-height: 1;
  transform: translate(-50%, -50%);
}
.pip.flip { transform: translate(-50%, -50%) rotate(180deg); }
.pip.ace { font-size: 3.4em; }

/* Bildkarten J / Q / K */
.court {
  position: absolute;
  top: .55em; bottom: .55em; left: 1.15em; right: 1.15em;
  border: .08em solid currentColor;
  border-radius: .25em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: .3em 0;
  background: repeating-linear-gradient(45deg, rgba(0,0,0,.035) 0 .12em, transparent .12em .5em);
}
.court .big { font-size: 2.4em; font-weight: 700; line-height: 1; font-variant: small-caps; }
.court .cs { font-size: 1.3em; line-height: 1; }
.court .cs.flip { transform: rotate(180deg); }

/* Kartenrücken (rotes Gittermuster wie beim Bicycle-Deck) */
.card.back { background: var(--paper); }
.card.back::before {
  content: "";
  position: absolute;
  inset: .4em;
  border-radius: .25em;
  border: .08em solid var(--back-dark);
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.55) 0 .07em, transparent .07em .55em),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.55) 0 .07em, transparent .07em .55em),
    var(--back-red);
}
.card.back::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 2.3em; height: 2.3em;
  transform: translate(-50%, -50%) rotate(45deg);
  background: var(--paper);
  border: .18em solid var(--back-red);
  outline: .08em solid var(--back-dark);
  border-radius: .2em;
}

/* ---------- Tischkarten: offene Karte liegt leicht versetzt auf der verdeckten ---------- */
.slots {
  display: flex;
  justify-content: center;
  gap: 1.2em;
  font-size: var(--card-size);
}
.slot { position: relative; width: 6.3em; height: 8.4em; flex: none; }
.slot .card { position: absolute; }
.slot .under { top: 0; left: 0; }
.slot .over {
  top: .55em;
  left: .65em;
  rotate: 4deg;
  box-shadow: 0 .12em .35em rgba(0, 0, 0, .55);
}

/* verkleinerte Karten beim Gegner */
.opp-block .card-row,
.opp-block .slots { font-size: calc(var(--card-size) * .72); }
.opp-block .card-row { min-height: 0; }

/* ---------- Hinweis bei unsichtbarer 3 (neben dem Ablagestapel) ---------- */
#pile-hint {
  position: absolute;
  left: 100%;
  top: 0;
  margin-left: 8px;
  width: 7em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 5px 6px;
  border: 1px solid var(--gold);
  border-radius: 6px;
  background: rgba(0, 0, 0, .45);
  color: var(--gold);
  font-size: 12px;
  line-height: 1.25;
  text-align: center;
}
#pile-hint[hidden] { display: none; }
.mini-card { font-size: calc(var(--card-size) * .6); }

/* ---------- Querformat auf dem Handy: bitte drehen ---------- */
#rotate-hint { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  #rotate-hint {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    font-size: 18px;
    background: var(--felt-dark);
    color: var(--gold);
  }
}

/* ---------- Namenseingabe ---------- */
#login {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
}
#login[hidden] { display: none; }
#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 320px);
  text-align: center;
}
#login-form h1 { margin: 0 0 8px; font-size: 34px; color: var(--gold); }
#login-form input {
  font: inherit;
  font-size: 18px;      /* mind. 16px, sonst zoomt iOS beim Fokussieren */
  padding: .6em .8em;
  border-radius: 8px;
  border: 1px solid var(--gold);
  background: rgba(0, 0, 0, .3);
  color: #f3efe2;
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
}
#login-error { min-height: 1.3em; font-size: 14px; color: #ff9a8f; }
