:root {
  --felt: #1a5c38;
  --felt-dark: #124327;
  --bg: #0d2318;
  --card-w: 62px;
  --card-h: 88px;
  --gold: #e8c34a;
  --red: #d64545;
  --ink: #1c2430;
  --panel: #16302257;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: radial-gradient(ellipse at 50% 30%, var(--felt) 0%, var(--bg) 90%);
  color: #eef3ee;
  overflow: hidden;
}

.hidden { display: none !important; }

.view { height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; }

/* ------------------------------ home / lobby ------------------------------ */

.home-card {
  background: rgba(10, 26, 18, 0.75);
  border: 1px solid rgba(232, 195, 74, 0.25);
  border-radius: 16px;
  padding: 40px 48px;
  display: flex; flex-direction: column; gap: 14px;
  align-items: center; min-width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

.logo {
  font-size: 2.4rem; letter-spacing: 2px; font-weight: 800; color: #fff;
}
.logo span { color: var(--gold); }
.logo.small { font-size: 1rem; }

.tagline { color: #9fbfae; font-size: .9rem; }

input {
  background: #0b1f14; color: #fff; border: 1px solid #2e5941;
  border-radius: 8px; padding: 12px 14px; font-size: 1rem; width: 100%;
  text-align: center; outline: none;
}
input:focus { border-color: var(--gold); }
#code-input { text-transform: uppercase; letter-spacing: 6px; font-weight: 700; }

.join-row { display: flex; gap: 8px; width: 100%; }

.btn {
  background: #274c38; color: #fff; border: 1px solid #3c7154;
  padding: 12px 22px; border-radius: 8px; font-size: 1rem; cursor: pointer;
  width: 100%; transition: transform .08s, background .15s;
}
.btn:hover:not(:disabled) { background: #336249; transform: translateY(-1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--gold); border-color: #b8952c; color: #241d05; font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: #f2d269; }
.btn.subtle { background: transparent; border-color: #33503f; color: #8fae9c; }
.btn.tiny { width: auto; padding: 5px 14px; font-size: .8rem; }
.btn.danger { background: #6b2a2a; border-color: #a04545; }
.btn.danger:hover:not(:disabled) { background: #8a3535; }

.status { color: #9fbfae; font-size: .85rem; min-height: 1.2em; }

.room-code {
  background: #0b1f14; border: 1px dashed var(--gold); color: var(--gold);
  padding: 4px 14px; border-radius: 8px; letter-spacing: 6px; font-weight: 800;
}
.room-code.small { font-size: .8rem; padding: 2px 10px; letter-spacing: 3px; }

.lobby-list { list-style: none; width: 100%; }
.lobby-list li {
  padding: 9px 14px; border-bottom: 1px solid #234534;
  display: flex; justify-content: space-between; font-size: 1rem;
}
.lobby-list .host-tag { color: var(--gold); font-size: .8rem; }

/* ------------------------------ game layout ------------------------------ */

#view-game { justify-content: space-between; padding: 8px 12px; }

.top-bar {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  color: #9fbfae; font-size: .9rem;
}
.top-right { display: flex; gap: 8px; align-items: center; }

.opponents {
  display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
  margin-top: 4px; min-height: 92px;
}

.opp {
  background: var(--panel); border: 2px solid transparent; border-radius: 12px;
  padding: 8px 14px; text-align: center; min-width: 108px; position: relative;
  transition: border-color .2s, box-shadow .2s;
}
.opp.turn {
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(232,195,74,.45);
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 10px rgba(232,195,74,.35); }
  50% { box-shadow: 0 0 22px rgba(232,195,74,.65); }
}
.opp.me { outline: 1px dashed rgba(232,195,74,.4); }
.opp .opp-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.opp .opp-cards { font-size: .85rem; color: #bcd8c8; }
.opp .opp-role {
  font-size: .68rem; padding: 1px 8px; border-radius: 10px; margin-top: 3px;
  display: inline-block; background: #2c5340; color: #cfe8da;
}
.opp .opp-role.president { background: var(--gold); color: #241d05; font-weight: 700; }
.opp .opp-role.slave { background: #5a2b2b; color: #f0c9c9; }
.opp .tag {
  position: absolute; top: -9px; right: -6px; font-size: .65rem;
  padding: 2px 8px; border-radius: 10px; font-weight: 700;
}
.opp .tag.passed { background: #444; color: #ccc; }
.opp .tag.finished { background: var(--gold); color: #241d05; }
.opp .tag.offline { background: var(--red); color: #fff; }
.opp .tag.two-out { background: #3a1010; color: #ff9c9c; border: 1px solid #a04545; }
.opp.gone { opacity: .35; filter: grayscale(1); }
.kick-btn {
  position: absolute; top: -9px; left: -6px; width: 20px; height: 20px;
  border-radius: 50%; border: 1px solid #a04545; background: #5a2626;
  color: #ffb0b0; font-size: .7rem; line-height: 1; cursor: pointer; padding: 0;
}
.kick-btn:hover { background: #8a3535; color: #fff; }
.spectator-line {
  text-align: center; font-size: .8rem; color: #8fae9c; margin-top: 2px;
}

.opp.skip-flash { animation: skipflash .8s; }
@keyframes skipflash {
  0%, 100% { background: var(--panel); }
  30% { background: #7a2e2e; }
}

/* ------------------------------ table ------------------------------ */

.table-zone {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; min-height: 150px;
}
.table-cards { display: flex; gap: 8px; min-height: var(--card-h); }
.table-info { color: #cfe8da; font-size: 1rem; text-align: center; }
.table-info .hint { color: #8fae9c; font-size: .85rem; display: block; margin-top: 2px; }

.table-zone.reset-flash { animation: resetflash .7s; }
@keyframes resetflash {
  0% { filter: brightness(2.2); }
  100% { filter: brightness(1); }
}

/* The 6-7 ritual. */
.six-seven {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; gap: 6px; pointer-events: none; z-index: 40;
  font-size: 5.5rem; font-weight: 900;
  text-shadow: 0 0 24px rgba(232, 195, 74, .9), 0 4px 12px rgba(0,0,0,.6);
}
.six-seven .ss-six {
  color: var(--gold);
  animation: ss-slam .9s cubic-bezier(.2, 2.2, .4, 1) both,
             ss-fade 1.8s linear both;
}
.six-seven .ss-seven {
  color: #ff9c4a;
  animation: ss-slam .9s .15s cubic-bezier(.2, 2.2, .4, 1) both,
             ss-tilt .5s .5s ease-in-out 2 alternate,
             ss-fade 1.8s linear both;
}
@keyframes ss-slam {
  0% { transform: scale(4) rotate(-20deg); opacity: 0; }
  60% { transform: scale(.9) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes ss-tilt {
  from { transform: rotate(-8deg) translateY(-6px); }
  to { transform: rotate(8deg) translateY(6px); }
}
@keyframes ss-fade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}
.table-zone { position: relative; }

.turn-banner {
  text-align: center; font-size: 1.05rem; font-weight: 700; min-height: 1.5em;
  color: var(--gold);
}
.turn-banner.waiting { color: #9fbfae; font-weight: 400; }

/* ------------------------------ cards ------------------------------ */

.card {
  width: var(--card-w); height: var(--card-h);
  background: #fdfdf5; border-radius: 8px; border: 1px solid #b9b9a8;
  color: var(--ink); position: relative; flex-shrink: 0;
  box-shadow: 0 3px 8px rgba(0,0,0,.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 800; user-select: none;
}
.card .rank { font-size: 1.25rem; line-height: 1; }
.card .suit { font-size: 1.15rem; line-height: 1.2; }
.card .corner {
  position: absolute; top: 4px; left: 6px; font-size: .7rem; line-height: 1;
  text-align: center;
}
.card.red { color: var(--red); }
.card.joker { background: linear-gradient(150deg, #fdf3d0, #e9d3f7); color: #7a3fa0; }
.card.joker .rank { font-size: 1.5rem; }

.hand .card { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.hand .card:hover { transform: translateY(-8px); }
.hand .card.selected {
  transform: translateY(-16px);
  box-shadow: 0 0 0 3px var(--gold), 0 10px 18px rgba(0,0,0,.5);
}
.hand .card.disabled-card { opacity: .55; cursor: default; }
.hand .card.disabled-card:hover { transform: none; }

/* ------------------------------ hand zone ------------------------------ */

.hand-zone { width: 100%; display: flex; flex-direction: column; gap: 10px; align-items: center; padding-bottom: 6px; }

.hand {
  display: flex; justify-content: center; padding: 18px 10px 4px;
  max-width: 100vw; overflow-x: auto;
}
.hand .card { margin-left: -18px; }
.hand .card:first-child { margin-left: 0; }

.actions { display: flex; gap: 12px; }
.actions .btn { width: 150px; }

/* ------------------------------ overlays ------------------------------ */

.overlay {
  position: fixed; inset: 0; background: rgba(4, 12, 8, 0.82);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.panel {
  background: #12271b; border: 1px solid rgba(232,195,74,.3); border-radius: 16px;
  padding: 30px 36px; display: flex; flex-direction: column; gap: 14px;
  align-items: center; max-width: 92vw; max-height: 88vh; overflow-y: auto;
}
.trade-hand { flex-wrap: wrap; max-width: 720px; row-gap: 10px; }

/* Blind-trade deck picker: all 54 cards in a compact grid. */
.deck-grid {
  display: grid !important;
  grid-template-columns: repeat(9, auto);
  gap: 6px; justify-content: center; padding: 4px;
}
.deck-grid .card { margin-left: 0 !important; }
.card.mini { width: 44px; height: 62px; border-radius: 6px; }

/* Card backs (deal animation + opponent fans) */
.card.back {
  background: repeating-linear-gradient(45deg, #7a2030, #7a2030 6px, #8d2b3c 6px, #8d2b3c 12px);
  border: 2px solid #d9c58a;
}
.deal-fly {
  position: fixed; width: 44px; height: 62px; z-index: 80; pointer-events: none;
  transition: left .55s ease-in, top .55s ease-in, transform .55s ease-in, opacity .55s ease-in;
}
.opp-fan { display: flex; justify-content: center; height: 26px; margin: 3px 0 1px; }
.mini-back {
  width: 15px; height: 22px; border-radius: 3px; margin: 0 -4px; display: inline-block;
  background: repeating-linear-gradient(45deg, #7a2030, #7a2030 3px, #8d2b3c 3px, #8d2b3c 6px);
  border: 1px solid #d9c58a; box-shadow: 0 1px 3px rgba(0,0,0,.4);
}

/* Discard pile — everything thrown this round, stacked on the right. */
.discard {
  position: fixed; right: 14px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  z-index: 30; pointer-events: none;
}
.discard-cards { position: relative; width: 60px; height: 80px; }
.discard-card {
  position: absolute; left: 0; top: 0;
}
.discard-card:nth-child(1) { transform: rotate(-9deg) translate(-4px, 3px); }
.discard-card:nth-child(2) { transform: rotate(5deg) translate(3px, -2px); }
.discard-card:nth-child(3) { transform: rotate(-3deg) translate(-1px, 1px); }
.discard-card:nth-child(4) { transform: rotate(8deg) translate(4px, 2px); }
.discard-card:nth-child(5) { transform: rotate(-6deg) translate(-3px, -1px); }
.discard-card:nth-child(6) { transform: rotate(2deg); }
.discard-count { font-size: .72rem; color: #9fbfae; }

/* Turn countdown */
.turn-timer { text-align: center; font-size: .95rem; color: #9fbfae; min-height: 1.3em; }
.turn-timer.urgent { color: var(--red); font-weight: 800; animation: pulse 1s infinite; }

/* Table shake on a skip */
.table-zone.table-shake { animation: tableshake .5s; }
@keyframes tableshake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-8px, 2px) rotate(-1deg); }
  40% { transform: translate(7px, -3px) rotate(1deg); }
  60% { transform: translate(-5px, 1px); }
  80% { transform: translate(4px, -1px); }
}

/* The tea. */
.tea {
  position: fixed; right: 16px; bottom: 14px; font-size: 2rem; cursor: pointer;
  z-index: 95; user-select: none; transition: transform .15s;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,.5));
}
.tea:hover { transform: scale(1.15); }
.tea.sipping { animation: sip 1s ease-in-out; }
@keyframes sip {
  0% { transform: scale(1) rotate(0); }
  30% { transform: scale(1.3) rotate(-25deg) translateY(-10px); }
  60% { transform: scale(1.3) rotate(-35deg) translateY(-12px); }
  100% { transform: scale(1) rotate(0); }
}

/* Lobby deck picker */
.deck-row {
  display: flex; gap: 8px; align-items: center; font-size: .9rem; color: #9fbfae;
}
.deck-row select {
  background: #0b1f14; color: #fff; border: 1px solid #2e5941;
  border-radius: 6px; padding: 6px 8px;
}
.card.mini .rank { font-size: .95rem; }
.card.mini .suit { font-size: .85rem; }
.card.mini .corner { display: none; }
.card.mini:hover { transform: translateY(-4px); }
.card.miss { opacity: .22; cursor: default !important; }
.card.miss:hover { transform: none; }
.card.taken {
  box-shadow: 0 0 0 3px var(--gold);
  opacity: .85; cursor: default !important;
}

/* Vote-kick panel */
.vote-panel {
  position: fixed; top: 16px; right: 16px; z-index: 90;
  background: #1c1010f0; border: 1px solid #a04545; border-radius: 12px;
  padding: 14px 18px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.6); min-width: 200px;
}
#vote-title { font-weight: 700; }
.vote-count { font-size: .85rem; color: #d8b0b0; }
.vote-buttons { display: flex; gap: 8px; }

.rankings { list-style: none; width: 100%; min-width: 280px; }
.rankings li {
  display: flex; justify-content: space-between; gap: 20px;
  padding: 8px 12px; border-bottom: 1px solid #234534; font-size: 1.05rem;
}
.rankings .role-label { color: var(--gold); font-weight: 700; }
.rankings li:first-child { background: rgba(232,195,74,.12); border-radius: 8px; }

/* ------------------------------ log & toast ------------------------------ */

.log {
  position: fixed; left: 10px; bottom: 10px; width: 230px; max-height: 30vh;
  overflow-y: auto; font-size: .74rem; color: #9fbfae;
  background: rgba(8,20,13,.6); border-radius: 8px; padding: 8px 10px;
  pointer-events: none;
}
.log div { padding: 1px 0; }
.log div:last-child { color: #e6f2ea; }

#toast-holder {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center;
}
.toast {
  background: #26483573; backdrop-filter: blur(6px);
  border: 1px solid #3c7154; color: #fff;
  padding: 10px 22px; border-radius: 24px; font-size: .95rem;
  animation: toastin .25s ease-out;
  box-shadow: 0 6px 20px rgba(0,0,0,.45);
}
.toast.error { background: #5a2626d9; border-color: #a04545; }
.toast.big { font-size: 1.05rem; font-weight: 700; }
@keyframes toastin {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 640px) {
  :root { --card-w: 46px; --card-h: 68px; }
  .home-card { padding: 28px 24px; min-width: 300px; }
  .log { display: none; }
  .opp { min-width: 84px; padding: 6px 8px; }
}
