*{box-sizing:border-box}
:root{
  --bg:#07111f;
  --panel:#0b1728;
  --panel2:#0e1b2e;
  --line:#26364d;
  --text:#f7f2e8;
  --muted:#9aa8bb;
  --gold:#e9bd62;
  --accent:#2386ff;
  --sq-light:#eee5d5;
  --sq-dark:#8191a6;
}
html,body{
  margin:0;
  width:100%;
  min-width:320px;
  min-height:100%;
  background:var(--bg);
  color:var(--text);
  font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  -webkit-text-size-adjust:100%;
  overflow-x:hidden;
}
button{font:inherit}
.screen{display:none;min-height:100dvh}
.screen.active{display:block}

/* ---------- Lobby: shared ---------- */
.lobby-screen.active{display:grid;place-items:center;padding:28px 20px}
.lobby-card{width:min(100%,440px);text-align:center}
.brand-mark{
  width:92px;height:92px;margin:0 auto 14px;border-radius:24px;
  display:grid;place-items:center;border:1px solid rgba(233,189,98,.45);
  background:#0c1a2b;color:var(--gold);font-size:58px
}
.lobby-card h1{margin:0;font-size:44px}.lobby-card h1 span{color:var(--gold)}
.lobby-card p{margin:8px 0 26px;color:var(--muted);font-size:16px}
.menu{display:grid;gap:12px}
.menu button{
  min-height:54px;padding:0 18px;display:flex;align-items:center;justify-content:space-between;
  border:1px solid var(--line);border-radius:16px;background:var(--panel);color:var(--text);font-size:17px
}
.menu .primary{justify-content:center;background:#1265d8;border-color:#3f8fff;font-weight:800}
.menu button:disabled{opacity:.45}

/* =========================================================
   DESKTOP / LAPTOP VIEW — restore original desktop layout
   ========================================================= */
.game-screen.active{
  display:block;
  padding-bottom:0;
  background:radial-gradient(circle at 50% -15%,#13243a 0,transparent 35%),var(--bg);
}
.app-header{
  height:64px;
  padding:8px 16px;
  display:grid;
  grid-template-columns:44px 1fr auto;
  align-items:center;
  gap:10px;
  border-bottom:1px solid var(--line);
  background:#081321;
}
.header-btn{
  width:40px;height:40px;border:1px solid var(--line);border-radius:12px;
  background:#0d1a2b;color:var(--text);font-size:20px;display:grid;place-items:center
}
.brand{display:flex;align-items:center;justify-content:center;gap:7px;white-space:nowrap}
.brand-icon{color:var(--gold);font-size:26px}
.brand strong{font-size:18px;letter-spacing:.03em}
.brand em{font-style:normal;color:var(--gold)}
.header-actions{display:flex;gap:6px}

.match-shell{
  width:min(100% - 32px,1120px);
  margin:0 auto;
  padding:18px 0 24px;
  display:grid;
  grid-template-columns:minmax(520px,760px) minmax(250px,320px);
  grid-template-areas:
    "opponent panel"
    "board panel"
    "player panel";
  gap:0 18px;
  align-items:start;
}
.player-row{
  width:100%;
  min-height:58px;
  padding:8px 2px;
  display:grid;
  grid-template-columns:42px 1fr auto;
  align-items:center;
  gap:10px;
}
.player-row:first-child{grid-area:opponent}
.player-row:nth-of-type(3){grid-area:player}
.avatar{
  width:38px;height:38px;border-radius:50%;display:grid;place-items:center;
  font-weight:900;font-size:15px
}
.avatar-dark{background:#213149}
.avatar-light{background:#edf2f7;color:#0b1220}
.player-copy{display:flex;flex-direction:column}
.player-copy strong{font-size:15px}
.player-copy small{font-size:12px;color:var(--muted)}
.player-row:nth-of-type(3) .player-copy small{color:#4aa1ff}
.clock{
  min-width:82px;padding:8px 10px;border:1px solid #3a4b65;border-radius:11px;
  background:#0a1525;text-align:center;font-size:13px;font-weight:800
}
.active-clock{background:#0c3d7c;border-color:#0f59b8}

.board{
  grid-area:board;
  width:100%;
  max-width:760px;
  aspect-ratio:1/1;
  display:grid;
  grid-template-columns:repeat(8,minmax(0,1fr));
  grid-template-rows:repeat(8,minmax(0,1fr));
  margin:0;
  border:2px solid #5f718a;
  border-radius:6px;
  overflow:hidden;
  touch-action:manipulation;
  user-select:none;
}
.square{
  display:grid;place-items:center;min-width:0;min-height:0;margin:0;padding:0;border:0;border-radius:0;
  position:relative;overflow:hidden;font-size:clamp(30px,5.2vw,58px);line-height:1
}
.square.light{background:var(--sq-light)}
.square.dark{background:var(--sq-dark)}
.square.selected::after{
  content:"";position:absolute;inset:4px;border:3px solid #fff;border-radius:3px;
  box-shadow:0 0 0 2px rgba(35,134,255,.55) inset;pointer-events:none
}
.piece.black{color:#05090e;text-shadow:0 1px 0 rgba(255,255,255,.16)}
.piece.white{color:#fff;-webkit-text-stroke:1px #4d5a6b;text-shadow:0 1px 2px #223248}

.piece-panel{
  grid-area:panel;
  margin:58px 0 0;
  border:1px solid var(--line);
  border-radius:16px;
  overflow:hidden;
  background:rgba(10,23,40,.98);
  position:sticky;
  top:82px;
}
.piece-summary{
  padding:14px;
  display:grid;
  grid-template-columns:52px minmax(0,1fr);
  gap:10px;
  align-items:center;
}
.piece-icon{
  width:48px;height:48px;border-radius:10px;background:#101f33;
  display:grid;place-items:center;font-size:34px
}
.piece-copy h2{margin:0 0 4px;font-size:18px}
.piece-copy p{margin:0;color:var(--muted);font-size:13px}
.stats{
  grid-column:1/-1;
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:6px;
}
.stats div{padding:8px 4px;border-radius:9px;background:#091525;text-align:center}
.stats span{display:block;color:var(--muted);font-size:9px;font-weight:700}
.stats strong{display:block;margin-top:4px;font-size:15px}
.helper{
  margin:0;padding:11px 13px 13px;border-top:1px solid var(--line);
  color:#b8c2cf;font-size:12px;line-height:1.45
}

/* Desktop navigation stays compact and centered, as before */
.bottom-nav{
  position:static;
  width:min(760px,calc(100% - 40px));
  height:58px;
  margin:0 auto 24px;
  display:grid;
  grid-template-columns:repeat(5,minmax(0,1fr));
  border:1px solid var(--line);
  border-radius:14px;
  overflow:hidden;
  background:#091321;
}
.nav-item{
  min-width:0;border:0;border-right:1px solid rgba(42,58,82,.45);
  background:transparent;color:#c5ceda;
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px
}
.nav-item.active{color:#59a8ff;background:#0c2442;box-shadow:inset 0 2px 0 #2990ff}
.nav-item:disabled{opacity:.65}
.nav-icon{font-size:19px;line-height:1}
.nav-item small{font-size:8px;font-weight:800;text-transform:uppercase}

/* =========================================================
   MOBILE VIEW ONLY — large app-like layout from reference
   ========================================================= */
@media (max-width:767px){
  .game-screen.active{
    display:block;
    padding-bottom:calc(92px + env(safe-area-inset-bottom));
  }

  .app-header{
    min-height:82px;
    padding:12px 16px;
    grid-template-columns:56px 1fr auto;
    gap:12px;
  }
  .header-btn{
    width:52px;height:52px;border-radius:15px;font-size:27px;
  }
  .brand{gap:10px}
  .brand-icon{font-size:36px}
  .brand strong{font-size:28px}
  .header-actions{gap:10px}

  .match-shell{
    width:100%;
    max-width:none;
    margin:0;
    padding:14px 0 22px;
    display:block;
  }
  .player-row{
    width:100%;
    min-height:86px;
    padding:12px 20px;
    grid-template-columns:58px minmax(0,1fr) auto;
    gap:14px;
  }
  .avatar{width:54px;height:54px;font-size:23px}
  .player-copy strong{font-size:24px;line-height:1.05}
  .player-copy small{margin-top:5px;font-size:18px}
  .clock{
    min-width:124px;
    padding:12px 16px;
    border-radius:15px;
    font-size:21px;
  }

  .board{
    width:100vw;
    max-width:100%;
    aspect-ratio:1/1;
    margin:0;
    border-left:0;
    border-right:0;
    border-radius:0;
  }
  .square{font-size:clamp(42px,12.2vw,78px)}
  .square.selected::after{inset:5px;border-width:4px}

  .piece-panel{
    margin:14px 14px 0;
    position:static;
    border-radius:20px;
  }
  .piece-summary{
    padding:18px;
    grid-template-columns:74px minmax(0,1fr);
    gap:16px;
  }
  .piece-icon{
    width:68px;height:68px;border-radius:14px;font-size:49px
  }
  .piece-copy h2{font-size:27px}
  .piece-copy p{font-size:19px}
  .stats{
    grid-column:1/-1;
    grid-template-columns:repeat(3,1fr);
    gap:12px;
  }
  .stats div{padding:10px 6px}
  .stats span{font-size:15px}
  .stats strong{font-size:24px}
  .helper{padding:17px 20px 19px;font-size:18px}

  .bottom-nav{
    position:fixed;
    z-index:50;
    left:0;right:0;bottom:0;
    width:100%;
    height:calc(88px + env(safe-area-inset-bottom));
    margin:0;
    padding-bottom:env(safe-area-inset-bottom);
    border:0;
    border-top:1px solid var(--line);
    border-radius:0;
    background:rgba(9,19,33,.98);
    backdrop-filter:blur(14px);
  }
  .nav-item{gap:7px}
  .nav-item.active{box-shadow:inset 0 3px 0 #2990ff}
  .nav-icon{font-size:35px}
  .nav-item small{font-size:13px;letter-spacing:.02em}
}

/* Smaller mobile phones */
@media (max-width:420px){
  .app-header{
    min-height:74px;padding:10px 11px;
    grid-template-columns:50px 1fr auto;gap:7px
  }
  .header-btn{width:46px;height:46px;font-size:24px}
  .brand-icon{font-size:31px}
  .brand strong{font-size:23px}
  .header-actions{gap:6px}

  .player-row{
    min-height:76px;padding:10px 13px;
    grid-template-columns:50px minmax(0,1fr) auto;gap:10px
  }
  .avatar{width:46px;height:46px;font-size:19px}
  .player-copy strong{font-size:20px}
  .player-copy small{font-size:15px}
  .clock{min-width:98px;padding:10px 11px;font-size:16px}

  .square{font-size:clamp(36px,12.1vw,58px)}

  .piece-summary{
    grid-template-columns:62px minmax(0,1fr);
    padding:15px;gap:12px
  }
  .piece-icon{width:58px;height:58px;font-size:42px}
  .piece-copy h2{font-size:22px}
  .piece-copy p{font-size:16px}
  .stats{grid-column:1/-1;grid-template-columns:repeat(3,1fr);gap:8px}
  .stats span{font-size:12px}
  .stats strong{font-size:19px}
  .helper{padding:14px 16px 16px;font-size:15px}

  .bottom-nav{height:calc(80px + env(safe-area-inset-bottom))}
  .nav-icon{font-size:29px}
  .nav-item small{font-size:10px}
}

/* Mobile landscape still uses mobile structure */
@media (max-width:767px) and (orientation:landscape) and (max-height:560px){
  .bottom-nav{display:none}
  .game-screen.active{padding-bottom:0}
  .app-header{min-height:58px;padding-top:5px;padding-bottom:5px}
  .header-btn{width:42px;height:42px}
  .match-shell{padding-top:4px}
  .player-row{min-height:48px;padding:4px 12px}
  .avatar{width:38px;height:38px}
  .player-copy strong{font-size:16px}
  .player-copy small{font-size:12px}
  .clock{min-width:82px;padding:6px 8px;font-size:13px}
  .board{width:min(78vh,100vw);margin:0 auto;border-left:2px solid #5f718a;border-right:2px solid #5f718a;border-radius:6px}
  .piece-panel{width:min(78vh,calc(100% - 20px));margin:8px auto 0}
}
