: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;

  /* 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;
  display: grid; grid-template-rows: auto 1fr auto;
  -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;
}
.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);
}
.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; }

/* ---------- centar stola ---------- */
.center { position: absolute; inset: 20% 22% 24%; z-index: 2; }
.goal { position: absolute; top: -4px; left: 0; right: 0; margin: 0; text-align: center; font-size: .9rem; color: var(--muted); }
.goal b { color: var(--accent); }
.center-msg { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; text-align: center; font-size: 1.1rem; color: var(--ink); }

.card-img { display: block; width: 100%; height: auto; border-radius: 6px; box-shadow: 0 2px 5px rgba(0,0,0,.4); background: #fff; }

.trick { position: absolute; inset: 0; }
.trick .slot { position: absolute; width: var(--trick-w); }
.trick .slot[data-rel="0"] { left: 50%; bottom: 0; transform: translateX(-50%) rotate(-2deg); }
.trick .slot[data-rel="1"] { right: 12%; top: 50%; transform: translateY(-50%) rotate(4deg); }
.trick .slot[data-rel="2"] { left: 50%; top: 10%; transform: translateX(-50%) rotate(2deg); }
.trick .slot[data-rel="3"] { left: 12%; top: 50%; transform: translateY(-50%) rotate(-4deg); }
.trick .slot.winner .card-img { box-shadow: 0 0 0 3px var(--accent), 0 4px 12px rgba(0,0,0,.5); }

.layout {
  position: absolute; inset: 30px 0 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
}
.layout .row { display: flex; align-items: center; width: calc(var(--mini-w) * 5.4); }
.layout .row img {
  width: var(--mini-w); margin-left: calc(var(--mini-w) * -.55); border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.45); background: #fff; flex: none;
}
.layout .row > :first-child { margin-left: 0; }
.ghost {
  width: var(--mini-w); aspect-ratio: 5 / 7; flex: none; margin-left: 6px;
  border: 2px dashed rgba(255,255,255,.35); border-radius: 5px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: rgba(255,255,255,.7); font-weight: 700; font-size: calc(var(--mini-w) * .36); line-height: 1;
}
.ghost small { font-size: .9em; margin-top: 2px; }
.ghost.red { color: #ff9a9a; }

/* ---------- ruka ---------- */
.hand-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; padding: 4px 16px 10px; }
.hand { display: flex; justify-content: center; }
.actions { justify-self: start; }
.hand .card { width: var(--card-w); margin-left: calc(var(--card-w) * -.22); transition: transform .12s; flex: none; }
.hand .card:first-child { margin-left: 0; }
.hand .card.legal { cursor: pointer; }
.hand .card.legal:hover, .hand .card.legal:focus-visible { transform: translateY(-12px); outline: none; }
.hand .card.illegal { filter: brightness(.5); }
.hand.my-turn .card.legal .card-img { box-shadow: 0 0 0 2px var(--accent), 0 2px 5px rgba(0,0,0,.4); }

/* ---------- izbor igre: padajući meni uz vaše ime ---------- */
.picker { position: relative; }
.pick-btn {
  font: inherit; font-weight: 700; font-size: .95rem; padding: 8px 12px; border-radius: 10px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border: 0; white-space: nowrap;
}
.pick-btn.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(242,193,78,.6); } 50% { box-shadow: 0 0 0 7px rgba(242,193,78,0); } }
.pick-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; min-width: 190px;
  background: var(--plate); border: 1px solid var(--plate-edge); border-radius: 10px; padding: 4px;
  box-shadow: 0 8px 20px rgba(0,0,0,.45); z-index: 10; backdrop-filter: blur(4px);
}
.pick-menu button {
  display: block; width: 100%; text-align: left; font: inherit; font-size: .95rem; background: none; border: 0;
  color: var(--ink); padding: 6px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.pick-menu button:hover, .pick-menu button:focus-visible { background: rgba(242,193,78,.18); color: var(--accent); outline: none; }

/* ---------- 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 { font: inherit; padding: 8px; border-radius: 8px; }
.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; }

/* ---------- telefon ---------- */
@media (max-width: 640px) {
  .table { inset: 9% 3% 12%; border-radius: 120px; }
  .center { inset: 22% 16% 25%; }
  .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, .seat-right { top: 46%; }
  .seat-left .plate, .seat-right .plate { flex-direction: column; text-align: center; padding: 6px; }
  .seat-left .backs, .seat-right .backs { display: none; }
  .seat-top .backs img { width: calc(var(--back-w) * .8); }
  .goal { font-size: .78rem; }
  .layout { inset: 40px 0 0; gap: 4px; }
  .trick .slot[data-rel="1"] { right: 2%; }
  .trick .slot[data-rel="3"] { left: 2%; }
  .hand .card { margin-left: calc(var(--card-w) * -.3); }
  .hand-row { grid-template-columns: 1fr; gap: 6px; }
  .hand-row > .hand-side:first-child { display: none; }
  .actions { order: -1; justify-self: center; }
  .actions:empty { display: none; }
  .pick-menu { left: 50%; transform: translateX(-50%); }
}

/* ===================== ekrani van stola (start, prijava, lobi, čekaonica) ===================== */
.screen {
  position: fixed; inset: 0; z-index: 20; overflow: auto;
  display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 30%, var(--room-2), var(--room) 75%);
}
.panel {
  width: min(420px, 100%); background: var(--plate); border: 1px solid var(--plate-edge);
  border-radius: 16px; padding: 24px; box-shadow: 0 16px 40px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 12px;
}
.panel.wide { width: min(760px, 100%); }
.panel.hero { align-items: stretch; text-align: center; }
.panel h2 { margin: 0; font-size: 1.6rem; }
.panel h3 { margin: 0 0 6px; font-size: 1rem; color: var(--muted); font-weight: 600; }
.panel label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; }
.panel input {
  font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--plate-edge);
  background: rgba(255,255,255,.06); color: var(--ink);
}
.panel input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.panel .btn { color: var(--ink); border-color: var(--plate-edge); }
.panel .btn.primary { color: var(--accent-ink); }
.btn.big { padding: 12px 18px; font-size: 1.05rem; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; align-self: center; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: .85rem; }
.error { color: #ff8a8a; margin: 0; min-height: 1.2em; font-size: .9rem; }

.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.me-box { display: flex; gap: 12px; align-items: center; color: var(--muted); }
.me-box b { color: var(--ink); }
.lobby-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.join { display: flex; gap: 6px; }
.join input { width: 8.5em; text-transform: uppercase; letter-spacing: .1em; }
.lobby-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
ol.list { counter-reset: r; }
.list li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.05); font-size: .95rem;
}
.list li.empty { color: var(--muted); background: none; padding-left: 0; }
.list li .btn { padding: 6px 12px; }

.code { font-family: ui-monospace, Consolas, monospace; color: var(--accent); letter-spacing: .12em; }
.wait-seats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.wait-seat {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px;
  border: 1px dashed var(--plate-edge); min-height: 64px;
}
.wait-seat.filled { border-style: solid; background: rgba(255,255,255,.05); }
.wait-seat .grow { flex: 1; min-width: 0; }
.wait-seat .name { font-size: 1rem; overflow: hidden; text-overflow: ellipsis; }
.wait-seat .btn { padding: 6px 10px; font-size: .85rem; }

/* chat */
.chat {
  position: fixed; right: 16px; bottom: 16px; z-index: 15; width: min(340px, calc(100vw - 32px)); height: min(420px, 60dvh);
  display: flex; flex-direction: column; background: #0b1811; border: 1px solid var(--plate-edge);
  border-radius: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.5);
}
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--plate-edge); }
.chat-log { flex: 1; overflow: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-log b { color: var(--accent); }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--plate-edge); }
.chat-form input { flex: 1; min-width: 0; font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--plate-edge); background: rgba(255,255,255,.06); color: var(--ink); }
.chat-form .btn { padding: 8px 12px; }
#chatBtn { position: relative; }
.badge { position: absolute; top: 0; right: 0; min-width: 16px; height: 16px; border-radius: 8px; background: #e25d5d; color: #fff; font-size: .65rem; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }
.plate.offline { opacity: .55; }
.plate .ai-tag { font-size: .7rem; color: var(--muted); font-weight: 600; margin-left: 4px; }

@media (max-width: 640px) {
  .lobby-cols { grid-template-columns: 1fr; }
  .wait-seats { grid-template-columns: 1fr; }
  .panel { padding: 18px; }
  /* na telefonu chat ide gore, da ne pokriva karte u ruci */
  .chat { top: 52px; bottom: auto; left: 8px; right: 8px; width: auto; height: 42dvh; }
}
