:root {
  --felt: #0f5132;
  --felt-2: #146c43;
  --ink: #f8fafc;
  --card: #fffdf8;
  --red: #c0262d;
  --black: #1f2937;
  --accent: #fbbf24;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 30%, var(--felt-2), var(--felt) 70%);
  display: flex;
  flex-direction: column;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Kopfzeile ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(6px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 6px calc(10px + env(safe-area-inset-left));
  background: rgba(0, 0, 0, .25);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; }
.info { display: flex; gap: 14px; margin-left: auto; font-variant-numeric: tabular-nums; }
.stat { display: inline-flex; align-items: center; gap: 4px; opacity: .95; }
.stat .ico { opacity: .7; }
.actions { display: flex; gap: 6px; }
.actions button {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, .12);
  color: var(--ink);
  font: inherit; font-size: .9rem;
  cursor: pointer;
}
.actions button:hover { background: rgba(255, 255, 255, .22); }
.actions button:disabled { opacity: .4; cursor: default; }
.actions button:focus-visible, .sheet button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 720px) {
  .actions .lbl { display: none; }
  .actions button { padding: 7px 10px; }
  .brand span { display: none; }
  .info { margin-left: 0; gap: 10px; }
  .actions { margin-left: auto; }
}

/* ---------- Spielfeld ---------- */
#board {
  position: relative;
  flex: 1 1 auto;
  margin: 0 auto;
  width: 100%;
  max-width: 900px;
  touch-action: none;
  overflow: hidden;
}

.slot {
  position: absolute;
  border-radius: var(--radius);
  border: 2px solid rgba(255, 255, 255, .18);
  background: rgba(0, 0, 0, .08);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255, 255, 255, .25);
  font-size: calc(var(--cw) * .45);
}
.slot.stock { cursor: pointer; }
.slot.found::after { content: attr(data-suit); }

.card {
  position: absolute;
  left: 0; top: 0;
  width: var(--cw);
  height: var(--ch);
  border-radius: var(--radius);
  transition: transform .18s ease-out;
  will-change: transform;
  cursor: default;
}
.card.dragging { transition: none; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .45)); }
.card.movable { cursor: grab; }

.card .face, .card .back {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}
.card .face {
  background: var(--card);
  color: var(--black);
  border: 1px solid #d6d3c8;
  font-weight: 700;
  line-height: 1;
}
.card.red .face { color: var(--red); }
.card .back {
  display: none;
  border: 2px solid #fff;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.14) 0 4px, transparent 4px 8px),
    linear-gradient(135deg, #1e40af, #3b82f6);
}
.card.down .face { display: none; }
.card.down .back { display: block; }

.card .corner {
  position: absolute;
  top: calc(var(--cw) * .06);
  left: calc(var(--cw) * .08);
  display: flex; flex-direction: row; align-items: baseline; gap: 1px;
  font-size: calc(var(--cw) * .25);
  letter-spacing: -.05em;
}
.card .corner .s { font-size: calc(var(--cw) * .2); }
.card .corner.br { top: auto; left: auto; bottom: calc(var(--cw) * .06); right: calc(var(--cw) * .08); transform: rotate(180deg); }
.card .pip {
  position: absolute;
  right: calc(var(--cw) * .08);
  top: calc(var(--cw) * .08);
  font-size: calc(var(--cw) * .24);
}
.card .center {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cw) * .55);
  padding-top: calc(var(--cw) * .15);
}
.card .center.face-card { font-size: calc(var(--cw) * .42); font-family: Georgia, serif; }

.hint .face, .hint .back, .slot.hint {
  box-shadow: 0 0 0 3px var(--accent), 0 0 16px 4px rgba(251, 191, 36, .7);
}
.shake { animation: shake .3s; }
@keyframes shake {
  0%, 100% { translate: 0; }
  25% { translate: -5px; }
  75% { translate: 5px; }
}

/* ---------- Unten / Hinweise ---------- */
.auto {
  position: fixed;
  left: 50%; bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  border: 0; border-radius: 999px;
  padding: 12px 22px;
  font: inherit; font-weight: 700;
  background: var(--accent); color: #422006;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  cursor: pointer;
  z-index: 2000;
}
.game-no {
  position: fixed;
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(6px + env(safe-area-inset-bottom));
  font-size: .75rem;
  opacity: .45;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.toast {
  position: fixed;
  left: 50%; top: calc(64px + env(safe-area-inset-top));
  transform: translate(-50%, -10px);
  background: rgba(17, 24, 39, .92);
  padding: 10px 16px; border-radius: 10px;
  font-size: .95rem;
  max-width: min(90vw, 420px); text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 3000;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Dialoge ---------- */
.sheet {
  border: 0;
  border-radius: 16px;
  padding: 0;
  width: min(92vw, 520px);
  max-height: 88vh;
  background: #111827;
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.sheet.small { width: min(92vw, 380px); }
.sheet::backdrop { background: rgba(0, 0, 0, .55); }
.sheet .inner { padding: 20px; overflow: auto; max-height: 88vh; }
.sheet h2 { margin: 0 0 14px; font-size: 1.3rem; }
.sheet p { margin: 0 0 14px; line-height: 1.45; color: #d1d5db; }
.sheet .row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.sheet button {
  border: 0; border-radius: 10px;
  padding: 10px 16px;
  font: inherit; font-weight: 600;
  background: #374151; color: var(--ink);
  cursor: pointer;
}
.sheet button.primary { background: var(--accent); color: #422006; }
.sheet button.danger { background: #7f1d1d; }
.sheet button.link { background: none; color: #9ca3af; padding: 10px 6px; font-weight: 500; }

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.tile {
  background: #1f2937;
  border-radius: 12px;
  padding: 10px 12px;
}
.tile .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .k { font-size: .78rem; color: #9ca3af; margin-top: 2px; }
.tile.wide { grid-column: span 3; }
.bar { height: 8px; border-radius: 4px; background: #374151; overflow: hidden; margin-top: 8px; }
.bar > div { height: 100%; background: #22c55e; }

.history { margin-top: 16px; }
.history h3 { font-size: .95rem; margin: 0 0 8px; color: #d1d5db; }
.history ol { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.history li {
  display: grid;
  grid-template-columns: 1.6em 1fr auto auto;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid #1f2937;
  font-variant-numeric: tabular-nums;
}
.history .w { color: #22c55e; }
.history .l { color: #ef4444; }
.history .d { color: #9ca3af; }
.empty-note { color: #9ca3af; font-size: .9rem; }

.win-hero { text-align: center; font-size: 3rem; margin-bottom: 4px; }
.win-badge { display: inline-block; background: var(--accent); color: #422006; border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 700; margin-left: 6px; }

@media (max-width: 420px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile.wide { grid-column: span 2; }
}
