:root {
  --bg: #0d1a12;
  --bg2: #132419;
  --panel: rgba(10, 20, 14, 0.85);
  --text: #eef3ee;
  --muted: #9db3a4;
  --accent: #e8b84a;
  --accent2: #c9962e;
  --danger: #e05656;
  --ok: #4fc46a;
  --radius: 14px;
  --hud-h: 64px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: radial-gradient(1200px 800px at 50% 30%, #17301f 0%, var(--bg) 60%, #070d09 100%);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#app { height: 100%; }
.screen { height: 100%; position: relative; }
.screen[hidden] { display: none !important; }

#screen-lobby, #screen-wait {
  display: flex; align-items: center; justify-content: center; padding: 20px;
  overflow: auto;
}
.card {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  width: min(440px, 100%);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
}
.logo { display: flex; align-items: center; gap: 14px; }
.logo h1 { margin: 0; font-size: 40px; letter-spacing: 1px; }
.eight {
  width: 54px; height: 54px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #555 0%, #111 45%, #000 100%);
  display: grid; place-items: center; font-weight: 800; font-size: 22px; color: #111;
  position: relative;
}
.eight::before { content: ""; position: absolute; width: 26px; height: 26px; border-radius: 50%; background: #fff; }
.eight { z-index: 0; }
.eight { text-shadow: none; }
.eight { isolation: isolate; }
.eight::before { z-index: -1; }
.sub { color: var(--muted); margin: 8px 0 18px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type=text] {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15); background: rgba(0,0,0,0.3); color: var(--text);
  font-size: 16px; outline: none;
}
input[type=text]:focus { border-color: var(--accent); }
.btn {
  display: block; width: 100%; padding: 13px 16px; margin-top: 10px;
  border-radius: 10px; border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06); color: var(--text); font-size: 16px; font-weight: 600;
  cursor: pointer; transition: transform .06s, background .15s;
}
.btn:hover { background: rgba(255,255,255,0.12); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #1b1305; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.small { width: auto; padding: 8px 14px; margin: 0; }
.btn:disabled { opacity: .5; cursor: default; }
.error { color: var(--danger); font-size: 14px; }
.help { margin-top: 18px; color: var(--muted); font-size: 13px; }
.help summary { cursor: pointer; }
.help ul { padding-left: 18px; line-height: 1.5; }
.linkbox { display: flex; gap: 8px; margin: 12px 0; }
.linkbox input { flex: 1; font-size: 14px; }
.linkbox .btn { width: auto; margin: 0; white-space: nowrap; }
.waiting { color: var(--muted); display: flex; align-items: center; gap: 10px; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent); animation: spin 1s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- HRA ---------- */
#screen-game { display: flex; flex-direction: column; height: 100%; }
#hud {
  height: var(--hud-h); flex: 0 0 auto;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: 6px 12px; background: rgba(0,0,0,0.35); border-bottom: 1px solid rgba(255,255,255,0.06);
}
.player { display: flex; flex-direction: column; gap: 3px; padding: 6px 10px; border-radius: 10px; min-width: 0; border: 1px solid transparent; transition: background .2s, border-color .2s; }
.player.active { background: rgba(232,184,74,0.12); border-color: rgba(232,184,74,0.5); }
.player.offline .pname::after { content: " (odpojen)"; color: var(--danger); font-weight: 400; font-size: 12px; }
#p1 { align-items: flex-end; text-align: right; }
.pname { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.pgroup { font-size: 12px; color: var(--muted); }
.pballs { display: flex; gap: 3px; flex-wrap: wrap; }
#p1 .pballs { justify-content: flex-end; }
.mini { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.5); position: relative; box-shadow: inset -2px -2px 3px rgba(0,0,0,0.4); }
.mini.stripe { background: #fff !important; overflow: hidden; }
.mini.stripe::after { content: ""; position: absolute; left: 0; right: 0; top: 4px; bottom: 4px; background: var(--c); }
.mini.gone { opacity: .18; }
#status { text-align: center; min-width: 120px; }
#status-main { font-weight: 700; font-size: 15px; }
#status-sub { font-size: 12px; color: var(--muted); min-height: 15px; }

#table-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
#table { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }

#power {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 46px; height: min(60%, 340px); display: flex; flex-direction: column; align-items: center; gap: 6px;
  touch-action: none; user-select: none; cursor: ns-resize; z-index: 3;
}
#power-track {
  flex: 1; width: 22px; border-radius: 11px; background: rgba(0,0,0,0.45); border: 1px solid rgba(255,255,255,0.15);
  position: relative; overflow: hidden; box-shadow: inset 0 2px 6px rgba(0,0,0,0.6);
}
#power-fill {
  position: absolute; left: 0; right: 0; top: 0; height: 0%;
  background: linear-gradient(180deg, #ffe08a, #e8b84a 40%, #e05656);
  transition: height .03s linear;
}
#power-label { font-size: 10px; letter-spacing: 2px; color: var(--muted); }
#power.disabled { opacity: .35; pointer-events: none; }

#banner {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  background: rgba(0,0,0,0.75); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-weight: 600; font-size: 15px; pointer-events: none; z-index: 4;
  border: 1px solid rgba(255,255,255,0.15); max-width: 90%; text-align: center;
  animation: fadein .2s ease-out;
}
#banner.foul { background: rgba(160,40,40,0.9); }
#banner.good { background: rgba(35,120,60,0.9); }
@keyframes fadein { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }
#bubble {
  position: absolute; left: 12px; bottom: 12px; max-width: 60%;
  background: rgba(255,255,255,0.92); color: #111; padding: 8px 12px; border-radius: 14px; font-size: 14px;
  pointer-events: none; z-index: 4; animation: fadein .2s ease-out;
}

#toolbar { position: absolute; left: 8px; top: calc(var(--hud-h) + 8px); display: flex; flex-direction: column; gap: 6px; z-index: 5; }
.tbtn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.5); color: #fff; font-size: 17px; cursor: pointer; position: relative;
}
.tbtn:hover { background: rgba(0,0,0,0.7); }
#chat-badge {
  position: absolute; top: -5px; right: -5px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px;
}

#chat {
  position: absolute; left: 8px; bottom: 8px; width: min(320px, calc(100% - 70px));
  background: var(--panel); border: 1px solid rgba(255,255,255,0.1); border-radius: 12px;
  display: flex; flex-direction: column; z-index: 6; backdrop-filter: blur(6px);
}
#chat[hidden] { display: none; }
#chat-log { height: 150px; overflow-y: auto; padding: 10px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
#chat-log .msg { background: rgba(255,255,255,0.06); padding: 5px 9px; border-radius: 10px; max-width: 90%; align-self: flex-start; word-break: break-word; }
#chat-log .msg.me { align-self: flex-end; background: rgba(232,184,74,0.25); }
#chat-log .msg b { color: var(--accent); font-weight: 600; margin-right: 4px; }
#chat-log .sys { color: var(--muted); font-size: 12px; text-align: center; }
#chat-emoji { display: flex; gap: 4px; padding: 0 8px; }
#chat-emoji button { flex: 1; background: transparent; border: 1px solid rgba(255,255,255,0.08); border-radius: 8px; font-size: 18px; padding: 4px 0; cursor: pointer; }
#chat-emoji button:hover { background: rgba(255,255,255,0.1); }
#chat-form { display: flex; gap: 6px; padding: 8px; }
#chat-form input { flex: 1; padding: 8px 10px; font-size: 14px; }

#overlay-end, #overlay-info {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55); z-index: 10; padding: 16px;
}
#overlay-end[hidden], #overlay-info[hidden] { display: none; }
#overlay-end .card, #overlay-info .card { text-align: center; }
#end-title { margin: 0 0 6px; font-size: 30px; }
#end-title.win { color: var(--ok); }
#end-title.lose { color: var(--danger); }
#end-reason { margin: 0; color: var(--text); }
#end-sub { color: var(--muted); font-size: 13px; min-height: 18px; }
.row { display: flex; gap: 10px; }
.row .btn { margin-top: 6px; }

@media (max-width: 640px) {
  :root { --hud-h: 58px; }
  #hud { padding: 4px 8px; gap: 4px; }
  .pgroup { display: none; }
  #status-main { font-size: 13px; }
  #status-sub { font-size: 11px; }
  #status { min-width: 90px; }
  .card { padding: 22px 18px; }
  .logo h1 { font-size: 32px; }
  #power { width: 40px; right: 4px; }
  #chat-log { height: 120px; }
}
@media (orientation: portrait) {
  #power { height: min(45%, 300px); }
  #toolbar { flex-direction: row; top: auto; bottom: 8px; }
  #chat { bottom: 54px; }
}
