/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #0d0d1a;
  color: #e8e8e8;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===== Loading Screen ===== */
.loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  background: #0d0d1a;
  z-index: 100;
}

.loading-screen p {
  font-size: 1.1rem;
  font-weight: 300;
  letter-spacing: 0.05em;
  color: #8888aa;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.08);
  border-top-color: #C4943C;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Grid Container ===== */
.grid-container {
  width: 100vw;
  height: 100vh;
  overflow: auto;
  scrollbar-color: #2a2a4a #0d0d1a;
}

.grid-container::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.grid-container::-webkit-scrollbar-track {
  background: #0d0d1a;
}

.grid-container::-webkit-scrollbar-thumb {
  background: #2a2a4a;
  border-radius: 5px;
}

.grid-container::-webkit-scrollbar-thumb:hover {
  background: #3a3a5a;
}

.grid-container::-webkit-scrollbar-corner {
  background: #0d0d1a;
}

/* ===== Timeline Grid ===== */
.timeline-grid {
  display: grid;
  grid-template-columns: 140px repeat(31, 200px);
  grid-template-rows: 48px repeat(12, 140px);
  background: #1a1a2e;
}

/* ===== Corner Cell ===== */
.cell-corner {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #0d0d1a;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 300;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #6a6a8a;
}

/* ===== Column Headers (Time Periods) ===== */
.cell-col-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #0d0d1a;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: var(--grid-era-size, 1.2rem);
  font-weight: 500;
  color: #b0b0cc;
  padding: 0 8px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ===== Row Headers (Regions) ===== */
.cell-row-header {
  position: relative;
  z-index: 10;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: var(--grid-region-size, 1.2rem);
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #fff;
  min-height: 140px;
  box-shadow: 4px 0 12px rgba(0, 0, 0, 0.3);
}

.cell-row-header span {
  display: block;
  line-height: 1.3;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

/* ===== Event Cells ===== */
.cell-event {
  position: relative;
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease, filter 0.3s ease;
}

.cell-event:hover,
.cell-event:focus-visible {
  transform: scale(1.02);
  z-index: 5;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.cell-event:focus-visible {
  outline: 2px solid #C4943C;
  outline-offset: -2px;
}

.cell-event img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: filter 0.2s ease;
}

.cell-event:hover img {
  filter: brightness(1.1);
}

.cell-event .event-title-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 10px 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.4) 60%, transparent 100%);
  font-size: var(--grid-event-size, 1.15rem);
  font-weight: 500;
  color: #fff;
  line-height: 1.3;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.cell-event .event-date-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.02em;
  pointer-events: none;
}

/* Image placeholder for missing images */
.cell-event .event-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  opacity: 0.15;
}

.cell-event-group {
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
}

.cell-event-group .cell-event {
  flex: 1 1 0;
  min-height: 0;
  border-right: none;
  border-bottom: none;
}

.cell-event-group .cell-event:hover,
.cell-event-group .cell-event:focus-visible {
  transform: none;
  z-index: auto;
  box-shadow: inset 0 0 0 1px rgba(196, 148, 60, 0.45);
}

.cell-event-split .event-title-overlay {
  padding: 16px 8px 6px;
  font-size: calc(var(--grid-event-size, 1.15rem) * 0.78);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cell-event-split .event-date-badge {
  top: 4px;
  left: 4px;
}

/* ===== Empty Cells ===== */
.cell-empty {
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  background: #12122a;
}

/* Subtle alternating pattern for empty cells */
.cell-empty.alt {
  background: #141430;
}

/* ===== Tooltip ===== */
.tooltip {
  position: fixed;
  z-index: 50;
  max-width: 320px;
  padding: 10px 14px;
  background: #1e1e3a;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  font-size: var(--tooltip-size, 0.85rem);
  line-height: 1.5;
}

.tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.tooltip .tooltip-date {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  font-size: inherit;
}

.tooltip .tooltip-text {
  color: #b0b0cc;
  font-weight: 300;
}

/* ===== Detail Panel (Modal) ===== */
.detail-panel {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  pointer-events: none;
}

.detail-panel.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.detail-panel.open ~ #controls-wrap {
  display: none;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.detail-content {
  position: relative;
  z-index: 1;
  width: 90%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  background: #16162e;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
  transform: translateY(20px) scale(0.97);
  transition: transform 0.3s ease;
}

.detail-panel.open .detail-content {
  transform: translateY(0) scale(1);
}

.detail-content::-webkit-scrollbar {
  width: 6px;
}

.detail-content::-webkit-scrollbar-track {
  background: transparent;
}

.detail-content::-webkit-scrollbar-thumb {
  background: #2a2a4a;
  border-radius: 3px;
}

/* Drag handle: hidden on desktop, visible on mobile */
.detail-drag-handle {
  display: none;
}

.detail-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #e8e8e8;
  font-size: 1.5rem;
  cursor: pointer;
  transition: background 0.2s ease;
  line-height: 1;
}

.detail-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

.detail-close:focus-visible {
  outline: 2px solid #C4943C;
  outline-offset: 2px;
}

/* ===== Detail Nav (Prev/Next) ===== */
.detail-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  background: none;
  color: #e8e8e8;
  border: none;
  cursor: pointer;
  padding: 0;
}

.detail-nav-prev { left: calc(50% - 388px); }
.detail-nav-next { right: calc(50% - 388px); }

.detail-nav-arrow {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.detail-nav:hover .detail-nav-arrow {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.detail-nav-preview {
  position: absolute;
  top: 50%;
  width: 180px;
  display: none;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-50%) scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
  background: rgba(13, 13, 26, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.detail-nav-next .detail-nav-preview { left: 56px; }
.detail-nav-prev .detail-nav-preview { right: 56px; }

.detail-nav:hover .detail-nav-preview {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) scale(1);
}

.detail-nav-preview img {
  width: 180px;
  height: 101px;
  object-fit: cover;
  display: block;
}

.detail-nav-title {
  padding: 6px 8px 2px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-align: left;
}

.detail-nav-date {
  padding: 0 8px 6px;
  font-size: 0.65rem;
  color: #8888aa;
  text-align: left;
}

@media (min-width: 1400px) {
  .detail-nav-preview { display: flex; }
}

.detail-nav:focus-visible .detail-nav-arrow {
  outline: 2px solid #C4943C;
  outline-offset: 2px;
}

.detail-nav[hidden] {
  display: none;
}

.detail-image-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #0d0d1a;
}

.detail-image-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d0d1a;
  z-index: 1;
  transition: opacity 0.3s ease;
}

.detail-image-loader.hidden {
  opacity: 0;
  pointer-events: none;
}

.detail-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.3s ease;
}

.detail-body {
  padding: 24px 28px 32px;
}

.detail-date {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 4px;
  font-size: var(--detail-date-size, 1.0rem);
  font-weight: 800;
  color: #fff;
  margin-bottom: 14px;
  letter-spacing: 0.04em;
}

.detail-title {
  font-size: 2.4rem;
  font-weight: 700;
  margin-bottom: 12px;
  line-height: 1.25;
  color: #fff;
}

.detail-region {
  display: inline-block;
  font-size: var(--detail-region-size, 0.85rem);
  font-weight: 400;
  color: #8888aa;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  width: 100%;
}

.detail-description {
  font-size: var(--detail-desc-size, 0.95rem);
  font-weight: 300;
  line-height: 1.8;
  color: #c0c0d8;
}

.detail-article-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 20px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #6a9fff;
  text-decoration: none;
  transition: color 0.2s ease;
}

.detail-article-link:hover {
  color: #8ab8ff;
  text-decoration: underline;
}

.detail-wiki-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-left: 24px;
  margin-top: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #C4943C;
  text-decoration: none;
  transition: color 0.2s ease;
}

.detail-wiki-link:hover {
  color: #e0b050;
  text-decoration: underline;
}

/* ===== Detail Actions (Copy/Share Buttons) ===== */
.detail-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.detail-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: transparent;
  color: #b0b0cc;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.detail-action-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #C4943C;
  border-color: rgba(196, 148, 60, 0.3);
}

.detail-action-btn:focus-visible {
  outline: 2px solid #C4943C;
  outline-offset: 2px;
}

.detail-action-btn.copied {
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.3);
}

.detail-lang-btn {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #e8e8e8;
}

/* ===== Search Overlay ===== */
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  justify-content: center;
  padding-top: 15vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.search-overlay.open {
  opacity: 1;
  visibility: visible;
}

.search-container {
  width: 90%;
  max-width: 560px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow-y: hidden;
  background: #16162e;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
  align-self: flex-start;
}

.search-input {
  flex-shrink: 0;
  width: 100%;
  padding: 16px 20px;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: transparent;
  color: #e8e8e8;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 400;
  outline: none;
}

.search-input::placeholder {
  color: #6a6a8a;
}

.search-chips {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 16px;
  max-height: 180px;
  overflow-y: auto;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.search-chip {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: transparent;
  color: #8888aa;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.search-chip:hover {
  background: rgba(255, 255, 255, 0.04);
  color: #b0b0cc;
}

.search-chip:focus-visible {
  outline: 2px solid #C4943C;
  outline-offset: 1px;
}

.search-chip.active {
  background: rgba(196, 148, 60, 0.15);
  color: #C4943C;
  border-color: rgba(196, 148, 60, 0.4);
}

.search-status {
  flex-shrink: 0;
  padding: 10px 16px;
  font-size: 0.85rem;
  color: #6a6a8a;
}

.search-results {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 40vh;
  overflow-y: auto;
  scrollbar-color: #2a2a4a #16162e;
}

.search-results::-webkit-scrollbar {
  width: 6px;
}

.search-results::-webkit-scrollbar-track {
  background: transparent;
}

.search-results::-webkit-scrollbar-thumb {
  background: #2a2a4a;
  border-radius: 3px;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.12s ease;
}

.search-result-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.search-result-item.active {
  background: rgba(196, 148, 60, 0.12);
}

.search-result-thumb {
  width: 60px;
  height: 34px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: #0d0d1a;
}

.search-result-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.search-result-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: #e8e8e8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
}

.search-result-date {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 600;
  color: #fff;
  font-size: 0.65rem;
}

.search-result-region {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #8888aa;
}

.search-result-region-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.search-hint {
  flex-shrink: 0;
  padding: 8px 16px 12px;
  font-size: 0.75rem;
  color: #4a4a6a;
}

.search-hint kbd {
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.04);
  font-family: inherit;
  font-size: 0.7rem;
  color: #6a6a8a;
}


/* ===== Search Button ===== */
.search-btn {
  position: absolute;
  bottom: 132px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: #1e1e3a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #8888aa;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.search-btn:hover {
  background: #2a2a4a;
  color: #C4943C;
}

.search-btn:focus-visible {
  outline: 2px solid #C4943C;
  outline-offset: 2px;
}

/* ===== Region Color Utilities (row header backgrounds + silhouettes) ===== */
.region-scotland { background: url('../images/regions/scotland.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #2C6B8A 0%, #1a4f6a 100%); }
.region-wales { background: url('../images/regions/wales.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #8B2E2E 0%, #6b1414 100%); }
.region-ireland { background: url('../images/regions/ireland.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #2E7D4F 0%, #1a5d35 100%); }
.region-northern-england { background: url('../images/regions/northern-england.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #6B5B8A 0%, #4f3f6e 100%); }
.region-northwest-england { background: url('../images/regions/northwest-england.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #4A7BA6 0%, #306090 100%); }
.region-midlands { background: url('../images/regions/midlands.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #8B7B42 0%, #6b5b28 100%); }
.region-east-england { background: url('../images/regions/east-england.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #4A8B5C 0%, #306b42 100%); }
.region-london { background: url('../images/regions/london.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #B44A4A 0%, #943030 100%); }
.region-southeast-england { background: url('../images/regions/southeast-england.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #5B7FA3 0%, #3f5f83 100%); }
.region-southwest-england { background: url('../images/regions/southwest-england.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #7B6B52 0%, #5b4b38 100%); }
.region-crown-parliament { background: url('../images/regions/crown-parliament.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #C4943C 0%, #a47420 100%); }
.region-overseas-empire { background: url('../images/regions/overseas-empire.webp?v=1') right center / auto 90% no-repeat, linear-gradient(135deg, #5B6B8B 0%, #3f4f6f 100%); }

/* ===== Loading to Grid Transition ===== */
.grid-container.fade-in {
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.loading-screen.fade-out {
  opacity: 0;
  transition: opacity 0.3s ease-out;
}

/* ===== Skip to content (Accessibility) ===== */
.skip-link {
  position: fixed;
  top: -100%;
  left: 16px;
  z-index: 100;
  padding: 8px 16px;
  background: #C4943C;
  color: #0d0d1a;
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: 0 0 6px 6px;
  text-decoration: none;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
}

/* ===== Timeline Selector ===== */
.site-switch {
  position: absolute;
  right: 72px;
  bottom: 20px;
  z-index: 66;
}

.site-switch__label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-switch__group {
  display: flex;
}

.site-switch__link {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  background: #1e1e3a;
  color: #b0b0cc;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.site-switch__link:hover {
  background: #2a2a4a;
  color: #C4943C;
}

.site-switch__link:focus-visible {
  outline: 2px solid #C4943C;
  outline-offset: 2px;
}

.site-switch__link[aria-current="page"] {
  background: #2a2a4a;
  color: #C4943C;
  border-color: rgba(196, 148, 60, 0.4);
}

.site-switch__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ===== Controls Wrapper (zoom-compensated) ===== */
.controls-wrap {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 65;
  transform-origin: bottom right;
}

/* ===== Language Button ===== */
.lang-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: #1e1e3a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #b0b0cc;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.lang-btn:hover {
  background: #2a2a4a;
  color: #C4943C;
}

/* ===== Settings Panel ===== */
.settings-btn {
  position: absolute;
  bottom: 76px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: #1e1e3a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #8888aa;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.settings-btn:hover {
  background: #2a2a4a;
  color: #C4943C;
}

.settings-panel {
  position: absolute;
  bottom: 188px;
  right: 20px;
  width: 260px;
  background: #16162e;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  padding: 18px 20px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.settings-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.settings-panel h3 {
  font-size: var(--settings-size, 0.9rem);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #6a6a8a;
  margin-bottom: 16px;
}

.settings-panel h3 + .settings-slider-group ~ h3 {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.settings-slider-group {
  margin-bottom: 14px;
}

.settings-slider-group:last-child {
  margin-bottom: 0;
}

.settings-slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: var(--settings-size, 0.9rem);
  color: #b0b0cc;
}

.settings-slider-value {
  font-size: var(--settings-size, 0.9rem);
  color: #6a6a8a;
  font-variant-numeric: tabular-nums;
}

.settings-panel input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: #2a2a4a;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.settings-panel input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: #C4943C;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s ease;
}

.settings-panel input[type="range"]::-webkit-slider-thumb:hover {
  background: #d4a44c;
}

.settings-panel input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: #C4943C;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

/* ===== Settings Backdrop ===== */
.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 64;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.settings-backdrop.open {
  opacity: 1;
  visibility: visible;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .site-switch {
    right: 72px;
    bottom: 20px;
  }

  .timeline-grid {
    grid-template-columns: 100px repeat(31, 140px);
    grid-template-rows: 40px repeat(12, 110px);
  }

  .cell-row-header {
    font-size: 0.72rem;
    padding: 0 10px;
    min-height: 110px;
  }

  .cell-col-header {
    font-size: 0.68rem;
  }

  /* Bottom-sheet modal */
  .detail-panel {
    align-items: flex-end;
  }

  .detail-content {
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    transform: translateY(100%);
  }

  .detail-panel.open .detail-content {
    transform: translateY(0);
  }

  .detail-drag-handle {
    display: flex;
    justify-content: center;
    padding: 12px 0 4px;
    cursor: grab;
    touch-action: none;
  }

  .detail-drag-handle span {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.2);
  }

  .detail-close {
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    font-size: 1.8rem;
  }

  .detail-nav {
    top: 35%;
  }

  .detail-nav-arrow {
    width: 44px;
    height: 44px;
  }

  .detail-nav-prev { left: 12px; }
  .detail-nav-next { right: 12px; }

  .detail-body {
    padding: 18px 20px 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .detail-title {
    font-size: 1.5rem;
  }

  .detail-action-btn {
    width: 44px;
    height: 44px;
  }

  .search-overlay {
    padding-top: 5vh;
  }

  .search-container {
    width: 95%;
    max-height: 80vh;
  }

  .search-chip {
    font-size: 0.68rem;
    padding: 10px 12px;
  }

  .search-results {
    max-height: 50vh;
  }

  .search-result-thumb {
    width: 48px;
    height: 27px;
  }

  .cell-event .event-title-overlay {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Safe area padding for notched phones */
  .controls-wrap {
    bottom: env(safe-area-inset-bottom, 0px);
    right: env(safe-area-inset-right, 0px);
  }
}

/* ===== Landscape phones ===== */
@media (orientation: landscape) and (max-height: 500px) {
  .detail-image-wrap {
    max-height: 40vh;
  }
}
