/* Ensure OL viewport fills any map target globally (all pages) */
.route-map-embed .route-map-box { position: relative; }
.route-map-embed .route-map-box .ol-viewport,
.route-map-embed .route-map-box canvas { position: absolute !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important; width: 100% !important; height: 100% !important; }
:root {
  --wii-blue: #0078d7;
  --bg-light: #f4f7fb;
  --text-gray: #333;
  --accent-gray: #666;
  --border-gray: #ddd;
  --input-bg: #e3f1ff;
  --input-border: #c3e3fb;
  --post-content-max: 900px; /* single source of truth for post content width */
}
body {
  margin: 0;
  font-family: "Segoe UI", sans-serif;
  background-color: var(--bg-light);
  color: var(--text-gray);
  font-size: 18px;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden; /* prevent accidental horizontal scroll */
}

/* Feed loading spinner */
#feed-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 0;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(0,0,0,0.1);
  border-top-color: var(--wii-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
body.no-scroll { overflow: hidden; }
header {
  background: white;
  padding: 0.75rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-gray);
}

/* Hide nav toggle checkbox globally (still usable for CSS toggle) */
.nav-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
header h1 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--wii-blue);
}
header h1 a.site-title-link {
  color: var(--wii-blue);
  text-decoration: none;
}
nav a {
  margin-left: 1.2rem;
  text-decoration: none;
  color: var(--wii-blue);
  font-weight: 500;
  font-size: 0.95rem;
  display: inline-block;
  padding: 0.4rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 6px;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

nav a:hover,
nav a:focus-visible {
  background-color: var(--input-bg);
  border-color: var(--input-border);
  outline: none;
}
/* Ensure current page link does NOT look hovered unless actually hovered */
nav a[aria-current="page"]:not(:hover):not(:focus) {
  background: transparent !important;
}

/* Indicate current page subtly */
/* Current page: no special box style; only hover shows box */
nav a[aria-current="page"] {
  text-decoration: none;
}

/* Better mobile navigation tap targets */
@media (max-width: 640px) {
  header { padding: 0.75rem 1rem; flex-wrap: wrap; position: sticky; top: 0; z-index: 1000; background: #fff; }
  .nav-toggle { display: none; }
  .nav-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--wii-blue);
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0, 120, 215, 0.15);
  }
  .nav-toggle-btn:active { background: #d7ebff; border-color: var(--wii-blue); }

  header nav {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 0;
    margin-top: 0.75rem;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
    /* Force consistent initial paint on mobile Safari */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform;
  }
  .nav-toggle:checked + .nav-toggle-btn + nav { display: flex; }

  header nav a {
    margin: 0;
    display: block;
    padding: 0.9rem 1rem;
    min-height: 44px;
    border: 0;
    border-radius: 0;
    background: #fff; /* ensure consistent paint and contrast for separators */
    position: relative;
    z-index: 0; /* establish stacking context for separator */
  }
  /* Standard 1px separators between items using background to avoid border conflicts */
  header nav a {
    background-image: linear-gradient(to bottom, var(--border-gray), var(--border-gray));
    background-size: 100% 1px;
    background-repeat: no-repeat;
    background-position: top left;
  }
  header nav a:first-child { background-image: none; }
  /* Ensure consistent single-pixel separators; no special thickness for account link */
  header nav a:hover, header nav a:focus-visible { background: var(--bg-light); border-color: var(--border-gray); }
  header nav a[aria-current="page"]:not(:hover):not(:focus) {
    background: transparent !important;
    border-left: 0;
    /* Force visible separator for current page link on mobile */
    border-top: 1px solid var(--border-gray) !important;
  }
  header nav a:active { border-color: var(--wii-blue); background: #f0f8ff; }
  /* Current page in mobile dropdown: no special treatment */
  header nav a[aria-current="page"] {
    background: transparent;
    border-left: 0;
    text-decoration: none;
  }
}

/* Hide toggle button on larger screens */
@media (min-width: 641px) {
  .nav-toggle-btn { display: none; }
  header nav { display: flex; }
  /* Desktop only: hide border for current page link to avoid hover-like box */
  nav a[aria-current="page"]:not(:hover):not(:focus) { border-color: transparent !important; }
}
main {
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  gap: 20px;
}
select, input[type="date"], input[type="search"] {
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
  color: var(--wii-blue);
  cursor: pointer;
  outline-offset: 2px;
}

#author-filter {
  margin-left: 1.5rem;
}
.filter-label-margin {
  margin-left: 1.5rem;
}
input[type="date"] {
  width: 150px;
}
input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  filter: invert(35%) sepia(83%) saturate(422%) hue-rotate(180deg) brightness(92%) contrast(88%);
}
footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.8rem;
  color: #aaa;
  background: #f0f3f8;
  margin-top: auto;
}
.wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.controls {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  padding: 1rem 2rem;
  align-items: center;
  flex-wrap: wrap;
}
.controls label {
  color: var(--wii-blue);
  font-weight: 600;
  margin-right: 0.3rem;
  user-select: none;
}
.post-preview {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.5rem;
  width: 600px;
  max-width: 100%;
  border: 1px solid var(--border-gray);
  border-left: 4px solid var(--wii-blue);
  background: #fff;
  margin-bottom: 1rem;
  box-sizing: border-box;
  flex-wrap: wrap; /* allow excerpt to break onto its own full row */
}
.post-preview img {
  width: 120px;
  height: 90px;
  object-fit: contain;
  border-radius: 0.25rem;
  flex-shrink: 0;
}
.post-content {
  flex: 1;
}
.post-content h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--wii-blue);
}
.meta {
  font-size: 0.85rem;
  color: var(--accent-gray);
  margin: 0.2rem 0 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.author-profile-pic {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-gray);
}
.excerpt {
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--text-gray);
  flex-basis: 100%;
  margin-top: 0.25rem;
}
.content {
  max-width: 2400px;
  margin-left: 0;
  margin-right: 0;
  padding: 0 2rem;
  flex: 1;
  overflow-x: hidden;
}
.full-post {
  background: #fff;
  border: 1px solid var(--border-gray);
  border-left: 4px solid var(--wii-blue);
  padding: 2rem;
  margin: 1rem auto;
  max-width: 1200px;
  box-sizing: border-box;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

body[data-page="landing"] .full-post {
  max-width: 90vw;
  margin-left: auto;
  margin-right: auto;
  width: auto;
}

body[data-page="landing"] #blog-feed {
  margin-left: 0;
  padding-left: 0;
  padding-right: 0;
  display: block;
}

body[data-page="landing"] .content {
  margin: 0 auto;
  padding: 0;
  display: block;
}

body[data-page="landing"] .full-post {
  max-width: 90vw;
  margin-left: auto;
  margin-right: auto;
}

body[data-page="landing"] #blog-feed {
  padding-left: 0;
  padding-right: 0;
}

.full-post h2 {
  font-size: 1.75rem;
  margin-bottom: 6px;
  color: #222;
}

.full-post .meta {
  font-size: 0.9rem;
  color: #777;
  margin-bottom: 6px;
}

.full-post .full-content {
  font-size: 1rem;
  line-height: 1.6;
  white-space: pre-wrap;
  color: #333;
  overflow-wrap: anywhere;
}

/* Landing (index) page: visually clamp long content with fade, hinting more */
body[data-page="landing"] .full-post .full-content {
  max-height: 12rem; /* ~7-8 lines depending on content */
  overflow: hidden;
  position: relative;
}
/* Disable media interactions in index teasers so clicking plays no media and the card remains clickable */
body[data-page="landing"] .full-post .full-content video,
body[data-page="landing"] .full-post .full-content audio,
body[data-page="landing"] .full-post .full-content iframe {
  pointer-events: none;
  user-select: none;
}
/* Disable map interactions entirely on landing page */
body[data-page="landing"] .route-map-embed,
body[data-page="landing"] .route-map-embed * {
  pointer-events: none !important;
  -ms-touch-action: none;
  touch-action: none;
}
body[data-page="landing"] .full-post .full-content::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3rem;
  background: linear-gradient(to bottom, rgba(255,255,255,0), #fff);
  z-index: 2;
}
body[data-page="landing"] .read-more-row { margin-top: 0.5rem; }
body[data-page="landing"] .read-more-btn {
  text-align: center;
  text-decoration: none;
  color: var(--wii-blue);
  font-weight: 600;
}

/* Ensure post body media never overflows on any page */
.full-post .full-content img,
.full-post .full-content video,
.full-post .full-content iframe,
.post-content-full img,
.post-content-full video,
.post-content-full iframe {
  max-width: 100%;
  height: auto;
  display: block;
}

.post-content-full { overflow-wrap: anywhere; }
.excerpt { overflow-wrap: anywhere; }
/* Also disable media interactions in search/list previews */
.post-content-full .route-map-embed { margin: 1rem 0; }
.post-content-full .route-map-embed .route-map-box { width: 100%; height: 320px; border: 1px solid var(--border-gray); border-radius: 8px; background: #f8fafc; position: relative; }
.post-content-full .route-map-embed .route-map-box .ol-viewport, .post-content-full .route-map-embed .route-map-box canvas { position:absolute; inset:0; width:100% !important; height:100% !important; }
.map-hint-overlay { position:absolute; inset:0; display:none; align-items:center; justify-content:center; background: rgba(255,255,255,0.7); color:#333; font-weight:600; font-size: .95rem; text-align:center; padding: 0 1rem; }
.route-map-box.ctrl-hint .map-hint-overlay { display:flex; }
/* Remove text stats block for maps per latest requirement */
.post-content-full .route-map-embed .route-map-stats { display:none; }

/* OpenLayers v10 minimal control styling when no CSS is bundled */
.ol-control { position: absolute; background: rgba(255,255,255,0.9); border: 1px solid var(--border-gray); border-radius: 6px; }
.ol-zoom { top: 0.5rem; left: 0.5rem; }
.ol-rotate { top: 0.5rem; right: 0.5rem; }
.ol-scale-line { bottom: 0.5rem; left: 0.5rem; background: rgba(255,255,255,0.9); padding: 2px 4px; border-radius: 4px; }
.ol-control button { border: none; background: transparent; padding: 0.25rem 0.4rem; cursor: pointer; font-size: 1rem; color: #333; }
.ol-control button:hover { background: #eef4ff; }
/* Do not hide OL overlay/viewport containers; only disable unwanted built-in overlays via controls: [] */

/* Shimmer loading (matches large media loading animation) */
.shimmer { position: relative; overflow: hidden; background: #f6f7f9; }
.shimmer::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background-image: linear-gradient(90deg, rgba(255,255,255,0) 0, rgba(255,255,255,0.7) 50%, rgba(255,255,255,0) 100%); animation: shimmer-move 1.2s infinite; }
@keyframes shimmer-move { 100% { transform: translateX(100%); } }
.post-preview video,
.post-preview audio,
.post-preview iframe { pointer-events: none; user-select: none; }

#blog-feed {
  display: block;
  gap: 20px;
  padding: 0;
  max-width: none;
  margin: 0 auto;
  width: auto;
}

#blog-feed > .post-preview {
  margin-left: auto !important;
  margin-right: auto !important;
}

.post-preview {
  max-width: 1000px;
  width: 100%;
  border: 1px solid var(--border-gray);
  border-left: 4px solid var(--wii-blue);
  background: #fff;
  margin-bottom: 1rem;
  box-sizing: border-box;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.5rem;
  cursor: pointer;
}

.clickable-card { cursor: pointer; }
.post-link { text-decoration: none; color: inherit; display: block; max-width: 1000px; margin: 0 auto; }

body[data-page="landing"] #blog-feed {
  margin-left: 0;
  align-items: center;
}

/* Nudge search page content slightly right on desktop for better visual balance */
@media (min-width: 1024px) {
  body[data-page="search"] .content {
    padding-left: calc(2rem + 140px); /* base padding + left gutter */
  }
}

/* Post detail page layout and featured sidebar */
body[data-page="post"] .post-page {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr) 320px; /* left gutter, main, sidebar */
  gap: 2rem;
  padding: 1.5rem 2rem;
}

body[data-page="post"] .post-main {
  grid-column: 2;
  max-width: var(--post-content-max, 900px);
}

body[data-page="post"] .post-body h2 {
  margin: 0 0 0.5rem 0;
  font-size: 2rem;
  color: #222;
}

body[data-page="post"] .post-body .meta {
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-gray);
  padding-bottom: 0.5rem;
}

body[data-page="post"] .post-content-full {
  font-size: 1rem;
  line-height: 1.7;
  color: #333;
}
body[data-page="post"] .post-content-full img { cursor: zoom-in; }

/* Lightbox overlay for post images */
.lightbox-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  flex-direction: column;
}
.lightbox-overlay.visible { display: flex; }
.lightbox-overlay img {
  max-width: 98vw;
  max-height: 92vh;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
/* Download button for lightbox */
.lightbox-download {
  position: static;
  background: #fff;
  color: var(--wii-blue);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  padding: 0.4rem 0.65rem;
  font-weight: 600;
  text-decoration: none;
  margin: 12px auto 0;
  display: inline-flex;
}
.lightbox-download { margin-top: 12px; }
.lightbox-download:hover { background: var(--bg-light); }

body[data-page="post"] .featured-sidebar {
  grid-column: 3;
  position: sticky;
  top: 1rem;
  align-self: start;
}

body[data-page="post"] .featured-sidebar h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 700;
  color: #333;
}

body[data-page="post"] .featured-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

body[data-page="post"] .featured-link {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  padding: 0.9rem;
  border: 1px solid var(--border-gray);
  background: #fff;
  text-decoration: none;
  color: inherit;
}

body[data-page="post"] .featured-link:hover {
  border-color: var(--wii-blue);
}

body[data-page="post"] .featured-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

body[data-page="post"] .featured-text { display: flex; flex-direction: column; }
body[data-page="post"] .featured-title { font-size: 1rem; font-weight: 600; color: #222; }
body[data-page="post"] .featured-author { font-size: 0.85rem; color: var(--accent-gray); }

@media (max-width: 900px) {
  body[data-page="post"] .post-page { grid-template-columns: 1fr; }
  body[data-page="post"] .post-main { grid-column: 1; }
  body[data-page="post"] .featured-sidebar { grid-column: 1; position: static; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border-gray); }
  body[data-page="post"] .featured-sidebar h3 { font-size: 1.15rem; font-weight: 800; }
}

@media (max-width: 600px) {
  #blog-feed {
    margin-left: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }
  .content {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }
  .post-preview {
    width: 96% !important;
    max-width: 96% !important;
    margin: 0 auto 1rem auto !important;
    box-sizing: border-box !important;
    padding: 1rem !important;
  }
  .post-preview img {
    width: 96px !important;
    height: 96px !important;
  }
  /* Slightly larger headings for readability on mobile */
  .post-content h2, .full-post h2 { font-size: 1.3rem; }
  body { font-size: 16px; }
}

#clear-date {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 0.5rem;
  color: var(--wii-blue);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.6rem;
  margin-left: -0.6rem;
  height: 28px;
  user-select: none;
  transition: background-color 0.2s;
}
#clear-date:hover {
  background-color: var(--wii-blue);
  color: white;
}
#load-more {
  display: block;
  margin: 24px auto;
  padding: 10px 24px;
  background-color: #007acc;
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.3s;
  max-width: fit-content;
}

#back-to-top {
  position: fixed;
  bottom: 1.5rem; /* distance from bottom */
  right: 1.5rem;  /* distance from right */
  display: none;

  /* Style to match your other buttons */
  background-color: var(--wii-blue, #007aff);
  color: white;
  font-family: inherit;
  font-size: 1rem;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  z-index: 9999;
  transition: background-color 0.3s ease, opacity 0.3s ease;
}
#back-to-top:hover {
  background-color: #005fa3;
}
@media (max-width: 600px) {
  .post-preview {
    flex-direction: column;
    align-items: stretch;
  }
  .post-preview img {
    width: 100%;
    height: auto;
  }
  .controls {
    justify-content: center;
    gap: 0.75rem;
  }
}
/* Auth Forms (Login/Register) */
.auth-form {
  max-width: 400px;
  margin: 2.5rem auto 0 auto;
  padding: 2rem 2.5rem 1.5rem 2.5rem;
  background: #fff;
  border: 1px solid var(--border-gray);
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}
.auth-form label {
  font-weight: 600;
  color: var(--wii-blue);
  margin-bottom: 0.2rem;
}
.auth-form input[type="text"],
.auth-form input[type="password"] {
  padding: 0.7rem 1rem;
  border: 1px solid var(--input-border);
  font-size: 1rem;
  background: var(--input-bg);
  color: var(--text-gray);
  margin-bottom: 0.5rem;
}
.auth-form button[type="submit"] {
  background: var(--wii-blue);
  color: #fff;
  border: none;
  padding: 0.7rem 1.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.5rem;
  transition: background 0.2s;
}
.auth-form button[type="submit"]:hover {
  background: #005fa3;
}
.auth-form p {
  text-align: center;
  margin-top: 1rem;
}

.error-message {
  color: red;
  text-align: center;
}

/* Center auth page content */
body[data-page="login"] .content,
body[data-page="register"] .content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 60vh;
  padding-top: 8vh;
}
/* Center headings on login/profile pages */
body[data-page="login"] .content h2,
body[data-page="profile"] .content h2 { text-align: center; }

/* Editor Page Layout */
.editor-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  background: var(--bg-light);
}

.editor-container h1 {
  font-size: 2rem;
  margin-bottom: 24px;
  text-align: center;
  color: #333;
}

.editor-container form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.editor-container label {
  font-weight: bold;
  margin-bottom: 4px;
  color: #444;
}

.editor-container input[type="text"] {
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 10px;
  font-size: 1rem;
}

#editor {
  min-height: 300px;
  height: auto; /* grow with content */
  border: none; /* styling handled in create.css */
  border-radius: 0;
  background: transparent;
}

.editor-container button[type="submit"] {
  align-self: flex-end;
  padding: 10px 20px;
  background: #007acc;
  color: white;
  font-size: 1rem;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.3s ease;
}

.editor-container button[type="submit"]:hover {
  background: #005fa3;
}

/* Responsive tweaks */
@media (max-width: 600px) {
  .editor-container {
    margin: 20px;
    padding: 16px;
  }

  .editor-container h1 {
    font-size: 1.5rem;
  }

  #editor {
    min-height: 200px;
    height: auto;
  }
}
