:root {
  color-scheme: dark;
  --bg: #101412;
  --panel: #181f1b;
  --panel-2: #202923;
  --line: #334039;
  --text: #f4f2e8;
  --muted: #aeb8ae;
  --light: #e2d0a3;
  --dark: #55725e;
  --accent: #e0a84b;
  --danger: #d96652;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(360px, 720px) minmax(240px, 320px);
  gap: 20px;
  align-items: start;
  justify-content: center;
  padding: 24px;
}

.authView {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(224,168,75,.12), transparent 34%),
    radial-gradient(circle at 70% 30%, rgba(85,114,94,.34), transparent 34%),
    var(--bg);
}

.authShell {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(300px, 380px);
  gap: 28px;
  align-items: center;
}

.authBrand h1 {
  font-size: clamp(44px, 8vw, 86px);
}

.authCopy {
  max-width: 440px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.5;
}

.authBox {
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 24px 80px rgba(0,0,0,.38);
}

.panel, .moves {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.hidden { display: none !important; }

.brand {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 30px; }
h2 { font-size: 18px; }

.badge {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.join { display: grid; gap: 12px; margin-bottom: 16px; }

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d110f;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

input:focus { border-color: var(--accent); }

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #1a1307;
  padding: 11px 14px;
  font-weight: 800;
  cursor: pointer;
}

button.secondary {
  width: 100%;
  margin-top: 16px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}

button.compact {
  width: auto;
  margin-top: 0;
}

button.danger {
  width: 100%;
  margin-top: 16px;
  background: var(--danger);
  color: #fff7f2;
}

.buttonRow, .matchControls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.profile {
  display: grid;
  grid-template-columns: 1fr 86px auto;
  gap: 10px;
  align-items: stretch;
  margin-bottom: 14px;
}

.profile > div {
  display: grid;
  gap: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

.profile strong {
  overflow: hidden;
  text-overflow: ellipsis;
}

.rankName {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 8px;
  align-items: center;
  min-width: 0;
}

.rankName small {
  grid-column: 2;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.rankLogo {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 28px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 16px;
}

.rankSovereign .rankLogo,
.leaderOne .leaderLogo {
  color: #fff4bd;
  border-color: #ffd56a;
  box-shadow: 0 0 18px rgba(255, 213, 106, .42);
}

.rankSamurai .rankLogo,
.leaderTwo .leaderLogo {
  color: #d9fff3;
  border-color: #7ee2c4;
  box-shadow: 0 0 16px rgba(126, 226, 196, .34);
}

.rankElite .rankLogo,
.leaderThree .leaderLogo {
  color: #ffb4a8;
  border-color: #d96652;
  box-shadow: 0 0 16px rgba(217, 102, 82, .34);
}

.rankKnight .rankLogo,
.leaderTop .leaderLogo {
  color: #d7d2ff;
  border-color: #8f86df;
}

.rankRising .rankLogo {
  color: #d7f0ff;
  border-color: #72a9c5;
}

.error {
  min-height: 20px;
  margin: 0;
  color: #ffb1a6;
  font-size: 13px;
}

.status, .scoreboard { display: grid; gap: 10px; margin-top: 14px; }

.status > div, .scoreboard > div {
  display: grid;
  gap: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

span { color: var(--muted); font-size: 13px; }
strong { font-size: 17px; }
b { color: var(--accent); }

.boardWrap { width: min(86vw, 720px); }

.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  border: 10px solid #2a2014;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.35);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  user-select: none;
  cursor: pointer;
}

.square.light { background: var(--light); }
.square.dark { background: var(--dark); }
.square.selected { outline: 4px solid var(--accent); outline-offset: -4px; }
.square.legal::after {
  content: "";
  width: 26%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(16, 20, 18, .34);
}

.piece {
  position: absolute;
  line-height: 1;
  font-size: clamp(34px, 8vw, 72px);
  text-shadow: 0 3px 5px rgba(0,0,0,.28);
}

.piece.white { color: #fff8df; }
.piece.black { color: #111712; }

.moves { max-height: calc(100vh - 48px); overflow: auto; }

.movesHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

#moveList { margin: 0; padding-left: 24px; color: var(--muted); line-height: 1.8; }

.leaderboard {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard li {
  display: grid;
  gap: 5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.leaderboard li.leaderOne {
  background: linear-gradient(135deg, rgba(224,168,75,.24), var(--panel-2));
  border-color: rgba(255,213,106,.65);
}

.leaderboard li.leaderTwo {
  background: linear-gradient(135deg, rgba(126,226,196,.18), var(--panel-2));
  border-color: rgba(126,226,196,.5);
}

.leaderboard li.leaderThree {
  background: linear-gradient(135deg, rgba(217,102,82,.16), var(--panel-2));
  border-color: rgba(217,102,82,.45);
}

.leaderMain {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
}

.leaderLogo {
  display: grid;
  place-items: center;
  width: 34px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #101412;
  border: 1px solid var(--line);
  font-size: 18px;
}

.leaderboard span {
  color: var(--muted);
}

.moveTitle {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.resultOverlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: rgba(3, 5, 4, .78);
  animation: resultFade .22s ease-out;
}

.matchOverlay {
  position: fixed;
  z-index: 18;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 5, 4, .68);
  backdrop-filter: blur(6px);
}

.promotionOverlay {
  position: fixed;
  z-index: 19;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 5, 4, .62);
  backdrop-filter: blur(5px);
}

.promotionBox {
  width: min(360px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,.48);
}

.promotionBox h2 {
  font-size: 28px;
  margin-bottom: 16px;
}

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

.promotionChoices button {
  aspect-ratio: 1;
  padding: 0;
  font-size: 42px;
  line-height: 1;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.promotionChoices button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.matchLoader {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  justify-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,.48);
}

.matchLoader h2 {
  font-size: 30px;
}

.matchLoader p {
  margin: 0 0 4px;
  color: var(--muted);
}

.spinner {
  width: 58px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 5px solid rgba(244,242,232,.16);
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  animation: spin .72s linear infinite;
}

.resultBurst {
  position: absolute;
  width: 42vmin;
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(2px);
  opacity: .42;
  animation: burstPulse 1s ease-out infinite alternate;
}

.victory .resultBurst { background: var(--accent); }
.defeat .resultBurst { background: var(--danger); }
.draw .resultBurst { background: var(--muted); }

.resultBox {
  position: relative;
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 26px 90px rgba(0,0,0,.5);
  animation: resultPop .38s cubic-bezier(.17, .84, .44, 1.2);
}

.resultBox h2 {
  font-size: 52px;
  margin: 4px 0 10px;
}

.duelStage {
  position: relative;
  height: 156px;
  margin: 8px 0 4px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(0,0,0,.18), transparent 38%, rgba(255,255,255,.05)),
    var(--panel-2);
  border: 1px solid var(--line);
}

.loserKing {
  position: absolute;
  left: 42px;
  bottom: 24px;
  font-size: 86px;
  line-height: 1;
  z-index: 2;
  transform-origin: 50% 85%;
  text-shadow: 0 8px 18px rgba(0,0,0,.45);
}

.winner-white .bladePiece,
.loser-white .loserKing {
  color: #fff8df;
}

.winner-black .bladePiece,
.loser-black .loserKing {
  color: #111712;
  text-shadow: 0 0 2px rgba(255,255,255,.5), 0 8px 18px rgba(0,0,0,.45);
}

.winnerBlade {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.bladePiece {
  position: absolute;
  right: 22px;
  bottom: 22px;
  font-size: 82px;
  line-height: 1;
  transform: translateX(180px) rotate(-12deg);
  text-shadow: 0 8px 18px rgba(0,0,0,.45);
}

.slash {
  position: absolute;
  left: 44px;
  top: 54px;
  width: 0;
  height: 10px;
  border-radius: 999px;
  transform: rotate(-21deg);
  transform-origin: left center;
  background: linear-gradient(90deg, transparent, #fff7c6 18%, #fff, #e0a84b 78%, transparent);
  box-shadow: 0 0 18px rgba(255, 243, 182, .9), 0 0 34px rgba(224, 168, 75, .48);
  opacity: 0;
}

.slashOne {
}

.slashTwo {
  top: 72px;
  left: 62px;
  height: 6px;
  opacity: 0;
}

.impactText {
  position: absolute;
  right: 22px;
  top: 18px;
  z-index: 4;
  color: var(--accent);
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0;
  opacity: 0;
  transform: scale(.72) rotate(-7deg);
  text-shadow: 0 0 18px rgba(224,168,75,.75);
}

.play .loserKing {
  animation: kingDefeated 1.35s ease-in-out both;
}

.play .bladePiece {
  animation: attackerRush 1.35s cubic-bezier(.18,.82,.22,1) both;
}

.play .slashOne {
  animation: animeSlash 1.35s ease-out both;
}

.play .slashTwo {
  animation: animeSlash 1.35s ease-out .08s both;
}

.play .impactText {
  animation: impactPop 1.35s ease-out both;
}

.defeat .resultBox {
  animation: resultPop .38s cubic-bezier(.17, .84, .44, 1.2), defeatShake .5s ease-out .12s;
}

.resultBox p:not(.eyebrow) {
  color: var(--muted);
  margin: 0 0 18px;
}

@keyframes resultFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes resultPop {
  from { transform: translateY(18px) scale(.9); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes burstPulse {
  from { transform: scale(.7); opacity: .26; }
  to { transform: scale(1.35); opacity: .5; }
}

@keyframes defeatShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(9px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}

@keyframes attackerRush {
  0% { transform: translateX(180px) rotate(-12deg) scale(.96); opacity: 0; }
  38% { transform: translateX(70px) rotate(-8deg) scale(1); opacity: 1; }
  54% { transform: translateX(-106px) rotate(-19deg) scale(1.08); opacity: 1; }
  100% { transform: translateX(-82px) rotate(-13deg) scale(1); opacity: 1; }
}

@keyframes animeSlash {
  0%, 36% { width: 0; opacity: 0; filter: blur(0); }
  48% { width: 285px; opacity: 1; filter: blur(.2px); }
  68% { width: 285px; opacity: .85; }
  100% { width: 285px; opacity: 0; filter: blur(3px); }
}

@keyframes kingDefeated {
  0%, 42% { transform: translateX(0) rotate(0) scale(1); opacity: 1; filter: brightness(1); }
  54% { transform: translateX(-4px) rotate(-7deg) scale(1.03); filter: brightness(1.7); }
  72% { transform: translateX(-18px) translateY(12px) rotate(-22deg) scale(.95); opacity: .88; filter: brightness(.8); }
  100% { transform: translateX(-22px) translateY(18px) rotate(-28deg) scale(.9); opacity: .55; filter: brightness(.6); }
}

@keyframes impactPop {
  0%, 47% { opacity: 0; transform: scale(.72) rotate(-7deg); }
  56% { opacity: 1; transform: scale(1.18) rotate(-7deg); }
  76% { opacity: 1; transform: scale(1) rotate(-7deg); }
  100% { opacity: .82; transform: scale(.98) rotate(-7deg); }
}

@media (max-width: 1080px) {
  .app { grid-template-columns: minmax(280px, 720px); }
  .boardWrap { width: min(94vw, 720px); order: -1; }
  .moves { max-height: 260px; }
}

@media (max-width: 520px) {
  .app { padding: 12px; }
  .authView { padding: 12px; }
  .authShell { grid-template-columns: 1fr; gap: 18px; }
  .profile { grid-template-columns: 1fr 80px; }
  .profile button { grid-column: 1 / -1; }
}
