@import url("https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Playfair+Display:wght@600;700&family=Space+Grotesk:wght@400;500;600;700&display=swap");

:root{
  color-scheme:dark;
  --bg:#07101f;
  --deep:#040915;
  --panel:rgba(15,29,52,.78);
  --solid:#101e35;
  --line:rgba(174,208,255,.16);
  --text:#eef5ff;
  --muted:#91a6c4;
  --gold:#f5c96a;
  --cyan:#63e2dd;
  --blue:#8db8ff;
  --light:#d7bf91;
  --dark:#517299;
  --shadow:0 22px 70px rgba(0,0,0,.37);
}

@media(prefers-color-scheme:light){
  :root{
    color-scheme:light;
    --bg:#e7eef8;
    --deep:#d5e0ee;
    --panel:rgba(249,252,255,.85);
    --solid:#f8fbff;
    --line:rgba(26,54,90,.15);
    --text:#14243e;
    --muted:#536884;
    --light:#e9d5aa;
    --dark:#6285a7;
    --shadow:0 20px 50px rgba(34,55,84,.18);
  }
}

:root[data-theme="light"]{
  color-scheme:light;
  --bg:#e7eef8;
  --deep:#d5e0ee;
  --panel:rgba(249,252,255,.85);
  --solid:#f8fbff;
  --line:rgba(26,54,90,.15);
  --text:#14243e;
  --muted:#536884;
}

*{box-sizing:border-box}

body{
  margin:0;
  min-width:320px;
  min-height:100vh;
  color:var(--text);
  background:
    radial-gradient(circle at 76% 8%,rgba(58,99,161,.28),transparent 28rem),
    radial-gradient(circle at 8% 82%,rgba(51,151,142,.15),transparent 25rem),
    linear-gradient(145deg,var(--bg),var(--deep));
  font-family:"Space Grotesk",-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
}

button,input{font:inherit}
button{color:inherit;cursor:pointer}
button:focus-visible,input:focus-visible{outline:3px solid var(--cyan);outline-offset:3px}

.app-shell{
  width:min(1540px,100%);
  margin:auto;
  padding:22px clamp(14px,3vw,42px) 38px;
}

.topbar,.opponent-strip,.panel,.board-frame{
  border:1px solid var(--line);
  background:var(--panel);
  box-shadow:var(--shadow);
  backdrop-filter:blur(18px);
}

.topbar{
  min-height:76px;
  padding:13px 17px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  border-radius:18px;
}

.brand{display:flex;align-items:center;gap:12px}

.brand-mark{
  display:grid;
  place-items:center;
  width:48px;
  height:48px;
  border:1px solid rgba(245,201,106,.6);
  border-radius:14px;
  color:#111727;
  background:linear-gradient(135deg,#fff2bd,var(--gold));
  font:700 29px "Playfair Display",Georgia,serif;
}

.eyebrow,.label{
  margin:0 0 3px;
  color:var(--gold);
  font:500 10px "DM Mono",monospace;
  letter-spacing:.13em;
}

h1,h2,p{margin-top:0}

h1{
  margin:0;
  font:600 clamp(20px,3vw,27px) "Playfair Display",Georgia,serif;
}

h2{
  margin:0;
  font:600 22px "Playfair Display",Georgia,serif;
}

.engine-badge{
  display:flex;
  align-items:center;
  gap:8px;
  padding:9px 11px;
  border:1px solid var(--line);
  border-radius:999px;
  color:var(--muted);
  font:500 11px "DM Mono",monospace;
  text-transform:uppercase;
}

.pulse,.live-dot,.status-orb{
  width:8px;
  height:8px;
  border-radius:50%;
  background:var(--cyan);
  box-shadow:0 0 12px var(--cyan);
}

.opponent-strip{
  display:flex;
  gap:14px;
  align-items:center;
  margin-top:15px;
  padding:14px 16px;
  border-radius:18px;
}

.portrait{
  flex:0 0 auto;
  display:grid;
  place-items:center;
  width:53px;
  height:53px;
  border:1px solid rgba(255,255,255,.28);
  border-radius:16px;
  color:#fff;
  box-shadow:inset 0 0 18px rgba(255,255,255,.15);
  font:700 28px "Playfair Display",Georgia,serif;
}

.portrait-scout{background:linear-gradient(135deg,#233950,#825e8e)}
.portrait-baker{background:linear-gradient(135deg,#8d442b,#e7a451)}
.portrait-archivist{background:linear-gradient(135deg,#333a51,#76879d)}
.portrait-pilot{background:linear-gradient(135deg,#234860,#57a4b2)}
.portrait-gardener{background:linear-gradient(135deg,#305742,#9fb64f)}

.opponent-copy{min-width:0}
.opponent-copy h2{font-size:20px}

.opponent-copy p:last-child{
  margin:4px 0 0;
  color:var(--muted);
  font-size:13px;
  line-height:1.35;
}

.change-bot,.secondary-btn,.text-button{
  border:1px solid var(--line);
  border-radius:11px;
  background:rgba(139,180,255,.07);
}

.change-bot{
  min-height:44px;
  margin-left:auto;
  padding:0 14px;
  white-space:nowrap;
  font-size:13px;
  font-weight:600;
}

.change-bot:hover,.secondary-btn:hover{background:rgba(139,180,255,.16)}

.game-layout{
  display:grid;
  grid-template-columns:minmax(210px,.77fr) minmax(320px,680px) minmax(210px,.77fr);
  align-items:start;
  gap:clamp(14px,2vw,25px);
  margin-top:20px;
}

.panel{
  border-radius:18px;
  padding:17px;
}

.panel-heading{
  display:flex;
  align-items:center;
  justify-content:space-between;
  color:var(--muted);
  font:500 11px "DM Mono",monospace;
  letter-spacing:.08em;
  text-transform:uppercase;
}

.panel-heading.small{margin-bottom:9px}
.live-dot{width:6px;height:6px;font-size:0}

.score-block{
  display:grid;
  grid-template-columns:1fr 30px 1fr;
  align-items:end;
  gap:6px;
  margin:24px 0 18px;
}

.score-block strong{
  display:block;
  font:600 19px "Playfair Display",Georgia,serif;
}

.bot-score{text-align:right}

.versus{
  color:var(--gold);
  text-align:center;
  font:500 10px "DM Mono",monospace;
}

.status-card{
  display:flex;
  gap:10px;
  padding:12px;
  border:1px solid var(--line);
  border-radius:13px;
  background:rgba(6,15,30,.22);
}

.status-orb{margin-top:5px;flex:0 0 auto}
.status-card strong{font-size:13px}

.status-card p{
  margin:3px 0 0;
  color:var(--muted);
  font-size:12px;
  line-height:1.35;
}

.meter-group{margin:20px 0}

.meter-head{
  display:flex;
  justify-content:space-between;
  color:var(--muted);
  font-size:12px;
}

.meter-head strong{color:var(--text)}

.eval-meter{
  height:8px;
  margin-top:8px;
  overflow:hidden;
  border-radius:10px;
  background:#182940;
}

#evalFill{
  height:100%;
  width:50%;
  border-radius:inherit;
  background:linear-gradient(90deg,#f9edcb,#fff);
  transition:width .35s ease;
}

.move-card{
  border-top:1px solid var(--line);
  padding-top:15px;
}

.text-button{
  min-height:28px;
  padding:3px 8px;
  color:var(--muted);
  font-size:10px;
}

.move-list{
  max-height:300px;
  overflow:auto;
  margin:0;
  padding:0;
  list-style:none;
  font:12px "DM Mono",monospace;
}

.move-list li{
  display:grid;
  grid-template-columns:24px 1fr 1fr;
  gap:6px;
  padding:7px 3px;
  border-bottom:1px solid var(--line);
}

.move-list span{color:var(--muted)}
.move-list em{color:var(--blue);font-style:normal}

.board-zone{position:relative;min-width:0}

.reef-atmosphere{
  position:absolute;
  z-index:0;
  inset:28px -34px 53px;
  overflow:hidden;
  pointer-events:none;
  opacity:.33;
}

.reef-atmosphere img{
  position:absolute;
  display:block;
  max-width:none;
  object-fit:contain;
  filter:drop-shadow(0 12px 18px rgba(0,0,0,.46));
}

.reef-seaweed{
  height:62%;
  width:auto;
  bottom:-2%;
  left:-4%;
  transform:rotate(-5deg);
}

.reef-seaweed-right{
  height:51%;
  left:auto;
  right:-8%;
  bottom:2%;
  transform:scaleX(-1) rotate(-3deg);
}

.reef-rock{
  width:45%;
  height:auto;
  left:0;
  bottom:-14%;
  opacity:.8;
}

.board-frame{
  position:relative;
  z-index:1;
  overflow:hidden;
  padding:10px;
  border-radius:19px;
}

.board-header,.board-footer{
  display:flex;
  justify-content:space-between;
  padding:4px 3px 10px;
  color:var(--muted);
  font:500 10px "DM Mono",monospace;
  letter-spacing:.06em;
  text-transform:uppercase;
}

.board-footer{padding:10px 3px 2px}

/* Explicit eight-row grid: every board cell is independently locked to a 1:1 square. */
.chessboard{
  display:grid;
  width:100%;
  aspect-ratio:1 / 1;
  grid-template-columns:repeat(8,minmax(0,1fr));
  grid-template-rows:repeat(8,minmax(0,1fr));
  border:2px solid rgba(245,201,106,.48);
  box-shadow:0 0 0 5px rgba(4,10,22,.34),0 18px 35px rgba(0,0,0,.35);
}

/* No piece or empty-cell content can alter a square's height. */
.square{
  position:relative;
  display:grid;
  place-items:center;
  min-width:0;
  min-height:0;
  width:100%;
  height:100%;
  aspect-ratio:1 / 1;
  overflow:hidden;
  border:0;
  padding:0;
}

.square.light{background:linear-gradient(135deg,#ead8b1,var(--light))}
.square.dark{background:linear-gradient(135deg,#668aac,var(--dark))}

.square.last:before{
  content:"";
  position:absolute;
  inset:0;
  background:rgba(246,212,103,.32);
}

.square.selected{
  z-index:2;
  box-shadow:inset 0 0 0 4px var(--cyan);
}

.square.legal-dot:after{
  content:"";
  position:absolute;
  width:20%;
  aspect-ratio:1;
  border-radius:50%;
  background:rgba(10,24,42,.42);
}

.square.legal-capture:after{
  content:"";
  position:absolute;
  inset:7%;
  border:clamp(2px,.45vw,4px) solid rgba(12,25,44,.55);
  border-radius:50%;
}

.piece{
  position:relative;
  z-index:1;
  font-family:"Times New Roman",Georgia,serif;
  font-size:clamp(27px,6.9vw,63px);
  line-height:1;
  transition:transform .14s ease;
}

.square:hover .piece{transform:translateY(-4%) scale(1.07)}

.white-piece{
  color:#fff8e8;
  text-shadow:0 2px 1px #664e36,0 4px 7px rgba(0,0,0,.44);
}

.black-piece{
  color:#14233c;
  text-shadow:0 1px 0 rgba(255,255,255,.32),0 3px 5px rgba(0,0,0,.35);
}

.rank-label,.file-label{
  position:absolute;
  z-index:2;
  color:rgba(9,24,45,.66);
  font:700 clamp(8px,1.2vw,11px) "DM Mono",monospace;
}

.rank-label{top:3px;left:4px}
.file-label{right:4px;bottom:3px}
.dark .rank-label,.dark .file-label{color:rgba(255,255,255,.65)}

.board-actions{
  position:relative;
  z-index:1;
  display:grid;
  grid-template-columns:1.3fr 1fr 1fr 1fr;
  gap:9px;
  margin-top:17px;
}

.primary-btn,.secondary-btn{
  min-height:46px;
  padding:0 10px;
  font-size:12px;
  font-weight:700;
}

.primary-btn{
  border:0;
  border-radius:12px;
  color:#152238;
  background:linear-gradient(135deg,#fff2bf,var(--gold));
  box-shadow:0 6px 0 #9f7026,0 10px 22px rgba(0,0,0,.22);
}

.primary-btn:hover{
  filter:brightness(1.08);
  transform:translateY(-1px);
}

.secondary-btn{border-radius:12px}

.quiet-note{
  position:relative;
  z-index:1;
  margin:13px 0 0;
  color:var(--muted);
  text-align:center;
  font-size:11px;
}

.quote-box{
  position:relative;
  margin:19px 0;
  padding:16px 13px 14px 36px;
  border-left:2px solid var(--gold);
  border-radius:0 12px 12px 0;
  background:rgba(6,15,30,.2);
}

.quote-mark{
  position:absolute;
  top:-6px;
  left:10px;
  color:var(--gold);
  font:44px "Playfair Display",Georgia,serif;
}

.quote-box p{
  margin:0;
  color:var(--text);
  font:600 16px/1.4 "Playfair Display",Georgia,serif;
}

.difficulty-card,.style-card,.how-card{
  margin-top:16px;
  padding:13px;
  border:1px solid var(--line);
  border-radius:13px;
  background:rgba(6,15,30,.18);
}

.difficulty-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
}

.difficulty-top strong{
  display:block;
  font:600 16px "Playfair Display",Georgia,serif;
}

.rating{
  color:var(--gold);
  font:500 17px "DM Mono",monospace;
}

input[type=range]{
  width:100%;
  height:28px;
  margin:9px 0 1px;
  accent-color:var(--gold);
}

.difficulty-scale{
  display:flex;
  justify-content:space-between;
  color:var(--muted);
  font-size:10px;
}

.style-card p,.how-card p{
  margin:5px 0 0;
  color:var(--muted);
  font-size:13px;
  line-height:1.4;
}

.style-card p{color:var(--text)}

.style-bars{
  display:flex;
  gap:5px;
  margin-top:12px;
}

.style-bars i{
  display:block;
  flex:1;
  height:5px;
  border-radius:10px;
  background:#233652;
}

.style-bars i.active{
  background:var(--gold);
  box-shadow:0 0 8px rgba(245,201,106,.55);
}

.modal-backdrop{
  position:fixed;
  z-index:10;
  inset:0;
  display:grid;
  place-items:center;
  padding:16px;
  background:rgba(1,6,15,.74);
  backdrop-filter:blur(8px);
}

.hidden{display:none!important}

.modal{
  width:min(700px,100%);
  max-height:min(740px,92vh);
  overflow:auto;
  padding:clamp(18px,4vw,29px);
  border:1px solid var(--line);
  border-radius:20px;
  background:var(--solid);
  box-shadow:0 28px 100px rgba(0,0,0,.6);
}

.modal-header{
  display:flex;
  justify-content:space-between;
  align-items:start;
  margin-bottom:18px;
}

.close-button{
  width:44px;
  height:44px;
  border:1px solid var(--line);
  border-radius:12px;
  background:transparent;
  color:var(--muted);
  font-size:28px;
}

.bot-grid{
  display:grid;
  grid-template-columns:repeat(2,1fr);
  gap:10px;
}

.bot-option{
  display:flex;
  min-height:98px;
  gap:10px;
  padding:11px;
  border:1px solid var(--line);
  border-radius:14px;
  background:rgba(90,130,183,.06);
  text-align:left;
}

.bot-option:hover,.bot-option.active{
  border-color:var(--gold);
  background:rgba(245,201,106,.1);
}

.bot-option .portrait{
  width:42px;
  height:42px;
  border-radius:12px;
  font-size:22px;
}

.bot-option-copy{min-width:0}
.bot-option strong,.bot-option small,.bot-option em{display:block}

.bot-option strong{
  font:600 15px "Playfair Display",Georgia,serif;
}

.bot-option small{
  margin-top:3px;
  color:var(--gold);
  font:9px "DM Mono",monospace;
}

.bot-option em{
  margin-top:7px;
  color:var(--muted);
  font-size:11px;
  font-style:normal;
}

.promotion-modal{
  width:min(480px,100%);
  text-align:center;
}

.promotion-options{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:9px;
  margin-top:19px;
}

.promotion-options button{
  display:flex;
  min-height:104px;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:5px;
  border:1px solid var(--line);
  border-radius:13px;
  background:rgba(139,180,255,.08);
  color:#fff8e8;
  text-shadow:0 2px 1px #664e36;
  font:48px Georgia,serif;
}

.promotion-options button:hover{
  border-color:var(--gold);
  background:rgba(245,201,106,.13);
}

.promotion-options span{
  color:var(--muted);
  text-shadow:none;
  font:11px "Space Grotesk",sans-serif;
}

.toast{
  position:fixed;
  z-index:20;
  left:50%;
  bottom:24px;
  max-width:calc(100vw - 28px);
  padding:12px 16px;
  border:1px solid rgba(245,201,106,.46);
  border-radius:12px;
  background:#172641;
  color:#fff;
  box-shadow:var(--shadow);
  font-size:13px;
  opacity:0;
  transform:translate(-50%,90px);
  transition:.28s ease;
}

.toast.visible{
  opacity:1;
  transform:translate(-50%,0);
}

.thinking{
  color:var(--gold)!important;
  animation:blink 1s ease-in-out infinite;
}

@keyframes blink{50%{opacity:.35}}

@media(max-width:1080px){
  .game-layout{grid-template-columns:minmax(270px,.75fr) minmax(330px,1.25fr)}

  .right-panel{
    grid-column:1/-1;
    display:grid;
    grid-template-columns:1fr 1fr 1fr;
    gap:13px;
  }

  .right-panel .panel-heading{grid-column:1/-1}
  .quote-box,.difficulty-card,.style-card,.how-card{margin:0}
  .how-card{display:none}
}

@media(max-width:720px){
  .app-shell{padding:12px 10px 28px}
  .topbar{border-radius:14px}
  .engine-badge{font-size:9px}
  .opponent-strip{padding:12px}
  .opponent-copy h2{font-size:17px}
  .opponent-copy p:last-child{display:none}
  .change-bot{padding:0 9px;font-size:11px}

  .game-layout{
    display:flex;
    flex-direction:column;
    gap:14px;
  }

  .board-zone{
    width:100%;
    order:-1;
  }

  .left-panel,.right-panel{width:100%}

  .left-panel{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:14px;
  }

  .left-panel>.panel-heading,.move-card{grid-column:1/-1}
  .score-block,.status-card,.meter-group,.move-card{margin:0}
  .move-list{max-height:120px}

  .right-panel{display:block}
  .right-panel .panel-heading{margin-bottom:15px}
  .right-panel>*+*{margin-top:13px}
  .how-card{display:block}

  .board-actions{grid-template-columns:1fr 1fr}
  .bot-grid{grid-template-columns:1fr}
  .reef-atmosphere{inset:25px -18px 50px;opacity:.26}
}

@media(max-width:410px){
  .brand-mark{
    width:40px;
    height:40px;
    font-size:24px;
  }

  h1{font-size:19px}

  .engine-badge{
    padding:7px;
    font-size:0;
  }

  .engine-badge .pulse{margin:2px}

  .portrait{
    width:45px;
    height:45px;
  }

  .board-frame{padding:7px}
  .board-header,.board-footer{font-size:8px}
  .primary-btn,.secondary-btn{padding:0 5px;font-size:10px}
}
