:root{
  --bg0:#070a14;
  --bg1:#0b1020;
  --card:#0f1730;
  --text:#e9ecff;
  --muted:#aab3d4;
  --accent:#5b7cfa;
  --ok:#2ed573;
  --fail:#ff4757;
  --warn:#ffa502;
  --shadow: 0 12px 40px rgba(0,0,0,.35);
  --radius: 18px;
  --ring: 0 0 0 3px rgba(91,124,250,.25);
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family:var(--font);
  color:var(--text);
  background: radial-gradient(1000px 800px at 20% 0%, #17204b 0%, var(--bg1) 45%, var(--bg0) 100%);
}

.app{
  min-height:100%;
  display:flex;
  flex-direction:column;
  gap:18px;
  padding: clamp(14px, 2.4vw, 22px);
  max-width: 1100px;
  margin: 0 auto;
}

.topbar{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:18px;
}
.brand__title{
  font-weight:800;
  letter-spacing:.3px;
  font-size: clamp(20px, 2.6vw, 28px);
}
.brand__subtitle{
  margin-top:6px;
  color:var(--muted);
  font-size: 13px;
}

.hud{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  justify-content:flex-end;
}
.hud__item{
  background: rgba(15,23,48,.75);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
  padding: 10px 12px;
  min-width: 92px;
  box-shadow: var(--shadow);
}
.hud__label{
  color:var(--muted);
  font-size:12px;
}
.hud__value{
  font-weight:900;
  font-size: 22px;
  margin-top:2px;
}

.stage{
  flex: 1 1 auto;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  text-align:center;
  padding: clamp(22px, 4vw, 40px);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(15,23,48,.65) 0%, rgba(11,16,32,.35) 100%);
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: var(--shadow);
}

.word{
  font-weight: 950;
  letter-spacing: .8px;
  text-transform: uppercase;
  font-size: clamp(36px, 7.5vw, 88px);
  line-height: 1.02;
  text-wrap: balance;
}
.word:empty{
  display:none;
}
.word.is-countdown{
  display:block;
  letter-spacing: 1.2px;
}
.hint{
  margin-top: 16px;
  max-width: 70ch;
  color: var(--muted);
  font-size: 14px;
}
.word:empty + .hint{
  margin-top: 0;
}

.pairing{
  margin-top: 18px;
  display:flex;
  gap: 16px;
  align-items:center;
  justify-content:center;
  width: 100%;
  max-width: 820px;
}
.pairing[hidden]{ display:none; }
.pairing__qr{
  flex: 0 0 auto;
  padding: 10px;
  border-radius: 16px;
  background: rgba(233,236,255,.95);
  box-shadow: var(--shadow);
}
.pairing__qr canvas{
  display:block;
  /* Keep QR crisp on mobile (avoid blurred CSS scaling). */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.pairing__text{
  flex: 1 1 auto;
  text-align:left;
  background: rgba(15,23,48,.55);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  padding: 12px 14px;
}
.pairing__title{
  margin-bottom: 6px;
}
.pairing__desc{
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.pairing__linkRow{
  margin-top: 10px;
}
.pairing__link{
  word-break: break-all;
  color: rgba(140,164,255,.98);
  text-decoration: none;
  border-bottom: 1px dashed rgba(140,164,255,.55);
}
.pairing__link:hover{
  border-bottom-color: rgba(140,164,255,.9);
}
.pairing__sidRow{
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}
.pairing__sid{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  color: rgba(233,236,255,.9);
  font-weight: 700;
}

.panel{
  display:flex;
  flex-direction:column;
  gap:12px;
}

.controls{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
}
.btn{
  appearance:none;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(15,23,48,.70);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 14px;
  cursor:pointer;
  font-weight:700;
  letter-spacing:.2px;
  box-shadow: var(--shadow);
  transition: transform .06s ease, border-color .12s ease, background .12s ease;
}
.btn:active{ transform: translateY(1px); }
.btn:focus{ outline:none; box-shadow: var(--shadow), var(--ring); }
.btn--primary{
  background: linear-gradient(180deg, rgba(91,124,250,.95) 0%, rgba(71,100,230,.9) 100%);
  border-color: rgba(120,145,255,.75);
}
.btn--ok{ border-color: rgba(46,213,115,.65); }
.btn--fail{ border-color: rgba(255,71,87,.65); }
.btn[disabled]{
  opacity:.55;
  cursor:not-allowed;
}

.fallback{
  background: rgba(15,23,48,.5);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  padding: 12px;
}
.fallback__title{
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.fallback__buttons{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}

.details{
  background: rgba(15,23,48,.5);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.details > summary{
  cursor:pointer;
  color: var(--muted);
  font-weight: 700;
}
.details__grid{
  margin-top: 10px;
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.details__box{
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(11,16,32,.35);
}
.details__label{
  font-size: 12px;
  color: var(--muted);
}
.details__value{
  margin-top:4px;
  font-weight: 800;
}
.results{
  margin-top: 12px;
}
.results__title{
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}
.results__list{
  margin:0;
  padding-left: 18px;
  display:flex;
  flex-direction:column;
  gap: 4px;
  max-height: 220px;
  overflow:auto;
}
.results__list#wordsList{
  max-height: 360px;
}
.results__list li{
  color: rgba(233,236,255,.9);
  font-size: 13px;
}
.tag{
  display:inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid rgba(255,255,255,.12);
}
.tag--ok{ color: rgba(46,213,115,.95); border-color: rgba(46,213,115,.35); }
.tag--fail{ color: rgba(255,71,87,.95); border-color: rgba(255,71,87,.35); }

.flash-ok .stage{
  border-color: rgba(46,213,115,.45);
  box-shadow: var(--shadow), 0 0 0 6px rgba(46,213,115,.10);
}
.flash-fail .stage{
  border-color: rgba(255,71,87,.45);
  box-shadow: var(--shadow), 0 0 0 6px rgba(255,71,87,.10);
}

@media (max-width: 720px){
  .topbar{
    align-items:flex-start;
    flex-direction:column;
  }
  .hud{
    justify-content:flex-start;
  }
  .details__grid{
    grid-template-columns: 1fr;
  }
  .pairing{
    flex-direction:column;
    align-items:stretch;
  }
  .pairing__text{
    text-align:left;
  }
}
