/* Untangle – Neon-Arcade-Variante (violetter Akzent). */

:root {
  --bg:       #0a0a14;
  --bg-2:     #1c1230;
  --fg:       #e8e8ff;
  --muted:    #9aa6c0;
  --accent:   #cc79a7;
  --accent-2: #56b4e9;
  --cross:    #d55e00;          /* farbblind-sicheres Warn-Orange */
  --board-bg: rgba(255, 255, 255, 0.04);
  --radius:   14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  background: radial-gradient(900px 500px at 50% -10%, var(--bg-2), var(--bg) 60%);
  color: var(--fg);
  font: 16px/1.5 ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; align-items: center;
  overscroll-behavior: none;
}

.bg-grid {
  position: fixed; inset: 0; z-index: -1;
  background-image:
    linear-gradient(rgba(204, 121, 167, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(86, 180, 233, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(800px 460px at 50% 0%, #000 30%, transparent 80%);
}

.top {
  width: 100%; max-width: 480px; padding: 1rem 1.1rem 0;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.back { color: var(--muted); text-decoration: none; font-weight: 600; letter-spacing: 0.03em; white-space: nowrap; }
.back:hover { color: var(--accent); }
.scores { display: flex; gap: 0.6rem; }
.score-box {
  display: flex; flex-direction: column; align-items: center; min-width: 84px;
  padding: 0.35rem 0.7rem; background: var(--board-bg);
  border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 10px;
  font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.2rem;
}
.score-label { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }

.wrap { width: 100%; max-width: 480px; padding: 0.6rem 1.1rem 2.5rem; display: flex; flex-direction: column; align-items: center; }
.title-row { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0.4rem 0 0.2rem; }
.game-title {
  margin: 0; font-size: clamp(2rem, 8vw, 2.8rem); font-weight: 900; letter-spacing: 0.04em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 14px rgba(204, 121, 167, 0.4));
}
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0 1rem; width: 100%; }

.btn {
  font: inherit; font-weight: 700; color: var(--fg);
  background: var(--board-bg); border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px; padding: 0.55rem 1rem; cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary { border-color: transparent; background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #1a0c16; box-shadow: 0 8px 24px -10px var(--accent); }

/* Spielfeld (quadratisch) */
.board {
  position: relative; width: 100%; max-width: 480px; aspect-ratio: 1 / 1;
  margin-top: 0.4rem; background: var(--board-bg);
  border: 1px solid rgba(255, 255, 255, 0.08); border-radius: var(--radius);
  touch-action: none; user-select: none; -webkit-user-select: none; overflow: hidden;
}
#graph { display: block; width: 100%; height: 100%; }

.edge {
  stroke: rgba(180, 190, 230, 0.45); stroke-width: 0.6; stroke-linecap: round;
  transition: stroke 0.12s ease, stroke-width 0.12s ease;
}
.edge--cross { stroke: var(--cross); stroke-width: 1.1; stroke-dasharray: 2 1.6; }
.board.solved .edge { stroke: var(--accent); stroke-width: 0.8; filter: drop-shadow(0 0 1px var(--accent)); }

.node {
  fill: var(--accent); stroke: #fff; stroke-width: 0.5; cursor: grab;
  filter: drop-shadow(0 0 2px rgba(204, 121, 167, 0.7));
  transition: r 0.08s ease;
}
.node--drag { r: 3.6; cursor: grabbing; fill: var(--accent-2); }
.board.solved .node { fill: #f0e442; }

/* Overlay (Setup / Gelöst) */
.overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center; padding: 0.9rem;
  background: rgba(8, 8, 16, 0.82); backdrop-filter: blur(3px);
  border-radius: var(--radius); animation: fade-in 0.2s ease;
}
.overlay[hidden] { display: none; }
.overlay-card { position: relative; width: 100%; max-width: 340px; text-align: center; }
.overlay-close {
  position: absolute; top: 0.4rem; right: 0.4rem;
  width: 1.9rem; height: 1.9rem; border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16); background: rgba(255, 255, 255, 0.05);
  color: var(--muted); font-size: 0.9rem; font-weight: 800; cursor: pointer; line-height: 1;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.overlay-close:hover { color: var(--fg); border-color: var(--accent); }
.overlay-title {
  margin: 0 0 0.3rem; font-size: clamp(1.5rem, 7vw, 2rem); font-weight: 900;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.overlay-title.win { background: linear-gradient(90deg, #f0e442, var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.overlay-sub { margin: 0 0 1rem; color: var(--fg); font-weight: 700; }
.opt-list { display: flex; flex-direction: column; gap: 0.6rem; }
.opt-btn { width: 100%; }
.overlay-actions { display: flex; gap: 0.7rem; justify-content: center; margin-top: 0.3rem; }
.link-btn { margin-top: 0.9rem; background: none; border: none; color: var(--muted); font: inherit; text-decoration: underline; cursor: pointer; }
.link-btn:hover { color: var(--fg); }

/* Eintrag-Formular */
.lb-form { margin: 0.2rem 0 1rem; }
.lb-form-label { display: block; font-size: 0.8rem; font-weight: 700; color: var(--accent); margin-bottom: 0.4rem; }
.lb-form-row { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
#unt-name {
  flex: 1; min-width: 8rem; font: inherit; font-weight: 700; color: var(--fg);
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px; padding: 0.55rem 0.7rem;
}
#unt-name:focus { outline: none; border-color: var(--accent); }
.lb-result { margin: 0 0 1rem; font-weight: 800; color: var(--accent); }

/* Bestenliste */
.leaderboard { width: 100%; max-width: 480px; margin-top: 1.6rem; }
.lb-title { margin: 0 0 0.2rem; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
.lb-sub { margin: 0 0 0.7rem; font-size: 0.8rem; color: var(--muted); }
.lb-tabs { display: flex; gap: 0.4rem; margin: 0 0 0.7rem; flex-wrap: wrap; }
.lb-tab {
  font: inherit; font-size: 0.8rem; font-weight: 700; color: var(--muted);
  background: var(--board-bg); border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px; padding: 0.3rem 0.8rem; cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.lb-tab:hover { color: var(--fg); }
.lb-tab.is-active { color: #1a0c16; background: var(--accent); border-color: transparent; }
.lb-list { list-style: none; margin: 0; padding: 0; }
.lb-empty { color: var(--muted); font-size: 0.9rem; padding: 0.4rem 0; }
.lb-row {
  display: grid; grid-template-columns: 2.6rem 1fr auto; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.7rem; margin-bottom: 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.07); border-radius: 10px; background: var(--board-bg);
}
.lb-rank { font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-time { font-weight: 800; font-variant-numeric: tabular-nums; }
.lb-row--me { border-color: color-mix(in srgb, var(--accent) 65%, transparent); box-shadow: 0 0 22px -10px var(--accent); }
.lb-row--me .lb-rank { color: var(--accent); }

.credit { margin: 1.4rem 0 0; font-size: 0.74rem; color: var(--muted); text-align: center; }
.credit a { color: var(--accent); text-decoration: none; }
.credit a:hover { text-decoration: underline; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .overlay { animation: none; } .node, .edge { transition: none; } }
