:root {
  --room: #0d1f17;
  --room-2: #13291f;
  --felt: #177245;
  --felt-dark: #0e4d2e;
  --rail: #6b4424;
  --rail-dark: #4a2e17;
  --bar: #091610;
  --ink: #f5f7f5;
  --muted: #b8cbbf;
  --accent: #f2c14e;
  --accent-ink: #2b2100;
  --plate: rgba(8, 20, 14, .82);
  --plate-edge: rgba(255, 255, 255, .14);
  --dialog-bg: #fbfaf7;
  --dialog-ink: #1b1b1b;
  --good: #1d8a4a;
  --av0: #2f7dd1;
  --av1: #c0392b;
  --av2: #8e44ad;
  --av3: #d68910;

  /* veličine se prilagođavaju i širini i visini prozora */
  --card-w: clamp(50px, min(10.5vw, 13vh), 100px);
  --trick-w: clamp(46px, min(9vw, 11.5vh), 92px);
  --back-w: clamp(26px, min(5vw, 6.5vh), 50px);
  --mini-w: clamp(26px, min(4.2vw, 7.2vh), 58px);
}
@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;
  /* minmax(0, 1fr): bez ovoga se kolona širi prema najdužem tekstu, pa i sto */
  display: grid; grid-template-rows: auto 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 16px; background: var(--bar); }
.topbar h1 { font-size: 1.2rem; margin: 0; letter-spacing: .03em; }
.contract { display: flex; flex-direction: column; align-items: center; line-height: 1.2; text-align: center; min-width: 0; }
.contract b { color: var(--accent); font-size: 1.2rem; }
.contract span { font-size: .85rem; color: var(--muted); }
.contract span strong { color: var(--ink); font-weight: 600; }
.top-buttons { display: flex; }
.icon-btn { background: none; border: 0; color: var(--ink); font-size: 1.4rem; cursor: pointer; padding: 4px 8px; }

/* ---------- sto ---------- */
.room { position: relative; min-height: 0; }
.table {
  position: absolute; inset: 7% 9% 13%;
  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);
}

.seat { position: absolute; display: flex; align-items: center; gap: 8px; z-index: 3; }
.seat-top { top: 1%; left: 50%; transform: translateX(-50%); flex-direction: row; }
.seat-left { left: 1.5%; top: 50%; transform: translateY(-55%); flex-direction: column; }
.seat-right { right: 1.5%; top: 50%; transform: translateY(-55%); flex-direction: column; }
.seat-me { bottom: 1%; left: 50%; transform: translateX(-50%); }

/* pločica igrača */
.plate {
  position: relative; display: flex; align-items: center; gap: 10px;
  background: var(--plate); border: 1px solid var(--plate-edge); border-radius: 14px;
  padding: 7px 14px 7px 8px; box-shadow: 0 4px 12px rgba(0,0,0,.35); min-width: 150px;
}
.plate.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(242,193,78,.45); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 1.15rem; color: #fff;
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar-preview { display: grid; place-items: center; margin: 8px 0 12px; }
.avatar-preview .avatar { width: 96px; height: 96px; font-size: 2.4rem; }
.file-btn { display: inline-block; cursor: pointer; text-align: center; }
.name { font-weight: 700; font-size: 1.12rem; line-height: 1.15; white-space: nowrap; }
.sub { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.sub b { color: var(--ink); }
.dealer-chip {
  position: absolute; top: -9px; right: -9px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; color: #111; font-weight: 800; font-size: .85rem; display: grid; place-items: center;
  border: 2px solid var(--accent); box-shadow: 0 2px 4px rgba(0,0,0,.4);
}
/* desni igrač: oznaka delioca sa unutrašnje strane, da ne viri van ekrana */
.seat-right .dealer-chip { right: auto; left: -9px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.chip { font-size: .8rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); white-space: nowrap; }
.chip.pass { background: #e25d5d; color: #fff; }

.backs { display: flex; }
.backs img { width: var(--back-w); margin-left: calc(var(--back-w) * -.7); border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.45); }
.backs img:first-child { margin-left: 0; }
.seat-left .backs, .seat-right .backs { flex-direction: column; }
.seat-left .backs img, .seat-right .backs img { margin-left: 0; margin-top: calc(var(--back-w) * -1.2); }
.seat-left .backs img:first-child, .seat-right .backs img:first-child { margin-top: 0; }

/* ---------- toast, dijalozi ---------- */
.toast {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,.8); padding: 8px 14px; border-radius: 10px; font-size: 1rem; font-weight: 600;
  opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90%; text-align: center; z-index: 5;
}
.toast.show { opacity: 1; }

.btn {
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; border: 1px solid rgba(127,127,127,.4);
  background: transparent; color: var(--dialog-ink); cursor: pointer; text-decoration: none; text-align: center;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
dialog { border: 0; border-radius: 14px; padding: 20px; background: var(--dialog-bg); color: var(--dialog-ink); width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h2 { margin-top: 0; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
dialog select, dialog textarea, dialog input { font: inherit; padding: 8px; border-radius: 8px; }
dialog textarea { resize: vertical; }
.dialog-buttons { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.result { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.result th, .result td { padding: 5px 7px; 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; }
.result td.best { color: var(--good); font-weight: 700; }
.sheet-dialog { width: min(560px, calc(100vw - 32px)); }
.sheet-scroll { max-height: 62vh; overflow: auto; }
.sheet h3 { margin: 14px 0 4px; font-size: .95rem; }
.sheet h3:first-child { margin-top: 0; }
.sheet .pending td { opacity: .35; }
.sheet .mine { font-weight: 700; }


/* ===================== Remi ===================== */
:root {
  --card-w: clamp(44px, min(6.2vw, 11vh), 84px);
  --meld-w: clamp(28px, min(3.4vw, 6vh), 46px);
  --pile-w: clamp(46px, min(6vw, 10vh), 80px);
}

/* karte (crtane u CSS-u — dva špila, džokeri) */
.card {
  width: var(--card-w); aspect-ratio: 5 / 7; border-radius: 7px; flex: none; position: relative;
  background: #fffdf8; border: 1px solid #cfc8b8; box-shadow: 0 2px 4px rgba(0,0,0,.35);
  color: #1b1b1b; font-weight: 700; user-select: none; overflow: hidden;
}
/* karte su slike (icons/cards, CC0 set kao u Preferansu, Lori i Tabliću) */
.card { overflow: hidden; }
.card img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.card.back { border: 0; background: none; }
.card.small { --w: var(--meld-w); width: var(--meld-w); border-radius: 4px; }
.card.pile { --w: var(--pile-w); width: var(--pile-w); }

/* centar: špil, gomila, kombinacije */
.center { position: absolute; inset: 17% 17% 21%; z-index: 2; display: grid; grid-template-rows: auto 1fr; gap: 8px; }
.piles { display: flex; justify-content: center; align-items: flex-end; gap: 18px; }
.pile-box { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .78rem; color: var(--muted); }
.pile-slot { position: relative; border-radius: 8px; }
.pile-slot.clickable { cursor: pointer; }
.pile-slot.clickable .card { box-shadow: 0 0 0 3px var(--accent), 0 4px 10px rgba(0,0,0,.4); }
.pile-slot.clickable:hover .card { transform: translateY(-3px); }
.pile-empty { width: var(--pile-w); aspect-ratio: 5 / 7; border: 2px dashed rgba(255,255,255,.3); border-radius: 8px; }
.melds { display: flex; flex-wrap: wrap; align-content: flex-start; justify-content: center; gap: 8px 12px; overflow: auto; padding: 4px; }
.meld {
  display: flex; padding: 4px 6px 4px 4px; border-radius: 8px; background: rgba(0,0,0,.18);
  border: 2px solid transparent; position: relative;
}
.meld .card + .card { margin-left: calc(var(--meld-w) * -.45); }
.meld.target { cursor: pointer; border-color: rgba(242,193,78,.55); }
.meld.target:hover { border-color: var(--accent); background: rgba(242,193,78,.12); }
.meld .owner { position: absolute; top: -7px; left: -4px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid rgba(0,0,0,.4); }
/* boje igrača (avatar i oznaka vlasnika kombinacije), iste kao u Lori i Tabliću */
.p0 { background: var(--av0); }
.p1 { background: var(--av1); }
.p2 { background: var(--av2); }
.p3 { background: var(--av3); }
.melds .empty { color: var(--muted); font-size: .9rem; align-self: center; }

/* priprema otvaranja (kombinacije koje još nisu na stolu) */
/* sloj preko stola, iznad vašeg mesta — ne sme da pomera sto */
.staged { position: absolute; left: 50%; bottom: 15%; transform: translateX(-50%); z-index: 4; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; width: min(90%, 900px); pointer-events: none; }
.staged .meld { pointer-events: auto; }
.staged .meld { background: rgba(242,193,78,.14); border-color: rgba(242,193,78,.5); }
.staged .pts { align-self: center; font-weight: 700; color: var(--accent); margin-left: 6px; font-size: .85rem; }

/* ruka */
/* stalna visina: broj dugmadi i karata ne sme da menja veličinu stola */
.hand-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 14px; padding: 4px 16px 10px; height: calc(var(--card-w) * 1.4 + 30px); }
.topbar { height: 54px; }
.contract span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; display: block; }
.hand { display: flex; justify-content: center; padding-top: 14px; }
.hand { min-width: 0; max-width: 100%; }
/* --ml računa app.js prema broju karata, da ruka uvek stane u širinu */
.hand .card { margin-left: var(--ml, calc(var(--card-w) * -.38)); cursor: pointer; transition: transform .1s; }
.hand .card:first-child { margin-left: 0; }
.hand .card:hover { transform: translateY(-5px); }
.hand .card.sel { transform: translateY(-14px); box-shadow: 0 0 0 3px var(--accent), 0 6px 12px rgba(0,0,0,.45); }
.hand .card.fresh { outline: 2px dashed #7cd0ff; outline-offset: -4px; }
.hand.locked .card { cursor: default; }
.actions { display: grid; grid-template-columns: repeat(2, minmax(0, auto)); gap: 6px; justify-self: start; align-content: end; max-height: 100%; }
.actions .btn { color: var(--ink); border-color: var(--plate-edge); padding: 8px 12px; font-size: .92rem; text-align: left; }
.actions .btn.primary { color: var(--accent-ink); }
.actions .btn:disabled { opacity: .4; cursor: not-allowed; }
.side-left { justify-self: end; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.hint { color: var(--muted); font-size: .88rem; text-align: right; max-width: 230px; }
.hint b { color: var(--ink); }
.badge-open { font-size: .72rem; font-weight: 700; color: #7ee2a0; }

@media (max-width: 760px) {
  :root { --card-w: clamp(38px, 10.5vw, 60px); }
  .table { inset: 9% 3% 12%; border-radius: 120px; }
  .center { inset: 16% 6% 20%; }
  .plate { min-width: 0; padding: 5px 8px 5px 5px; gap: 6px; }
  .avatar { width: 30px; height: 30px; font-size: .95rem; }
  .name { font-size: .95rem; }
  .sub { font-size: .75rem; }
  .seat-left .plate, .seat-right .plate { flex-direction: column; text-align: center; padding: 6px; }
  .seat .backs { display: none; }
  /* minmax(0, …): dugačak savet (nowrap) ne sme da proširi kolonu van ekrana */
  .hand-row { grid-template-columns: minmax(0, 1fr); grid-template-rows: 18px calc(var(--card-w) * 1.4 + 16px) 1fr; gap: 4px; height: calc(var(--card-w) * 1.4 + 124px); padding: 2px 8px 8px; }
  .side-left { justify-self: stretch; align-items: center; min-width: 0; }
  .hint { text-align: center; max-width: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; font-size: .8rem; }
  .actions { display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; justify-self: center; overflow: hidden; }
  .actions .btn { padding: 6px 9px; font-size: .8rem; }
  .hand { padding-top: 12px; }
  .topbar { height: 58px; }
  .staged { bottom: 12%; }
}

/* ---------- 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; }
.list li.mine { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.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;
}

/* predlog instalacije na telefonu (ui/install.js) */
.install { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin: 8px 0; border-radius: 12px; border: 1px solid var(--accent); background: rgba(127, 127, 127, .12); }
.install[hidden] { display: none; }
.install-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; text-align: left; }
.install-txt span { font-size: .88rem; opacity: .85; }
.install-x { flex: none; align-self: flex-start; width: 28px; height: 28px; padding: 0; border-radius: 50%; cursor: pointer; border: 1px solid rgba(127, 127, 127, .5); background: transparent; color: inherit; }
.install .btn { white-space: nowrap; color: var(--accent-ink); }
