@import url('https://fonts.googleapis.com/css2?family=UnifrakturMaguntia&family=EB+Garamond:ital,wght@0,400;0,600;1,400&display=swap');

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --parchment: #f4e4bc;
  --parchment-dark: #e8d5a3;
  --ink: #2c1810;
  --ink-light: #5c3a1e;
  --border: #8B6914;
  --shadow: rgba(44, 24, 16, 0.3);
}

body {
  font-family: 'EB Garamond', Georgia, serif;
  background: var(--parchment);
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
}

/* ── Login Screen ─────────────────────────────────────────── */

#login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #f4e4bc 0%, #d4b896 60%, #b89060 100%);
  z-index: 9999;
}

#login-screen.hidden {
  display: none;
}

.login-box {
  background: var(--parchment);
  border: 2px solid var(--border);
  border-radius: 4px;
  padding: 2.5rem 3rem;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 4px 24px var(--shadow), inset 0 0 40px rgba(139, 105, 20, 0.05);
  text-align: center;
  position: relative;
}

.login-box::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid var(--border);
  border-radius: 2px;
  opacity: 0.4;
  pointer-events: none;
}

.login-title {
  font-family: 'UnifrakturMaguntia', cursive;
  font-size: 2rem;
  color: var(--ink);
  margin-bottom: 0.5rem;
}

.login-subtitle {
  font-style: italic;
  color: var(--ink-light);
  font-size: 0.9rem;
  margin-bottom: 2rem;
  animation: flicker 3s ease-in-out infinite;
}

@keyframes flicker {
  0%, 100% { opacity: 1; }
  45% { opacity: 1; }
  50% { opacity: 0.6; }
  55% { opacity: 1; }
  80% { opacity: 1; }
  85% { opacity: 0.7; }
  90% { opacity: 1; }
}

.form-group {
  margin-bottom: 1rem;
  text-align: left;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--ink-light);
  font-size: 0.9rem;
}

.form-group input {
  width: 100%;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  background: #fdf6e3;
  color: var(--ink);
  font-family: 'EB Garamond', serif;
  font-size: 1rem;
  border-radius: 3px;
  outline: none;
  transition: box-shadow 0.2s;
}

.form-group input:focus {
  box-shadow: 0 0 0 2px rgba(139, 105, 20, 0.35);
}

.btn {
  padding: 0.65rem 2rem;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #c8a84b 0%, #a07c2a 100%);
  color: #fdf6e3;
  font-family: 'EB Garamond', serif;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 3px;
  cursor: pointer;
  width: 100%;
  margin-top: 0.5rem;
  letter-spacing: 0.03em;
  transition: filter 0.15s;
}

.btn:hover {
  filter: brightness(1.1);
}

.btn:active {
  filter: brightness(0.95);
}

.btn-danger {
  background: linear-gradient(180deg, #c84b4b 0%, #a02a2a 100%);
}

.btn-small {
  width: auto;
  padding: 0.35rem 1rem;
  font-size: 0.85rem;
}

.error-msg {
  color: #8b2020;
  font-style: italic;
  font-size: 0.88rem;
  margin-top: 0.5rem;
  min-height: 1.2em;
}

/* ── Map – Tinte auf Pergament ────────────────────────────── */

#map {
  position: fixed;
  inset: 0;
  z-index: 1;
  /*
   * Three layers of parchment texture:
   * 1. Faint paper-grain via SVG fractal noise
   * 2. Subtle horizontal ruling (old vellum feel)
   * 3. Warm radial gradient: golden centre → burnt-sienna edges
   */
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.72' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='250' height='250' filter='url(%23n)' opacity='0.14'/%3E%3C/svg%3E"),
    repeating-linear-gradient(
      transparent, transparent 31px,
      rgba(110, 65, 10, 0.06) 31px, rgba(110, 65, 10, 0.06) 32px
    ),
    radial-gradient(ellipse at 50% 38%,
      #e2c87a 0%, #ccaa5c 30%, #b88a40 65%, #9a6828 100%);
}

#map.hidden { display: none; }

/* Aged-paper vignette: sits above all map content, clicks pass through */
#map-vignette {
  position: fixed;
  inset: 0;
  z-index: 750;
  pointer-events: none;
  background: radial-gradient(ellipse at center,
    transparent 28%,
    rgba(50, 22, 6, 0.22) 58%,
    rgba(28, 10, 2, 0.62) 100%);
}

/*
 * CARTO Light tile pipeline → ink-on-parchment:
 *   grayscale   – strip colour so all roads become neutral grey
 *   brightness  – pre-darken so medium-grey roads fall below the 50% contrast pivot
 *   contrast    – snap: near-white land → white; grey roads → near-black ink strokes
 *   url(#quill) – SVG displacement filter: 1-2 px wobble → hand-drawn quill feel
 *   multiply    – white × parchment = parchment (transparent); black × parchment = ink
 */
.leaflet-tile-pane {
  filter: grayscale(1) brightness(0.72) contrast(3.8) url(#quill);
  mix-blend-mode: multiply;
}

/* Parchment-style zoom buttons */
.leaflet-control-zoom a {
  background: rgba(242, 224, 178, 0.94) !important;
  color: var(--ink) !important;
  border-color: var(--border) !important;
  font-family: 'EB Garamond', serif !important;
  font-size: 1.15rem !important;
  font-weight: 700 !important;
  text-shadow: none !important;
  line-height: 26px !important;
}
.leaflet-control-zoom a:hover {
  background: var(--parchment-dark) !important;
}
.leaflet-bar {
  border: 1px solid var(--border) !important;
  box-shadow: 2px 3px 8px rgba(44, 24, 16, 0.4) !important;
}

/* Attribution */
.leaflet-control-attribution {
  background: rgba(242, 224, 178, 0.84) !important;
  color: var(--ink-light) !important;
  font-family: 'EB Garamond', serif !important;
  font-size: 0.68rem !important;
  border-top-left-radius: 3px !important;
}
.leaflet-control-attribution a {
  color: var(--ink) !important;
}

/* ── Legend ───────────────────────────────────────────────── */

#legend {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 500;
  background: var(--parchment);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.75rem 1rem;
  min-width: 160px;
  box-shadow: 0 2px 8px var(--shadow);
}

#legend.hidden {
  display: none;
}

.legend-title {
  font-family: 'UnifrakturMaguntia', cursive;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.3rem 0;
  font-size: 0.9rem;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.2);
}

.legend-settings {
  margin-top: 0.6rem;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.legend-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0.25rem 0;
  font-size: 0.82rem;
}

.legend-setting-row label {
  color: var(--ink-light);
  font-style: italic;
  flex-shrink: 0;
}

.legend-setting-row select {
  background: var(--parchment);
  border: 1px solid var(--border);
  color: var(--ink);
  font-family: 'EB Garamond', serif;
  font-size: 0.82rem;
  border-radius: 2px;
  padding: 1px 4px;
  cursor: pointer;
}

/* ── Leaflet custom marker ────────────────────────────────── */

.user-label {
  background: rgba(242, 228, 190, 0.92);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 2px;
  font-family: 'EB Garamond', serif;
  font-size: 0.85rem;
  font-style: italic;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 1px 2px 5px rgba(44, 24, 16, 0.35);
  color: var(--ink);
  letter-spacing: 0.03em;
}
/* Remove Leaflet's default tooltip chrome */
.user-label::before { display: none; }

/* ── Admin Panel ──────────────────────────────────────────── */

body.admin-page {
  overflow: auto;
  background: radial-gradient(ellipse at top, #f4e4bc 0%, #d4b896 100%);
  min-height: 100vh;
}

.admin-header {
  background: var(--ink);
  color: var(--parchment);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.admin-header h1 {
  font-family: 'UnifrakturMaguntia', cursive;
  font-size: 1.8rem;
  letter-spacing: 0.05em;
}

.admin-content {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.card {
  background: var(--parchment);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 8px var(--shadow);
}

.card h2 {
  font-family: 'UnifrakturMaguntia', cursive;
  font-size: 1.4rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--parchment-dark);
}

th {
  font-weight: 600;
  color: var(--ink-light);
  background: var(--parchment-dark);
}

tr:last-child td {
  border-bottom: none;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
}

.status-online { background: #4caf50; }
.status-offline { background: #9e9e9e; }

/* Settings form */

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 600px) {
  .settings-grid { grid-template-columns: 1fr; }
}

/* Modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--parchment);
  border: 2px solid var(--border);
  border-radius: 4px;
  padding: 2rem;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 4px 24px var(--shadow);
  text-align: center;
}

.modal h3 {
  font-family: 'UnifrakturMaguntia', cursive;
  font-size: 1.4rem;
  margin-bottom: 1rem;
}

.modal img {
  max-width: 260px;
  border: 1px solid var(--border);
  display: block;
  margin: 1rem auto;
}

.qr-instructions {
  font-style: italic;
  font-size: 0.9rem;
  color: var(--ink-light);
  margin-top: 0.5rem;
}

.mini-map {
  height: 240px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.72' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.12'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at 50% 40%, #ddc070 0%, #c8a060 50%, #a87030 100%);
}

.mini-map .leaflet-tile-pane {
  filter: grayscale(1) brightness(0.72) contrast(3.8);
  mix-blend-mode: multiply;
}

/* ── Footstep Trail (Marauder's Map) ──────────────────────── */

@keyframes footstep-march {
  0%   { opacity: 0; transform: scale(0.25); }
  10%  { opacity: 1; transform: scale(1.15); }
  28%  { opacity: var(--base-opacity, 0.5); transform: scale(1); }
  100% { opacity: var(--base-opacity, 0.5); transform: scale(1); }
}

.footstep-anim {
  animation-name: footstep-march;
  animation-timing-function: ease-out;
  animation-iteration-count: infinite;
  animation-fill-mode: both;
  width: 10px;
  height: 18px;
}
