/* ============ Schach Anderheyden – chess.com-inspiriertes UI ============ */
:root {
  --bg: #312e2b;
  --panel: #272522;
  --panel2: #3c3936;
  --accent: #81b64c;
  --accent-dark: #5d9948;
  --sq-light: #eeeed2;
  --sq-dark: #769656;
  --sq-highlight: rgba(255, 255, 51, .5);
  --sq-lastmove: rgba(255, 255, 51, .4);
  --text: #e8e6e3;
  --text-dim: #a09d9a;
  --danger: #d84a4a;
  --gold: #f5c749;
  --radius: 10px;
  --shadow: 0 4px 14px rgba(0, 0, 0, .35);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  transition: background .5s;
  overscroll-behavior: none;
}

button { font-family: inherit; cursor: pointer; border: none; }
input, select {
  font-family: inherit; font-size: 16px;
  background: var(--panel2); color: var(--text);
  border: 2px solid transparent; border-radius: var(--radius);
  padding: 12px 14px; width: 100%; outline: none;
  transition: border-color .2s;
}
input:focus { border-color: var(--accent); }

.hidden { display: none !important; }

/* ---------- Layout ---------- */
#app { max-width: 1100px; margin: 0 auto; padding: 12px 12px 84px; }
@media (min-width: 900px) { #app { padding-bottom: 24px; } }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 2px 14px;
}
.topbar .logo {
  font-weight: 800; font-size: 1.25rem; letter-spacing: -.5px;
  display: flex; align-items: center; gap: 8px; flex: 1;
}
.topbar .logo .logo-icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--accent); display: grid; place-items: center;
  font-size: 20px; box-shadow: var(--shadow);
}
.topbar .user-chip {
  background: var(--panel2); border-radius: 20px;
  padding: 6px 14px; font-size: .85rem; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
.topbar .user-chip .elo { color: var(--gold); }

/* ---------- Navigation ---------- */
nav.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--panel); border-top: 1px solid rgba(255,255,255,.06);
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav.bottomnav button {
  background: none; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .68rem; font-weight: 600; padding: 4px 10px; border-radius: 8px;
  transition: color .2s;
}
nav.bottomnav button .nav-ico { font-size: 1.35rem; }
nav.bottomnav button.active { color: var(--accent); }
@media (min-width: 900px) {
  nav.bottomnav {
    position: sticky; top: 0; bottom: auto; border-top: 0;
    border-radius: var(--radius); margin-bottom: 16px;
    justify-content: flex-start; gap: 4px; padding: 6px;
  }
  nav.bottomnav button { flex-direction: row; font-size: .85rem; gap: 7px; padding: 9px 16px; }
  nav.bottomnav button.active { background: var(--panel2); }
}

/* ---------- Cards / Panels ---------- */
.card {
  background: var(--panel); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card h2 { font-size: 1.05rem; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .sub { font-size: .75rem; color: var(--text-dim); font-weight: 400; margin-left: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 1rem;
  border-radius: var(--radius); padding: 13px 20px; width: 100%;
  box-shadow: 0 4px 0 var(--accent-dark);
  transition: transform .08s, box-shadow .08s, filter .2s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn.secondary { background: var(--panel2); box-shadow: 0 4px 0 rgba(0,0,0,.3); }
.btn.danger { background: var(--danger); box-shadow: 0 4px 0 #a83232; }
.btn.small { padding: 8px 14px; font-size: .85rem; width: auto; box-shadow: 0 3px 0 var(--accent-dark); }
.btn.small.secondary { box-shadow: 0 3px 0 rgba(0,0,0,.3); }
.btn:disabled { filter: grayscale(.6) brightness(.7); cursor: default; }

/* ---------- Auth ---------- */
#screen-auth { max-width: 420px; margin: 4vh auto 0; }
#screen-auth .auth-hero { text-align: center; margin-bottom: 22px; }
#screen-auth .auth-hero .big { font-size: 3.4rem; }
#screen-auth .auth-hero h1 { font-size: 1.6rem; margin-top: 4px; }
#screen-auth .auth-hero p { color: var(--text-dim); font-size: .9rem; margin-top: 4px; }
#screen-auth form { display: flex; flex-direction: column; gap: 10px; }
.auth-toggle { text-align: center; margin-top: 12px; font-size: .9rem; color: var(--text-dim); }
.auth-toggle a { color: var(--accent); font-weight: 700; cursor: pointer; text-decoration: none; }
.form-error { color: var(--danger); font-size: .85rem; min-height: 1.2em; text-align: center; }

/* ---------- Home / Lobby ---------- */
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-tile {
  background: var(--panel2); border-radius: var(--radius);
  padding: 18px 14px; text-align: center; color: var(--text);
  transition: transform .12s, background .2s;
  border: 2px solid transparent;
}
.mode-tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.mode-tile .tile-ico { font-size: 2.2rem; display: block; margin-bottom: 6px; }
.mode-tile .tile-name { font-weight: 800; }
.mode-tile .tile-sub { font-size: .75rem; color: var(--text-dim); margin-top: 3px; }

.lobby-list { display: flex; flex-direction: column; gap: 8px; }
.lobby-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel2); border-radius: var(--radius); padding: 12px 14px;
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } }
.lobby-row .avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); display: grid; place-items: center;
  font-weight: 800; font-size: 1.1rem; color: #fff; flex-shrink: 0;
}
.lobby-row .who { flex: 1; min-width: 0; }
.lobby-row .who .name { font-weight: 700; }
.lobby-row .who .meta { font-size: .75rem; color: var(--text-dim); }
.online-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 4px; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.empty-hint { color: var(--text-dim); text-align: center; padding: 18px 8px; font-size: .9rem; }

/* ---------- Themenwahl ---------- */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.theme-tile {
  border-radius: var(--radius); padding: 14px 10px; text-align: center;
  background: var(--panel2); border: 2px solid transparent; color: var(--text);
  transition: transform .12s, border-color .2s;
}
.theme-tile:hover { transform: translateY(-2px); }
.theme-tile.active { border-color: var(--accent); background: linear-gradient(160deg, var(--panel2), rgba(255,255,255,.06)); }
.theme-tile .t-ico { font-size: 1.9rem; display: block; }
.theme-tile .t-name { font-weight: 800; font-size: .9rem; margin-top: 4px; }
.theme-tile .t-tag { font-size: .68rem; color: var(--text-dim); margin-top: 2px; }
.theme-tile .t-board { display: flex; height: 10px; border-radius: 4px; overflow: hidden; margin-top: 8px; }
.theme-tile .t-board span { flex: 1; }

/* ---------- Brett ---------- */
.game-wrap { display: flex; flex-direction: column; gap: 10px; }
@media (min-width: 900px) {
  .game-wrap { flex-direction: row; align-items: flex-start; }
  .game-side { width: 320px; flex-shrink: 0; }
  .game-main { flex: 1; min-width: 0; }
}

.player-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 4px;
}
.player-bar .avatar {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--panel2); display: grid; place-items: center; font-size: 1.15rem;
}
.player-bar .p-name { font-weight: 700; font-size: .95rem; }
.player-bar .p-sub { font-size: .72rem; color: var(--text-dim); }
.player-bar .captures { margin-left: auto; font-size: .95rem; letter-spacing: 1px; opacity: .85; max-width: 50%; text-align: right; }
.player-bar .turn-ind {
  width: 10px; height: 10px; border-radius: 50%; background: transparent; flex-shrink: 0;
}
.player-bar.to-move .turn-ind { background: var(--accent); animation: pulse 1.4s infinite; }

#board-frame {
  position: relative; width: 100%; max-width: min(92vw, 560px);
  margin: 0 auto; user-select: none; touch-action: none;
}
@media (min-width: 900px) { #board-frame { max-width: 560px; margin: 0; } }
#board {
  position: relative; width: 100%; aspect-ratio: 1/1;
  border-radius: 6px; overflow: hidden; box-shadow: var(--shadow);
}
.sq { position: absolute; width: 12.5%; height: 12.5%; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq .coord {
  position: absolute; font-size: clamp(8px, 1.6vw, 11px); font-weight: 700; opacity: .8;
}
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 2px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }
.sq.lastmove::before { content: ''; position: absolute; inset: 0; background: var(--sq-lastmove); }
.sq.selected::before { content: ''; position: absolute; inset: 0; background: var(--sq-highlight); }
.sq.dest::after {
  content: ''; position: absolute; inset: 35%;
  border-radius: 50%; background: rgba(0,0,0,.22);
}
.sq.dest.capture::after {
  inset: 0; border-radius: 0; background: none;
  border: calc(min(3.5vw, 20px)) solid rgba(0,0,0,.18); box-sizing: border-box;
}
.sq.check::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(255,60,60,.75) 15%, rgba(255,60,60,0) 75%);
}

/* Figuren */
.piece {
  position: absolute; width: 12.5%; height: 12.5%;
  display: grid; place-items: center;
  transition: transform .22s cubic-bezier(.4, 1.2, .5, 1);
  z-index: 2; cursor: grab; will-change: transform;
}
.piece.dragging { transition: none; z-index: 10; cursor: grabbing; transform-origin: center; }
.piece.captured-anim { animation: poof .28s ease forwards; }
@keyframes poof { to { opacity: 0; transform: scale(.3); } }

.pc { display: grid; place-items: center; width: 100%; height: 100%; }
.pc-uni { font-size: clamp(24px, 9.5vw, 56px); line-height: 1; }
@media (min-width: 900px) { .pc-uni { font-size: 54px; } }
.pc-uni.pc-w { color: #fff; text-shadow: 0 0 2px #000, 0 2px 3px rgba(0,0,0,.55); }
.pc-uni.pc-b { color: #2b2b2b; text-shadow: 0 0 2px rgba(255,255,255,.45), 0 2px 3px rgba(0,0,0,.4); }

.pc-emoji { position: relative; }
.pc-emoji .pc-token {
  position: absolute; inset: 8%;
  border-radius: 50%; box-shadow: 0 2px 5px rgba(0,0,0,.4);
}
.pc-emoji.pc-w .pc-token { background: radial-gradient(circle at 35% 30%, #ffffff, #d8d8d8); border: 2px solid #bbb; }
.pc-emoji.pc-b .pc-token { background: radial-gradient(circle at 35% 30%, #5a5a5a, #262626); border: 2px solid #111; }
.pc-emoji .pc-glyph { position: relative; font-size: clamp(17px, 6.6vw, 38px); line-height: 1; filter: drop-shadow(0 1px 1px rgba(0,0,0,.35)); }
@media (min-width: 900px) { .pc-emoji .pc-glyph { font-size: 36px; } }

/* ---------- Spielinfo / Züge ---------- */
.game-status {
  text-align: center; font-weight: 700; font-size: .95rem;
  padding: 10px; border-radius: var(--radius); background: var(--panel);
}
.game-status.thinking .dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

.movelist {
  display: grid; grid-template-columns: auto 1fr 1fr; gap: 2px 10px;
  font-size: .88rem; max-height: 180px; overflow-y: auto; padding: 4px 2px;
}
.movelist .mv-no { color: var(--text-dim); }
.movelist .mv { font-weight: 600; }
.game-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.game-actions .btn { flex: 1; }

/* ---------- Werbung ---------- */
.ad-banner {
  background: linear-gradient(120deg, var(--panel2), var(--panel));
  border: 1px dashed rgba(255,255,255,.22);
  border-radius: var(--radius); padding: 10px 12px 6px;
  margin: 12px 0; transition: opacity .3s; position: relative; overflow: hidden;
}
.ad-banner.ad-swap { opacity: 0; }
.ad-banner.ad-hidden { display: none; }
.ad-inner { display: flex; align-items: center; gap: 10px; }
.ad-badge {
  position: absolute; top: 0; right: 0;
  background: var(--gold); color: #4a3a00; font-size: .58rem; font-weight: 800;
  padding: 2px 8px; border-radius: 0 0 0 8px; letter-spacing: .5px;
}
.ad-icon { font-size: 1.7rem; flex-shrink: 0; }
.ad-body { font-size: .8rem; line-height: 1.35; padding-right: 20px; }
.ad-body strong { color: var(--gold); }
.ad-close {
  position: absolute; right: 4px; bottom: 26px;
  background: none; color: var(--text-dim); font-size: 1.2rem; padding: 4px 8px;
}
.ad-fineprint { font-size: .6rem; color: var(--text-dim); margin-top: 5px; font-style: italic; }

/* ---------- Bestenliste ---------- */
.lb-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: var(--radius);
  background: var(--panel2); margin-bottom: 7px; animation: slideIn .25s ease;
}
.lb-row .rank { font-weight: 800; width: 34px; text-align: center; font-size: 1.05rem; }
.lb-row.top1 { background: linear-gradient(120deg, #6b5618, var(--panel2) 60%); }
.lb-row.top2 { background: linear-gradient(120deg, #55565c, var(--panel2) 60%); }
.lb-row.top3 { background: linear-gradient(120deg, #5c4331, var(--panel2) 60%); }
.lb-row .lb-name { font-weight: 700; flex: 1; }
.lb-row .lb-name .you { color: var(--accent); font-size: .72rem; font-weight: 800; margin-left: 6px; }
.lb-row .lb-stats { font-size: .72rem; color: var(--text-dim); }
.lb-row .lb-elo { font-weight: 800; color: var(--gold); font-size: 1.05rem; }

/* ---------- Achievements ---------- */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.ach-card {
  position: relative; border-radius: 14px; padding: 16px 12px 14px;
  background: linear-gradient(155deg, var(--panel2) 0%, var(--panel) 100%);
  border: 1px solid rgba(255,255,255,.07);
  text-align: center; overflow: hidden;
  transition: transform .15s;
}
.ach-card:hover { transform: translateY(-3px); }
.ach-card.earned {
  border-color: var(--gold);
  background: linear-gradient(155deg, rgba(245,199,73,.16) 0%, var(--panel) 70%);
  box-shadow: 0 0 18px rgba(245,199,73,.12);
}
.ach-card.earned::before {
  content: ''; position: absolute; top: -60%; left: -60%;
  width: 60%; height: 220%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.16), transparent);
  transform: rotate(20deg); animation: shine 3.5s infinite;
}
@keyframes shine { 0% { left: -70%; } 60%, 100% { left: 130%; } }
.ach-card .a-ico { font-size: 2.3rem; filter: grayscale(1) opacity(.35); }
.ach-card.earned .a-ico { filter: none; }
.ach-card .a-name { font-weight: 800; font-size: .85rem; margin-top: 8px; }
.ach-card .a-desc { font-size: .7rem; color: var(--text-dim); margin-top: 4px; line-height: 1.35; }
.ach-card .a-rarity {
  display: inline-block; margin-top: 8px; font-size: .6rem; font-weight: 800;
  padding: 2px 10px; border-radius: 10px; letter-spacing: .5px;
  background: var(--panel2); color: var(--text-dim);
}
.ach-card.earned .a-rarity.r-gold { background: var(--gold); color: #4a3a00; }
.ach-card.earned .a-rarity.r-silver { background: #c8c8d0; color: #333; }
.ach-card.earned .a-rarity.r-bronze { background: #c98d5a; color: #3d2200; }

/* ---------- Einstellungen ---------- */
.setting-row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 4px; border-bottom: 1px solid rgba(255,255,255,.06);
}
.setting-row:last-child { border-bottom: 0; }
.setting-row .s-label { flex: 1; }
.setting-row .s-label .s-sub { font-size: .74rem; color: var(--text-dim); margin-top: 2px; }
.switch { position: relative; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; border-radius: 30px;
  background: var(--panel2); transition: background .2s; cursor: pointer;
}
.switch .slider::before {
  content: ''; position: absolute; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; top: 3px; left: 3px;
  transition: transform .2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* ---------- Modals & Toasts ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.65); display: grid; place-items: center;
  animation: fadeIn .2s ease; padding: 18px;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--panel); border-radius: 16px; padding: 24px 20px;
  width: 100%; max-width: 380px; text-align: center;
  animation: popIn .28s cubic-bezier(.34, 1.4, .64, 1);
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
@keyframes popIn { from { opacity: 0; transform: scale(.85) translateY(14px); } }
.modal .m-icon { font-size: 3rem; }
.modal h3 { margin: 8px 0 6px; font-size: 1.25rem; }
.modal p { color: var(--text-dim); font-size: .9rem; margin-bottom: 18px; }
.modal .m-actions { display: flex; gap: 10px; }
.modal .m-actions .btn { flex: 1; }
.promo-grid { display: flex; gap: 10px; justify-content: center; margin-top: 6px; }
.promo-grid button {
  font-size: 2.1rem; background: var(--panel2); border-radius: 12px;
  width: 62px; height: 62px; display: grid; place-items: center;
  transition: transform .1s, background .2s;
}
.promo-grid button:hover { background: var(--accent); transform: scale(1.08); }

#toasts { position: fixed; top: 14px; left: 0; right: 0; z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--panel); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 11px 18px; font-size: .88rem; font-weight: 600;
  box-shadow: var(--shadow); animation: toastIn .3s ease;
  max-width: 92vw;
}
.toast.gold { border-left-color: var(--gold); }
.toast.error { border-left-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px); } }

/* Achievement-Popup (Karte) */
.ach-popup {
  position: fixed; inset: 0; z-index: 300; display: grid; place-items: center;
  background: rgba(0,0,0,.7); animation: fadeIn .25s;
}
.ach-popup .card-flip {
  width: 240px; border-radius: 18px; padding: 26px 18px; text-align: center;
  background: linear-gradient(155deg, #6b5618, var(--panel) 75%);
  border: 2px solid var(--gold);
  box-shadow: 0 0 50px rgba(245,199,73,.4);
  animation: cardReveal .7s cubic-bezier(.34, 1.3, .6, 1);
}
@keyframes cardReveal {
  0% { transform: rotateY(90deg) scale(.7); opacity: 0; }
  100% { transform: rotateY(0) scale(1); opacity: 1; }
}
.ach-popup .a-ico { font-size: 3.6rem; }
.ach-popup .label { color: var(--gold); font-size: .7rem; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; }
.ach-popup h3 { margin: 6px 0; }
.ach-popup p { font-size: .8rem; color: var(--text-dim); }

/* Konfetti */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 250; }

/* Hilfen */
.stat-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-chip { background: var(--panel2); border-radius: 8px; padding: 8px 14px; font-size: .8rem; }
.stat-chip b { display: block; font-size: 1.1rem; color: var(--accent); }
.level-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0 2px; }
.level-btn {
  background: var(--panel2); border-radius: var(--radius); padding: 12px 6px;
  color: var(--text); text-align: center; border: 2px solid transparent;
}
.level-btn .l-ico { font-size: 1.5rem; display: block; }
.level-btn .l-name { font-size: .72rem; font-weight: 700; margin-top: 3px; }
.level-btn.active { border-color: var(--accent); background: rgba(129,182,76,.14); }
.color-pick { display: flex; gap: 8px; margin-top: 10px; }
.color-pick button {
  flex: 1; background: var(--panel2); border-radius: var(--radius); padding: 10px;
  color: var(--text); font-weight: 700; border: 2px solid transparent; font-size: .85rem;
}
.color-pick button.active { border-color: var(--accent); }
