:root {
  --bg-color: #1a202c;
  --card-color: #2d3748;
  --text-color: #ffffff;
  --text-muted-color: #a0aec0;
  --correct-color: #38a169;
  --close-color: #dd6b20;
  --incorrect-color: #c53030;
  --font-family: 'Poppins', sans-serif;
  /* Ny variabel för havsfärg (om SVG är transparent) */
  --ocean-color: #0070d8; 
}
body[data-theme="colorblind"] {
  --correct-color: #0077b6;
  --close-color: #fb8500;
  --incorrect-color: #e63946;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: var(--font-family);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px;
  min-height: 100vh;
}
#loader {
  position: fixed; left: 50%; top: 50%; z-index: 200;
  width: 50px; height: 50px; border: 5px solid var(--text-muted-color);
  border-top-color: var(--text-color); border-radius: 50%;
  animation: spin 1s linear infinite;
  transform: translate(-50%, -50%);
}
#loader.hidden { display: none; }
@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } }

header {
  text-align: center; margin-bottom: 20px;
  position: relative; width: 100%; max-width: 500px;
  transition: all 0.5s ease-in-out;
}
.header-top-row { display: flex; justify-content: space-between; align-items: center; height: 30px; margin-bottom: 10px; }
.header-icons-right { display: flex; align-items: center; gap: 10px; }

#mode-switcher, #help-icon, #stats-icon, #color-theme-switcher, #language-button {
  background: var(--card-color); border: none; padding: 0; font: inherit;
  color: var(--text-muted-color); cursor: pointer; width: 30px; height: 30px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s, background-color 0.2s;
}
#mode-switcher:hover, #help-icon:hover, #stats-icon:hover, #color-theme-switcher:hover, #language-button:hover {
  transform: scale(1.1); background-color: #4a5568;
}
#help-icon { font-weight: 700; color: var(--text-color); }
#stats-icon svg, #mode-switcher svg, #color-theme-switcher svg { width: 18px; height: 18px; }

#language-switcher { position: relative; }
#language-button { font-weight: 700; font-size: 0.8rem; }
#language-dropdown {
  position: absolute; top: 35px; right: 0; background-color: var(--bg-color);
  border-radius: 8px; padding: 5px; z-index: 20; display: flex;
  flex-direction: column; gap: 5px; border: 1px solid var(--card-color);
}
#language-dropdown a {
  color: var(--text-color); text-decoration: none; padding: 5px 10px;
  border-radius: 4px; font-weight: 700; font-size: 0.8rem;
}
#language-dropdown a:hover { background-color: var(--card-color); }

#logo-container { 
  position: relative;
  width: 100%;
  max-width: 350px;
  margin: 0 auto 10px auto;
  transition: all 0.5s ease-in-out;
}
#h1-title {
  font-size: 2.5rem;
  font-weight: 900;
  transition: all 0.5s ease-in-out;
}
#expert-stamp {
  position: absolute; bottom: -5px; right: -15px;
  width: 110px; height: auto; transform: rotate(-10deg);
  pointer-events: none;
}
#expert-stamp.hidden { display: none; }
#expert-stamp text {
  font-family: 'Poppins', 'Impact', sans-serif; font-weight: 900;
  font-size: 24px; fill: white; stroke: #1e1e1e;
  stroke-width: 1.5px; paint-order: stroke;
}
#h2-subtitle {
  font-size: 1.1rem; font-weight: 400; color: var(--text-color);
  padding: 0 10px; margin-bottom: 10px;
  transition: all 0.5s ease-in-out;
  max-height: 100px; overflow: hidden;
}
header.shrunk #logo-container, header.shrunk #h2-subtitle {
  opacity: 0; max-height: 0; margin: 0; padding: 0;
}

main#game-container { 
  width: 100%;
  max-width: 500px;
  flex-grow: 1;
}
#guess-counter-wrapper { height: 20px; margin-bottom: 10px; }
#guess-counter { text-align: right; color: var(--text-muted-color); padding-right: 15px; font-size: 0.9rem; }

#search-section { position: relative; margin-bottom: 15px; }
#search-wrapper { position: relative; }

/* --- SHAKE ANIMATION v1.12 --- */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.shake {
  animation: shake 0.4s ease-in-out;
}

#guess-input {
  width: 100%; padding: 15px; border-radius: 25px; border: none;
  background-color: var(--card-color); color: var(--text-color);
  font-size: 1rem; font-family: var(--font-family);
}
#guess-input:focus { outline: 2px solid var(--text-muted-color); }
#search-results {
  position: absolute; width: 100%; background-color: #2d3748;
  border-radius: 15px; margin-top: 5px; z-index: 10;
  max-height: 220px; overflow-y: auto;
}
.search-result-item { padding: 10px 15px; cursor: pointer; }
.search-result-item.highlighted, .search-result-item:hover { background-color: #4a5568; }
.search-result-item em { color: var(--text-muted-color); font-size: 0.9rem; margin-left: 8px; }

#color-guide-container {
  display: flex; justify-content: center; gap: 20px; margin-top: 20px;
  margin-bottom: 15px; transition: opacity 0.3s ease-in-out;
  width: 100%; max-width: 500px;
}
.guide-item { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.guide-color-box { width: 25px; height: 25px; border-radius: 5px; transition: background-color 0.3s; }
.guide-item span { font-size: 0.75rem; color: var(--text-muted-color); font-weight: 600; }
.guide-color-box.correct { background-color: var(--correct-color); }
.guide-color-box.close { background-color: var(--close-color); }
.guide-color-box.incorrect { background-color: var(--incorrect-color); }

#guesses-container { display: flex; flex-direction: column; gap: 15px; }
.guess-card { background-color: var(--card-color); border-radius: 15px; padding: 12px; animation: slideIn 0.5s ease-out forwards; }
.guess-header { display: flex; align-items: center; gap: 15px; margin-bottom: 12px; }
.guess-number { margin-left: auto; color: var(--text-muted-color); font-size: 0.9rem; }

/* BILDANPASSNING v1.10 */
.city-image { 
    height: 60px; 
    width: auto; 
    max-width: 120px; 
    border-radius: 8px; 
    object-fit: contain; 
    background-color: #4a5568; 
    cursor: pointer; 
    transition: transform 0.2s; 
}
.city-image:hover { transform: scale(1.05); }
.city-name { font-size: 1.5rem; font-weight: 600; }

.attributes-grid { 
  display: grid; 
  grid-template-columns: repeat(6, 1fr); 
  gap: 6px; 
}

.attribute-tile {
  background-color: #4a5568; border-radius: 10px; padding: 6px;
  color: var(--text-color); transform: rotateY(90deg); opacity: 0;
  display: flex; flex-direction: column; justify-content: center;
  text-align: center; min-width: 0; transition: background-color 0.3s;
}

/* --- New Grid Layout --- */
[data-attribute="country"],
[data-attribute="continent"],
[data-attribute="is_capital"],
[data-attribute="distance"],
[data-attribute="population"],
[data-attribute="elevation_m"],
[data-attribute="year_founded"] {
  grid-column: span 2;
}
[data-attribute="map"] {
  grid-column: span 4;
  padding: 6px;
}
/* ------------------------ */

.attribute-tile .label { display: block; margin-bottom: 4px; color: var(--text-color); font-size: 0.7rem; font-weight: 600; text-transform: uppercase; }
.attribute-tile .value { font-weight: 600; display: inline-flex; justify-content: center; align-items: center; gap: 0.25em; font-size: 1rem; line-height: 1.2; }
.value.up-arrow::after, .value.down-arrow::after { content: '↑'; color: var(--text-color); }
.value.down-arrow::after { content: '↓'; }

.attribute-tile[data-attribute="country"] { justify-content: flex-start; gap: 4px; }
.flag-image { width: 44px; height: 33px; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.2); margin: 0 auto; object-fit: cover; }
.country-name { font-size: 0.9rem !important; }

.attribute-tile.correct { background-color: var(--correct-color); }
.attribute-tile.close { background-color: var(--close-color); }
.attribute-tile.incorrect { background-color: var(--incorrect-color); }

/* --- MAP STYLES (Single Map) --- */
.map-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1;
  border-radius: 6px;
  overflow: hidden;
  /* Bakgrundsfärgen här syns om SVG:n är transparent */
  background-color: var(--ocean-color); 
  margin-top: 4px;
}

.map-strip {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.map-strip img {
  width: 100%;
  height: 100%;
  object-fit: fill; 
  user-select: none;
  -webkit-user-drag: none;
  display: block;
  shape-rendering: geometricPrecision; 
}

.map-pin {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: auto;
  transform: translate(-50%, -250%) scale(2.5); 
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  /* BOUNCE EFFECT: Mjukare landning v1.16 */
  transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.5s;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
  will-change: transform, opacity;
}

.map-pin.landed {
  opacity: 1;
  transform: translate(-50%, -100%) scale(1);
}
/* --- END MAP STYLES --- */

/* --- COMPASS STYLES v1.13 --- */
.attribute-tile[data-attribute="distance"] { 
    justify-content: space-between; 
    padding-bottom: 6px; 
}
.compass-container { 
    position: relative; 
    width: 65%;
    max-width: 100px;
    min-width: 60px;
    aspect-ratio: 1 / 1; 
    margin: 2px auto;
}
.compass-base, .compass-arrow { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.compass-arrow { transform-origin: center center; }
.distance-text { font-size: 0.9rem !important; font-weight: 700; }
.compass-arrow.animated { animation: compass-stabilize 2s cubic-bezier(0.25, 1, 0.5, 1) forwards; }
@keyframes compass-stabilize {
  0% { transform: rotate(-360deg); animation-timing-function: ease-in; }
  30% { transform: rotate(calc(var(--direction-degrees, 0deg) + 360deg)); animation-timing-function: ease-out; }
  55% { transform: rotate(calc(var(--direction-degrees, 0deg) - 30deg)); animation-timing-function: ease-in-out; }
  75% { transform: rotate(calc(var(--direction-degrees, 0deg) + 15deg)); animation-timing-function: ease-out; }
  90% { transform: rotate(calc(var(--direction-degrees, 0deg) - 5deg)); animation-timing-function: ease-in-out; }
  100% { transform: rotate(var(--direction-degrees, 0deg)); }
}
/* --- END COMPASS STYLES --- */

@keyframes slideIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes flipIn { from { transform: rotateY(90deg); opacity: 0; } to { transform: rotateY(0deg); opacity: 1; } }

.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background-color: rgba(0, 0, 0, 0.7); display: flex;
  justify-content: center; align-items: center; z-index: 100; padding: 20px;
}
.modal.hidden { display: none; }
.modal-content {
  background-color: var(--card-color); padding: 20px 15px; border-radius: 15px;
  text-align: center; animation: slideIn 0.3s ease-out; display: flex;
  flex-direction: column; align-items: center; max-width: 90%;
  width: 500px; position: relative; max-height: 90vh; overflow-y: auto;
}
.image-modal-content {
    width: auto;
    max-width: 95%;
    background-color: transparent;
    box-shadow: none;
    padding: 0;
    overflow: visible;
}
.image-modal-content .modal-close-button {
    background-color: var(--card-color);
    top: -15px;
    right: -15px;
    z-index: 10;
}
#full-size-image {
    max-width: 100%;
    max-height: 85vh;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    display: block;
}

.modal-close-button {
  position: absolute; top: 10px; right: 10px; width: 30px; height: 30px;
  background: #4a5568; color: var(--text-muted-color); border: none;
  border-radius: 50%; font-size: 1.5rem; line-height: 1; display: flex;
  align-items: center; justify-content: center; cursor: pointer; padding: 0; margin: 0;
}
.modal-close-button:hover { background-color: #718096; }
#share-encouragement { color: var(--text-muted-color); font-size: 0.9rem; margin-bottom: 15px; }
.modal-button-group { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 280px; margin-bottom: 15px; }
#modal-switch-mode-button { padding: 10px 20px; border: none; border-radius: 20px; color: var(--bg-color); font-weight: 700; cursor: pointer; transition: transform 0.2s, background-color 0.2s; }
#modal-switch-mode-button:hover { transform: scale(1.05); }
#modal-share-button { padding: 10px 20px; border: none; border-radius: 20px; font-weight: 700; cursor: pointer; transition: transform 0.2s, background-color 0.2s; background-color: var(--correct-color); color: #ffffff; display: flex; align-items: center; justify-content: center; gap: 8px; }
#modal-share-button:hover { transform: scale(1.05); }

#modal-title { font-size: 1.8rem; line-height: 1.4; margin-bottom: 5px; padding-right: 30px; }
#modal-city-reveal { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 15px; }
#modal-city-image { width: 120px; height: 120px; border-radius: 16px; object-fit: cover; background-color: #4a5568;}
#modal-city-name { font-size: 1.8rem; font-weight: 700; }
#modal-text, #play-again-text { color: var(--text-muted-color); font-size: 0.9rem; font-style: normal; font-weight: 400; }
#modal-text { margin-bottom: 15px; }
#modal-streak-text { color: var(--text-muted-color); font-size: 0.9rem; line-height: 1.4; margin-top: -5px; margin-bottom: 15px; }
#play-again-text { margin-bottom: 15px; }
.modal-streaks-container { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 5px 15px; margin-bottom: 20px; color: var(--text-muted-color); font-size: 1.1rem; line-height: 1.4; width: 100%; }
.modal-streaks-container .streak-item { white-space: nowrap; }
.modal-streaks-container span { font-weight: 700; color: var(--text-color); }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; width: 100%; margin-bottom: 25px; }
.stat-item { text-align: center; }
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { font-size: 0.8rem; color: var(--text-muted-color); }
.distribution-title { font-size: 1.2rem; margin-bottom: 15px; }
#stats-distribution-container { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.dist-row { display: flex; align-items: center; gap: 10px; }
.dist-label { font-weight: 600; width: 20px; text-align: right; }
.dist-bar-wrapper { flex-grow: 1; background-color: #4a5568; border-radius: 4px; }
.dist-bar { background-color: var(--text-muted-color); height: 20px; border-radius: 4px; text-align: right; padding-right: 5px; color: var(--bg-color); font-weight: 600; font-size: 0.8rem; white-space: nowrap; }

#help-modal .modal-content { text-align: left; }
#help-modal .modal-title-help { width: 100%; text-align: center; }
#help-modal .help-section { margin-bottom: 20px; }
#help-modal .help-section p { margin-bottom: 5px; }
#help-modal .legend-grid { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: center; max-width: 250px; margin: 15px 0; }
#help-modal .legend-item { width: 25px; height: 25px; border-radius: 5px; }
#help-modal .legend-item.correct { background-color: var(--correct-color); }
#help-modal .legend-item.close { background-color: var(--close-color); }
#help-modal .legend-item.incorrect-legend { background-color: var(--incorrect-color); }
#help-modal .legend-grid span { font-weight: 600; }

footer { width: 100%; max-width: 500px; text-align: center; padding: 20px 0 10px 0; color: var(--text-muted-color); font-size: 0.8rem; }
footer p { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 8px; }
.footer-icon-link, .footer-link { color: var(--text-muted-color); text-decoration: none; display: inline-flex; align-items: center; transition: color 0.2s, transform 0.2s; }
.footer-icon-link:hover, .footer-link:hover { color: var(--text-color); transform: scale(1.05); text-decoration: underline; }
.footer-icon-link svg { width: 20px; height: 20px; stroke: currentColor; }
.hidden { display: none !important; }

@media (max-width: 480px) {
  .city-name { font-size: 1.2rem; }
  .city-image { height: 50px; } /* Anpassa även mobilt */
  .attribute-tile .value { font-size: 0.9rem; }
  .stat-value { font-size: 1.5rem; }
}