:root {
  --bg: #0f1a1f;
  --felt: #134034;
  --felt-dark: #0c2b23;
  --panel: #182a30;
  --panel-2: #20363d;
  --line: #2f4b52;
  --text: #f1ead8;
  --muted: #a9b5b0;
  --gold: #e0b44c;
  --gold-dark: #b38a2a;
  --red: #d9534f;
  --green: #4caf6a;
  --radius: 12px;
  --card-w: 74px;
  --card-h: 108px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(ellipse at top, #18303a 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, sans-serif, "Noto Color Emoji";
  min-height: 100vh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
h1, h2, h3, .pirate { font-family: "Pirata One", Georgia, serif; font-weight: 400; letter-spacing: .5px; }
h1 { font-size: 3.2rem; margin: 0; color: var(--gold); text-shadow: 0 3px 0 #000a; }
h2 { font-size: 2rem; margin: 0 0 .5rem; color: var(--gold); }
h3 { font-size: 1.4rem; margin: 0 0 .5rem; }
a { color: var(--gold); }
button {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 10px;
  padding: .7rem 1.2rem; background: var(--gold); color: #1d1405;
  box-shadow: 0 3px 0 var(--gold-dark); transition: transform .08s, filter .15s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--gold-dark); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); box-shadow: none; }
button.small { padding: .35rem .7rem; font-size: .85rem; }
input {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: .7rem .9rem; width: 100%;
}
input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.wrap { max-width: 560px; margin: 0 auto; padding: 2rem 16px; }
.center { text-align: center; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem; margin-top: 1.2rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.stack > * + * { margin-top: .8rem; }
.hero { padding-top: 2rem; }
.hero p { color: var(--muted); margin: .3rem 0 0; }
.avatars { display: flex; flex-wrap: wrap; gap: .4rem; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  font-size: 22px; flex: none; border: 2px solid transparent;
}
.avatars .avatar { cursor: pointer; }
.avatars .avatar.sel { border-color: var(--gold); }
.code { font-family: ui-monospace, monospace; font-size: 2rem; letter-spacing: .3rem; color: var(--gold); }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .name { flex: 1; }
.tag { font-size: .72rem; padding: .1rem .45rem; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.tag.host { background: var(--gold); color: #1d1405; }

/* ---------- Game ---------- */
.game { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .6rem 16px; background: #0009; border-bottom: 1px solid var(--line);
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
}
.topbar .title { font-family: "Pirata One", serif; color: var(--gold); font-size: 1.5rem; }
.topbar .info { display: flex; gap: 1rem; align-items: center; color: var(--muted); }
.topbar .info b { color: var(--text); }
.timer { font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }
.timer.low { color: var(--red); font-weight: 700; }

.seats { display: flex; gap: .5rem; padding: .7rem 16px; overflow-x: auto; }
.seat {
  flex: 1 0 128px; max-width: 200px; background: var(--panel); border: 2px solid var(--line);
  border-radius: var(--radius); padding: .5rem .6rem; display: flex; gap: .5rem; align-items: center;
  transition: border-color .2s, box-shadow .2s;
}
.seat.active { border-color: var(--gold); box-shadow: 0 0 0 3px #e0b44c40; }
.seat.me { background: var(--panel-2); }
.seat.offline { opacity: .5; }
.seat .meta { min-width: 0; flex: 1; }
.seat .pname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }
.seat .stats { font-size: .78rem; color: var(--muted); display: flex; gap: .5rem; }
.seat .stats b { color: var(--text); }
.seat .score { font-family: "Pirata One", serif; font-size: 1.4rem; color: var(--gold); }

.table-area {
  flex: 1; margin: 0 16px; border-radius: 24px; min-height: 230px;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 85%);
  border: 6px solid #3a2a17; box-shadow: inset 0 0 40px #0008;
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1rem; gap: .8rem;
}
.table-cards { display: flex; flex-wrap: wrap; gap: .8rem; justify-content: center; }
.played { display: flex; flex-direction: column; align-items: center; gap: .3rem; }
.played.fresh { animation: drop .25s ease-out; }
.played .who { font-size: .75rem; color: #fffc; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-family: "Pirata One", serif; font-size: 1.5rem; color: #fffe; text-align: center; text-shadow: 0 2px 4px #000; }
.status small { display: block; font-family: Inter, sans-serif; font-size: .85rem; color: #fffa; text-shadow: none; }
@keyframes drop { from { transform: translateY(-20px) scale(.9); opacity: 0; } }

.bidbar { padding: .8rem 16px 0; text-align: center; }
.bidbar .bids { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: center; margin-top: .4rem; }
.bidbar .bids button { min-width: 46px; }
.bidbar .bids button.sel { background: var(--green); box-shadow: 0 3px 0 #2e7a45; color: #fff; }

.hand-wrap { padding: .8rem 16px 1.2rem; }
.hand-label { color: var(--muted); font-size: .85rem; margin-bottom: .4rem; text-align: center; }
.hand { display: flex; gap: .45rem; justify-content: center; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
  width: var(--card-w); height: var(--card-h); border-radius: 9px; position: relative; flex: none;
  background: #fbf6e8; color: #222; border: 3px solid var(--c, #888);
  box-shadow: 0 3px 8px #0007; display: flex; align-items: center; justify-content: center;
  user-select: none; transition: transform .12s, box-shadow .12s, opacity .2s;
}
.card .num { position: absolute; top: 3px; left: 6px; font-weight: 700; font-size: 1.05rem; color: var(--c); }
.card .num.br { top: auto; left: auto; bottom: 3px; right: 6px; transform: rotate(180deg); }
.card .ico { font-size: 2.1rem; line-height: 1; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.card .lbl { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-size: .58rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--c); }
.card.special { background: linear-gradient(160deg, #fff8e6, #f1e2bd); }
.card.dark { background: linear-gradient(160deg, #3a3a3a, #161616); color: #eee; }
.card.playable { cursor: pointer; }
.card.playable:hover { transform: translateY(-10px); box-shadow: 0 10px 18px #000a; }
.card.disabled { opacity: .38; filter: grayscale(.5); }
.card.winning { box-shadow: 0 0 0 3px var(--gold), 0 0 22px var(--gold); }
.card.mini { --card-w: 46px; --card-h: 66px; border-width: 2px; }
.card.mini .ico { font-size: 1.3rem; }
.card.mini .num { font-size: .8rem; }
.card.mini .lbl { display: none; }
.t-parrot { --c: #2e9a4a; }
.t-map { --c: #7b4bb4; }
.t-chest { --c: #c99712; }
.t-roger { --c: #1a1a1a; }
.t-roger.dark { --c: #e6e6e6; border-color: #000; }
.t-pirate { --c: #c0392b; }
.t-king { --c: #b8860b; }
.t-mermaid { --c: #138d90; }
.t-escape { --c: #7f8c8d; }
.t-kraken { --c: #8e1b3c; }
.t-whale { --c: #2563a6; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; background: #000b; display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem; width: min(640px, 100%); max-height: 90vh; overflow: auto; }
.scroll-x { overflow-x: auto; }
table.scores { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.scores th, table.scores td { padding: .4rem .5rem; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.scores th:first-child, table.scores td:first-child { text-align: left; }
table.scores .pos { color: var(--green); }
table.scores .neg { color: var(--red); }
table.scores tfoot td { font-weight: 700; color: var(--gold); }
.podium li .rank { font-family: "Pirata One", serif; font-size: 1.6rem; color: var(--gold); width: 1.6em; }

#toasts { font-family: inherit; }
#toasts { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: .4rem; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: #000d; border: 1px solid var(--line); padding: .55rem 1rem; border-radius: 10px; animation: toast .25s ease-out; text-align: center; }
.toast.error { border-color: var(--red); }
@keyframes toast { from { transform: translateY(10px); opacity: 0; } }

.rules { font-size: .9rem; color: var(--muted); }
.rules summary { cursor: pointer; color: var(--text); font-weight: 600; }
.rules ul { padding-left: 1.2rem; }

@media (max-width: 600px) {
  :root { --card-w: 56px; --card-h: 82px; }
  .card .ico { font-size: 1.6rem; }
  .card .lbl { display: none; }
  h1 { font-size: 2.5rem; }
  .seat { flex-basis: 112px; }
  .table-area { min-height: 190px; border-width: 4px; }
}
