/* =========================================================
   Number Game — Styles
   Palette: dark bg #0A0A12, P1 orange #FF6B35, P2 blue #00C2FF
   ========================================================= */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0A0A12;
  color: #ECECF1;
  font-family: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.mono { font-family: 'Space Mono', 'Courier New', monospace; }
.upper { text-transform: uppercase; }
.muted { color: #8B8B9A; font-size: 0.9rem; }

button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input { font-family: inherit; outline: none; }

/* ========= Screens ========= */
.screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: flex; }

/* ========= Buttons ========= */
.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: 14px 22px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  transition: transform 0.1s, opacity 0.2s, background 0.2s;
  min-height: 48px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, #FF6B35, #ff8c61);
  color: white;
  box-shadow: 0 4px 18px rgba(255, 107, 53, 0.35);
}
.btn-ghost {
  background: rgba(255, 255, 255, 0.07);
  color: #ECECF1;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.btn-danger {
  background: rgba(255, 70, 70, 0.12);
  color: #ff7070;
  border: 1px solid rgba(255, 70, 70, 0.3);
}
.btn-icon {
  background: rgba(255, 255, 255, 0.07);
  color: #ECECF1;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.error-msg {
  color: #ff7a7a;
  font-size: 0.88rem;
  min-height: 1.2em;
  text-align: center;
}

/* ========================================================
   Screen 1: Home
   ======================================================== */
#screen-home {
  justify-content: center;
  align-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 107, 53, 0.08), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(0, 194, 255, 0.08), transparent 40%),
    #0A0A12;
}
.home-wrap {
  width: 100%;
  max-width: 400px;
  max-height: 100%;
  overflow-y: auto;
  padding: 24px 4px;
}
.logo {
  text-align: center;
  font-size: clamp(2rem, 9vw, 2.6rem);
  font-weight: 800;
  background: linear-gradient(90deg, #FF6B35, #00C2FF);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 6px;
}
.subtitle {
  text-align: center;
  color: #8B8B9A;
  margin-bottom: 28px;
  font-size: 0.95rem;
}
.tabs {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 22px;
}
.tab-btn {
  flex: 1;
  padding: 12px;
  background: transparent;
  color: #8B8B9A;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: all 0.2s;
}
.tab-btn.active {
  background: rgba(255, 255, 255, 0.08);
  color: #ECECF1;
}
.tab-panel { display: none; flex-direction: column; gap: 14px; }
.tab-panel.active { display: flex; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span {
  font-size: 0.85rem;
  color: #B0B0BF;
  font-weight: 600;
}
.field input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ECECF1;
  padding: 14px;
  border-radius: 10px;
  font-size: 1rem;
  transition: border-color 0.2s, background 0.2s;
}
.field input:focus {
  border-color: #FF6B35;
  background: rgba(255, 255, 255, 0.08);
}
.field input.mono { font-size: 1.2rem; letter-spacing: 0.15em; text-align: center; }

/* ========================================================
   Screen 2: Waiting
   ======================================================== */
#screen-wait {
  justify-content: center;
  align-items: center;
  padding: 20px;
}
.wait-wrap {
  text-align: center;
  width: 100%;
  max-width: 420px;
}
.wait-wrap h2 { font-size: 1.6rem; margin-bottom: 6px; }
.room-code {
  font-family: 'Space Mono', monospace;
  font-size: clamp(2.5rem, 14vw, 4rem);
  font-weight: 700;
  letter-spacing: 0.2em;
  padding: 28px 16px;
  margin: 28px 0;
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.1), rgba(0, 194, 255, 0.1));
  border: 2px dashed rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  color: #FFD6C4;
}
.wait-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 32px;
}
.spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border: 3px solid rgba(255, 255, 255, 0.08);
  border-top-color: #FF6B35;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.spinner.small { width: 28px; height: 28px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ========================================================
   Screen 3: Game
   ======================================================== */
#screen-game {
  flex-direction: column;
  padding: 10px;
  gap: 10px;
}

/* ---- Top bar (round + turn + close) ---- */
.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.round-pill {
  background: rgba(255, 255, 255, 0.06);
  color: #B0B0BF;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}
.round-pill b { color: #ECECF1; margin-inline-start: 4px; }

.turn-pill {
  flex: 1;
  text-align: center;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.04);
  color: #ECECF1;
  max-width: 220px;
  margin: 0 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all 0.25s;
}
.turn-pill.my-turn {
  background: linear-gradient(135deg, #FF6B35, #ff8c61);
  color: white;
  box-shadow: 0 2px 12px rgba(255, 107, 53, 0.4);
}
.turn-pill.their-turn {
  background: rgba(0, 194, 255, 0.15);
  color: #00C2FF;
  border: 1px solid rgba(0, 194, 255, 0.3);
}

/* ---- Player cards header ---- */
.game-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}
.player-card {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  min-width: 0;
  transition: all 0.25s;
}
#card-p1 { border-color: rgba(255, 107, 53, 0.4); }
#card-p2 { border-color: rgba(0, 194, 255, 0.4); }
#card-p1.active-turn {
  background: rgba(255, 107, 53, 0.1);
  box-shadow: 0 0 18px rgba(255, 107, 53, 0.25);
}
#card-p2.active-turn {
  background: rgba(0, 194, 255, 0.1);
  box-shadow: 0 0 18px rgba(0, 194, 255, 0.25);
}
.player-name {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 8px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#card-p1 .player-name { color: #FF6B35; }
#card-p2 .player-name { color: #00C2FF; }

.revealed {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  direction: ltr;
}
.revealed span {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  font-weight: 700;
  font-size: 1.05rem;
  color: #555566;
}
.revealed span.known {
  color: #51cf66;
  background: rgba(81, 207, 102, 0.18);
  border: 1px solid rgba(81, 207, 102, 0.4);
}

.vs-badge {
  font-weight: 800;
  font-size: 0.85rem;
  color: #8B8B9A;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 50%;
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#btn-leave-game {
  flex-shrink: 0;
}

/* ---- Game main: guess area or waiting ---- */
.game-main {
  flex: 1;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  position: relative;
}
.guess-area, .waiting-area {
  width: 100%;
  max-width: 360px;
  display: none;     /* hidden by default; JS adds .is-active to show */
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.guess-area.is-active,
.waiting-area.is-active {
  display: flex;
}
.guess-prompt {
  font-size: 0.95rem;
  color: #B0B0BF;
  font-weight: 600;
}
.guess-inputs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 320px;
  direction: ltr;   /* Digits entered left-to-right */
}
.digit-input {
  width: 100%;
  height: 64px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.12);
  color: #ECECF1;
  border-radius: 12px;
  text-align: center;
  font-size: 1.8rem;
  font-weight: 700;
  padding: 0;
  transition: border-color 0.15s, background 0.15s, opacity 0.2s;
}
.digit-input:focus {
  border-color: #FF6B35;
  background: rgba(255, 107, 53, 0.1);
  outline: none;
}
.digit-input:disabled {
  opacity: 0.45;
  background: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.05);
  color: #666677;
}
.btn-guess {
  width: 100%;
  max-width: 320px;
  transition: all 0.2s;
}
.btn-guess:disabled {
  background: rgba(255, 255, 255, 0.08);
  color: #666677;
  box-shadow: none;
  cursor: not-allowed;
}

/* ---- Waiting area (opponent's turn) ---- */
.waiting-area {
  flex-direction: row;
  justify-content: center;
  padding: 24px 20px;
  background: rgba(0, 194, 255, 0.06);
  border: 1px dashed rgba(0, 194, 255, 0.25);
  border-radius: 14px;
  flex-direction: row;
}
.waiting-area .waiting-text {
  color: #B0B0BF;
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ---- Logs ---- */
.logs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-height: 0;
  flex-shrink: 0;
}
.logs-col {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 24vh;
  overflow: hidden;
}
#logs-p1 { border-color: rgba(255, 107, 53, 0.25); }
#logs-p2 { border-color: rgba(0, 194, 255, 0.25); }

.logs-title {
  font-size: 0.78rem;
  padding: 6px 10px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  flex-shrink: 0;
}
#logs-p1 .logs-title { color: #FF6B35; }
#logs-p2 .logs-title { color: #00C2FF; }

.logs-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column-reverse;
  gap: 5px;
  min-height: 0;
}
.log-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  flex-shrink: 0;
  direction: ltr;
}
.log-row span {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.3);
  font-size: 0.95rem;
}
.log-row span.ok  { background: rgba(81, 207, 102, 0.22);  color: #51cf66; }
.log-row span.bad { background: rgba(255, 107, 107, 0.18); color: #ff7070; }
.logs-empty {
  color: #555566;
  font-size: 0.8rem;
  text-align: center;
  padding: 20px 8px;
}


/* ========================================================
   Screen 4: End
   ======================================================== */
#screen-end {
  justify-content: center;
  align-items: center;
  padding: 20px;
}
.end-wrap {
  text-align: center;
  width: 100%;
  max-width: 420px;
}
.end-title {
  font-size: clamp(2rem, 10vw, 3rem);
  font-weight: 800;
  background: linear-gradient(90deg, #FF6B35, #00C2FF);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 8px;
}
.end-sub { color: #B0B0BF; margin-bottom: 28px; }
.end-secret-label { font-size: 0.9rem; color: #8B8B9A; margin-bottom: 8px; }
.end-secret {
  font-size: clamp(2.2rem, 12vw, 3.2rem);
  font-weight: 700;
  letter-spacing: 0.25em;
  padding: 20px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  margin-bottom: 24px;
  color: #FFD6C4;
}
.end-stats { color: #B0B0BF; margin-bottom: 24px; font-size: 0.95rem; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 30, 45, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #ECECF1;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* shake anim */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.shake { animation: shake 0.3s ease; }

/* ========================================================
   Desktop tweaks
   ======================================================== */
@media (min-width: 720px) {
  #screen-game { padding: 20px; gap: 16px; max-width: 800px; margin: 0 auto; }
  .game-header { gap: 16px; }
  .player-card { padding: 18px; }
  .player-name { font-size: 1.15rem; }
  .revealed span { font-size: 1.4rem; height: 44px; }
  .turn-pill { font-size: 1rem; padding: 10px 20px; max-width: 300px; }
  .round-pill { font-size: 0.95rem; padding: 8px 18px; }
  .digit-input { height: 80px; font-size: 2.2rem; }
  .guess-inputs { gap: 14px; }
  .guess-area, .waiting-area { max-width: 420px; }
  .logs-col { max-height: 28vh; }
  .log-row span { height: 36px; font-size: 1.1rem; }
  .vs-badge { min-width: 42px; height: 42px; font-size: 0.95rem; }
}

/* =========================================================
   Chat, Voice, Rematch — added features
   ========================================================= */

/* ---- Topbar icons (chat & voice) ---- */
.btn-chat, .btn-voice, .btn-voice-mute {
  position: relative;
}
.btn-chat .icon, .btn-voice .icon, .btn-voice-mute .icon { font-size: 1rem; }
.btn-chat .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #FF4444;
  color: white;
  font-size: 0.65rem;
  font-weight: 800;
  border-radius: 999px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #0A0A12;
}

/* Voice button states:
     idle      = dim, mic icon
     ringing   = dim + pulse border  (incoming handled by modal anyway)
     calling   = yellow-ish (outgoing dialing)
     connected = bright green glow (live call)
*/
.btn-voice {
  opacity: 0.55;
  transition: all 0.2s;
}
.btn-voice.calling {
  opacity: 1;
  background: #eab308;
  color: white;
}
.btn-voice.in-call {
  opacity: 1;
  background: #22c55e;
  color: white;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.55);
  animation: voice-pulse 1.8s ease-in-out infinite;
}
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(34, 197, 94, 0.45); }
  50%      { box-shadow: 0 0 14px rgba(34, 197, 94, 0.85); }
}

/* Mute toggle — only visible during an active call */
.btn-voice-mute {
  background: rgba(255, 255, 255, 0.07);
}
.btn-voice-mute.muted {
  background: rgba(239, 68, 68, 0.85);
  color: white;
}

/* ---- Chat panel (slides up from bottom) ---- */
.chat-panel {
  position: fixed;
  inset: auto 0 0 0;
  height: 70vh;
  background: #13131C;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px 18px 0 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
  padding-bottom: env(safe-area-inset-bottom);
}
.chat-panel.open {
  transform: translateY(0);
}
.chat-panel[hidden] { display: none; }
.chat-panel[hidden].open { display: flex; }  /* allow transition */

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.chat-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  max-width: 80%;
  padding: 9px 14px;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.35;
  word-wrap: break-word;
}
.chat-msg.mine {
  align-self: flex-end;
  background: linear-gradient(135deg, #FF6B35, #ff8c61);
  color: white;
  border-bottom-right-radius: 4px;
}
.chat-msg.theirs {
  align-self: flex-start;
  background: rgba(0, 194, 255, 0.15);
  color: #ECECF1;
  border: 1px solid rgba(0, 194, 255, 0.25);
  border-bottom-left-radius: 4px;
}
.chat-msg .author {
  display: block;
  font-size: 0.72rem;
  opacity: 0.75;
  margin-bottom: 2px;
  font-weight: 600;
}
.chat-empty {
  text-align: center;
  color: #666677;
  padding: 40px 12px;
  font-size: 0.9rem;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.chat-input-row input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ECECF1;
  padding: 12px 14px;
  border-radius: 22px;
  font-size: 1rem;
  outline: none;
}
.chat-input-row input:focus {
  border-color: #FF6B35;
}
.btn-send {
  background: linear-gradient(135deg, #FF6B35, #ff8c61);
  color: white;
  border: none;
  padding: 0 18px;
  border-radius: 22px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  min-height: 44px;
}
.btn-send:disabled { opacity: 0.5; }

/* ---- Modal (rematch, incoming call) ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in 0.2s ease;
}
.modal[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: #13131C;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  padding: 28px 22px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  animation: slide-up 0.25s ease;
}
@keyframes slide-up { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-card h3 {
  margin-bottom: 8px;
  font-size: 1.3rem;
}
.modal-card p { color: #B0B0BF; margin-bottom: 18px; font-size: 0.92rem; }

.secret-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.12);
  color: #ECECF1;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 14px;
  direction: ltr;
}
.secret-input:focus {
  border-color: #FF6B35;
  outline: none;
}
.modal-card .btn { width: 100%; margin-bottom: 8px; }

.end-actions {
  display: flex;
  gap: 10px;
  flex-direction: column;
}
.end-actions .btn { width: 100%; }


/* ---- Floating chat popup (new message notification inside the page) ---- */
.chat-popup-container {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 64px);
  right: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2500;
  pointer-events: none;
}
.chat-popup {
  background: linear-gradient(135deg, #13131C, #1a1a28);
  border: 1px solid rgba(0, 194, 255, 0.4);
  border-left: 4px solid #00C2FF;
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  max-width: 380px;
  margin-inline-start: auto;
  margin-inline-end: auto;
  width: 100%;
  transform: translateY(-18px);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: auto;
  cursor: pointer;
}
.chat-popup.show {
  transform: translateY(0);
  opacity: 1;
}
.chat-popup-author {
  color: #00C2FF;
  font-weight: 700;
  font-size: 0.82rem;
  margin-bottom: 2px;
}
.chat-popup-body {
  color: #ECECF1;
  font-size: 0.95rem;
  word-wrap: break-word;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
