/* Version: Reverted to CSS Grid Layout */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

:root {
  --card-width: auto;
  --card-height: 210px;
  --top-bar-height: 64px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
  margin: 0;
  color: #e0e6f8;
  background: #10101a; 
  cursor: default;
  overflow-y: auto;
}

body.sidebar-open {
    overflow-x: hidden;
}

#backgroundCanvas { 
  position: fixed; 
  top: 0; 
  left: 0; 
  width: 100%; 
  height: 100%; 
  z-index: -1; 
}

.page-wrapper {
    transition: transform 0.4s ease-in-out;
}

body.sidebar-open .page-wrapper {
    transform: translateX(300px);
}

.main-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 20px;
  padding-top: calc(var(--top-bar-height) + 20px);
  box-sizing: border-box;
}

.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--top-bar-height);
  background: rgba(26, 26, 46, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-sizing: border-box;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-toggle {
  background: transparent;
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease;
}
.menu-toggle:hover { background: rgba(255, 255, 255, 0.1); }
.menu-toggle svg { width: 24px; height: 24px; }

.logo-container {
  display: flex;
  align-items: center;
}
.logo-container img {
  height: 100px;
  width: auto;
}

.search-container {
  flex-grow: 1;
  text-align: center;
  margin: 0 16px;
}
.search-wrapper {
  position: relative;
  max-width: 500px;
  margin: 0 auto;
}
.search-icon {
  position: absolute;
  top: 50%;
  left: 18px;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  fill: rgba(255, 255, 255, 0.6);
  pointer-events: none;
}
#searchInput {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 20px 12px 50px;
  font-size: 16px;
  border-radius: 50px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  background-color: rgba(0, 0, 0, 0.2);
  color: #ffffff;
  transition: all 0.3s ease;
}
#searchInput::placeholder { color: rgba(255, 255, 255, 0.6); }
#searchInput:focus {
  outline: none;
  box-shadow: 0 4px 15px rgba(0, 123, 255, 0.5);
  border-color: rgba(128, 189, 255, 0.6);
  background-color: rgba(255, 255, 255, 0.1);
}

.header-button {
  position: relative;
  background: transparent;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}
.header-button:hover { background: rgba(255, 255, 255, 0.1); }
.header-button svg { 
  width: 24px; 
  height: 24px; 
  fill: white;
  transition: fill 0.3s ease;
}
.header-button.has-favorites svg { fill: #ffd700; }
.badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background-color: #ff4d4d;
  color: white;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 11px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #1a1a2e;
}

.fixed-cards-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    width: 100%;
    max-width: 1000px;
}
.fixed-cards-container .time-card { 
    width: 300px;
}


/* MODIFIED: Reverted to CSS Grid */
.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    width: 100%;
    max-width: 1000px;
    min-height: 690px;
}

@media (max-width: 992px)  { 
  .grid-container, #favoritesGrid {
    grid-template-columns: repeat(2, 1fr); 
    min-height: 1000px; 
  } 
}
@media (max-width: 768px)  { 
  .grid-container, #favoritesGrid {
    grid-template-columns: 1fr; 
    min-height: 100%; 
  } 
}

.time-card {
  height: var(--card-height);
  background: rgba(30, 30, 50, 0.4); 
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px; padding: 20px; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(15px) saturate(1.5); -webkit-backdrop-filter: blur(15px) saturate(1.5);
  display: flex; flex-direction: column; justify-content: space-between;
  box-sizing: border-box; transition: all 0.4s ease; position: relative; color: #e0e6f8;
  overflow: hidden;
}

.time-card.placeholder {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: none;
}

.time-card:hover { transform: translateY(-8px) scale(1.03); box-shadow: 0 12px 35px rgba(0, 0, 0, 0.5); background: rgba(45, 45, 70, 0.5); }
.time-card.is-user-country { 
    border-color: #00aaff; 
    box-shadow: 0 0 25px rgba(0, 170, 255, 0.6), 0 8px 30px rgba(0, 0, 0, 0.6); 
    transform: scale(1.05);
    overflow: visible;
}
.is-user-country::after { content: 'Your Location'; position: absolute; top: -10px; background: #00aaff; color: white; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: bold; left: 50%; transform: translateX(-50%); }

.time-info { width: 100%; display: flex; flex-direction: column; text-align: left; overflow: hidden; height:100%; }
.time-info-header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 4px; }
.flag { flex-shrink: 0; width: 40px; height: 28px; object-fit: cover; margin-top: 4px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, 0.1); }
.h3-container { flex-grow: 1; overflow: hidden; min-width: 0; }
.time-info-header h3 { margin: 0; font-size: 20px; color: #e0e6f8; font-weight: 500; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.name-cn { font-size: 14px; color: #b0c4de; margin-left: 52px; margin-bottom: 12px; }
.time-info p { margin: 0; font-size: 32px; font-weight: 600; color: #ffffff; text-align: center; }
.time-info .weekday { margin-top: 4px; font-size: 12px; color: #a0b0c0; text-align: center; margin-bottom: 12px; }

.timezone-details { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-top: auto; 
    padding-top: 8px; 
    border-top: 1px solid rgba(255, 255, 255, 0.1); 
}
.utc-offset { font-size: 12px; font-weight: 500; color: #c0d0f0; }
.timezone { font-size: 11px; color: #8a9bb3; background-color: rgba(0,0,0,0.2); padding: 2px 6px; border-radius: 5px; }

@keyframes marquee-scroll { 0% { transform: translateX(0); } 20% { transform: translateX(0); } 80% { transform: translateX(-100%); } 100% { transform: translateX(-100%); } }
.h3-container.marquee h3 { display: inline-block; padding-right: 20px; animation: marquee-scroll 8s linear infinite; overflow: visible; text-overflow: clip; }

/* MODIFIED: Reverted to grid-column for spanning */
.loader-container, .message {
    grid-column: 1 / -1;
    text-align: center;
}
.message { color: white; font-size: 20px; text-shadow: 1px 1px 2px #000; padding: 40px 0; }
.loader-container { display: flex; flex-direction: column; align-items: center; gap: 15px; padding: 40px 0; }
.loader { border: 6px solid rgba(255, 255, 255, 0.2); border-top: 6px solid #fff; border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.loader-text { color: rgba(255, 255, 255, 0.8); font-size: 16px; }

.pagination-container { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); z-index: 100; }
#pageInfo { display: flex; justify-content: center; align-items: center; gap: 12px; }
.pagination-dot { width: 12px; height: 12px; border-radius: 50%; background: rgba(255, 255, 255, 0.2); border: 1px solid rgba(255, 255, 255, 0.3); cursor: pointer; transition: all 0.3s ease; padding: 0; flex-shrink: 0; }
.pagination-dot:hover { background: rgba(255, 255, 255, 0.4); }
.pagination-dot.active { background: rgba(255, 255, 255, 0.9); box-shadow: 0 0 10px rgba(255, 255, 255, 0.7), 0 0 5px rgba(255, 255, 255, 0.5) inset; transform: scale(1.2); cursor: default; }

#prevPageBtn, #nextPageBtn {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 999;
    background: transparent;
    border: none;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
#prevPageBtn svg, #nextPageBtn svg { width: 32px; height: 32px; fill: rgba(255, 255, 255, 0.5); transition: all 0.3s ease; }
#prevPageBtn { left: 30px; }
#nextPageBtn { right: 30px; }
#prevPageBtn:hover:not(:disabled), #nextPageBtn:hover:not(:disabled) { background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 70%); }
#prevPageBtn:hover:not(:disabled) svg, #nextPageBtn:hover:not(:disabled) svg { fill: rgba(255, 255, 255, 0.9); transform: scale(1.1); }
#prevPageBtn:disabled, #nextPageBtn:disabled { opacity: 0.2; cursor: not-allowed; }
#prevPageBtn:disabled svg, #nextPageBtn:disabled svg { fill: rgba(255, 255, 255, 0.2); }

@media (max-width: 900px) {
    #prevPageBtn, #nextPageBtn { display: none !important; }
}
@media (max-width: 768px) {
    .pagination-container { display: none !important; }
}

.bottom-right-container {
    position: fixed; bottom: 15px; right: 15px; z-index: 200;
    display: flex; align-items: center; gap: 15px;
}
.visitor-counter { color: white; text-shadow: 1px 1px 3px rgba(0,0,0,0.8); font-size: 14px; padding: 5px 15px; border-radius: 20px; background-color: rgba(0, 0, 0, 0.3); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.bmc-button {
    display: flex; align-items: center; gap: 8px; color: white; 
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8); font-size: 14px; 
    padding: 5px 15px; border-radius: 20px; background-color: rgba(0, 0, 0, 0.3); 
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    text-decoration: none; transition: all 0.3s ease;
}
.bmc-button:hover { background-color: rgba(255, 129, 6, 0.5); box-shadow: 0 0 10px rgba(255, 129, 6, 0.5); }
.bmc-button svg { width: 20px; height: 20px; }

.ad-container { width: 100%; max-width: 1000px; margin-top: 40px; text-align: center; z-index: 50; }

.card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.info-icon, .pin-icon, .dst-indicator {
  width: 24px;
  height: 24px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid transparent;
  padding: 0;
}

.info-icon, .pin-icon {
  font-weight: bold;
  font-family: serif;
}

.info-icon:hover, .pin-icon:hover, .dst-indicator:hover {
  background-color: rgba(255, 255, 255, 0.3);
  color: white;
  transform: scale(1.1);
  border-color: rgba(255, 255, 255, 0.5);
}
.pin-icon svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}
.pin-icon.active {
  background-color: rgba(255, 215, 0, 0.3);
  color: #ffd700;
}

.dst-indicator {
    color: #ffd700;
    cursor: help;
}

#shareBtn svg path {
    fill: white;
}


.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1002;
  opacity: 0;
  transition: opacity 0.3s ease;
  cursor: pointer;
  visibility: hidden;
}
.modal-overlay.visible {
  opacity: 1;
  visibility: visible;
}
.modal-content {
  background: rgba(30, 30, 50, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 18px;
  padding: 30px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  cursor: auto;
  transform: scale(0.9);
  transition: transform 0.3s ease;
}
#favoritesModal .modal-content {
    max-width: 1000px;
}
#converterModal .modal-content {
    max-width: 420px;
}

#favoritesGrid {
    min-height: auto;
    max-height: 60vh;
    overflow-y: auto;
    overflow-x: hidden;
}
#favoritesGrid.grid-container {
  min-height: auto;
}
.modal-overlay.visible .modal-content {
  transform: scale(1);
}
.modal-close-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  font-size: 30px;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  line-height: 1;
  transition: color 0.3s ease, transform 0.3s ease;
}
.modal-close-btn:hover {
  color: white;
  transform: rotate(90deg);
}
#modalTitle, #favoritesModalTitle {
  margin-top: 0;
  margin-bottom: 20px;
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  padding-bottom: 15px;
}
#modalBody {
  color: #e0e6f8;
  line-height: 1.6;
}
#modalBody .loader {
  margin: 40px auto;
}
#modalBody p {
  margin: 0 0 1em;
}

.lang-section {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.lang-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.lang-section h3 {
  font-size: 16px;
  color: #a0b0c0;
  margin-top: 0;
  margin-bottom: 8px;
  font-weight: 500;
}
.lang-section p {
  font-size: 14px;
  margin-bottom: 0;
}

.modal-stats {
  display: flex;
  gap: 20px;
  background-color: rgba(0,0,0,0.2);
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.stat-item {
  flex: 1;
  min-width: 150px;
}
.stat-item h4 {
  margin: 0 0 5px 0;
  font-size: 14px;
  color: #a0b0c0;
  font-weight: 500;
}
.stat-item p {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
}

.modal-source {
  margin-top: 25px;
  text-align: right;
  font-size: 12px;
  color: #8a9bb3;
}

/* ============================================= */
/* STYLES FOR DST, SIDEBAR, MODAL                */
/* ============================================= */

/* Sidebar */
#sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 300px;
    height: 100%;
    background: rgba(20, 20, 35, 0.95);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 2000;
    transition: left 0.4s ease-in-out;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
}
body.sidebar-open #sidebar {
    left: 0;
}
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: var(--top-bar-height);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}
.sidebar-header h2 {
    margin: 0;
    font-size: 20px;
}
.sidebar-header .modal-close-btn {
    position: static;
}
.sidebar-content {
    padding: 15px;
    overflow-y: auto;
}
ul.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}
.sidebar-menu button {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
    background: transparent;
    border: none;
    color: #e0e6f8;
    padding: 15px;
    text-align: left;
    font-size: 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.sidebar-menu button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}
.sidebar-menu button svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
    flex-shrink: 0;
}

/* Overlay */
#overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s, visibility 0.4s;
}
body.sidebar-open #overlay {
    opacity: 1;
    visibility: visible;
    cursor: pointer;
}

/* Timezone Converter Modal */
.converter-container { padding: 0; }
.converter-container h2 { margin-top: 0; margin-bottom: 25px; text-align: center; color: #ffffff; border-bottom: 1px solid rgba(255, 255, 255, 0.1); padding-bottom: 15px; }
.converter-row { display: flex; flex-direction: column; margin-bottom: 15px; }
.converter-row label { font-size: 14px; color: #a0b0c0; margin-bottom: 5px; }
.converter-row select, #timeInput { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.2); background-color: rgba(0, 0, 0, 0.3); color: white; font-size: 16px; box-sizing: border-box; }
.converter-row select:focus, #timeInput:focus { outline: none; border-color: #00aaff; }
#timeInput { color-scheme: dark; }

.converter-actions { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.converter-actions input { flex-grow: 1; }
#swapTimezonesBtn { flex-shrink: 0; background: rgba(255,255,255,0.1); border: 1px solid rgba(255, 255, 255, 0.2); color: white; width: 42px; height: 42px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; }
#swapTimezonesBtn:hover { background: #00aaff; border-color: #00aaff; }
#swapTimezonesBtn svg { width: 24px; height: 24px; }

#conversionResult { text-align: center; background: rgba(0,0,0,0.3); padding: 15px; border-radius: 8px; }
#conversionResult p { margin: 0 0 5px 0; color: #a0b0c0; font-size: 14px; }
#resultTime { font-size: 28px; font-weight: 600; color: #ffffff; display: block; }
#resultDate { font-size: 14px; color: #b0c4de; }
