/* Tablić — izgled kao Lora i Remi: soba, drveni ovalni sto, pločice igrača. */
:root {
  --room: #0d1f17;
  --room-2: #13291f;
  --felt: #177245;
  --felt-dark: #0e4d2e;
  --rail: #6b4424;
  --rail-dark: #4a2e17;
  --bar: #091610;
  --ink: #f5f7f5;
  --muted: #b8cbbf;
  --card: #fffdf8;
  --card-edge: #cfc8b8;
  --accent: #f2c14e;
  --accent-ink: #2b2100;
  --select: #3fa7ff;
  --plate: rgba(8, 20, 14, .82);
  --plate-edge: rgba(255, 255, 255, .14);
  --dialog-bg: #fbfaf7;
  --dialog-ink: #1b1b1b;
  --chip-bg: #ffffff;
  --chip-ink: #111111;
  /* boje avatara: iste kao u Lori i Remiju (mesto 0 = vi) */
  --av0: #2f7dd1;
  --av1: #c0392b;
  --av2: #8e44ad;
  --av3: #d68910;

  /* veličine prate i širinu i visinu prozora */
  --card-w: clamp(46px, min(12vw, 10.5vh), 86px);
  --hand-w: clamp(50px, min(14vw, 12vh), 96px);
  --back-w: clamp(20px, min(4.6vw, 4.6vh), 40px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --dialog-bg: #1d2420; --dialog-ink: #eef2ef; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 40%, var(--room-2), var(--room) 70%);
  height: 100dvh; overflow: hidden;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- zaglavlje ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; background: var(--bar); }
.topbar h1 { font-size: 1.15rem; margin: 0; letter-spacing: .03em; }
.score { font-size: .95rem; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; justify-content: center; }
.score b { font-size: 1.2rem; color: var(--accent); }
.score .sep { color: var(--muted); }
.score span:not(.mine):not(.sep) { color: var(--muted); }
.top-buttons { display: flex; }
.icon-btn { background: none; border: 0; color: var(--ink); font-size: 1.35rem; cursor: pointer; padding: 4px 8px; }

/* ---------- soba i sto ---------- */
.room { position: relative; min-height: 0; }
.table {
  position: absolute; inset: 9% 8% 15%;
  border-radius: 999px;
  background: radial-gradient(ellipse at 50% 45%, var(--felt) 0%, var(--felt-dark) 75%);
  border: clamp(8px, 1.4vw, 16px) solid var(--rail);
  box-shadow: 0 0 0 3px var(--rail-dark), inset 0 0 40px rgba(0, 0, 0, .45), 0 12px 30px rgba(0, 0, 0, .5);
}
.table-area {
  position: absolute; inset: 22% 17% 27%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.deck-info { font-size: .78rem; color: var(--muted); text-align: center; }
.table-cards { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 6px; max-width: 100%; }

/* ---------- mesta i pločice ---------- */
.seat { position: absolute; display: flex; align-items: center; gap: 6px; z-index: 3; }
.seat-top { top: 0; left: 50%; transform: translateX(-50%); }
.seat-left { left: 1%; top: 48%; transform: translateY(-50%); flex-direction: column; }
.seat-right { right: 1%; top: 48%; transform: translateY(-50%); flex-direction: column; }
.seat-me { bottom: 1%; left: 50%; transform: translateX(-50%); }

.plate {
  position: relative; display: flex; align-items: center; gap: 8px;
  background: var(--plate); border: 1px solid var(--plate-edge); border-radius: 14px;
  padding: 6px 12px 6px 6px; box-shadow: 0 4px 12px rgba(0, 0, 0, .35);
}
.plate.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(242, 193, 78, .45); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 1.05rem; color: var(--ink);
}
.avatar.p0 { background: var(--av0); }
.avatar.p1 { background: var(--av1); }
.avatar.p2 { background: var(--av2); }
.avatar.p3 { background: var(--av3); }
.plate .name { font-weight: 700; font-size: 1rem; line-height: 1.15; white-space: nowrap; }
.plate .sub { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.plate .sub.tablas { color: var(--accent); font-weight: 600; }
.dealer-chip {
  position: absolute; top: -9px; right: -9px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--chip-bg); color: var(--chip-ink); font-weight: 800; font-size: .8rem; display: grid; place-items: center;
  border: 2px solid var(--accent); box-shadow: 0 2px 4px rgba(0, 0, 0, .4);
}
.seat-right .dealer-chip { right: auto; left: -9px; }

.mini-hand { display: flex; }
.mini-hand .card { width: var(--back-w); border-radius: 4px; }
.mini-hand .card + .card { margin-left: calc(var(--back-w) * -.62); }
.seat-left .mini-hand, .seat-right .mini-hand { flex-direction: column; }
.seat-left .mini-hand .card + .card, .seat-right .mini-hand .card + .card { margin-left: 0; margin-top: calc(var(--back-w) * -1.15); }

/* ---------- karte ---------- */
.card {
  width: var(--card-w); aspect-ratio: 5 / 7; border-radius: 7px;
  background: var(--card); border: 1px solid var(--card-edge);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .35);
  position: relative; user-select: none; overflow: hidden;
  cursor: default; transition: transform .12s ease, box-shadow .12s ease; flex: none;
}
.card img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.card .pts {
  position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%); font-size: calc(var(--card-w) * .16); font-weight: 700;
  background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 0 4px; line-height: 1.3;
}
.card.back { border: 0; background: none; }
.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-3px); }
.card.selected { transform: translateY(-10px); box-shadow: 0 0 0 3px var(--select), 0 6px 10px rgba(0, 0, 0, .4); }
.table-cards .card.selected { transform: translateY(-4px); }
.card.taking { box-shadow: 0 0 0 3px var(--accent), 0 6px 10px rgba(0, 0, 0, .4); transform: translateY(-4px); }
.card.incoming { box-shadow: 0 0 0 3px var(--select), 0 6px 10px rgba(0, 0, 0, .4); animation: incoming .3s ease; }
@keyframes incoming { from { transform: translateY(-24px) scale(.9); opacity: 0; } }

/* ---------- moja ruka i dugmad ---------- */
.bottom { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 4px 10px 10px; }
.hint { margin: 0; min-height: 1.3em; text-align: center; font-size: .92rem; }
.hand { display: flex; justify-content: center; gap: 5px; flex-wrap: nowrap; min-height: calc(var(--hand-w) * 1.4); }
.hand .card { width: var(--hand-w); }
.hand .card .pts { font-size: calc(var(--hand-w) * .16); }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.btn {
  font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .1); color: var(--ink); cursor: pointer; text-decoration: none; text-align: center;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.toast {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  background: rgba(0, 0, 0, .75); padding: 6px 12px; border-radius: 8px; font-size: .88rem;
  opacity: 0; transition: opacity .2s; pointer-events: none; width: max-content; max-width: 100%; text-align: center; z-index: 4;
}
.toast.show { opacity: 1; }
.toast.tabla { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* ---------- prozori ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 20px; background: var(--dialog-bg); color: var(--dialog-ink);
  width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { margin-top: 0; }
dialog .btn { color: var(--dialog-ink); border-color: rgba(0, 0, 0, .2); }
dialog .btn.primary { color: var(--accent-ink); }
.dialog-buttons { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.result { width: 100%; border-collapse: collapse; }
.result th, .result td { padding: 6px 8px; text-align: right; border-bottom: 1px solid rgba(127, 127, 127, .25); }
.result th:first-child, .result td:first-child { text-align: left; }
.result tr.total td { font-weight: 700; }
.note { font-size: .9rem; opacity: .8; }
.players-pick { border: 1px solid rgba(127, 127, 127, .35); border-radius: 10px; padding: 8px 12px 12px; margin: 0; }
.players-pick legend { font-weight: 700; padding: 0 4px; }
.players-pick label { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; }
.menu-daily { display: flex; flex-direction: column; gap: 4px; margin-top: 14px; }
.menu-daily .btn { align-self: flex-start; }

/* ---------- proslava table: sto se strese, preko njega iskoči natpis ---------- */
.table-area.slam { animation: slam .45s ease; }
@keyframes slam {
  0% { transform: scale(1); }
  25% { transform: scale(1.03) rotate(-.5deg); }
  50% { transform: scale(.99) rotate(.4deg); }
  100% { transform: scale(1); }
}
.tabla-burst {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: clamp(2.4rem, 11vw, 4.5rem); font-weight: 900; letter-spacing: .06em; color: var(--accent);
  text-shadow: 0 3px 0 var(--accent-ink), 0 6px 18px rgba(0, 0, 0, .6); pointer-events: none; z-index: 5;
  animation: burst 1.5s ease forwards;
}
.tabla-burst small { font-size: .32em; letter-spacing: 0; color: var(--ink); text-shadow: 0 2px 6px rgba(0, 0, 0, .7); }
@keyframes burst {
  0% { transform: scale(.3); opacity: 0; }
  20% { transform: scale(1.15); opacity: 1; }
  35% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.05); }
}
@media (prefers-reduced-motion: reduce) {
  .table-area.slam, .tabla-burst, .card.incoming { animation: none; }
}

/* uski ekran: bočne pločice bez imena ispod avatara, da ne pokriju karte na stolu */
@media (max-width: 480px) {
  .seat-left .plate, .seat-right .plate { flex-direction: column; padding: 6px; gap: 2px; text-align: center; }
  .table-area { inset: 22% 22% 27%; }
}

/* ---------- online: lobi, čekaonica, chat ---------- */
.lobby {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center;
  background: rgba(0, 0, 0, .6); padding: 12px; overflow-y: auto;
}
.lobby-box {
  width: min(460px, 100%); background: var(--dialog-bg); color: var(--dialog-ink);
  border-radius: 14px; padding: 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.lobby-head { display: flex; align-items: center; justify-content: space-between; }
.lobby-head h2 { margin: 0; }
.lobby-head .icon-btn { color: var(--dialog-ink); }
.lobby-msg { background: var(--accent); color: var(--accent-ink); border-radius: 8px; padding: 8px 10px; font-weight: 600; }
.lobby .panel { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.lobby .panel[hidden] { display: none; }
.lobby label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.lobby input, .lobby select, #chatInput { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid rgba(127, 127, 127, .5); }
.lobby .btn { color: var(--dialog-ink); border-color: rgba(0, 0, 0, .2); }
.lobby .btn.primary { color: var(--accent-ink); }
.lobby h3 { margin: 8px 0 0; font-size: 1rem; }
.lobby .row, #chatForm { display: flex; gap: 8px; align-items: center; }
.lobby .row > input, .lobby .row > select, #chatInput { flex: 1; min-width: 0; }
.error { color: var(--av1); margin: 0; min-height: 1.2em; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
ol.list { list-style: decimal inside; }
.list li { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 6px 8px; border-radius: 8px; background: rgba(127, 127, 127, .12); }
.list li .btn { padding: 5px 10px; }
.chat-list { list-style: none; margin: 0 0 10px; padding: 0; max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
#chatBtn { position: relative; }
.badge {
  position: absolute; top: 0; right: 0; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 4px;
  background: var(--av1); color: var(--ink); font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center;
}
