:root {
  --bg: #0d1420;
  --panel: #16202e;
  --line: #24354a;
  --text: #e8eef6;
  --muted: #92a4b8;
  --accent: #3d8bfd;
  --danger: #c0392b;
  --bar: 40px;
  --bar-drop: 0px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100svh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: auto;
  width: 100%;
  height: 100vh;
  height: 100svh;
}

/* --- prijava --- */

#login {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.login-split,
.login-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  width: 100%;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.login-brand { display: none !important; }

.logo-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 0 12px;
  padding: 0;
  background: none;
  border: none;
}

.logo-frame img {
  display: block;
  width: 100%;
  max-width: 343px;
  max-height: 68px;
  height: auto;
  object-fit: contain;
}

.host-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 2px 0 8px;
}

.host-dl {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  border-radius: 9px;
  padding: 10px 16px;
}

.host-note, .host-rules {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.host-live {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 100%;
}

.host-id {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.host-gear {
  width: 27px;
  height: 27px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  border: none;
  background: transparent;
  box-shadow: none;
}

.host-gear:hover,
.host-gear:active {
  background: transparent;
  border: none;
}

.host-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.host-card {
  width: min(420px, 100%);
  max-height: calc(100vh - 32px);
  overflow-x: hidden;
  overflow-y: auto;
  background: #141c28;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 16px 18px;
}

.host-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.host-card-head button {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 20px;
}

.host-status {
  min-height: 18px;
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.host-card input[type="number"] {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  color: var(--text);
  background: #0f1825;
  border: 1px solid var(--line);
  border-radius: 9px;
}

.host-card .primary { width: 100%; margin-top: 12px; }

.host-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.host-actions button { flex: 1; }

.rules {
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 18px 48px;
  line-height: 1.5;
}

.rules a { color: var(--accent); }

.card {
  width: 100%;
  max-width: 400px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
}

.card > *:not(#bookBox) {
  flex: none;
}

.sub { margin: 4px 0 18px; color: var(--muted); font-size: 14px; }

@media (max-width: 859px) {
  .sub { display: none; }

  #login {
    padding-top: max(22px, env(safe-area-inset-top));
  }

  .logo-frame {
    margin: 6px 0 18px;
  }

  .card {
    padding-top: 26px;
  }

  label { margin: 10px 0 4px; }

  .card .primary { margin-top: 14px; }

  .book-title { margin: 16px 0 8px; }
}

@media (min-width: 860px) {
  #login {
    padding: 0;
    overflow: hidden;
  }

  .login-split {
    flex: 1 1 auto;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    height: 100%;
    min-height: 100%;
  }

  .login-brand {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1 1 50%;
    width: 50%;
    max-width: 50%;
    min-width: 0;
    height: 100%;
    padding: 40px;
    overflow: hidden;
  }

  .login-brand img {
    display: block;
    width: auto;
    height: auto;
    max-width: min(70%, 520px);
    max-height: 42vh;
    object-fit: contain;
  }

  .login-form {
    flex: 1 1 50%;
    width: 50%;
    max-width: 50%;
    min-width: 0;
    height: 100%;
    padding: 24px;
    justify-content: center;
  }

  .card {
    flex: 0 1 auto;
    max-height: calc(100% - 36px);
  }

  .book {
    max-height: min(46vh, 380px);
  }

  .logo-frame { display: none !important; }
  .card > .host-slot { display: none !important; }
}

label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }

input[type="text"], input[type="password"], #idInput, select {
  width: 100%;
  padding: 12px;
  font-size: 17px;
  color: var(--text);
  background: #0f1825;
  border: 1px solid var(--line);
  border-radius: 9px;
}

#idInput { letter-spacing: 3px; font-variant-numeric: tabular-nums; }

input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.check { display: flex; align-items: center; gap: 8px; margin: 14px 0 0; color: var(--muted); }
.check input { width: 18px; height: 18px; }

button {
  font: inherit;
  color: var(--text);
  background: #1e2b3d;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  cursor: pointer;
}

button:active { background: #2a3a52; }
button.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
button.danger { background: var(--danger); border-color: var(--danger); }

.card .primary { width: 100%; margin-top: 18px; padding: 13px; font-size: 16px; }

.msg { min-height: 20px; margin: 12px 0 0; font-size: 14px; color: #ffcf8b; }
.msg.error { color: #ff9a8b; }
.msg.ok { color: #8be09a; }
.hint {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  max-width: 400px;
}

.book-title {
  margin: 22px 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex: none;
}

#bookBox {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
  width: 100%;
}

.book {
  list-style: none;
  margin: 0;
  padding: 0 2px 4px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  flex: 1 1 auto;
  max-height: 190px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.book-item {
  position: relative;
  display: grid;
  grid-template-columns: 12px max-content auto 1fr min-content;
  grid-template-areas:
    "dot name more space join"
    "dot meta meta meta join";
  align-items: center;
  column-gap: 6px;
  width: 100%;
  padding: 10px 8px 10px 10px;
  background: #0f1825;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: left;
  flex: none;
}

.book-dot {
  grid-area: dot;
  width: 9px;
  height: 9px;
  margin: 0;
  border-radius: 50%;
  background: #c0392b;
  box-shadow: 0 0 0 3px #c0392b33;
  align-self: center;
}

.book-dot.on {
  background: #1f9d55;
  box-shadow: 0 0 0 3px #1f9d5533;
}

.book-name {
  grid-area: name;
  max-width: 220px;
  padding: 0;
  background: none;
  border: 0;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-more {
  grid-area: more;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  width: 10px;
  height: 15px;
  padding: 0;
  background: none;
  border: 0;
}

.book-more span {
  display: block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--muted);
}

.book-pop {
  position: absolute;
  top: 28px;
  left: 12px;
  z-index: 5;
  min-width: 132px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px #0007;
}

.book-pop button {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 8px 10px;
}

.book-meta {
  grid-area: meta;
  display: block;
  margin-top: 2px;
  padding: 0;
  background: none;
  border: 0;
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.book-join {
  grid-area: join;
  align-self: center;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: transparent;
  border: 1px solid #fff;
  border-radius: 8px;
  white-space: nowrap;
}

.book-join.hidden { display: none !important; }
.small { color: var(--muted); font-size: 12px; }

@media (max-width: 859px) {
  #bookBox {
    flex: none;
  }

  .book {
    flex: none;
    padding-bottom: 0;
    height: calc(2 * 58px + 8px);
    max-height: calc(2 * 58px + 8px);
  }
}

/* --- sesija --- */

#session {
  overflow: hidden;
  width: 100%;
  max-width: 100%;
}

body.pc-control #session,
body.pc-control #stage,
body.pc-control #viewport,
body.pc-control #viewport canvas {
  cursor: none;
}

body.pc-control #topbar,
body.pc-control #keysbar,
body.pc-control #menu,
body.pc-control #lost,
body.pc-control #fileBar {
  cursor: default;
}

body.pc-control #topbar button,
body.pc-control #keysbar button,
body.pc-control #menu button,
body.pc-control #lost button,
body.pc-control #fileBar button {
  cursor: pointer;
}

body.fs-clean #topbar {
  transform: translateY(-120%);
  pointer-events: none;
}

body.fs-clean.fs-peek #topbar {
  transform: none;
  pointer-events: auto;
}

body.fs-clean #stage {
  inset: 0;
}

body.fs-clean #fileBar {
  top: env(safe-area-inset-top, 0px);
}

body.fs-clean.fs-peek #fileBar {
  top: calc(var(--bar) + env(safe-area-inset-top, 0px) + var(--bar-drop));
}

#stage {
  position: absolute;
  inset: calc(var(--bar) + env(safe-area-inset-top, 0px) + var(--bar-drop)) 0 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #05080d;
  touch-action: none;
}

#viewport {
  position: relative;
  transform-origin: center center;
  will-change: transform;
}

#viewport canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
}

#overlay { pointer-events: none; }

#topbar {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + var(--bar-drop));
  left: 0;
  right: 0;
  z-index: 4;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 max(6px, env(safe-area-inset-right, 0px)) 0 max(6px, env(safe-area-inset-left, 0px));
  background: #101a28;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  touch-action: pan-x;
}

#topbar::-webkit-scrollbar { display: none; }

#topbar button { padding: 5px 9px; font-size: 13px; white-space: nowrap; touch-action: manipulation; }
#topbar button.on { background: var(--accent); border-color: var(--accent); }

@media (orientation: portrait) and (pointer: coarse) {
  :root { --bar-drop: 14px; }
}

@media (orientation: landscape) and (pointer: coarse) {
  :root { --bar: 48px; }

  #topbar {
    align-items: stretch;
    gap: 0;
    padding-top: 2px;
    padding-bottom: 2px;
  }

  #topbar button {
    min-height: 44px;
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
  }
}
#statLabel { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

body:not(.pc-control) #statLabel,
body:not(.pc-control) .pc-bar { display: none !important; }

body.pc-control .mob-bar { display: none !important; }
.spacer { flex: 1; }

#keysbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 6px 6px max(6px, env(safe-area-inset-bottom));
  background: rgba(16, 26, 40, 0.96);
  border-top: 1px solid var(--line);
}

#keysbar button { min-width: 44px; padding: 8px 6px; font-size: 13px; }
#keysbar button.on { background: var(--accent); border-color: var(--accent); }

.panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(340px, calc(100vw - 28px));
  max-height: calc(100vh - 80px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.panel h2 { margin: 0 0 10px; font-size: 17px; }
.panel label { display: block; margin: 14px 0 4px; }
.panel input[type="range"] { width: 100%; }
.panel output { color: var(--text); font-weight: 600; }
.row { display: flex; gap: 8px; margin-top: 16px; }
.row button { flex: 1; }

.kbd-catcher {
  position: absolute;
  top: 0;
  left: -120px;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0.01;
  font-size: 16px;
  pointer-events: none;
  caret-color: transparent;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  padding: 9px 14px;
  border-radius: 20px;
  background: rgba(8, 14, 22, 0.9);
  border: 1px solid var(--line);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  white-space: nowrap;
}

#toast.show { opacity: 1; }

.file-bar {
  position: absolute;
  top: var(--bar);
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: rgba(16, 26, 40, 0.96);
  border-bottom: 1px solid var(--line);
}

.file-bar span {
  font-size: 12px;
  color: var(--muted);
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-track {
  flex: 1;
  height: 8px;
  border-radius: 99px;
  background: #0b1220;
  overflow: hidden;
}

#fileFill {
  height: 100%;
  width: 0;
  background: var(--accent);
}

.file-bar button {
  padding: 4px 8px;
  font-size: 12px;
}

.file-pick {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0.01;
  left: -200px;
  top: 0;
  pointer-events: none;
}

.paste-catch {
  position: absolute;
  width: 240px;
  height: 80px;
  left: -999px;
  top: 0;
  opacity: 0.01;
  color: transparent;
  caret-color: transparent;
  overflow: hidden;
  outline: none;
  pointer-events: none;
}
