:root {
  --bg: #000000;
  --text: #f0f4ff;
  --text-dim: #8fa3c4;
  --font-display: 'Segoe UI', system-ui, sans-serif;
  --accent: #e8a317;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

.hidden {
  display: none !important;
}

/* Top bar */
.top-bar {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1000;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
}

.top-bar .icon-btn {
  margin-left: 8px;
}

.top-bar .icon-btn:first-child {
  margin-left: 0;
}

.icon-btn {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
  font-size: 1.25rem;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.sound-unlock-banner {
  position: fixed;
  left: 50%;
  bottom: 4vh;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  z-index: 1100;
  border: 2px solid var(--accent);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.82);
  color: #f0f4ff;
  font: inherit;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  padding: 0.85rem 1.35rem;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.sound-unlock-banner:hover {
  background: rgba(232, 163, 23, 0.2);
}

.realtime-banner {
  position: fixed;
  left: 50%;
  top: 4vh;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  z-index: 1100;
  border: 2px solid #c44;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.88);
  color: #f0f4ff;
  font: inherit;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  padding: 0.65rem 1.1rem;
  cursor: pointer;
  max-width: min(92vw, 42rem);
  text-align: center;
}

.realtime-banner:hover {
  background: rgba(196, 68, 68, 0.22);
}

/* Pairing / waiting: bez top-bara i bannera dźwięku */
#app.is-waiting .top-bar,
#app.is-waiting .sound-unlock-banner {
  display: none !important;
}

/* Brand + message (waiting before pairing) */
.brand-message {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  text-align: center;
  padding: 4vh 4vw;
  max-width: 36rem;
  width: 100%;
}

.brand-message__logo {
  width: 70%;
  max-width: 14rem;
  height: auto;
  margin-bottom: 1.5rem;
  object-fit: contain;
}

.brand-message__samiku {
  width: 100%;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  min-height: 3.25rem;
  margin-bottom: 1.5rem;
}

.brand-message__text {
  font-size: 1.75rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  line-height: 1.35;
}

/* Waiting screen */
.waiting-screen {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

#app.is-waiting .waiting-screen {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
}

#app:not(.is-waiting) .waiting-screen {
  display: none;
}

/* Combined connect screen (QR + code) — TV / webOS-safe flex */
.pairing-connect {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  padding: 4vh 4vw;
  box-sizing: border-box;
  text-align: left;
}

.pairing-connect__row {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -webkit-flex-direction: row;
  flex-direction: row;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
}

.pairing-connect__qr {
  width: 52%;
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 52%;
  flex: 0 0 52%;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding-right: 2vw;
  box-sizing: border-box;
}

.pairing-connect__panel {
  width: 48%;
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 48%;
  flex: 0 0 48%;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding-left: 2vw;
  box-sizing: border-box;
  max-width: 28rem;
}

.pairing-connect__title {
  font-size: 2.4rem;
  color: var(--text);
  margin-bottom: 1rem;
  line-height: 1.2;
}

.pairing-connect__howto {
  font-size: 1.2rem;
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 0.65rem;
}

.pairing-connect__howto-login {
  font-size: 0.95rem;
  color: var(--text-dim);
  line-height: 1.4;
  margin-bottom: 1.75rem;
}

.pairing-connect__or {
  font-size: 1rem;
  color: var(--text-dim);
  margin-bottom: 0.85rem;
}

.pairing-connect__footer {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  text-align: center;
  padding-top: 1.5vh;
}

.pairing-connect__samiku {
  display: inline-block;
  line-height: 0;
  text-decoration: none;
}

.pairing-connect__samiku img {
  display: block;
  width: 140px;
  height: auto;
}

/* QR column */
.pairing-tv-qr__frame {
  width: 55vh;
  height: 55vh;
  max-width: 90%;
  padding: 0.35rem;
  border: 3px solid var(--accent);
  border-radius: 18px;
  background: #ffffff;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  box-sizing: border-box;
  text-align: center;
  word-break: break-all;
}

.pairing-tv-qr__frame[hidden] {
  display: none !important;
}

.pairing-tv-qr__fallback {
  font-size: 0.75rem;
  color: #333;
  margin: 0.35rem 0;
  padding: 0 0.5rem;
}

.pairing-tv-qr__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #ffffff;
  border: 0;
}

.pairing-tv-qr__status {
  margin-top: 1rem;
  font-size: 1.05rem;
  color: var(--text-dim);
  text-align: center;
  max-width: 55vh;
  line-height: 1.4;
}

.pairing-tv-qr__status--ended {
  color: var(--text);
}

.pairing-tv-qr__status-msg {
  display: block;
  margin-bottom: 0.85rem;
}

.pairing-tv-qr__refresh {
  display: -webkit-inline-box;
  display: -webkit-inline-flex;
  display: inline-flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  margin-top: 0.25rem;
}

.pairing-tv-qr__refresh-icon {
  display: block;
  width: 48px;
  height: 48px;
  line-height: 0;
}

.pairing-tv-qr__refresh-icon svg {
  display: block;
  width: 48px;
  height: 48px;
}

.pairing-tv-qr__refresh-label {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.pairing-tv-qr__refresh:hover {
  color: #ffc14d;
}

/* Code form (secondary) */
.pairing-code {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: start;
  -webkit-align-items: flex-start;
  align-items: flex-start;
  width: 100%;
}

.pairing-code__form {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  width: 100%;
}

.pairing-code__input {
  width: 8rem;
  margin-right: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.35em;
  text-align: center;
  padding: 0.65rem 0.5rem;
  border: 2px solid rgba(232, 163, 23, 0.65);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.pairing-code__submit {
  min-height: 3rem;
  margin-bottom: 0.5rem;
  padding: 0 1.25rem;
  border: 2px solid var(--accent);
  border-radius: 10px;
  background: rgba(232, 163, 23, 0.25);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.pairing-code__submit:hover:not(:disabled) {
  background: rgba(232, 163, 23, 0.4);
}

.pairing-code__submit:disabled {
  opacity: 0.5;
  cursor: default;
}

.pairing-code__message {
  margin-top: 0.5rem;
  font-size: 1rem;
  color: var(--text-dim);
  line-height: 1.4;
}

/* Portrait only — wide / landscape stays left–right even when window is narrower */
@media (orientation: portrait) {
  .pairing-connect {
    -webkit-box-pack: start;
    -webkit-justify-content: flex-start;
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .pairing-connect__row {
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    flex-direction: column;
    -webkit-box-pack: start;
    -webkit-justify-content: flex-start;
    justify-content: flex-start;
    -webkit-box-flex: 0;
    -webkit-flex: 0 0 auto;
    flex: 0 0 auto;
  }

  .pairing-connect__qr,
  .pairing-connect__panel {
    width: 100%;
    -webkit-flex: 0 0 auto;
    flex: 0 0 auto;
    max-width: none;
    padding-left: 0;
    padding-right: 0;
  }

  .pairing-connect__qr {
    margin-bottom: 2vh;
  }

  .pairing-tv-qr__frame {
    width: 50vh;
    height: 50vh;
  }

  .pairing-tv-qr__status {
    max-width: 50vh;
  }

  .pairing-connect__title {
    font-size: 2rem;
  }

  .pairing-connect__panel {
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
    text-align: center;
  }

  .pairing-code {
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
  }

  .pairing-code__form {
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
  }

  .pairing-connect__footer {
    margin-top: 3vh;
    padding-top: 1vh;
    padding-bottom: 1vh;
    position: relative;
    z-index: 1;
  }

  .pairing-connect__samiku img {
    width: 110px;
  }
}

/* Game board shell — letterbox 16:9 (tapeta + UI w jednym stage, niezależnie od TV) */
.game-board {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  container-type: size;
}

/* Pełny ekran pod tablicą — widać tylko poza boxem 16:9. */
.stage-letterbox {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  z-index: 0;
  background: #000000;
  pointer-events: none;
}

/* Chrome < 88 / bez cqw: wypełnij viewport. Letterbox 16:9 tylko gdy silnik zna obie cechy. */
.game-board .board-root {
  position: relative;
  z-index: 1;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

@supports (aspect-ratio: 16 / 9) and (width: 1cqw) {
  .game-board .board-root {
    aspect-ratio: 16 / 9;
    width: min(100cqw, calc(100cqh * 16 / 9));
    height: auto;
  }
}

/* Chromium 85 / Tizen 6 — brak aspect-ratio i cqw; letterbox przez vh/vw. */
@supports not (width: 1cqw) {
  .game-board .board-root {
    width: min(100%, 177.78vh);
    height: min(100%, 56.25vw);
  }
}

/* Po sparowaniu tablica wypełnia viewport (jak embed). */
#game-board:not(.hidden) {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
}

/* Podgląd szablonu w iframe hosta (`?embed=1`) */
html.is-embed,
html.is-embed body,
#app.is-embed {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

#app.is-embed .top-bar,
#app.is-embed .sound-unlock-banner,
#app.is-embed .waiting-screen {
  display: none !important;
}

#app.is-embed.is-theme-loading .waiting-screen {
  display: -webkit-box !important;
  display: -webkit-flex !important;
  display: flex !important;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  z-index: 20;
  background: #000;
}

#app.is-embed.is-theme-loading .brand-message__text {
  display: none;
}

#app.is-embed.is-theme-loading #game-board {
  visibility: hidden;
}

#app.is-embed #game-board {
  display: flex !important;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
}

/* Embed (Theme Lab / host) — iframe jest już 16:9; bez drugiego letterboxu (zoom). */
#app.is-embed .game-board .board-root {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  max-width: none;
  max-height: none;
}

/* Embed HTML chrome — rodzic iframe (Theme Lab / host) jest już 16:9; fill bez drugiego letterboxu. */
html.is-embed.is-html-chrome,
html.is-embed.is-html-chrome body,
#app.is-embed.is-html-chrome {
  background: transparent;
}

#app.is-embed.is-html-chrome .game-board,
#app.is-embed.is-html-chrome .board-root {
  overflow: visible;
}

#app.is-embed.is-html-chrome .stage-letterbox,
#app.is-embed.is-html-chrome .flipdot-wall,
#app.is-embed.is-html-chrome .flipdot-plate-host::before {
  display: none;
}

#app.is-embed.is-html-chrome #flipdot-html-chrome {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Theme Lab: chrome w rodzicu (#html-preview); embed = kropki na przezroczystym tle. */
#app.is-embed.is-parent-chrome #flipdot-html-chrome {
  display: none !important;
}

#app.is-embed.is-parent-chrome .flipdot-answer-board,
#app.is-embed.is-parent-chrome .flipdot-board {
  background: transparent;
}

/* Flip-dot HTML chrome (TV) — letterbox 16:9 jak static/dynamic. headerOffsetY w ramie, nie na pasach. */
#app.is-html-chrome:not(.is-embed) .game-board {
  overflow: hidden;
}

#app.is-html-chrome:not(.is-embed) #flipdot-html-chrome {
  position: relative;
  z-index: 1;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

@supports (aspect-ratio: 16 / 9) and (width: 1cqw) {
  #app.is-html-chrome:not(.is-embed) #flipdot-html-chrome {
    aspect-ratio: 16 / 9;
    width: min(100cqw, calc(100cqh * 16 / 9));
    height: auto;
  }
}

@supports not (width: 1cqw) {
  #app.is-html-chrome:not(.is-embed) #flipdot-html-chrome {
    width: min(100%, 177.78vh);
    height: min(100%, 56.25vw);
  }
}

#app.is-html-chrome .flipdot-wall,
#app.is-html-chrome .flipdot-plate-host::before {
  display: none;
}

#app.is-html-chrome #board-root {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  max-width: none;
  max-height: none;
}

/* HTML embed: wymiary/offset ustawia flipdotHtmlChrome (16:9 pod clip dziury ramki). */
#app.is-html-chrome .hb-board-slot #board-root {
  inset: auto;
  right: auto;
  bottom: auto;
  width: auto;
  height: auto;
}
