/* Toepen - mobile-first PWA styling */

:root {
  --felt: #0f3d26;
  --felt-light: #16543a;
  --felt-line: #1e6b4a;
  --card-bg: #fcfaf2;
  --card-red: #ce2029;
  --card-black: #1c1c24;
  --gold: #e8b84b;
  --text: #f2f0e6;
  --text-dim: #9db8a8;
  --danger: #e0564b;
  --ok: #58b368;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  background: var(--felt);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
}

body { -webkit-user-select: none; user-select: none; }
input, textarea { -webkit-user-select: text; user-select: text; }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 12px) 14px calc(var(--safe-bottom) + 16px);
}

button {
  font: inherit;
  border: none;
  border-radius: var(--radius);
  padding: 13px 18px;
  background: var(--felt-light);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.06s, opacity 0.2s;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; pointer-events: none; }
button.primary { background: var(--gold); color: #2a2108; }
button.danger { background: var(--danger); color: #fff; }
button.ghost { background: transparent; border: 1.5px solid var(--felt-line); }
button.small { padding: 8px 14px; font-size: 0.85rem; border-radius: 10px; }

input {
  font: inherit;
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius);
  border: 1.5px solid var(--felt-line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  outline: none;
}
input:focus { border-color: var(--gold); }
input::placeholder { color: var(--text-dim); }

h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------- auth ---------- */
.auth {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding-bottom: 15vh;
}
.auth .logo { text-align: center; margin-bottom: 18px; }
.auth .logo img { width: 96px; border-radius: 22px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4); }
.auth .logo h1 { margin-top: 12px; letter-spacing: 0.02em; }
.auth .switch { text-align: center; color: var(--text-dim); font-size: 0.9rem; margin-top: 8px; }
.auth .switch a { color: var(--gold); text-decoration: none; font-weight: 600; }
.error-msg { color: var(--danger); font-size: 0.9rem; text-align: center; min-height: 1.2em; }

/* ---------- home ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.topbar .user { color: var(--text-dim); font-size: 0.9rem; }

.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }

.section { margin-bottom: 20px; }
.section h2 { margin-bottom: 8px; }
.empty { color: var(--text-dim); font-size: 0.92rem; padding: 14px 4px; }

.game-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--felt-light);
  border-radius: var(--radius);
  padding: 13px 14px;
  margin-bottom: 8px;
  text-align: left;
  font-weight: 500;
}

/* swipe-naar-links om een potje te verlaten/verwijderen */
.swipe-wrap { position: relative; overflow: hidden; border-radius: var(--radius); margin-bottom: 8px; }
.swipe-wrap .game-card {
  margin-bottom: 0;
  position: relative;
  z-index: 1;
  touch-action: pan-y;
  will-change: transform;
}
.swipe-action {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 88px;
  border: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--danger);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}
.game-card .info { flex: 1; min-width: 0; }
.game-card .names { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-card .meta { color: var(--text-dim); font-size: 0.82rem; margin-top: 3px; }
.game-card .badge {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text-dim);
}
.game-card .badge.turn {
  background: var(--gold);
  color: #2a2108;
  animation: pulse-badge 1.8s ease-out infinite;
}
@keyframes pulse-badge {
  0% { box-shadow: 0 0 0 0 rgba(232, 184, 75, 0.55); }
  70% { box-shadow: 0 0 0 9px rgba(232, 184, 75, 0); }
  100% { box-shadow: 0 0 0 0 rgba(232, 184, 75, 0); }
}
.game-card .badge.wait { background: rgba(0, 0, 0, 0.25); }
.game-card .badge.won { background: var(--ok); color: #fff; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: #123;
  background: var(--felt-light);
  width: 100%;
  max-width: 480px;
  border-radius: 22px 22px 0 0;
  padding: 22px 18px calc(var(--safe-bottom) + 22px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: slideup 0.18s ease-out;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0.6; } }
.modal h3 { font-size: 1.15rem; }
.modal .row { display: flex; gap: 10px; align-items: center; }
.modal label { color: var(--text-dim); font-size: 0.88rem; flex: 1; }
.seg { display: flex; gap: 6px; }
.seg button { padding: 9px 14px; border-radius: 10px; background: rgba(0,0,0,0.25); font-size: 0.9rem; }
.seg button.sel { background: var(--gold); color: #2a2108; }

/* ---------- game ---------- */
.game-screen { flex: 1; display: flex; flex-direction: column; }

.game-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.game-top .back { background: transparent; padding: 6px 10px 6px 0; font-size: 1.4rem; line-height: 1; }
.game-top .code { font-weight: 800; letter-spacing: 0.12em; }
.game-top .stake {
  margin-left: auto;
  background: rgba(0, 0, 0, 0.3);
  border: 1.5px solid var(--gold);
  color: var(--gold);
  font-weight: 800;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.9rem;
}

.opponents { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin: 6px 0 4px; }
.opp { text-align: center; width: 76px; position: relative; opacity: 1; transition: opacity 0.3s; }
.opp.inactive { opacity: 0.38; }
.opp .avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--felt-light);
  border: 2.5px solid var(--felt-line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.15rem;
  margin: 0 auto 4px;
}
.opp.turn .avatar {
  border-color: var(--gold);
  animation: pulse-ring 1.6s ease-out infinite;
}
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(232, 184, 75, 0.65); }
  70% { box-shadow: 0 0 0 13px rgba(232, 184, 75, 0); }
  100% { box-shadow: 0 0 0 0 rgba(232, 184, 75, 0); }
}
.opp .name { font-size: 0.8rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp .pts { font-size: 0.75rem; color: var(--text-dim); }
.opp .cards-left {
  position: absolute;
  top: -4px;
  right: 6px;
  background: var(--card-bg);
  color: var(--card-black);
  font-size: 0.7rem;
  font-weight: 800;
  border-radius: 6px;
  padding: 2px 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.opp .tag {
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 6px;
  padding: 1px 6px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text-dim);
}
.opp .tag.folded { color: var(--danger); }

.table-area {
  flex: 1;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: radial-gradient(ellipse at center, var(--felt-light) 0%, transparent 75%);
  border-radius: 20px;
  margin: 4px 0;
  position: relative;
  padding: 10px 4px;
}
.table-msg { color: var(--text-dim); font-size: 0.95rem; text-align: center; padding: 0 20px; }
.table-msg strong { color: var(--text); }

/* zitplaatsen aan tafel: per speler een stapel gespeelde kaarten */
.seats { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; width: 100%; }
.seat { width: 78px; display: flex; flex-direction: column; align-items: center; }
.seat .stack {
  position: relative;
  width: 48px;
  height: 118px; /* 64px kaart + 3 x 18px offset */
  margin-top: 8px;
}
.stack .card.small {
  position: absolute;
  left: 2px;
  transition: transform 0.2s;
}
.stack .card.small:nth-child(odd) { rotate: -2.5deg; }
.stack .card.small:nth-child(even) { rotate: 2.5deg; }
.stack .card.small.old { opacity: 0.72; }
.stack .card.small.current { box-shadow: 0 0 0 2px var(--gold), 0 3px 8px rgba(0, 0, 0, 0.45); }
.stack .card.small.won-trick::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 7px;
  box-shadow: inset 0 0 0 1.5px rgba(232, 184, 75, 0.45);
}
.stack .card.small.drop-in { animation: stack-drop 0.4s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes stack-drop {
  0% { transform: translateY(-34px) scale(1.25); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
.seat .empty-slot {
  width: 44px;
  height: 64px;
  border-radius: 7px;
  border: 1.5px dashed rgba(255, 255, 255, 0.14);
  margin-top: 8px;
}

/* kaart die van je hand naar de tafel vliegt */
.fly-clone {
  position: fixed;
  margin: 0;
  z-index: 200;
  pointer-events: none;
  transition: transform 0.45s cubic-bezier(0.4, 0.8, 0.3, 1), opacity 0.45s;
  transform-origin: top left;
}

/* speelkaart */
.card {
  width: 58px;
  height: 84px;
  border-radius: 9px;
  background: var(--card-bg);
  color: var(--card-black);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  position: relative;
  border: none;
  padding: 0;
}
.card.red { color: var(--card-red); }
.card .rank { font-size: 1.25rem; line-height: 1; }
.card .suit { font-size: 1.3rem; line-height: 1.1; }
.card .corner { position: absolute; top: 5px; left: 7px; font-size: 0.72rem; line-height: 1; text-align: center; }
.card.small { width: 44px; height: 64px; border-radius: 7px; }
.card.small .rank { font-size: 1rem; }
.card.small .suit { font-size: 1.05rem; }
.card.small .corner { display: none; }

/* klop banner */
.toep-banner {
  background: rgba(0, 0, 0, 0.45);
  border: 1.5px solid var(--gold);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 6px 0;
  animation: banner-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes banner-pop {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.toep-banner .row { display: flex; gap: 10px; }
.toep-banner .row button { flex: 1; }
.toep-banner strong { color: var(--gold); }

/* mijn hand */
.my-area { margin-top: 6px; }
.status-line { text-align: center; color: var(--text-dim); font-size: 0.9rem; min-height: 1.3em; margin-bottom: 8px; }
.status-line.yours { color: var(--gold); font-weight: 700; }
.status-line.yours::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  margin-right: 7px;
  vertical-align: 1px;
  animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.6); opacity: 0.5; }
}
.hand { display: flex; justify-content: center; gap: 8px; padding: 4px 0 10px; flex-wrap: wrap; }
.hand .card { transition: transform 0.15s ease-out, box-shadow 0.15s; }
.hand .card.playable:active { transform: translateY(-10px); }
.hand .card.playable { box-shadow: 0 0 0 2.5px var(--gold), 0 4px 10px rgba(0, 0, 0, 0.4); }
.hand .card.disabled { opacity: 0.55; }
.hand .card.selectable { box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35); }
.hand .card.selected {
  transform: translateY(-14px);
  box-shadow: 0 0 0 2.5px var(--gold), 0 10px 16px rgba(0, 0, 0, 0.45);
}
.hand .card.dealt { animation: deal-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) backwards; }
@keyframes deal-in {
  0% { transform: translateY(40px) rotate(4deg) scale(0.7); opacity: 0; }
  100% { transform: translateY(0) rotate(0) scale(1); opacity: 1; }
}

/* inzet-bump */
.stake.bump { animation: stake-bump 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes stake-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.action-bar { display: flex; gap: 10px; margin-bottom: 8px; }
.action-bar button { flex: 1; }

.my-stats { text-align: center; color: var(--text-dim); font-size: 0.82rem; margin-bottom: 6px; }
.my-stats b { color: var(--text); }

/* wachtkamer */
.lobby { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 16px; padding-top: 8vh; }
.lobby .code-big {
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: 0.35em;
  padding-left: 0.35em;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius);
  padding: 14px 20px 14px calc(20px + 0.35em);
}
.lobby .hint { color: var(--text-dim); text-align: center; font-size: 0.92rem; max-width: 280px; }
.lobby ul { list-style: none; width: 100%; }
.lobby li {
  background: var(--felt-light);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 8px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
}
.lobby li .you { color: var(--text-dim); font-weight: 400; }
.lobby .actions { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: auto; }

/* log */
.log { margin-top: 10px; }
.log summary { color: var(--text-dim); font-size: 0.85rem; cursor: pointer; padding: 6px 0; }
.log .entries { max-height: 180px; overflow-y: auto; font-size: 0.82rem; color: var(--text-dim); padding: 6px 2px; }
.log .entries div { padding: 2px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }

/* game over */
.gameover {
  text-align: center;
  padding: 24px 16px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: var(--radius);
  border: 1.5px solid var(--gold);
  margin: 8px 0;
  animation: banner-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.gameover .trophy { font-size: 3rem; display: inline-block; animation: trophy-bounce 1.2s ease-in-out infinite; }
@keyframes trophy-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-9px); }
}
.gameover h3 { margin: 8px 0 4px; font-size: 1.3rem; }

/* scorebord */
.scores { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-top: 8px; }
.scores td { padding: 7px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.07); }
.scores td:last-child { text-align: right; font-weight: 700; }
.scores tr.dead td { color: var(--text-dim); text-decoration: line-through; }

/* toast */
#toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 24px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #24140f;
  color: #ffd9d4;
  border: 1px solid var(--danger);
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  max-width: 88vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.info { background: #10241a; color: #d2f0dd; border-color: var(--ok); }

/* feestje bij ronde- of spelwinst */
.party-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.party-card {
  background: rgba(8, 26, 17, 0.88);
  border: 2px solid var(--gold);
  border-radius: 18px;
  padding: 22px 30px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  animation: party-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), party-fade 0.3s ease-in 1.9s forwards;
}
@keyframes party-pop {
  0% { transform: scale(0.5) rotate(-4deg); opacity: 0; }
  70% { transform: scale(1.08) rotate(1deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes party-fade {
  to { opacity: 0; transform: scale(0.92); }
}
.party-title { font-size: 1.45rem; font-weight: 800; color: var(--gold); }
.party-sub { color: var(--text); margin-top: 6px; font-size: 0.95rem; }
.confetti {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 15px;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(112vh) rotate(720deg); }
}

/* notificatie-banner */
.notif-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 0.88rem;
  color: var(--text-dim);
}
.notif-banner button { flex-shrink: 0; }
