/* ========== CSS Variables ========== */
:root {
  --color-primary: #1a3a6b;
  --color-primary-light: #2755a0;
  --color-accent: #f57c00;
  --color-accent-hover: #e65100;
  --color-bg: #f0f4f8;
  --color-card: #ffffff;
  --color-text: #2d3436;
  --color-text-light: #636e72;
  --color-border: #dfe6e9;
  --color-success: #27ae60;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --header-height: 56px;
  --font-base: -apple-system, 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Meiryo', 'Yu Gothic', sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font-base);
  color: var(--color-text);
  background: var(--color-bg);
}

a {
  color: var(--color-primary-light);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

/* ========== Header ========== */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: var(--header-height);
  background: var(--color-primary);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  box-shadow: var(--shadow-md);
}

.site-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
  text-decoration: none;
  flex-shrink: 0;
}

.site-title:hover {
  text-decoration: none;
  opacity: 0.9;
}

/* ========== Search ========== */
.search-container {
  position: relative;
  flex: 1;
  max-width: 420px;
}

.search-input {
  width: 100%;
  height: 36px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  font-size: 0.9rem;
  font-family: var(--font-base);
  outline: none;
  transition: background 0.2s;
}

.search-input::placeholder {
  color: rgba(255, 255, 255, 0.65);
}

.search-input:focus {
  background: rgba(255, 255, 255, 0.28);
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--color-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  list-style: none;
  overflow: hidden;
  z-index: 2000;
  max-height: 320px;
  overflow-y: auto;
}

.search-result-item {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
}

.search-result-item:hover {
  background: var(--color-bg);
}

.search-result-en {
  color: var(--color-text-light);
  font-size: 0.82rem;
}

/* ========== Map ========== */
#map {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

.map-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 500;
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 20px 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-md);
  font-size: 0.95rem;
  color: var(--color-text-light);
}

/* ========== Loading Spinner ========== */
.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary-light);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* ========== Country Popup (Light View) ========== */
.country-popup {
  position: fixed;
  top: calc(var(--header-height) + 12px);
  right: 12px;
  z-index: 800;
  width: 280px;
  background: var(--color-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.popup-close-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--color-text-light);
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}

.popup-close-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.popup-header {
  padding: 18px 16px 12px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.popup-flag {
  font-size: 2.4rem;
  line-height: 1;
  flex-shrink: 0;
}

.popup-name-ja {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.3;
  padding-right: 24px;
}

.popup-info {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.popup-info-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.9rem;
}

.popup-info-label {
  flex-shrink: 0;
  width: 44px;
  font-size: 0.75rem;
  color: var(--color-text-light);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.popup-info-value {
  color: var(--color-text);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: baseline;
}

.popup-reading {
  font-size: 0.82rem;
  color: var(--color-text-light);
}

.popup-actions {
  padding: 12px 16px 16px;
}

/* ========== Buttons ========== */
.btn-primary {
  display: inline-block;
  width: 100%;
  padding: 10px 16px;
  background: var(--color-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font-base);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--color-accent-hover);
  text-decoration: none;
  color: #ffffff;
}

.btn-back {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.9rem;
  text-decoration: none;
  white-space: nowrap;
}

.btn-back:hover {
  color: #ffffff;
  text-decoration: none;
}

/* ========== Today's Country Widget ========== */
.today-widget {
  position: fixed;
  bottom: 24px;
  left: 12px;
  z-index: 800;
  background: var(--color-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 10px 14px;
  min-width: 150px;
  border-left: 4px solid var(--color-accent);
}

.today-header {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-accent);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.today-body {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.today-flag {
  font-size: 1.5rem;
  line-height: 1;
}

.today-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
}

.today-link {
  font-size: 0.8rem;
  color: var(--color-primary-light);
  font-weight: 500;
}

/* ========== Map Region Colors (applied via Leaflet path styles) ========== */
/* These colors are set in JS — here for reference only */

/* ========== Detail Page ========== */
.detail-page {
  background: var(--color-bg);
  min-height: 100vh;
}

.detail-page .site-header {
  position: sticky;
}

.country-detail {
  max-width: 800px;
  margin: 0 auto;
  padding: calc(var(--header-height) + 24px) 16px 80px;
}

.detail-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 0;
  color: var(--color-text-light);
}

/* Detail Hero */
.detail-hero {
  display: flex;
  align-items: center;
  gap: 20px;
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.detail-flag-img {
  width: 96px;
  height: auto;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  object-fit: contain;
}

.detail-name-ja {
  font-size: 2rem;
  font-weight: 800;
  color: var(--color-primary);
  line-height: 1.2;
  margin-bottom: 6px;
}

.detail-region {
  font-size: 0.9rem;
  color: var(--color-text-light);
  display: flex;
  align-items: center;
  gap: 4px;
}

.detail-capital {
  font-size: 0.88rem;
  color: var(--color-text-light);
  margin-top: 4px;
}

/* Detail Cards */
.detail-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

@media (max-width: 480px) {
  .detail-cards {
    grid-template-columns: 1fr;
  }
}

.detail-card {
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.detail-card h3 {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--color-text-light);
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.local-name {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 4px;
}

.local-reading {
  font-size: 0.9rem;
  color: var(--color-text-light);
}

.en-reading {
  margin-top: 4px;
  font-size: 0.9rem;
  color: var(--color-text-light);
}

.en-name {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--color-text);
}

.detail-card--capital {
  grid-column: 1 / -1;   /* 2カラム全幅 */
}

.capital-name {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-text);
}

/* Wikipedia Links */
.wiki-links {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.wiki-links-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--color-text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 4px;
}

.wiki-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--color-primary-light);
  text-decoration: none;
  transition: all 0.15s;
}

.wiki-link:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary-light);
  color: #ffffff;
  text-decoration: none;
}

/* Etymology */
.detail-etymology {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}

.etymology-section {
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--color-primary-light);
}

.etymology-section h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 10px;
}

.etymology-section p {
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--color-text);
}

/* Neighbors */
.neighbors-section {
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}

.neighbors-section h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 14px;
}

.neighbors-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.neighbor-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--color-text);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
}

.neighbor-card:hover {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #ffffff;
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* 実際に国境を接する国 — 先頭に並び、枠線で区別 */
.neighbor-card--border {
  border-color: var(--color-primary-light);
  background: rgba(39, 85, 160, 0.06);
  font-weight: 600;
}

/* ========== Island Nation Markers ========== */
.island-marker {
  background: rgba(255, 255, 255, 0.92) !important;
  border: 2px solid var(--color-primary) !important;
  border-radius: 50% !important;
  width: 28px !important;
  height: 28px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s, box-shadow 0.15s;
}

.island-marker:hover {
  transform: scale(1.25);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.island-marker span {
  display: block;
  line-height: 1;
}

/* Island toggle button (Leaflet custom control) */
.island-toggle-btn {
  background: white;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-base);
}

.island-toggle-btn:hover {
  background: var(--color-bg);
}

.island-toggle-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.neighbor-flag {
  font-size: 1.2rem;
  line-height: 1;
}

/* Not Found */
.not-found {
  text-align: center;
  padding: 60px 0;
  color: var(--color-text-light);
}

.not-found p {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

/* FAB Back Button (floating) */
.fab-back {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 52px;
  height: 52px;
  background: var(--color-primary);
  color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  box-shadow: var(--shadow-md);
  text-decoration: none;
  transition: background 0.2s, transform 0.15s;
  z-index: 900;
}

.fab-back:hover {
  background: var(--color-primary-light);
  transform: scale(1.08);
  text-decoration: none;
}

/* ========== Leaflet Overrides ========== */
.leaflet-container {
  background: #a8d4e8;
  font-family: var(--font-base);
}

.leaflet-control-attribution {
  font-size: 10px;
}

/* ========== Responsive ========== */
@media (max-width: 600px) {
  .site-title {
    font-size: 0.95rem;
  }

  .search-container {
    max-width: none;
  }

  .country-popup {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: slideUp 0.25s ease-out;
  }

  @keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .today-widget {
    display: none;
  }

  .detail-hero {
    flex-direction: column;
    text-align: center;
    padding: 20px 16px;
  }

  .detail-name-ja {
    font-size: 1.6rem;
  }

  .detail-flag-img {
    width: 72px;
  }
}
