:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #eeeadf;
  background: #121513;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  padding: clamp(16px, 3vw, 40px);
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 7% 5%, rgba(177, 145, 87, 0.17), transparent 26rem),
    radial-gradient(circle at 92% 93%, rgba(58, 86, 67, 0.26), transparent 30rem),
    #121513;
}

.hidden { display: none !important; }

.main-menu {
  width: min(100%, 760px);
  min-height: min(620px, calc(100vh - 32px));
  display: grid;
  place-items: center;
  padding: clamp(28px, 6vw, 64px);
}

.menu-content { width: 100%; text-align: center; }
.main-menu h1 {
  color: #73bb63;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(3rem, 10vw, 6.4rem);
  font-weight: 900;
  letter-spacing: .04em;
  line-height: .95;
}
.mode-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(14px, 3vw, 24px);
  margin-top: clamp(42px, 8vw, 72px);
}
.mode-card {
  min-height: 168px;
  display: grid;
  place-items: center;
  padding: 24px;
  border: 1px solid rgba(115, 187, 99, .47);
  border-radius: 13px;
  color: #dcedd7;
  background: rgba(36, 48, 37, .78);
  box-shadow: 0 16px 38px rgba(0, 0, 0, .2);
}
.mode-card:hover { border-color: #8ad378; background: rgba(49, 70, 51, .9); }
.mode-card-title { font-size: clamp(1.1rem, 2.7vw, 1.55rem); font-weight: 850; letter-spacing: .08em; }

.app {
  width: min(100%, 1100px);
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 255px;
  gap: 18px;
  align-items: start;
}

.game-card,
.moves-card {
  border: 1px solid rgba(238, 234, 223, 0.11);
  background: rgba(28, 32, 29, 0.84);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(16px);
}

.game-card {
  position: relative;
  overflow: hidden;
  padding: clamp(18px, 2.4vw, 28px);
  border-radius: 20px;
}

.game-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(125deg, rgba(213, 181, 113, 0.07), transparent 36%);
}

.moves-card {
  border-radius: 16px;
  padding: 20px;
}

header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }

h1, h2, p { margin: 0; }

h1 {
  color: #f4f0e5;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 4vw, 2.8rem);
  font-weight: 500;
  line-height: 0.95;
  letter-spacing: -0.055em;
}

h2 { color: #f0ede3; font-size: 0.86rem; letter-spacing: 0.12em; text-transform: uppercase; }

.eyebrow,
.math-popup-eyebrow {
  color: #c8a96e;
  font-size: 0.67rem;
  font-weight: 750;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.eyebrow { margin-bottom: 9px; }

.math-popup-input {
  border: 1px solid rgba(238, 234, 223, 0.16);
  border-radius: 8px;
  background: #222722;
  color: #eeeadf;
  font: inherit;
  outline: none;
}

.math-popup-input:focus { border-color: #c8a96e; box-shadow: 0 0 0 3px rgba(200, 169, 110, 0.12); }

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 12px;
  color: #191b18;
  background: #d0af72;
  box-shadow: none;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 750;
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
}

button:hover { transform: translateY(-1px); background: #e0c083; }
button:active { transform: translateY(0); }
button.secondary { background: transparent; border-color: rgba(238,234,223,.2); color: #d9d6ca; }
button.secondary:hover { background: rgba(238,234,223,.08); }

.status {
  position: relative;
  z-index: 1;
  min-height: 24px;
  margin: 18px 0 12px;
  color: #b8b7ac;
  font-size: 0.84rem;
  font-weight: 600;
}

.board-shell { position: relative; }

.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template: repeat(8, minmax(0, 1fr)) / repeat(8, minmax(0, 1fr));
  overflow: hidden;
  border: 7px solid #563f29;
  border-radius: 10px;
  box-shadow: 0 20px 38px rgba(0,0,0,.34), inset 0 0 0 1px rgba(255,235,194,.17);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  font-size: clamp(1.75rem, 7.2vw, 4.25rem);
  line-height: 1;
  text-shadow: none;
}

.square:hover { transform: none; }
.light { background: #e1d1ae; }
.dark { background: #886744; }
.square.selected { outline: 3px solid #e5bf72; outline-offset: -3px; box-shadow: inset 0 0 0 99px rgba(227,185,106,.18); }
.square.legal::after { content: ""; position: absolute; width: 18%; aspect-ratio: 1; border-radius: 50%; background: rgba(30, 43, 33, .42); }
.square.capture::after { content: ""; position: absolute; width: 82%; aspect-ratio: 1; border: 3px solid rgba(103, 36, 29, .68); border-radius: 50%; }

.piece { position: relative; z-index: 1; display: inline-block; transition: transform .2s ease, filter .2s ease; }
.piece-moving { animation: piece-pop .35s ease; }
.white { color: #fff9e8; text-shadow: 0 1px 0 #65563d, 0 3px 4px rgba(0,0,0,.23); }
.black { color: #272421; text-shadow: 0 1px 0 rgba(255,255,255,.22); }

.hint { position: relative; z-index: 1; margin-top: 15px; color: #8f9087; font-size: .78rem; line-height: 1.55; }

.moves { list-style-position: inside; padding: 0; margin: 15px 0 0; max-height: 510px; overflow: auto; color: #c9c7bd; font-size: .82rem; display: grid; gap: 5px; }
.moves li { padding: 9px 10px; border-radius: 7px; border: 1px solid rgba(238,234,223,.07); background: rgba(255,255,255,.035); }

.popup { position: absolute; inset: 50% auto auto 50%; z-index: 3; padding: 10px 14px; border-radius: 7px; opacity: 0; pointer-events: none; transform: translate(-50%, -50%) scale(.94); box-shadow: 0 14px 35px rgba(0,0,0,.32); font-size: .74rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; transition: opacity .25s ease, transform .25s ease; }
.popup.show { opacity: 1; transform: translate(-50%, -50%) scale(1); animation: pop-in .75s ease; }
.popup.turn { color: #171915; background: #d0af72; }
.popup.check { color: #fff6ed; background: #a64735; animation: shake .45s ease, pop-in .55s ease; }
.popup.win { color: #171915; background: #e0c083; animation: burst .7s ease; }

.math-popup { position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; padding: 24px; opacity: 0; pointer-events: none; background: rgba(8,10,8,.74); backdrop-filter: blur(5px); transition: opacity .25s ease; }
.math-popup.open { opacity: 1; pointer-events: auto; }
.math-popup.hidden { display: none; }
.math-popup-card { width: min(100%, 420px); display: grid; gap: 12px; padding: 26px; border: 1px solid rgba(238,234,223,.13); border-radius: 16px; background: #202520; box-shadow: 0 25px 60px rgba(0,0,0,.38); animation: modal-pop .35s ease; }
.math-popup-title { color: #f4f0e5; font-family: Georgia, "Times New Roman", serif; font-size: 1.5rem; font-weight: 500; }
.math-popup-target, .math-popup-label { color: #b6b6ab; font-size: .87rem; font-weight: 600; }
.math-popup-question { padding: 13px; border-radius: 9px; background: #171b17; color: #e1c384; font-size: clamp(1.8rem,3.2vw,2.3rem); font-weight: 800; text-align: center; }
.math-popup-timer { color: #db8068; font-size: .86rem; font-weight: 800; text-align: center; }
.math-popup-input { padding: 11px 13px; font-size: 1rem; font-weight: 700; }
.math-popup-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 3px; }

.difficulty-popup { position: fixed; inset: 0; z-index: 9; display: grid; place-items: center; padding: 24px; background: rgba(8,10,8,.74); backdrop-filter: blur(5px); }
.difficulty-popup-card { width: min(100%, 440px); padding: 28px; border: 1px solid rgba(115,187,99,.36); border-radius: 16px; background: #202520; box-shadow: 0 25px 60px rgba(0,0,0,.38); text-align: center; animation: modal-pop .35s ease; }
.difficulty-popup-card h2 { margin-top: 10px; color: #f4f0e5; font-family: Georgia, "Times New Roman", serif; font-size: 1.45rem; font-weight: 500; letter-spacing: 0; text-transform: none; }
.difficulty-options { display: grid; gap: 10px; margin-top: 24px; }
.difficulty-options button { padding: 13px; color: #ddf0d8; background: #335137; border-color: rgba(115,187,99,.4); font-size: .9rem; }
.difficulty-options button:hover { background: #47734b; }

@keyframes pop-in { 0% { transform: translate(-50%,-50%) scale(.7); opacity:0; } 70% { transform: translate(-50%,-50%) scale(1.05); opacity:1; } 100% { transform: translate(-50%,-50%) scale(1); opacity:1; } }
@keyframes shake { 0%,100% { transform: translate(-50%,-50%) rotate(0); } 25% { transform: translate(-50%,-50%) rotate(-2deg); } 50% { transform: translate(-50%,-50%) rotate(2deg); } 75% { transform: translate(-50%,-50%) rotate(-1deg); } }
@keyframes burst { 0% { transform: translate(-50%,-50%) scale(.6); opacity:0; } 40% { transform: translate(-50%,-50%) scale(1.1); opacity:1; } 70% { transform: translate(-50%,-50%) scale(.95); } 100% { transform: translate(-50%,-50%) scale(1); } }
@keyframes piece-pop { 0% { transform: scale(.86) translateY(2px); } 50% { transform: scale(1.08) translateY(-4px); } 100% { transform: scale(1) translateY(0); } }
@keyframes modal-pop { 0% { transform: translateY(10px) scale(.96); opacity:0; } 100% { transform: translateY(0) scale(1); opacity:1; } }

@media (max-width: 780px) {
  body { place-items: start center; }
  .app { grid-template-columns: 1fr; }
  .moves-card { width: 100%; }
  header { align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; justify-content: space-between; }
}

@media (max-width: 430px) {
  .header-actions button { flex: 1; }
  .mode-cards { grid-template-columns: 1fr; margin-top: 44px; }
  .mode-card { min-height: 112px; }
}
