@import url('https://fonts.googleapis.com/css2?family=Lilita+One&family=Nunito:wght@600;800&display=swap');

:root {
  --bg: #2b1d4e;
  --bg2: #3d2a6b;
  --panel: #fff8ec;
  --ink: #2b1d4e;
  --gold: #ffb627;
  --blue: #2f8cff;
  --red: #ff4d5a;
  --green: #3ccf6e;
  --purple: #8e44ad;
  --energy: #e040fb;
  --display: 'Lilita One', 'Arial Rounded MT Bold', 'Trebuchet MS', sans-serif;
  --body: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: #150e29 radial-gradient(circle at 50% 0%, #4b3388, #150e29 70%);
  color: #fff;
  font-family: var(--body);
  user-select: none;
  -webkit-user-select: none;
}
button, input { font-family: inherit; }

#app {
  position: relative;
  width: 100%;
  max-width: 520px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0, 0, 0, .6);
}

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,.025) 0 20px, transparent 20px 40px), var(--bg);
}
.screen.active { display: flex; }

/* ---------- Buttons ---------- */
.btn {
  border: 0; border-radius: 14px;
  padding: 12px 16px;
  font-family: var(--display); font-size: 18px; letter-spacing: .5px;
  color: #fff; cursor: pointer;
  background: #6c5ce7;
  box-shadow: 0 4px 0 rgba(0,0,0,.35), inset 0 -3px 0 rgba(0,0,0,.15);
  text-shadow: 0 2px 0 rgba(0,0,0,.3);
  transition: transform .06s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.btn:disabled { filter: grayscale(.8) brightness(.8); cursor: default; }
.btn.primary { background: linear-gradient(#ffc94a, #f39c12); color: #4a2a00; text-shadow: 0 1px 0 rgba(255,255,255,.4); }
.btn.secondary { background: linear-gradient(#5dade2, #2e86de); }
.btn.big { width: 100%; padding: 16px; font-size: 22px; }
.btn.tiny { padding: 6px 10px; font-size: 14px; border-radius: 10px; }
.btn.diff { flex: 1; background: linear-gradient(#a29bfe, #6c5ce7); }
.btn.diff[data-diff="easy"] { background: linear-gradient(#55efc4, #00b894); }
.btn.diff[data-diff="hard"] { background: linear-gradient(#ff7675, #d63031); }

/* ---------- Menü ---------- */
.logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px 0 10px; }
.logo h1 {
  margin: 0; text-align: center; line-height: .9;
  font-family: var(--display); font-size: 46px; font-weight: 400;
  color: var(--gold);
  text-shadow: 0 4px 0 #b86e00, 0 7px 0 rgba(0,0,0,.35);
  transform: rotate(-3deg);
}
.logo h1 em { font-style: normal; font-size: 58px; color: #fff; text-shadow: 0 4px 0 var(--purple), 0 7px 0 rgba(0,0,0,.35); }
.logo span { font-size: 52px; animation: bob 1.6s ease-in-out infinite; }
.logo .logo-cat { animation-delay: .8s; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(6deg); } }

.profile-card {
  background: rgba(255,255,255,.08); border-radius: 18px; padding: 12px;
  border: 2px solid rgba(255,255,255,.12);
}
.name-row { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.name-row input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 10px; border: 0;
  font-size: 16px; font-weight: 800; color: var(--ink); background: var(--panel);
}
.stats-row { display: flex; justify-content: space-around; margin: 10px 0; text-align: center; }
.stats-row b { display: block; font-family: var(--display); font-weight: 400; font-size: 22px; color: var(--gold); }
.stats-row small { opacity: .75; }
.faction-pick { display: flex; gap: 8px; }
.faction-pick.small { margin: 6px 0; }
.fbtn {
  flex: 1; padding: 10px; border-radius: 12px; cursor: pointer;
  border: 3px solid transparent; background: rgba(255,255,255,.1); color: #fff;
  font-family: var(--display); font-size: 17px;
}
.fbtn.on[data-faction="dog"] { border-color: #5dade2; background: rgba(46,134,222,.35); }
.fbtn.on[data-faction="cat"] { border-color: #c39bd3; background: rgba(142,68,173,.4); }

.menu-buttons { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.btn-group { background: rgba(0,0,0,.2); border-radius: 18px; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.btn-group h3 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 18px; opacity: .9; }
.join-row, .diff-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1; min-width: 0; text-align: center; text-transform: uppercase;
  font-family: var(--display); font-size: 24px; letter-spacing: 6px;
  border-radius: 14px; border: 0; color: var(--ink); background: var(--panel);
}
.join-row input.hint { box-shadow: 0 0 0 3px var(--gold); }
.menu-foot { display: flex; align-items: center; gap: 8px; }
.menu-foot span { flex: 1; opacity: .7; font-size: 14px; }

/* ---------- Deck ---------- */
.sub-head { display: flex; align-items: center; gap: 10px; }
.sub-head h2 { flex: 1; margin: 0; font-family: var(--display); font-weight: 400; font-size: 24px; }
.coins-pill { background: rgba(0,0,0,.3); padding: 6px 10px; border-radius: 20px; font-weight: 800; }
.deck-info { margin: 10px 0 6px; font-family: var(--display); font-size: 17px; opacity: .9; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile {
  position: relative; border-radius: 12px; overflow: hidden; cursor: pointer;
  border: 3px solid rgba(255,255,255,.85);
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
  background: #222;
}
.tile canvas { display: block; width: 100%; height: auto; aspect-ratio: 1; }
.tile .cost, .card .cost {
  position: absolute; top: 2px; left: 2px;
  width: 24px; height: 24px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f8a5ff, var(--energy) 60%, #7b1fa2);
  font-family: var(--display); font-size: 15px; line-height: 24px; text-align: center;
  text-shadow: 0 1px 0 rgba(0,0,0,.5); border: 2px solid #fff;
}
.cost.small { width: 18px; height: 18px; font-size: 11px; line-height: 15px; }
.tile .lvl {
  position: absolute; bottom: 0; left: 0; right: 0; text-align: center;
  font-size: 11px; font-weight: 800; background: rgba(0,0,0,.6); padding: 1px 0;
}
.tile .lvl.up { background: var(--green); color: #053; }
.tile.locked canvas { filter: grayscale(1) brightness(.4); }
.tile.locked::after {
  content: '🔒'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 26px;
}
.tile .lock-req { position: absolute; bottom: 0; left: 0; right: 0; text-align: center; font-size: 11px; font-weight: 800; background: rgba(0,0,0,.7); z-index: 1; }
.tile.in-deck { border-color: var(--gold); }
.tile.in-deck::before { content: '✓'; position: absolute; top: 2px; right: 4px; color: var(--gold); font-weight: 800; z-index: 1; text-shadow: 0 1px 2px #000; }
.swap-hint { display: none; margin-top: 8px; padding: 8px 10px; border-radius: 12px; background: var(--gold); color: #4a2a00; font-weight: 800; align-items: center; gap: 8px; justify-content: space-between; }
.swap-hint.show { display: flex; }
.deck-grid.swapping .tile { animation: wiggle .35s ease-in-out infinite; }
@keyframes wiggle { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }

/* ---------- Modal ---------- */
.modal { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(10,5,25,.7); z-index: 50; padding: 16px; }
.modal.open { display: flex; }
.modal-box { position: relative; width: 100%; max-width: 420px; background: var(--panel); color: var(--ink); border-radius: 20px; padding: 16px; box-shadow: 0 8px 0 rgba(0,0,0,.35); max-height: 90%; overflow-y: auto; }
.modal-x { position: absolute; top: 8px; right: 8px; border: 0; background: rgba(0,0,0,.1); border-radius: 50%; width: 32px; height: 32px; font-size: 16px; cursor: pointer; color: var(--ink); }
.modal-head { display: flex; gap: 12px; align-items: center; }
.modal-head canvas { width: 96px; height: 96px; border-radius: 14px; border: 3px solid var(--ink); flex: none; }
.modal-head h3 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 22px; padding-right: 30px; }
.modal-head p { margin: 4px 0 0; font-size: 14px; }
.m-level { font-weight: 800; color: var(--purple); }
.m-stats { width: 100%; margin: 12px 0; border-collapse: collapse; font-size: 14px; }
.m-stats td { padding: 5px 6px; border-bottom: 1px solid rgba(0,0,0,.08); }
.m-stats td:last-child { text-align: right; font-weight: 800; }
.m-stats .gain { color: #1e9e50; font-size: 12px; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn { flex: 1; font-size: 16px; }
.help-box h3 { margin-top: 0; font-family: var(--display); font-weight: 400; font-size: 24px; }
.help-box ul { padding-left: 4px; list-style: none; margin: 0; }
.help-box li { margin-bottom: 10px; font-size: 15px; line-height: 1.35; }

/* ---------- Lobby & Ergebnis ---------- */
.lobby-box, .result-box { margin: auto 0; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.lobby-box h2, .result-box h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 34px; }
.room-code {
  font-family: var(--display); font-size: 72px; letter-spacing: 12px; color: var(--gold);
  background: rgba(0,0,0,.3); border-radius: 20px; padding: 10px 0 10px 12px;
  text-shadow: 0 5px 0 #b86e00;
}
.waiting .dots::after { content: ''; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.res-emoji { font-size: 90px; animation: bob 1.6s ease-in-out infinite; }
.res-crowns { font-size: 34px; }
.res-rewards { display: flex; justify-content: center; gap: 12px; font-family: var(--display); font-size: 22px; }
.res-rewards span { background: rgba(0,0,0,.3); padding: 8px 14px; border-radius: 14px; }
.res-unlock:empty, .res-msg:empty { display: none; }
.res-unlock { background: var(--gold); color: #4a2a00; border-radius: 14px; padding: 10px; font-weight: 800; }
.res-msg { opacity: .85; }

/* ---------- Spiel ---------- */
#game { padding: 0; overflow: hidden; background: #234a1f; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: max(6px, env(safe-area-inset-top)) 10px 6px;
  background: linear-gradient(#5b1f2a, #3d1520);
  border-bottom: 3px solid var(--red);
}
.topbar .side { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar .side span:first-child { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crowns { font-size: 15px; letter-spacing: 2px; color: rgba(255,255,255,.5); }
.clock { text-align: center; background: rgba(0,0,0,.35); border-radius: 10px; padding: 2px 12px; }
.clock small { display: block; font-size: 10px; opacity: .7; }
.clock b { font-family: var(--display); font-weight: 400; font-size: 22px; }
.clock b.ot { color: #ff8a8a; animation: pulse .8s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.quit { background: rgba(255,255,255,.15); box-shadow: none; }

.field-wrap { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#field { display: block; touch-action: none; }

.banner {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(.6);
  opacity: 0; pointer-events: none; white-space: nowrap;
  font-family: var(--display); font-size: 24px; padding: 10px 18px; border-radius: 16px;
  background: rgba(0,0,0,.7); transition: all .25s;
}
.banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.banner.good { background: rgba(47,140,255,.92); }
.banner.bad { background: rgba(255,77,90,.92); }
.banner.ot { background: rgba(224,64,251,.92); }
.countdown {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  font-family: var(--display); font-size: 120px; color: #fff; text-shadow: 0 8px 0 rgba(0,0,0,.4);
  background: rgba(0,0,0,.25); pointer-events: none;
}
.countdown.show { display: flex; }
.countdown span { animation: pop .9s ease-out; }
@keyframes pop { 0% { transform: scale(2.2); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 100% { transform: scale(.9); opacity: .9; } }
.toast {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.75); padding: 6px 14px; border-radius: 12px; font-weight: 800;
  opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; }

.hud {
  position: relative;
  background: linear-gradient(#1d3f6e, #12284a);
  border-top: 3px solid var(--blue);
  padding: 4px 8px max(8px, env(safe-area-inset-bottom));
}
.hud-top { display: flex; align-items: center; gap: 8px; height: 26px; }
.me-name { font-weight: 800; font-size: 14px; }
.emote-btn { margin-left: auto; box-shadow: none; background: rgba(255,255,255,.15); }
.emote-menu {
  position: absolute; right: 8px; bottom: 100%; margin-bottom: 6px; display: none;
  grid-template-columns: repeat(3, auto); gap: 6px; padding: 8px;
  background: rgba(0,0,0,.8); border-radius: 14px; z-index: 5;
}
.emote-menu.open { display: grid; }
.emote-menu button { border: 0; background: #fff; color: var(--ink); border-radius: 10px; padding: 8px 10px; font-weight: 800; font-size: 15px; cursor: pointer; }

.hand-row { display: flex; gap: 6px; align-items: flex-end; }
.next { width: 13%; text-align: center; opacity: .85; }
.next small { font-size: 10px; display: block; }
.next > div { position: relative; border-radius: 8px; overflow: hidden; border: 2px solid rgba(255,255,255,.5); }
.next canvas { display: block; width: 100%; height: auto; aspect-ratio: 1; }
.next .cost { position: absolute; top: 1px; left: 1px; }
.cards { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.card {
  position: relative; border-radius: 12px; overflow: hidden; cursor: grab;
  border: 3px solid #fff; background: #222; touch-action: none;
  box-shadow: 0 4px 0 rgba(0,0,0,.4);
  transition: transform .12s, filter .15s;
}
.card canvas { display: block; width: 100%; height: auto; aspect-ratio: 1; pointer-events: none; }
.card .cname {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: 9.5px; font-weight: 800; text-align: center;
  background: rgba(0,0,0,.6); padding: 1px 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
.card .cost { pointer-events: none; }
.card.disabled { filter: grayscale(.85) brightness(.7); }
.card.disabled::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0;
  height: calc((1 - var(--charge, 0)) * 100%); background: rgba(0,0,0,.35); pointer-events: none;
}
.card.selected { transform: translateY(-10px); border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold), 0 8px 0 rgba(0,0,0,.4); }

.energy { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.energy-bar {
  flex: 1; height: 16px; border-radius: 10px; overflow: hidden; position: relative;
  background: rgba(0,0,0,.5); border: 2px solid rgba(255,255,255,.4);
}
.energy-bar::after {
  content: ''; position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 2px), rgba(0,0,0,.45) calc(10% - 2px) 10%);
}
#energyFill { height: 100%; width: 50%; background: linear-gradient(#f8a5ff, var(--energy) 60%, #9c27b0); transition: width .1s linear; }
.energy-num {
  width: 32px; height: 32px; border-radius: 50%; text-align: center; line-height: 28px;
  font-family: var(--display); font-size: 20px;
  background: radial-gradient(circle at 35% 30%, #f8a5ff, var(--energy) 60%, #7b1fa2); border: 2px solid #fff;
}

@media (min-height: 800px) {
  .card .cname { font-size: 11px; }
}

/* ---------- Laden, Anmeldung, Konto ---------- */
.loading-paw { margin: auto; font-size: 64px; animation: bob 1s ease-in-out infinite; }
.auth-box {
  display: flex; flex-direction: column; gap: 12px; margin-top: 8px;
  background: rgba(255,255,255,.08); border: 2px solid rgba(255,255,255,.12); border-radius: 18px; padding: 14px;
}
.auth-box label, .pw-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 800; font-size: 14px; }
.auth-box input, .pw-form input {
  padding: 12px; border-radius: 12px; border: 0; font-size: 17px; font-weight: 800;
  color: var(--ink); background: var(--panel); user-select: text; -webkit-user-select: text;
}
.auth-tabs { display: flex; gap: 6px; background: rgba(0,0,0,.25); padding: 4px; border-radius: 14px; }
.auth-tab {
  flex: 1; border: 0; border-radius: 10px; padding: 9px 6px; cursor: pointer;
  font-family: var(--display); font-size: 16px; color: rgba(255,255,255,.75); background: transparent;
}
.auth-tab.on { background: var(--gold); color: #4a2a00; }
.auth-box:not(.register) .reg-only { display: none; }
.auth-error { min-height: 1.2em; color: #ff8a8a; font-weight: 800; font-size: 14px; }
.auth-error.ok { color: #1e9e50; }
.auth-note { margin: 0; font-size: 13px; opacity: .75; line-height: 1.4; }
.name-row b { flex: 1; font-family: var(--display); font-weight: 400; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-box h3 { margin: 0 0 8px; font-family: var(--display); font-weight: 400; font-size: 24px; padding-right: 36px; }
.acc-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; text-align: center; }
.acc-stats div { background: rgba(43,29,78,.08); border-radius: 10px; padding: 6px 2px; }
.acc-stats b { display: block; font-family: var(--display); font-weight: 400; font-size: 20px; color: var(--purple); }
.acc-stats small { font-size: 11px; opacity: .75; }
.acc-tabs { background: rgba(43,29,78,.12); margin-bottom: 8px; }
.acc-tabs .auth-tab { color: var(--ink); font-size: 14px; }
.acc-tab { display: none; }
.acc-tab.on { display: block; }
.list-row { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-bottom: 1px solid rgba(0,0,0,.08); font-size: 14px; }
.list-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .res { font-weight: 800; }
.list-row .res.win { color: #1e9e50; }
.list-row .res.loss { color: #d63031; }
.list-row .res.draw { color: #888; }
.list-row.me { background: rgba(255,182,39,.25); border-radius: 8px; }
.list-empty { padding: 14px; text-align: center; opacity: .6; }
.pw-form { display: flex; flex-direction: column; gap: 10px; }
.pw-form input { background: #fff; border: 2px solid rgba(43,29,78,.2); }
.logout { width: 100%; margin-top: 14px; }
