/* SK P2P Game — style.css */

:root{
  --bg:#0a0e17;
  --bg-2:#0d1220;
  --glass: rgba(255,255,255,0.045);
  --glass-strong: rgba(255,255,255,0.075);
  --glass-border: rgba(255,255,255,0.09);
  --line: rgba(255,255,255,0.07);
  --text: #eaf3ff;
  --text-dim: rgba(234,243,255,0.55);
  --text-faint: rgba(234,243,255,0.32);
  --cyan: #48e9ff;
  --cyan-dim: rgba(72,233,255,0.16);
  --magenta: #ff5fd8;
  --magenta-dim: rgba(255,95,216,0.16);
  --green: #49ffb0;
  --amber: #ffc65a;
  --danger: #ff6b7a;
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

*, *::before, *::after{ box-sizing: border-box; }

html, body{
  height: 100%;
  overscroll-behavior: none;
}

html{
  scroll-padding-top: var(--safe-t);
}

body{
  margin:0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  position: fixed;
  inset: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

input, textarea{
  user-select: text;
}

h1,h2,h3{
  font-family: "Space Grotesk", "Inter", sans-serif;
  margin: 0;
  letter-spacing: -0.01em;
}

button{
  font-family: inherit;
  border: none;
  cursor: pointer;
  color: inherit;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible, input:focus-visible{
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------------- background ---------------- */
.bg-glow{
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
}
.bg-glow.g1{
  width: 55vmax; height: 55vmax;
  top: -20vmax; left: -15vmax;
  background: radial-gradient(circle, var(--cyan), transparent 70%);
}
.bg-glow.g2{
  width: 50vmax; height: 50vmax;
  bottom: -22vmax; right: -18vmax;
  background: radial-gradient(circle, var(--magenta), transparent 70%);
}

/* ---------------- app shell (fixed, no page scroll ever) ---------------- */
.app{
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r)) calc(14px + var(--safe-b)) calc(16px + var(--safe-l));
  gap: 12px;
}

/* ---------------- topbar ---------------- */
.topbar{
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
}

.brand{
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark{
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, var(--cyan), var(--magenta));
  color: #061019;
  padding: 5px 8px;
  border-radius: 8px;
  line-height: 1;
}
.brand-name{
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
}

.presence-chip{
  display:flex;
  align-items:center;
  gap:6px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.presence-chip .dot{
  width:6px; height:6px; border-radius:50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  flex: 0 0 auto;
}

/* ---------------- stage: holds the 3 views, only one visible ---------------- */
.stage{
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

.view{
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.view.active{ display: flex; }

/* ---------------- glass / neomorphism base ---------------- */
.glass{
  background: linear-gradient(155deg, var(--glass-strong), var(--glass));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.06) inset,
    0 -1px 0 rgba(0,0,0,0.25) inset,
    0 20px 50px -20px rgba(0,0,0,0.65);
}

/* ---------------- lobby ---------------- */
.panel-lobby{
  width: min(380px, 100%);
  max-height: 100%;
  overflow: hidden;
  padding: clamp(22px, 5vh, 36px) clamp(20px, 5vw, 30px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.eyebrow{
  margin: 0;
  font-size: 12.5px;
  color: var(--cyan);
  font-weight: 500;
}

.panel-lobby h1{
  font-size: clamp(22px, 5.5vw, 28px);
  font-weight: 700;
  margin-bottom: 4px;
}

.field{
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}
.field-label{
  font-size: 12px;
  color: var(--text-faint);
  padding-left: 2px;
}

input[type="text"]{
  background: rgba(0,0,0,0.28);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 13px 15px;
  font-size: 15px;
  font-family: inherit;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="text"]::placeholder{ color: var(--text-faint); }
input[type="text"]:focus{
  border-color: rgba(72,233,255,0.5);
  box-shadow: 0 0 0 3px var(--cyan-dim);
  outline: none;
}

.btn{
  border-radius: var(--radius-sm);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, filter 0.12s ease, background 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:active{ transform: scale(0.96); }

.btn-primary{
  background: linear-gradient(135deg, var(--cyan), #3ab8ff);
  color: #04121a;
  box-shadow: 0 8px 24px -8px rgba(72,233,255,0.55);
}
.btn-primary:hover{ filter: brightness(1.06); }
.btn-primary.active{
  background: linear-gradient(135deg, var(--green), #2fe89a);
  box-shadow: 0 8px 24px -8px rgba(73,255,176,0.55);
}

.btn-lg{
  padding: 15px 20px;
  font-size: 15.5px;
  margin-top: 6px;
}

.btn-sm{
  padding: 9px 16px;
  font-size: 13.5px;
}

.btn-ghost{
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text-dim);
  padding: 12px 18px;
  font-size: 14px;
}
.btn-ghost:hover{ background: var(--glass-strong); color: var(--text); }

.hint{
  margin: 0;
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.5;
}

/* ---------------- queue ---------------- */
.panel-queue{
  width: min(320px, 100%);
  padding: clamp(28px, 6vh, 44px) 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.radar{
  position: relative;
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  flex: 0 0 auto;
}
.radar-core{
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 18px 4px rgba(72,233,255,0.7);
  z-index: 1;
}
.radar-ring{
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--cyan);
  opacity: 0;
  animation: radar-pulse 2.4s ease-out infinite;
}
.radar-ring.r2{ animation-delay: 0.8s; }
.radar-ring.r3{ animation-delay: 1.6s; }

@keyframes radar-pulse{
  0%{ transform: scale(0.25); opacity: 0.7; }
  100%{ transform: scale(1); opacity: 0; }
}

.panel-queue h2{
  font-size: 19px;
  font-weight: 600;
  display: flex;
  justify-content: center;
  min-width: 150px;
}
#queue-dots{
  display: inline-block;
  width: 20px;
  text-align: left;
}

.panel-queue .hint{ margin-bottom: 14px; }

/* ---------------- room shell ---------------- */
.room-shell{
  width: 100%;
  max-width: 920px;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.room-header{
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  gap: 10px;
  min-width: 0;
}

.opp-info{
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar{
  width: 34px; height: 34px;
  border-radius: 50%;
  flex: 0 0 auto;
  background:
    radial-gradient(circle at 32% 28%, rgba(255,255,255,0.55), transparent 45%),
    linear-gradient(135deg, var(--magenta), var(--cyan));
}

.opp-text{
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}
.opp-name{
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.opp-status{
  font-size: 11px;
  font-weight: 500;
}
.opp-status.good{ color: var(--green); }
.opp-status.bad{ color: var(--danger); }

/* ---------------- tabs (mobile switch, hidden on wide screens) ---------------- */
.room-tabs{
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 10px 12px 0;
}
.tab{
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-faint);
  background: transparent;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: color 0.15s ease;
}
.tab.active{
  color: var(--text);
}
.tab.active::after{
  content: "";
  position: absolute;
  left: 14px; right: 14px; bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
}
.badge{
  min-width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--magenta);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.badge.show{ opacity: 1; transform: scale(1); }

/* ---------------- room body: game + chat ---------------- */
.room-body{
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  padding: 10px 12px 12px;
  gap: 12px;
}

.panel{
  display: none;
  min-height: 0;
  min-width: 0;
  flex-direction: column;
}
.panel.active-panel{ display: flex; }

/* On wide screens show both panels side by side, ignore tabs */
@media (min-width: 720px){
  .room-tabs{ display: none; }
  .room-body{ padding-top: 14px; }
  .panel{ display: flex; }
  #panel-game{ flex: 1.1 1 0; }
  #panel-chat{
    flex: 1 1 0;
    border-left: 1px solid var(--line);
    padding-left: 14px;
  }
}
@media (max-width: 719.98px){
  .panel{ flex: 1 1 auto; width: 100%; }
}

/* ---------------- game ---------------- */
.game-wrap{
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.4vh, 20px);
  min-height: 0;
  padding: 4px;
}

.turn-indicator{
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  font-size: clamp(13px, 3vw, 15px);
  color: var(--text-dim);
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.turn-indicator.mine{
  color: var(--cyan);
  border-color: rgba(72,233,255,0.35);
}

.board{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(6px, 1.6vw, 10px);
  width: min(88vw, 340px);
  aspect-ratio: 1 / 1;
  flex: 0 1 auto;
}

.cell{
  background: rgba(255,255,255,0.045);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: clamp(28px, 8vw, 44px);
  line-height: 1;
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset, 0 6px 16px -10px rgba(0,0,0,0.6);
  transition: background 0.15s ease, transform 0.1s ease;
}
.cell:not(:disabled):hover{
  background: rgba(255,255,255,0.08);
}
.cell:not(:disabled):active{
  transform: scale(0.93);
}
.cell:disabled{ cursor: default; }
.cell.x{ color: var(--cyan); text-shadow: 0 0 18px rgba(72,233,255,0.5); }
.cell.o{ color: var(--magenta); text-shadow: 0 0 18px rgba(255,95,216,0.5); }
.cell.win{
  background: rgba(73,255,176,0.14);
  border-color: rgba(73,255,176,0.4);
}

.rematch-bar{
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  min-height: 34px;
}
.rematch-bar.show{
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.rematch-status{
  font-size: 12.5px;
  color: var(--text-faint);
}

/* ---------------- chat ---------------- */
.chat-wrap{
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 8px;
}

.chat-log{
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 4px 4px 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
  overscroll-behavior: contain;
}
.chat-log::-webkit-scrollbar{ width: 5px; }
.chat-log::-webkit-scrollbar-thumb{ background: rgba(255,255,255,0.15); border-radius: 4px; }

.msg{
  display: flex;
  max-width: 82%;
}
.msg.mine{ align-self: flex-end; justify-content: flex-end; }
.msg.theirs{ align-self: flex-start; }

.bubble{
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.mine .bubble{
  background: linear-gradient(135deg, var(--cyan), #2fb8e6);
  color: #04141c;
  border-bottom-right-radius: 5px;
}
.msg.theirs .bubble{
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 5px;
}

.typing-indicator{
  display: none;
  align-items: center;
  gap: 4px;
  padding-left: 6px;
  height: 14px;
}
.typing-indicator.show{ display: flex; }
.tdot{
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: tbounce 1.2s infinite ease-in-out;
}
.tdot:nth-child(2){ animation-delay: 0.15s; }
.tdot:nth-child(3){ animation-delay: 0.3s; }
@keyframes tbounce{
  0%, 60%, 100%{ transform: translateY(0); opacity: 0.5; }
  30%{ transform: translateY(-3px); opacity: 1; }
}

.chat-form{
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  align-items: center;
}
.chat-form input{
  flex: 1;
  min-width: 0;
  background: rgba(0,0,0,0.28);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  padding: 11px 16px;
  font-size: 14px;
  font-family: inherit;
}
.chat-form input:focus{
  border-color: rgba(72,233,255,0.5);
  box-shadow: 0 0 0 3px var(--cyan-dim);
  outline: none;
}
.send-btn{
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), #2fb8e6);
  color: #04141c;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease;
}
.send-btn:active{ transform: scale(0.9); }

/* ---------------- toast ---------------- */
.toast{
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translate(-50%, 12px);
  background: rgba(15,20,30,0.92);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: min(90vw, 360px);
  text-align: center;
  box-shadow: 0 14px 30px -12px rgba(0,0,0,0.6);
}
.toast.show{
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------- small screens: tighten paddings, avoid any cutoff ---------------- */
@media (max-height: 620px){
  .radar{ width: 70px; height: 70px; margin-bottom: 10px; }
  .panel-queue{ padding: 20px 24px; gap: 4px; }
  .panel-lobby{ gap: 10px; padding: 18px 22px; }
}

@media (prefers-reduced-motion: reduce){
  .radar-ring{ animation: none; opacity: 0.25; }
  .tdot{ animation: none; }
  *{ transition-duration: 0.01ms !important; }
}