/* ============================================================
   MateLink Chess — prototype styles
   Premium dark theme. No external fonts (self-contained).
   ============================================================ */

:root {
  --bg: #0c0f14;
  --bg-2: #11151c;
  --panel: #161b24;
  --panel-2: #1b212c;
  --border: #262d3a;
  --text: #e8edf4;
  --muted: #8b97a8;
  --muted-2: #5f6b7c;
  --accent: #2bd576;
  --accent-2: #1faa5d;
  --accent-soft: rgba(43, 213, 118, 0.14);
  --danger: #ef5868;
  --warn: #f0b542;

  /* board */
  --sq-light: #e9edcc;
  --sq-dark: #6f9655;
  --sel: rgba(43, 213, 118, 0.55);
  --last: rgba(240, 181, 66, 0.38);
  --check: rgba(239, 88, 104, 0.65);

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 78% -8%, rgba(43, 213, 118, 0.10), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, rgba(63, 120, 255, 0.08), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Mobile-first: the app is a portrait phone column and fills the screen.
   On a real phone the device wrappers collapse (see "display: contents" below). */
.device, .device-screen { display: contents; }
.device-notch { display: none; }

.app {
  min-height: 100vh;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;          /* no scrolling: the board shrinks to fit instead */
  display: flex;
  flex-direction: column;
  width: 100%;
  margin: 0 auto;
  padding: 0 14px;
}

.hidden { display: none !important; }

/* ---------------- Top bar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top, 16px)) 4px 14px;
}
.brand { display: flex; align-items: baseline; gap: 6px; font-weight: 700; letter-spacing: 0.2px; }
.brand-mark { font-size: 20px; line-height: 1; color: var(--accent); transform: translateY(2px); }
.brand-name { font-size: 16px; }
.brand-accent { color: var(--accent); }
.brand-tag {
  font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 2px; padding-left: 2px;
}
.conn {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 999px;
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); }
.conn[data-state="connecting"] .conn-dot { background: var(--warn); animation: pulse 1.1s infinite; }
.conn[data-state="connected"] .conn-dot { background: var(--accent); }
.conn[data-state="error"] .conn-dot { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------------- Main / screens ---------------- */
.main { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: flex-start; padding: 6px 0 8px; }
.screen { animation: fade 0.4s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------- Lobby ---------------- */
/* Lobby: vertically center the whole stack so there's no dead space at the bottom */
#lobby { flex: 1; display: flex; flex-direction: column; justify-content: center; }

.hero { text-align: center; margin: 0 0 96px; }
.hero-title { font-size: clamp(28px, 9vw, 38px); line-height: 1.12; margin: 0 0 12px; font-weight: 750; letter-spacing: -0.5px; }
.hero-title em { color: var(--accent); font-style: normal; }
.hero-sub { color: var(--muted); font-size: 15px; max-width: 520px; margin: 0 auto; line-height: 1.55; }

.lobby-cta { width: 100%; max-width: 360px; margin: 0 auto; }
.cta-2 { margin-top: 18px; }

/* Real Match panel: even vertical rhythm so rows aren't squished */
#realPanel { display: flex; flex-direction: column; gap: 16px; }
#realPanel .card-title { margin: 0; }
#realPanel .muted { margin: 0; }
#realPanel .or { margin: 2px 0; }
#realPanel #realBackBtn { margin: 2px 0 0; }

/* Invite panel: focused, join-only screen for people who arrived via a link */
#invitePanel { display: flex; flex-direction: column; gap: 16px; text-align: center; }
#invitePanel .card-title { margin: 0; }
#invitePanel .muted { margin: 0; }
#invitePanel .code-box { margin: 0; justify-content: center; }
#invitePanel .code-value { flex: none; }
.invite-mark {
  font-size: 40px; line-height: 1; color: var(--accent);
  align-self: center; margin-bottom: 2px;
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card-title { margin: 0 0 6px; font-size: 18px; }

.field { display: block; margin-bottom: 18px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; }

.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--muted-2); }

.lobby-actions { display: flex; flex-direction: column; gap: 14px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted-2); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.or::before, .or::after { content: ""; height: 1px; background: var(--border); flex: 1; }
.join-row { display: flex; gap: 10px; }
.join-row .input { flex: 1; }

.hint { color: var(--muted-2); font-size: 12.5px; line-height: 1.5; margin: 16px 0 0; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 0 0 16px; }

/* buttons */
.btn {
  font-family: inherit; font-size: 15px; font-weight: 600;
  border-radius: var(--radius-sm); padding: 12px 18px;
  border: 1px solid transparent; cursor: pointer;
  transition: transform 0.06s, background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn-primary { background: var(--accent); color: #06231a; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-text { background: none; color: var(--muted); padding: 8px; }
.btn-text:hover { color: var(--text); }

/* waiting panel */
.code-box {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--bg); border: 1px dashed var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 12px;
}
.code-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.code-value { font-size: 20px; font-weight: 700; letter-spacing: 1px; color: var(--accent); flex: 1; word-break: break-all; }
.link-box { display: flex; gap: 10px; margin-bottom: 18px; }
.link-box .input { flex: 1; font-size: 13px; color: var(--muted); }
.waiting-state { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.feature-strip {
  list-style: none; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  padding: 0; margin: 34px auto 0; max-width: 640px;
}
.feature-strip li {
  font-size: 13px; color: var(--muted); background: var(--panel);
  border: 1px solid var(--border); border-radius: 999px; padding: 7px 14px;
}

/* ---------------- Game ---------------- */
/* Portrait phone layout always: video tiles in a row on top, board below,
   controls at the bottom. The game screen fills the available height and the
   board shrinks to fit, so there is never any vertical scrolling. */
#game { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.game-layout {
  flex: 1; min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}
.board-col { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; }

.status-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 999px; padding: 9px 16px; font-size: 14.5px; font-weight: 600;
  min-width: 260px; justify-content: center;
}
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted-2); }
.status-dot.white { background: #f3f4ea; border: 1px solid #cfd2c0; }
.status-dot.black { background: #1d2230; border: 1px solid #3a4252; }
.status-dot.over { background: var(--accent); }

/* video rail — two tiles side by side at the top */
.rail { display: flex; flex-direction: row; gap: 10px; }
.tile {
  position: relative; flex: 1; min-width: 0; aspect-ratio: 5 / 4; background: #05070a;
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.tile-video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); background: #05070a; }
#oppVideo { transform: none; }
.tile-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 40%, #1b2433, #0a0e15);
}
.avatar {
  width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  color: #06231a; display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700; text-transform: uppercase;
}
.tile-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; gap: 8px;
  background: linear-gradient(0deg, rgba(0,0,0,0.72), transparent);
}
.tile-name { font-size: 13px; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,0.6); }
.tile-badges { display: flex; gap: 6px; align-items: center; }
.badge {
  font-size: 11px; background: rgba(0,0,0,0.45); border: 1px solid rgba(255,255,255,0.14);
  padding: 3px 8px; border-radius: 999px;
}
.badge-mic.muted { background: var(--danger); border-color: transparent; }
.badge-mic.muted::after { content: " off"; }

/* board */
.board-wrap {
  position: relative; flex: 1; min-height: 0; width: 100%;
  display: flex; align-items: center; justify-content: center;
}
.board {
  position: relative;            /* containing block for the move-animation overlay */
  width: 100%; max-width: 440px; aspect-ratio: 1;   /* JS fit() sets an exact px square */
  container-type: inline-size;   /* so pieces size to the board, not the viewport */
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 10px; overflow: hidden;
  box-shadow: var(--shadow), 0 0 0 1px var(--border);
  touch-action: manipulation;
}
.square {
  position: relative; display: flex; align-items: center; justify-content: center;
  user-select: none; cursor: default;
}
.square.light { background: var(--sq-light); }
.square.dark { background: var(--sq-dark); }
.board.interactive .square.has-mine { cursor: pointer; }
.square.sel::after {
  content: ""; position: absolute; inset: 0; background: var(--sel); mix-blend-mode: multiply;
}
.square.last::before {
  content: ""; position: absolute; inset: 0; background: var(--last);
}
.square.check .piece { box-shadow: 0 0 0 999px var(--check) inset; border-radius: 50%; }

.coord { position: absolute; font-size: 10px; font-weight: 700; opacity: 0.6; }
.coord.file { right: 4px; bottom: 2px; }
.coord.rank { left: 3px; top: 2px; }
.square.light .coord { color: #6f9655; }
.square.dark .coord { color: #e9edcc; }

.piece {
  position: relative; z-index: 2;
  font-size: 10.5cqw; line-height: 1;   /* 10.5% of board width = scales with the board */
  cursor: pointer;
  transition: transform 0.08s;
}
.piece.w { color: #ffffff; text-shadow: 0 1px 1px rgba(0,0,0,0.35), 0 0 2px rgba(0,0,0,0.55); }
.piece.b { color: #20242c; text-shadow: 0 1px 1px rgba(255,255,255,0.18); }
.piece:active { transform: scale(1.06); }

/* moving-piece slide + light trail (long-exposure style) */
.fly, .trail {
  position: absolute; z-index: 6; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
}
.fly { z-index: 7; }
.fly .piece {
  will-change: transform;
  filter: drop-shadow(0 0 5px rgba(43, 213, 118, 0.55));
}
.trail { opacity: 0.5; transition: opacity 0.32s ease; }
.trail .piece {
  filter: drop-shadow(0 0 5px rgba(43, 213, 118, 0.9)) drop-shadow(0 0 12px rgba(43, 213, 118, 0.5));
}

/* legal-move dots */
.dot {
  position: absolute; z-index: 1; width: 30%; height: 30%; border-radius: 50%;
  background: rgba(20, 25, 20, 0.32);
}
.square.light .dot { background: rgba(80, 110, 60, 0.5); }
.dot.capture {
  width: 86%; height: 86%; background: transparent; border-radius: 50%;
  box-shadow: 0 0 0 6px rgba(20, 25, 20, 0.28) inset;
}
.square.light .dot.capture { box-shadow: 0 0 0 6px rgba(80, 110, 60, 0.45) inset; }

/* overlays on the board */
.overlay-pick {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(6, 9, 14, 0.74); backdrop-filter: blur(3px); border-radius: 10px; z-index: 5;
}
.promo-card, .result-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 26px; text-align: center; box-shadow: var(--shadow); max-width: 86%;
}
.promo-card p { margin: 0 0 14px; color: var(--muted); }
.promo-options { display: flex; gap: 8px; }
.promo-pick {
  width: 58px; height: 58px; font-size: 38px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; color: #fff; transition: border-color 0.12s, transform 0.06s;
}
.promo-pick:hover { border-color: var(--accent); }
.promo-pick:active { transform: translateY(1px); }
.result-card h2 { margin: 0 0 8px; font-size: 26px; }
.result-card p { margin: 0 0 18px; color: var(--muted); }
.result-actions { display: flex; gap: 10px; justify-content: center; }

/* bottom control bar — two actions only */
.controls { display: flex; gap: 10px; margin-top: 16px; }
.action {
  flex: 1; font-family: inherit; font-size: 16px; font-weight: 600;
  padding: 14px 16px; border-radius: 14px; border: none; cursor: pointer;
  transition: transform 0.06s, background 0.15s, opacity 0.15s;
}
.action:active { transform: translateY(1px); }
.action:disabled { opacity: 0.4; cursor: default; }
.action-primary { background: var(--accent); color: #06231a; }
.action-primary:hover:not(:disabled) { background: var(--accent-2); }
.action-primary.action-danger { background: var(--danger); color: #2a0a0e; }
.action-exit {
  flex: 0 0 auto; min-width: 96px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
}
.action-exit:hover { border-color: var(--accent); }

/* ---------------- Footer + toast ---------------- */
.footer {
  display: flex; align-items: center; justify-content: center;
  padding: 4px; color: var(--muted-2); font-size: 12.5px;
}
.footer:empty, .footer-note:empty { display: none; }
/* iOS-style notification banner */
.toast {
  position: fixed; left: 50%; bottom: 128px; transform: translateX(-50%);
  width: calc(100% - 24px); max-width: 380px;
  display: flex; align-items: center; gap: 11px;
  background: rgba(28, 30, 36, 0.72);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  border: 0.5px solid rgba(255, 255, 255, 0.14);
  color: #f2f3f5; padding: 12px 14px; border-radius: 20px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
  z-index: 50; font-size: 14px; line-height: 1.35;
  animation: toast-in 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}
.toast-icon {
  flex: none; width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  color: #06231a; font-size: 17px;
}
.toast-text { flex: 1; text-align: left; }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------- Demo mode ---------------- */
.btn-lg { padding: 16px 20px; font-size: 17px; }
.demo-sub { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 10px 2px 0; text-align: center; }

.badge-demo { background: var(--warn); color: #241a04; border-color: transparent; font-weight: 700; }

.takeover { margin: -2px auto 0; }

/* opponent "speaking" equalizer (demo presence) */
.speaking {
  position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%);
  display: flex; align-items: flex-end; gap: 3px; height: 16px;
}
.speaking i {
  width: 3px; height: 5px; border-radius: 2px; background: var(--accent);
  animation: eq 1s ease-in-out infinite;
}
.speaking i:nth-child(2) { animation-delay: 0.18s; }
.speaking i:nth-child(3) { animation-delay: 0.36s; }
.speaking i:nth-child(4) { animation-delay: 0.12s; }
.speaking i:nth-child(5) { animation-delay: 0.30s; }
@keyframes eq { 0%, 100% { height: 5px; } 50% { height: 16px; } }

/* mic + camera controls overlaid on your own tile (iOS-style) */
.tile-controls {
  position: absolute; top: 8px; right: 8px; z-index: 4; display: flex; gap: 6px;
}
.tile-ctrl {
  position: relative; width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 12, 16, 0.55);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 0.5px solid rgba(255, 255, 255, 0.18); color: #fff;
  font-size: 14px; line-height: 1; cursor: pointer; transition: background 0.12s;
}
.tile-ctrl:hover { background: rgba(10, 12, 16, 0.8); }
.tile-ctrl.off { background: var(--danger); border-color: transparent; }
.tile-ctrl.off::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 2px; height: 18px; background: #fff; border-radius: 2px;
  transform: translate(-50%, -50%) rotate(45deg);
}

/* ---------------- Responsive ---------------- */

/* very narrow phones: tighten the control bar */
@media (max-width: 380px) {
  .controls { gap: 8px; }
  .action { padding: 13px 12px; font-size: 15px; }
}

/* Desktop / tablet: wrap the app in a phone frame, centered on the page.
   On a real phone (below this width) there is no frame and the app is full-bleed. */
@media (min-width: 760px) {
  body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 24px 16px;
  }
  /* Size by HEIGHT and keep a true phone aspect ratio, so the frame never looks
     "fat" on a short laptop viewport (width derives from height). */
  .device {
    display: block; position: relative;
    height: min(880px, 94vh);
    aspect-ratio: 390 / 844;
    width: auto;
    background: linear-gradient(160deg, #1a2130, #06080c);
    border-radius: 11% / 5.1%; padding: 0.34%;   /* thin bezel */
    box-shadow: 0 40px 90px rgba(0, 0, 0, 0.6), 0 0 0 1px #2b3344;
  }
  .device-notch {
    display: block; position: absolute; z-index: 40;
    top: 0.34%; left: 50%; transform: translateX(-50%);
    width: 32%; height: 22px; background: #05070a; border-radius: 0 0 14px 14px;
  }
  .device-screen {
    display: block; position: relative;
    width: 100%; height: 100%;
    background: var(--bg); border-radius: 8% / 3.7%; overflow: hidden;
  }
  .app {
    height: 100%; min-height: 0; overflow: hidden;
    padding: 0 16px;
  }
  /* push content below the notch so it never overlaps the brand / status pill */
  .topbar { padding-top: 24px; }
  .toast { position: absolute; bottom: 122px; }   /* inside the phone, clear of the controls */
}
