:root {
  --size: 34px;
  --tile-a: #5fb2ff;
  --tile-b: #2b6be0;
  --open: #e9eef6;
  --open-b: #d3dcea;
  --text: #eef3ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: #0b1530;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- animierter Hintergrund ---------- */
.bg {
  position: fixed; inset: -20%;
  background:
    radial-gradient(40% 35% at 20% 25%, rgba(70,120,255,.35), transparent 70%),
    radial-gradient(35% 30% at 80% 70%, rgba(150,60,255,.28), transparent 70%),
    radial-gradient(30% 30% at 60% 15%, rgba(0,200,255,.18), transparent 70%),
    #0b1530;
  animation: drift 24s ease-in-out infinite alternate;
  z-index: -1;
}
@keyframes drift {
  to { transform: translate(4%, -3%) rotate(6deg) scale(1.05); }
}

.app {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center;
  gap: 14px;
  padding: max(14px, env(safe-area-inset-top)) 12px 24px;
}

/* ---------- Kopfzeile ---------- */
.topbar {
  width: 100%; max-width: 1080px;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
}
h1 { margin: 0; font-size: 1.5rem; font-weight: 700; letter-spacing: .3px; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 44px; height: 44px; border-radius: 11px; box-shadow: 0 4px 14px rgba(40,110,255,.45); transition: transform .3s cubic-bezier(.3,1.6,.5,1); }
.brand:hover .logo { transform: rotate(-10deg) scale(1.08); }
@keyframes wobble { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }

.menu { display: flex; gap: 8px; align-items: center; }
select, .chip, .custom input {
  font: inherit; font-size: .95rem; color: var(--text);
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 10px;
  padding: 7px 10px;
  backdrop-filter: blur(8px);
}
select option { background: #16224a; }
.chip { cursor: pointer; min-width: 42px; transition: background .15s, transform .1s; }
.chip:hover { background: rgba(255,255,255,.16); }
.chip:active { transform: scale(.93); }
.chip.off { opacity: .45; }
.chip.mode[aria-pressed="true"] { background: #d93a3a; border-color: #ff7a7a; }

.custom {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: center;
  animation: fadeDown .25s ease-out;
}
.custom label { font-size: .9rem; display: flex; gap: 6px; align-items: center; }
.custom input { width: 72px; }
.chip.ok { background: #2b6be0; }
.hidden { display: none !important; }
@keyframes fadeDown { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- Spielfenster ---------- */
.game {
  max-width: 100%;
  padding: 14px;
  border-radius: 20px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 20px 60px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.12);
  backdrop-filter: blur(14px);
}

.hud {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; padding: 0 2px;
}

.lcd {
  position: relative;
  font: 700 30px/1 "DS-Digital", "Courier New", monospace;
  letter-spacing: 3px;
  color: #ff3b3b;
  text-shadow: 0 0 6px rgba(255,50,50,.9), 0 0 16px rgba(255,0,0,.5);
  background: linear-gradient(#170707, #0c0303);
  padding: 6px 10px 5px;
  border-radius: 8px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,.8), 0 1px 0 rgba(255,255,255,.1);
  min-width: 82px; text-align: center;
}
.lcd::before {
  content: "888";
  position: absolute; inset: 6px 10px 5px;
  color: rgba(255,60,60,.1); text-shadow: none;
}

.face {
  width: 54px; height: 54px; border-radius: 50%;
  font-size: 30px; line-height: 1;
  border: none; cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #fff6b0, #ffcf3a 55%, #e09a00);
  box-shadow: 0 4px 0 #a66d00, 0 8px 18px rgba(0,0,0,.4), inset 0 -3px 6px rgba(0,0,0,.15);
  transition: transform .1s;
}
.face:hover { transform: translateY(-2px) rotate(-6deg); }
.face:active { transform: translateY(3px); box-shadow: 0 1px 0 #a66d00, 0 4px 10px rgba(0,0,0,.4); }
.face.bounce { animation: faceBounce .5s cubic-bezier(.3,1.8,.5,1); }
@keyframes faceBounce { 0% { transform: scale(.6); } 100% { transform: scale(1); } }

.board-wrap {
  max-width: calc(100vw - 54px);
  max-height: calc(100vh - 230px);
  overflow: auto;
  border-radius: 12px;
  padding: 6px;
  background: rgba(0,0,10,.35);
  box-shadow: inset 0 2px 10px rgba(0,0,0,.5);
  will-change: transform;
}

.board {
  display: grid;
  gap: 3px;
  width: max-content;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  perspective: 600px;
}

/* ---------- Felder ---------- */
.cell {
  position: relative;
  width: var(--size); height: var(--size);
  display: grid; place-items: center;
  border-radius: calc(var(--size) * .2);
  background: linear-gradient(150deg, var(--tile-a), var(--tile-b));
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.45),
    inset 0 -3px 0 rgba(0,0,40,.3),
    0 2px 3px rgba(0,0,0,.35);
  cursor: pointer;
  transition: transform .09s, filter .12s;
  font-weight: 800;
  font-size: calc(var(--size) * .58);
}
.cell::after { /* Glanz */
  content: ""; position: absolute; inset: 2px 2px 50% 2px;
  border-radius: inherit;
  background: linear-gradient(rgba(255,255,255,.28), transparent);
  pointer-events: none;
}
.cell:not(.open):hover { filter: brightness(1.18) saturate(1.1); transform: translateY(-1px); }
.cell.pressed { transform: scale(.88) !important; filter: brightness(.85); }

.cell.open {
  cursor: default;
  background: linear-gradient(150deg, var(--open), var(--open-b));
  box-shadow: inset 0 1px 3px rgba(0,0,40,.25);
  animation: reveal .32s ease-out both;
  animation-delay: var(--d, 0ms);
}
.cell.open::after { display: none; }
@keyframes reveal {
  0%   { transform: scale(1) rotateX(0); filter: brightness(2.2); }
  35%  { transform: scale(.7) rotateX(70deg); }
  70%  { transform: scale(1.08) rotateX(0); filter: brightness(1.1); }
  100% { transform: none; filter: none; }
}

.num {
  animation: numIn .3s cubic-bezier(.3,1.7,.5,1) both;
  animation-delay: calc(var(--d, 0ms) + 120ms);
  text-shadow: 0 1px 0 rgba(255,255,255,.7);
}
@keyframes numIn { from { transform: scale(0); opacity: 0; } }

.n1 { color: #1f5fe0; } .n2 { color: #1d9440; } .n3 { color: #e0262b; }
.n4 { color: #23288f; } .n5 { color: #9a1b1b; } .n6 { color: #0a8c94; }
.n7 { color: #1a1a1a; } .n8 { color: #6b6b6b; }

.ico { width: 72%; height: 72%; pointer-events: none; }
.flagged .ico { animation: flagDrop .4s cubic-bezier(.3,1.6,.5,1); filter: drop-shadow(0 2px 1px rgba(0,0,0,.4)); }
@keyframes flagDrop {
  0% { transform: translateY(-80%) scale(1.5) rotate(-20deg); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
.qmark { color: #fff; text-shadow: 0 2px 2px rgba(0,0,0,.4); animation: numIn .25s ease-out; }

.cell.mine {
  background: radial-gradient(circle, #ff9a7a, #c4362a 70%);
  animation: mineIn .35s ease-out both;
}
.cell.mine .ico { animation: numIn .3s cubic-bezier(.3,1.8,.5,1) both; }
@keyframes mineIn { 0% { filter: brightness(3); transform: scale(1.3); } 100% { filter: none; transform: none; } }

.cell.boom {
  background: radial-gradient(circle, #fff3a0, #ff4d1a 45%, #8a0f0f);
  box-shadow: 0 0 18px 6px rgba(255,90,20,.8);
  z-index: 2;
  animation: boomPulse 1s ease-in-out infinite alternate;
}
@keyframes boomPulse { to { box-shadow: 0 0 8px 2px rgba(255,90,20,.5); } }

.cell.wrong { background: linear-gradient(150deg, #f6dcb6, #e9c48f); }
.cell.wrong::before {
  content: "✕"; position: absolute; color: #d0141a; font-size: calc(var(--size) * .9);
  text-shadow: 0 0 4px #fff;
}

.cell.won-flag { animation: winWave .6s ease-out both; animation-delay: var(--d, 0ms); }
@keyframes winWave { 50% { transform: translateY(-6px) scale(1.12); filter: brightness(1.4); } }

/* ---------- Effekte ---------- */
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.flash {
  position: fixed; inset: 0; pointer-events: none; z-index: 49;
  background: radial-gradient(circle at var(--fx, 50%) var(--fy, 50%), rgba(255,240,200,.95), rgba(255,120,40,.5) 30%, transparent 70%);
  opacity: 0;
}
.flash.on { animation: flash .6s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

.hint { margin: 0; font-size: .8rem; opacity: .6; text-align: center; }

/* ---------- Dialog ---------- */
.dialog {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(5,10,25,.55);
  backdrop-filter: blur(4px);
  animation: fadeIn .3s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } }
.dialog-card {
  width: min(340px, 88vw);
  text-align: center;
  padding: 26px 22px 22px;
  border-radius: 22px;
  background: linear-gradient(160deg, rgba(40,60,120,.95), rgba(20,28,60,.95));
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  animation: pop .45s cubic-bezier(.3,1.6,.5,1);
}
@keyframes pop { from { transform: scale(.6) translateY(30px); opacity: 0; } }
.dialog-icon { font-size: 56px; animation: wobble 1.6s ease-in-out infinite; }
.dialog h2 { margin: 8px 0 6px; font-size: 1.6rem; }
.dialog p { margin: 0 0 12px; opacity: .85; }
.dstats { font-size: .85rem; opacity: .75; margin-bottom: 16px; line-height: 1.6; }
.btn {
  font: inherit; font-weight: 700; font-size: 1rem;
  padding: 11px 26px; border-radius: 12px; border: none; cursor: pointer;
  color: #fff; background: linear-gradient(#4f9bff, #2a62d6);
  box-shadow: 0 4px 0 #1a3f94, 0 8px 18px rgba(0,0,0,.35);
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #1a3f94; }

@media (max-width: 560px) {
  h1 { font-size: 1.25rem; }
  .logo { width: 36px; height: 36px; }
  .lcd { font-size: 24px; min-width: 66px; }
  .face { width: 46px; height: 46px; font-size: 26px; }
  .game { padding: 8px; }
  .board { gap: 2px; }
  .board-wrap { padding: 4px; max-width: calc(100vw - 42px); max-height: calc(100vh - 250px); }
}

@media (prefers-reduced-motion: reduce) {
  .bg { animation: none; }
}

/* ---------- Konto & Bestenliste ---------- */
.menu { flex-wrap: wrap; justify-content: flex-end; }
.chip.account { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.account.in { background: rgba(61,220,151,.18); border-color: rgba(61,220,151,.5); }

.dialog-card { position: relative; }
.dialog-card.wide { width: min(440px, 92vw); max-height: 88vh; display: flex; flex-direction: column; }
.close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--text); font-size: 1.1rem; opacity: .6; cursor: pointer;
}
.close:hover { opacity: 1; }

.tabs { display: flex; gap: 4px; padding: 4px; margin: 6px 0 16px; border-radius: 12px; background: rgba(0,0,0,.25); }
.tab {
  flex: 1; font: inherit; font-size: .9rem; padding: 8px 6px; border: none; border-radius: 9px; cursor: pointer;
  background: transparent; color: var(--text); opacity: .7; transition: background .15s, opacity .15s;
}
.tab.active { background: rgba(255,255,255,.16); opacity: 1; font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: .85rem; margin-bottom: 12px; opacity: .95; }
.field input {
  font: inherit; font-size: 1rem; padding: 10px 12px; border-radius: 10px; color: var(--text);
  background: rgba(0,0,0,.3); border: 1px solid rgba(255,255,255,.18); outline: none;
}
.field input:focus { border-color: #5fb2ff; box-shadow: 0 0 0 3px rgba(95,178,255,.25); }
.form-error { min-height: 1.2em; margin: 0 0 10px; color: #ff8a8a; font-size: .9rem; }
.small { font-size: .8rem; opacity: .6; margin: 12px 0 0; }
.btn.secondary { background: linear-gradient(#5b6585, #3c4462); box-shadow: 0 4px 0 #262c42, 0 8px 18px rgba(0,0,0,.35); }

.acc-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 18px; }
.acc-stats div { background: rgba(0,0,0,.25); border-radius: 12px; padding: 10px 6px; font-size: .8rem; line-height: 1.5; }
.acc-stats b { display: block; font-size: .85rem; margin-bottom: 2px; }

.lb-wrap { overflow: auto; min-height: 120px; }
.lb { width: 100%; border-collapse: collapse; font-size: .95rem; }
.lb th { font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; opacity: .6; font-weight: 600; padding: 4px 8px; text-align: left; }
.lb td { padding: 9px 8px; border-top: 1px solid rgba(255,255,255,.07); text-align: left; }
.lb th:nth-child(3), .lb td:nth-child(3), .lb th:nth-child(4), .lb td:nth-child(4) { text-align: right; }
.lb td:first-child { width: 2.5em; font-weight: 700; }
.lb tr { animation: rowIn .35s ease-out both; }
.lb tr.me td { background: rgba(95,178,255,.18); }
.lb tr.me td:first-child { border-radius: 8px 0 0 8px; } .lb tr.me td:last-child { border-radius: 0 8px 8px 0; }
.lb .empty td { text-align: center; opacity: .6; padding: 24px; }
@keyframes rowIn { from { opacity: 0; transform: translateX(-12px); } }
.medal { font-size: 1.1rem; }

.donline { min-height: 0; margin-bottom: 8px; font-weight: 600; }
.donline:empty { display: none; }
.donline .rank { color: #ffd23f; }

.dialog-card.wide { overflow-y: auto; }
.opt { opacity: .6; font-size: .78rem; }
.small.left { text-align: left; }
.small a { color: #8cc6ff; }
.form-ok { min-height: 0; margin: 0 0 10px; color: #7ff0b8; font-size: .9rem; }
.form-ok:empty { display: none; }
.acc-section {
  text-align: left; margin: 0 0 12px; border-radius: 12px; background: rgba(0,0,0,.2);
  border: 1px solid rgba(255,255,255,.08);
}
.acc-section summary { cursor: pointer; padding: 11px 14px; font-weight: 600; list-style: none; }
.acc-section summary::-webkit-details-marker { display: none; }
.acc-section summary::after { content: "›"; float: right; transition: transform .2s; opacity: .6; }
.acc-section[open] summary::after { transform: rotate(90deg); }
.acc-section form { padding: 0 14px 14px; }
.btn.small-btn { padding: 8px 18px; font-size: .9rem; }
#logoutBtn { margin-top: 6px; }
