/* ============================================================
   CONNECT 4 — VIBRANT GAME UI
   Mobile-first, fun, colourful, always visible controls
   ============================================================ */

/* ---------- TOKENS ---------- */
:root {
  --red:        #ff3b3b;
  --red-dark:   #cc1f1f;
  --red-glow:   rgba(255,59,59,.45);
  --red-soft:   rgba(255,59,59,.12);

  --yellow:     #ffc107;
  --yellow-dark:#c98000;
  --yellow-glow:rgba(255,193,7,.45);
  --yellow-soft:rgba(255,193,7,.12);

  --board-bg:   #1a3a6e;
  --board-rim:  #0f2654;
  --hole-bg:    #0d1f45;

  --bg:         #eef1ff;
  --surface:    #ffffff;
  --surface2:   #e6eaff;
  --border:     #cdd4f0;
  --text:       #1a1d2e;
  --text2:      #5a6088;
  --text3:      #9aa0c0;

  --radius:     14px;
  --radius-sm:  8px;
  --radius-lg:  22px;
  --radius-xl:  30px;

  --shadow-sm:  0 2px 8px rgba(0,0,40,.1);
  --shadow:     0 4px 20px rgba(0,0,40,.13);
  --shadow-lg:  0 16px 60px rgba(0,0,40,.2);

  --font:  'Fredoka', sans-serif;
  --mono:  'Space Mono', monospace;

  --cell:  72px;
  --gap:   10px;
  --bpad:  18px;

  --ease:   cubic-bezier(.4,0,.2,1);
  --spring: cubic-bezier(.34,1.56,.64,1);
}

body.dark {
  --bg:       #0e1020;
  --surface:  #181b30;
  --surface2: #222640;
  --border:   rgba(255,255,255,.1);
  --text:     #eef0ff;
  --text2:    #8890b8;
  --text3:    #404878;
  --board-bg: #163278;
  --board-rim:#0c1e50;
  --hole-bg:  #080f28;
  --shadow-sm:0 2px 8px rgba(0,0,0,.5);
  --shadow:   0 4px 20px rgba(0,0,0,.5);
  --shadow-lg:0 20px 70px rgba(0,0,0,.65);
}

/* ---------- RESET ---------- */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{height:100%;-webkit-text-size-adjust:100%}
body{
  font-family:var(--font);
  background:var(--bg);
  color:var(--text);
  min-height:100vh;
  transition:background .3s,color .3s;
}
button{font-family:var(--font);cursor:pointer;border:none;background:none}
button:disabled{opacity:.4;cursor:not-allowed !important;pointer-events:none}

/* ============================================================
   HEADER
   ============================================================ */
.header{
  display:flex;align-items:center;justify-content:space-between;
  padding:12px 24px;
  background:var(--surface);
  border-bottom:2px solid var(--border);
  box-shadow:var(--shadow-sm);
  position:sticky;top:0;z-index:50;
}

.header-logo{display:flex;align-items:center;gap:8px}
.lc{
  display:inline-block;width:16px;height:16px;border-radius:50%;flex-shrink:0;
}
.lc-r{background:var(--red);box-shadow:0 0 10px var(--red-glow)}
.lc-y{background:var(--yellow);box-shadow:0 0 8px var(--yellow-glow)}
.logo-text{font-size:22px;font-weight:500;letter-spacing:.3px;color:var(--text)}
.logo-text strong{
  font-weight:700;
  background:linear-gradient(135deg,var(--red),var(--yellow));
  -webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text;
}

.header-scores{display:flex;align-items:center;gap:10px}
.score-chip{
  display:flex;align-items:center;gap:7px;
  padding:7px 14px;border-radius:999px;font-size:15px;font-weight:600;
  border:2px solid var(--border);background:var(--surface2);
  transition:border-color .2s;
}
.you-chip{border-color:rgba(255,59,59,.35)}
.ai-chip {border-color:rgba(255,193,7,.45)}
.sc-disc{width:14px;height:14px;border-radius:50%;flex-shrink:0}
.red-disc   {background:radial-gradient(circle at 35% 30%,#ff9090,var(--red) 58%,var(--red-dark))}
.yellow-disc{background:radial-gradient(circle at 35% 30%,#ffe48a,var(--yellow) 58%,var(--yellow-dark))}
.sc-label{font-size:11px;font-weight:700;letter-spacing:1px;color:var(--text2)}
.sc-num{
  font-size:20px;font-weight:700;min-width:22px;text-align:center;
  transition:transform .3s var(--spring);
}
.you-chip .sc-num{color:var(--red)}
.ai-chip  .sc-num{color:var(--yellow-dark)}
.sc-num.pop{animation:scPop .4s var(--spring)}
@keyframes scPop{0%,100%{transform:scale(1)}50%{transform:scale(1.7)}}
.score-sep{font-size:13px;color:var(--text3);font-weight:700}

.theme-btn{
  width:38px;height:38px;display:flex;align-items:center;justify-content:center;
  border-radius:var(--radius-sm);border:2px solid var(--border);
  color:var(--text2);background:var(--surface2);transition:all .2s;
}
.theme-btn:hover{background:var(--border);color:var(--text)}

/* ============================================================
   MAIN LAYOUT — desktop: sidebar | board | sidebar
   ============================================================ */
.layout{
  display:flex;flex:1;overflow-x:hidden;
  min-height:0;
}

/* ============================================================
   SIDEBARS
   ============================================================ */
.sidebar{
  width:220px;flex-shrink:0;
  display:flex;flex-direction:column;gap:12px;
  padding:20px 14px;
  background:var(--surface);
  border-right:2px solid var(--border);
  overflow-y:auto;
}
.sidebar-right{
  border-right:none;
  border-left:2px solid var(--border);
}
.sidebar::-webkit-scrollbar{width:4px}
.sidebar::-webkit-scrollbar-thumb{background:var(--border);border-radius:2px}

/* ============================================================
   PANELS
   ============================================================ */
.panel{
  background:var(--surface2);
  border:2px solid var(--border);
  border-radius:var(--radius);
  padding:14px;
  display:flex;flex-direction:column;gap:10px;
}
.panel-title{
  font-size:11px;font-weight:700;letter-spacing:1.5px;
  text-transform:uppercase;color:var(--text2);
}

/* ---------- PLAY BUTTONS ---------- */
.play-btn{
  display:flex;align-items:center;gap:12px;
  padding:12px 14px;border-radius:var(--radius);
  border:2.5px solid transparent;
  font-size:14px;font-weight:600;
  background:var(--surface);
  transition:all .2s var(--ease);text-align:left;
}
.play-red{border-color:rgba(255,59,59,.35);color:var(--red)}
.play-red:hover:not(:disabled){
  background:var(--red-soft);border-color:var(--red);
  transform:translateY(-2px);box-shadow:0 6px 20px var(--red-glow);
}
.play-yellow{border-color:rgba(255,193,7,.5);color:var(--yellow-dark)}
.play-yellow:hover:not(:disabled){
  background:var(--yellow-soft);border-color:var(--yellow);
  transform:translateY(-2px);box-shadow:0 6px 20px var(--yellow-glow);
}
.pb-disc{width:28px;height:28px;border-radius:50%;flex-shrink:0}
.pb-text{display:flex;flex-direction:column;gap:2px}
.pb-main{font-size:14px;font-weight:700}
.pb-sub{font-size:11px;font-weight:400;opacity:.7}

/* ---------- DIFFICULTY ---------- */
.diff-slider{
  -webkit-appearance:none;width:100%;height:6px;border-radius:3px;
  background:linear-gradient(to right,#22c55e,var(--yellow),var(--red));
  outline:none;
}
.diff-slider::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:20px;height:20px;border-radius:50%;
  background:var(--surface);border:3px solid var(--yellow);
  box-shadow:var(--shadow-sm);
  transition:transform .2s var(--spring);
}
.diff-slider::-webkit-slider-thumb:hover{transform:scale(1.25)}
.diff-row{
  display:flex;justify-content:space-between;align-items:center;
  font-size:12px;color:var(--text2);
}
.diff-end{font-size:11px;color:var(--text3)}
.diff-val{
  font-weight:700;color:var(--text);font-size:13px;
  background:var(--surface);border:2px solid var(--border);
  border-radius:999px;padding:2px 10px;
}

/* ---------- CONTROL BUTTONS ---------- */
.ctrl-btn{
  display:flex;align-items:center;justify-content:center;gap:8px;
  padding:10px 16px;border-radius:var(--radius-sm);
  font-size:13px;font-weight:600;
  transition:all .2s;border:2px solid transparent;
}
.btn-green{
  background:linear-gradient(135deg,#22c55e,#16a34a);
  color:#fff;box-shadow:0 3px 12px rgba(34,197,94,.35);
}
.btn-green:hover:not(:disabled){transform:translateY(-1px);box-shadow:0 6px 18px rgba(34,197,94,.5)}
.btn-outline{
  background:var(--surface);border-color:var(--border);color:var(--text2);
}
.btn-outline:hover:not(:disabled){background:var(--surface2);color:var(--text);border-color:var(--text3)}
.btn-danger{
  background:var(--surface);border-color:rgba(255,59,59,.35);color:var(--red);
}
.btn-danger:hover:not(:disabled){background:var(--red-soft);border-color:var(--red)}

/* ---------- EDITOR ---------- */
.editor-hint{font-size:12px;color:var(--text2);line-height:1.5}
.editor-toggle{display:flex;gap:6px}
.etoggle{
  flex:1;padding:7px;border-radius:var(--radius-sm);
  font-size:12px;font-weight:600;
  border:2px solid var(--border);color:var(--text2);background:var(--surface);
  cursor:pointer;transition:all .15s;
}
.etoggle.active{
  background:var(--surface2);border-color:var(--text3);color:var(--text);
}

/* ---------- PLAYER CARDS (right sidebar) ---------- */
.player-card-panel{
  flex-direction:row;align-items:center;gap:10px;
  transition:border-color .2s,background .2s;
}
.pcp-disc{width:36px;height:36px;border-radius:50%;flex-shrink:0}
.pcp-info{flex:1;min-width:0}
.pcp-name{font-size:15px;font-weight:700;color:var(--text)}
.pcp-role{font-size:11px;color:var(--text2)}
.pcp-arrow{
  font-size:18px;opacity:0;transition:opacity .2s;color:var(--text3);
}
.player-card-panel.active-red{border-color:var(--red);background:var(--red-soft)}
.player-card-panel.active-red .pcp-arrow{opacity:1;color:var(--red);content:'▶'}
.player-card-panel.active-yellow{border-color:var(--yellow);background:var(--yellow-soft)}
.player-card-panel.active-yellow .pcp-arrow{opacity:1;color:var(--yellow-dark)}

/* ---------- AI THINKING ---------- */
.thinking-panel{flex-direction:row;align-items:center;gap:10px}
.think-dots{display:flex;gap:5px}
.think-dots span{
  width:8px;height:8px;border-radius:50%;background:var(--yellow);
  animation:thinkBounce 1.1s ease-in-out infinite;
}
.think-dots span:nth-child(2){animation-delay:.18s}
.think-dots span:nth-child(3){animation-delay:.36s}
@keyframes thinkBounce{
  0%,80%,100%{transform:scale(.6);opacity:.35}
  40%{transform:scale(1.3);opacity:1}
}
.think-label{font-size:13px;font-weight:600;color:var(--yellow-dark)}

/* ---------- AI MOVE PANEL ---------- */
.ai-move-row{display:flex;align-items:center;justify-content:space-between}
.ai-move-col{font-size:28px;font-weight:700;color:var(--yellow-dark);font-family:var(--mono)}
.ai-move-score{font-size:12px;color:var(--text2);font-family:var(--mono)}

/* ---------- MOVE HISTORY ---------- */
.history-panel{flex:1;min-height:60px}
.history-list{
  display:flex;flex-direction:column;gap:3px;
  max-height:220px;overflow-y:auto;
}
.history-list::-webkit-scrollbar{width:3px}
.history-list::-webkit-scrollbar-thumb{background:var(--border)}
.hist-item{
  display:flex;align-items:center;gap:7px;
  padding:4px 8px;border-radius:6px;
  background:var(--surface);
  font-size:11px;color:var(--text2);
  font-family:var(--mono);
  animation:histSlide .2s var(--ease);
}
@keyframes histSlide{from{opacity:0;transform:translateX(6px)}to{opacity:1;transform:none}}
.hist-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}
.hist-dot.red{background:var(--red)}
.hist-dot.yellow{background:var(--yellow)}

/* ============================================================
   BOARD SECTION
   ============================================================ */
.board-wrap{
  flex:1;min-width:0;
  display:flex;flex-direction:column;
  align-items:center;justify-content:center;
  padding:24px 16px;gap:10px;
  background:
    radial-gradient(ellipse at 20% 60%,rgba(255,59,59,.07),transparent 50%),
    radial-gradient(ellipse at 80% 40%,rgba(255,193,7,.07),transparent 50%),
    var(--bg);
}

/* Turn pill */
.turn-bar{display:flex;justify-content:center}
.turn-pill{
  display:inline-flex;align-items:center;gap:9px;
  padding:8px 20px;border-radius:999px;
  background:var(--surface);border:2px solid var(--border);
  box-shadow:var(--shadow-sm);
  font-size:14px;font-weight:600;color:var(--text);
  transition:border-color .25s,box-shadow .25s;
  white-space:nowrap;
}
.turn-pill.red-turn{
  border-color:var(--red);
  box-shadow:0 0 0 4px var(--red-soft),var(--shadow-sm);
}
.turn-pill.yellow-turn{
  border-color:var(--yellow);
  box-shadow:0 0 0 4px var(--yellow-soft),var(--shadow-sm);
}
.tp-disc{width:16px;height:16px;border-radius:50%;flex-shrink:0;transition:background .2s}

/* Drop preview row */
.drop-row{
  display:grid;
  grid-template-columns:repeat(7,var(--cell));
  gap:var(--gap);
}
.drop-slot{
  height:var(--cell);
  display:flex;align-items:center;justify-content:center;
  cursor:pointer;position:relative;border-radius:50%;
}
.drop-slot::before{
  content:'';position:absolute;
  width:calc(var(--cell) - 14px);
  height:calc(var(--cell) - 14px);
  border-radius:50%;border:3px dashed transparent;
  transition:all .18s;
}
.drop-slot.preview-red::before{
  border-color:var(--red);background:var(--red-soft);
  box-shadow:0 0 18px var(--red-glow);
}
.drop-slot.preview-yellow::before{
  border-color:var(--yellow);background:var(--yellow-soft);
  box-shadow:0 0 18px var(--yellow-glow);
}

/* Board frame */
.board-outer{
  position:relative;
  padding:var(--bpad);
  background:var(--board-bg);
  border-radius:var(--radius-xl);
  border:4px solid var(--board-rim);
  box-shadow:
    0 8px 0 var(--board-rim),
    0 14px 50px rgba(0,0,80,.4),
    inset 0 1px 0 rgba(255,255,255,.12);
}

.board-grid{
  display:grid;
  grid-template-columns:repeat(7,var(--cell));
  grid-template-rows:repeat(6,var(--cell));
  gap:var(--gap);
  position:relative;z-index:1;
}

/* Column hit zones — overlay the board for click/hover */
.col-hit-zones{
  position:absolute;inset:0;
  display:grid;grid-template-columns:repeat(7,1fr);
  border-radius:var(--radius-xl);overflow:hidden;
  z-index:2;pointer-events:none;
}
.col-zone{pointer-events:auto;cursor:pointer;transition:background .15s}
.col-zone:hover{background:rgba(255,255,255,.07)}
.col-hit-zones.inactive .col-zone{pointer-events:none}

/* Cell */
.cell{
  width:var(--cell);height:var(--cell);border-radius:50%;
  position:relative;overflow:hidden;
  background:var(--hole-bg);
  box-shadow:inset 0 4px 14px rgba(0,0,0,.55),inset 0 -2px 4px rgba(255,255,255,.04);
}
/* top-left shine */
.cell::after{
  content:'';position:absolute;
  top:8%;left:12%;width:34%;height:26%;
  border-radius:50%;
  background:rgba(255,255,255,.11);
  pointer-events:none;z-index:3;
}

/* Disc */
.disc{
  position:absolute;inset:3px;border-radius:50%;
  /* No default transform — discs sit visible at position 0 */
  /* Empty discs are invisible via no background */
  z-index:1;
}
/* Animate drop: disc slides in from above */
.cell.drop-animate .disc{
  animation:discDrop .32s cubic-bezier(.68,-.55,.265,1.35) both;
}
@keyframes discDrop{
  from{transform:translateY(-200%)}
  to{transform:translateY(0)}
}
.disc.red{
  background:radial-gradient(circle at 35% 28%,#ff9090,var(--red) 55%,var(--red-dark));
  box-shadow:inset 0 -4px 8px rgba(0,0,0,.3),0 2px 16px var(--red-glow);
}
.disc.yellow{
  background:radial-gradient(circle at 35% 28%,#ffe88a,var(--yellow) 55%,var(--yellow-dark));
  box-shadow:inset 0 -4px 8px rgba(0,0,0,.3),0 2px 16px var(--yellow-glow);
}

/* Win highlight */
.cell.win-cell{animation:winPulse .55s var(--spring) both}
@keyframes winPulse{
  0%,100%{transform:scale(1)}
  50%{transform:scale(1.14)}
}
.cell.win-cell .disc{
  filter:brightness(1.15);
}

/* ============================================================
   WIN OVERLAY
   ============================================================ */
.overlay{
  position:fixed;inset:0;z-index:200;
  display:flex;align-items:center;justify-content:center;
  background:rgba(10,12,30,.75);
  backdrop-filter:blur(10px);
  animation:fadeIn .3s var(--ease);
}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
.overlay-box{
  display:flex;flex-direction:column;align-items:center;
  gap:12px;text-align:center;
  padding:44px 52px;
  background:var(--surface);
  border:3px solid var(--border);
  border-radius:var(--radius-xl);
  box-shadow:var(--shadow-lg);
  animation:boxPop .45s var(--spring);
}
@keyframes boxPop{
  from{opacity:0;transform:scale(.8) translateY(20px)}
  to{opacity:1;transform:scale(1) translateY(0)}
}
.ov-disc{
  width:64px;height:64px;border-radius:50%;
  animation:discSpin .6s var(--spring);
}
@keyframes discSpin{
  from{transform:scale(0) rotate(-180deg)}
  to{transform:scale(1) rotate(0)}
}
.ov-disc.red-disc{
  background:radial-gradient(circle at 35% 28%,#ff9090,var(--red) 55%,var(--red-dark));
  box-shadow:0 0 40px var(--red-glow);
}
.ov-disc.yellow-disc{
  background:radial-gradient(circle at 35% 28%,#ffe88a,var(--yellow) 55%,var(--yellow-dark));
  box-shadow:0 0 40px var(--yellow-glow);
}
.ov-emoji{font-size:36px;line-height:1}
.ov-title{font-size:36px;font-weight:700;color:var(--text)}
.ov-sub{font-size:15px;color:var(--text2);font-weight:500}
.ov-btns{display:flex;gap:10px;margin-top:6px}
.ov-btns .ctrl-btn{min-width:130px}
.etoggle {
  display: flex;
  align-items: center;
  gap: 7px;
}

.etoggle-disc {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Narrow desktop */
@media (max-width:1100px){
  :root{--cell:62px;--gap:9px;--bpad:14px}
  .sidebar{width:196px}
}

@media (max-width:900px){
  :root{--cell:52px;--gap:8px;--bpad:12px}
  .sidebar{width:170px;padding:14px 10px}
  .history-panel,.thinking-panel,.ai-move-panel{display:none}
}

/* ---- MOBILE (≤ 680px) ---- */
@media (max-width:680px){
  /* board cell size set dynamically by JS; safe fallback */
  :root{--cell:38px;--gap:5px;--bpad:9px}

  body{overflow-x:hidden;overflow-y:auto}

  /* Header — compact */
  .header{padding:9px 14px;gap:8px}
  .logo-text{font-size:18px}
  .lc{width:12px;height:12px}
  .score-chip{padding:5px 10px}
  .sc-num{font-size:16px}
  .sc-label{font-size:10px}
  .score-sep{display:none}
  .theme-btn{width:34px;height:34px}

  /* Layout: vertical stack */
  .layout{
    flex-direction:column;
    overflow-x:hidden;
  }

  /* ---------- SIDEBARS become horizontal strips below/above board ---------- */
  .sidebar{
    width:100%;
    flex-direction:column;
    border-right:none !important;
    border-left:none !important;
    border-top:2px solid var(--border);
    padding:14px 14px;
    gap:10px;
    overflow:visible;
  }

  /* Left sidebar → below the board */
  .sidebar-left{order:2}

  /* Right sidebar → below left */
  .sidebar-right{order:3}

  /* Board goes first */
  .board-wrap{order:1}

  /* Board wrap: no excess vertical padding */
  .board-wrap{
    padding:14px 12px 10px;
    justify-content:flex-start;
    gap:8px;
    background:var(--bg);
  }

  /* Board frame */
  .board-outer{
    border-radius:var(--radius-lg);
    border-width:3px;
    box-shadow:0 6px 0 var(--board-rim),0 10px 32px rgba(0,0,80,.35);
  }

  /* Drop row matches cell size */
  .drop-row{grid-template-columns:repeat(7,var(--cell))}
  .drop-slot{height:var(--cell)}
  .drop-slot::before{
    width:calc(var(--cell) - 10px);
    height:calc(var(--cell) - 10px);
  }

  /* Board grid */
  .board-grid{
    grid-template-columns:repeat(7,var(--cell));
    grid-template-rows:repeat(6,var(--cell));
  }

  /* Left sidebar on mobile: make play buttons horizontal row */
  .sidebar-left .panel:first-child{
    flex-direction:column;gap:8px;
  }
  /* Play buttons side by side */
  .sidebar-left .panel:first-child .play-btn{
    flex-direction:row;align-items:center;
    padding:10px 12px;
  }

  /* Game controls panel: buttons in a 2-col grid */
  .sidebar-left .panel:last-child{
    flex-direction:row;flex-wrap:wrap;gap:8px;
  }
  .sidebar-left .panel:last-child .panel-title{
    width:100%;margin-bottom:-2px;
  }
  .sidebar-left .panel:last-child .ctrl-btn{
    flex:1;min-width:calc(50% - 4px);font-size:12px;padding:9px 8px;
  }

  /* Right sidebar: show thinking + last move + history in one row */
  .sidebar-right{
    flex-direction:row;flex-wrap:wrap;align-items:flex-start;gap:10px;
  }
  .thinking-panel{display:flex;flex:1;min-width:140px}
  .ai-move-panel{display:flex;flex:1;min-width:120px}
  .history-panel{
    display:flex;width:100%;
  }
  .history-list{max-height:80px}

  /* Overlay */
  .overlay-box{padding:28px 22px;margin:14px;border-radius:var(--radius-lg)}
  .ov-title{font-size:28px}
  .ov-disc{width:52px;height:52px}
  .ov-emoji{font-size:26px}
  .ov-btns{flex-direction:column;width:100%}
  .ov-btns .ctrl-btn{width:100%;justify-content:center}
}

/* Very small phones */
@media (max-width:380px){
  :root{--cell:34px;--gap:4px;--bpad:8px}
  .header{padding:8px 10px}
  .logo-text{font-size:16px}
}

/* Landscape phone */
@media (orientation:landscape) and (max-height:500px){
  :root{--cell:36px;--gap:5px;--bpad:8px}
  .header{padding:6px 16px}
  .layout{flex-direction:row}
  .sidebar-left{
    width:190px;
    border-right:2px solid var(--border) !important;
    border-top:none !important;
    order:0;padding:10px;
  }
  .sidebar-right{display:none}
  .board-wrap{order:1;padding:8px;gap:5px}
  .history-panel,.thinking-panel,.ai-move-panel{display:none}
}
