:root {
  --felt: #0f3d2e;
  --felt-2: #145240;
  --ink: #f3efe4;
  --muted: #a9c2b6;
  --gold: #e6b94a;
  --red: #c8323c;
  --card: #fbf8f1;
  --card-ink: #1d1d1f;
  --danger: #e2574c;
  --radius: 10px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(ellipse at 50% 30%, var(--felt-2), var(--felt) 70%);
  color: var(--ink);
}

[hidden] { display: none !important; }

h1 { margin: 0 0 .25rem; font-size: 1.6rem; letter-spacing: .02em; }
.sub { color: var(--muted); margin: .25rem 0 1rem; font-size: .9rem; }

.view { max-width: 900px; margin: 0 auto; padding: 16px; }
#view-login, #view-wait { display: grid; place-items: center; min-height: 100dvh; }

.panel {
  background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 16px;
  padding: 24px;
  width: min(420px, 100%);
}

form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
input {
  font: inherit;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, .15);
  background: rgba(0, 0, 0, .25);
  color: var(--ink);
}
input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

.btn {
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(255, 255, 255, .08);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .14); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--gold); color: #2a1f05; border-color: transparent; }
.btn.primary:hover:not(:disabled) { background: #f0c75c; }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.player-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.player-list li {
  padding: 10px 12px;
  background: rgba(0, 0, 0, .2);
  border-radius: var(--radius);
  display: flex; gap: 6px; align-items: center;
}

.badge {
  font-size: .7rem;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .12);
  margin-left: 4px;
  white-space: nowrap;
}
.badge.host { background: var(--gold); color: #2a1f05; }
.badge.turn { background: #4ec98a; color: #06301b; }
.badge.off { background: rgba(226, 87, 76, .3); }

/* ---------- Meja ---------- */
#view-game {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}
.topbar span { margin-right: auto; }

/* Arena untuk meja dan pemain */
.arena {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 40px 0;
  min-height: 380px;
}

/* Meja di tengah (Bentuk Oval ala Casino) */
.table {
  width: 85%;
  max-width: 550px;
  height: 260px;
  border-radius: 130px; 
  background: radial-gradient(ellipse at center, #1a6b52, #0a2e22);
  border: 10px solid #4a3320; /* Warna pinggiran kayu/busa */
  box-shadow: 0 15px 35px rgba(0,0,0,0.6), inset 0 0 25px rgba(0,0,0,0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
  z-index: 1;
}

.table-who { color: #e6b94a; font-weight: bold; font-size: .9rem; }
.table-history { color: var(--muted); font-size: .75rem; opacity: .8; }

/* Wadah lawan dibuat tembus pandang menutupi arena */
.opponents {
  position: absolute;
  inset: 0;
  pointer-events: none; 
}

/* Kotak profil lawan */
.opp {
  position: absolute;
  pointer-events: auto; /* Biar tombol tetap bisa diklik */
  background: rgba(0, 0, 0, 0.7);
  border: 2px solid #555;
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 120px;
  text-align: center;
  box-shadow: 0 6px 15px rgba(0,0,0,0.4);
  backdrop-filter: blur(5px);
  z-index: 2;
  transition: all 0.3s ease;
}

.opp.turn { 
  border-color: #4ec98a; 
  box-shadow: 0 0 20px rgba(78, 201, 138, 0.5); 
  transform: scale(1.05);
}
.opp.done { opacity: .6; }

.opp-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 4px; }
.opp .badge { margin-left: 0; margin-right: 4px; }
.opp .cek { margin-top: 6px; width: 100%; border-color: rgba(226, 87, 76, .6); }

/* Posisi Duduk Lawan */
.pos-top {
  top: -25px;
  left: 50%;
  transform: translateX(-50%);
}
.pos-left {
  left: -15px;
  top: 50%;
  transform: translateY(-50%);
}
.pos-right {
  right: -15px;
  top: 50%;
  transform: translateY(-50%);
}

.turn-banner { text-align: center; font-weight: 600; min-height: 1.4em; color: var(--muted); }
.turn-banner.mine { color: var(--gold); }

/* ---------- Kartu ---------- */

.cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }

.card {
  width: 52px;
  height: 74px;
  border-radius: 7px;
  background: var(--card);
  color: var(--card-ink);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .35);
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 4px 5px;
  user-select: none;
  transition: transform .12s ease, box-shadow .12s ease;
}
.card.red { color: var(--red); }
.card .r { font-weight: 800; font-size: 1rem; line-height: 1; }
.card .s { font-size: 1.6rem; align-self: center; justify-self: center; line-height: 1; }

.hand .card { cursor: pointer; }
.hand .card.selected { transform: translateY(-12px); box-shadow: 0 0 0 3px var(--gold), 0 6px 10px rgba(0, 0, 0, .4); }
.hand .card.slip {
  transform: translateY(-6px) rotate(-6deg);
  box-shadow: 0 0 0 3px #9b6cff, 0 6px 10px rgba(0, 0, 0, .4);
  background: repeating-linear-gradient(45deg, var(--card), var(--card) 6px, #ece4ff 6px, #ece4ff 12px);
}

.me {
  background: rgba(0, 0, 0, .25);
  border-radius: 16px;
  padding: 12px 10px 10px;
  display: grid;
  gap: 10px;
  position: sticky;
  bottom: 0;
}
.hand { padding-top: 12px; }
.hint { text-align: center; font-size: .85rem; min-height: 1.2em; color: var(--muted); }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.actions .btn:not(.small) { min-width: 96px; }
.slip-toggle.active { background: #9b6cff; color: #fff; border-color: transparent; }

.log { color: var(--muted); font-size: .85rem; }
.log summary { cursor: pointer; }
.log ol { max-height: 200px; overflow: auto; padding-left: 20px; }

/* ---------- Overlay & toast ---------- */

.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .6);
  display: grid; place-items: center;
  padding: 16px;
  z-index: 10;
}
.overlay .panel { background: var(--felt); }
.ranking { font-size: 1.15rem; line-height: 1.8; }
.ranking li::marker { color: var(--gold); font-weight: 700; }
.rules ul { padding-left: 18px; line-height: 1.5; font-size: .9rem; }

.toasts {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  display: grid; gap: 6px; z-index: 20; width: min(420px, calc(100% - 32px));
}
.toast {
  background: #1d2a25; border: 1px solid rgba(255, 255, 255, .15);
  padding: 10px 14px; border-radius: var(--radius); font-size: .9rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .4);
}
.toast.error { border-color: var(--danger); }
.toast.alert { background: #5a1d22; border-color: var(--danger); font-weight: 600; }

/* ---------- HP ---------- */

@media (max-width: 600px) {
  .arena { min-height: 300px; margin: 20px 0; }
  .table { width: 100%; height: 220px; border-width: 6px; }
  .opp { min-width: 90px; padding: 6px; font-size: 0.8rem; }
  .pos-left { left: 0; }
  .pos-right { right: 0; }
  .pos-top { top: -15px; }
}
