/* =========================================
   0. THEME VARIABLES (Komi palette)
   ========================================= */
:root {
  --primary-color: #00447c;
  --hover-color: #002b52;
  --border-color: #005a36;
  --primary-rgb: 0, 68, 124;
  --primary-tint: rgba(var(--primary-rgb), 0.08);
  --primary-tint-strong: rgba(var(--primary-rgb), 0.12);
}

/* =========================================
   1. BASE RESET & TYPOGRAPHY
   ========================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  /* Üleminek sügavast tumesinisest kaunisse, väga tumedasse metsarohelisse */
  background: linear-gradient(to bottom, var(--primary-color) 0%, #004223 100%);
  background-attachment: fixed;
  font-family: "Lora", serif;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

h1,
h2,
h3,
h4,
h5,
h6,
.menu-label,
.menu-item,
.menu-toc {
  font-family: "Montserrat", sans-serif;
}

.pattern-left,
.pattern-right {
  position: fixed;
  top: 0;
  width: 20%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.pattern-left {
  left: 0;
  background: linear-gradient(to right, rgba(255, 255, 255, 0.1), transparent);
}

.pattern-right {
  right: 0;
  background: linear-gradient(to left, rgba(255, 255, 255, 0.1), transparent);
}

/* =========================================
   2. MAIN LAYOUT (DESKTOP)
   ========================================= */
.main-wrapper {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  height: 100vh;
  gap: 30px;
  padding: 0 20px;
  box-sizing: border-box;
}

.main-wrapper::after {
  content: "";
  width: 250px;
  flex-shrink: 0;
  display: block;
}

/* =========================================
   3. SIDE NAVIGATION
   ========================================= */
.sticky-menu {
  position: relative;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  width: 250px;
  flex-shrink: 0;
  box-sizing: border-box;
  overflow-x: hidden;
  max-height: 90vh;
  align-self: flex-start;
  margin-top: calc(50vh - 250px);
}

.sticky-menu-ornament {
  display: block;
  width: 100%;
  height: 34px;
  border-radius: 5px 5px 0 0;
  background-color: var(--primary-color);
  object-fit: cover;
  object-position: center top;
}

.sticky-menu ul {
  list-style: none;
}

#main-menu {
  padding: 10px;
}

.menu-label {
  font-weight: bold;
  font-size: 0.7rem;
  color: #888;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.menu-row {
  margin-bottom: 6px;
}

.menu-item {
  display: block;
  padding: 4px 5px;
  margin-bottom: 2px;
  cursor: pointer;
  transition: 0.3s;
  border-radius: 4px;
  font-weight: 500;
  font-size: 1rem;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  text-decoration: none;
  color: inherit;
}

a.menu-item {
  color: inherit;
}

.menu-item.active {
  background-color: var(--primary-color);
  color: white;
}

.menu-toc {
  list-style: none;
  margin: 4px 0 0 0;
  padding: 0 0 0 4px;
  max-height: 38vh;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.25;
}

.menu-toc:empty {
  display: none;
}

.menu-toc li {
  margin: 0;
}

.menu-toc a {
  display: block;
  color: #555;
  text-decoration: none;
  padding: 3px 4px 3px 8px;
  border-left: 3px solid transparent;
  border-radius: 0 3px 3px 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  transition:
    color 0.2s,
    border-color 0.2s,
    background 0.2s;
}

.menu-toc a:hover {
  color: var(--primary-color);
  background: var(--primary-tint);
}

.menu-toc a.active {
  color: var(--primary-color);
  font-weight: 600;
  border-left-color: var(--primary-color);
  background: var(--primary-tint-strong);
}

.menu-toc .toc-h3 {
  padding-left: 8px;
}

.menu-toc .toc-h4 {
  padding-left: 16px;
  font-size: 0.8rem;
  color: #666;
}

.menu-toc .toc-h4.active {
  color: var(--primary-color);
}

/* =========================================
   4. CONTENT AREA & TOOLBARS
   ========================================= */
.lang-toolbar {
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #d3d3d3;
  z-index: 20;
}

.language-links {
  margin: 0;
  font-family: "Montserrat", sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
}

.language-links .lang-sep {
  color: #bbb;
  margin: 0 4px;
  user-select: none;
}

.lang-link {
  color: #333;
  text-decoration: none;
  padding: 2px 0;
  transition: color 0.2s;
}

.lang-link:hover,
.lang-link.active {
  color: var(--primary-color);
}

.content-window {
  --content-inline-pad: 50px;
  background: white;
  min-width: 500px;
  max-width: 1000px;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  position: relative;
  border-radius: 5px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  z-index: 11;
  overflow: hidden;
}

#dynamicContent {
  animation: fadeIn 0.5s ease-out;
}

.content-window-scroll {
  padding: 0;
  overflow-y: auto;
  flex-grow: 1;
  min-height: 0;
  scrollbar-gutter: stable both-edges;
  scrollbar-width: thin;
  scrollbar-color: var(--primary-color) #f1f1f1;
}

.content-scroll-inner {
  padding: 0 var(--content-inline-pad) 50px;
  min-height: 100%;
  box-sizing: border-box;
}

.scroll-top-divider {
  height: 1px;
  background-color: #d3d3d3;
  margin: 4px 0 18px;
}

.content-window-scroll::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.content-window-scroll::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.content-window-scroll::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 4px;
}

.content-window-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--hover-color);
}

.content-window-scroll::-webkit-scrollbar-corner {
  background: #f1f1f1;
}

.scroll-content a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px solid transparent;
  transition: all 0.2s ease-in-out;
}

.scroll-content a:hover {
  color: var(--hover-color);
  border-bottom: 1px solid var(--border-color);
}

.scroll-content a[href$=".mp3"],
.scroll-content a[href$=".MP3"] {
  cursor: pointer;
}

.scroll-content a.komi-mp3-playing {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  border-radius: 4px;
}

.scroll-content p {
  text-align: justify;
  line-height: 1.5;
  margin-bottom: 15px;
}

.scroll-content h2,
.scroll-content h3,
.scroll-content h4 {
  margin-top: 15px;
  margin-bottom: 15px;
  color: #333;
}

.scroll-content hr {
  border: 0;
  border-top: 1px solid rgba(var(--primary-rgb), 0.2);
  margin: 14px 0;
}

.scroll-content .footnote {
  font-size: 0.88rem;
  color: #666;
  font-style: italic;
}

.scroll-content ul,
.scroll-content ol {
  padding-left: 30px;
  margin-bottom: 15px;
}

.scroll-content li {
  margin-bottom: 8px;
  line-height: 1.35;
  text-align: justify;
}

.scroll-content li > .video-embed {
  margin-top: 10px;
}

.scroll-content blockquote {
  margin: 18px 0;
  padding: 10px 15px;
  border-left: 4px solid var(--border-color);
  background: #f4f8fb;
  color: #242424;
  font-style: italic;
  line-height: 1.55;
  border-radius: 0 6px 6px 0;
  box-shadow: inset 0 0 0 1px var(--primary-tint);
}

.scroll-content table.komi-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.95rem;
}

.scroll-content table.komi-table td,
.scroll-content table.komi-table th {
  border: 1px solid rgba(var(--primary-rgb), 0.25);
  padding: 8px 10px;
  vertical-align: top;
}

.lang-block {
  display: none;
}

.lang-block.is-active {
  display: block;
}

.title-plaque {
  display: flex;
  justify-content: center;
  margin: 10px 0 6px;
}

.title-plaque-text {
  font-family: "Montserrat", sans-serif;
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 12px 32px;
  background: linear-gradient(
    135deg,
    var(--hover-color) 0%,
    var(--primary-color) 45%,
    var(--border-color) 100%
  );
  color: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(var(--primary-rgb), 0.25);
}

/* =========================================
   5. MEDIA & IMAGES (TEXT WRAPPING)
   ========================================= */
/* Desktop text wrapping */

.media-figure-right, .media-figure-left { 
  width: min(30%, 442px); 
  padding: 0; 
}

.media-figure-right {
  float: right;
  margin: 5px 0 12px 24px;
}

.media-figure-left {
  float: left;
  margin: 5px 24px 12px 0;
}

.media-figure-wide-right, .media-figure-wide-left {
  width: min(50%, 500px);
  padding: 0;
}
.media-figure-wide-right { float: right; margin: 5px 0 12px 24px; }
.media-figure-wide-left { float: left; margin: 5px 24px 12px 0; }

.in-text-media {
  display: flex;
  flex-wrap: wrap;
  gap: 20px 24px;
  align-items: flex-start;
  margin: 16px 0 24px;
}

.in-text-media-text {
  flex: 1 1 220px;
  min-width: 0;
}

.in-text-media-figure {
  flex: 0 1 260px;
  padding-top: 5px;
  margin: 0;
  max-width: 100%;
}

.in-text-media-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
  object-fit: cover;
}

.in-text-media-img-right {
  flex-direction: row;
}

.in-text-media-img-left {
  flex-direction: row;
}

@media (max-width: 620px) {
  .in-text-media-img-right,
  .in-text-media-img-left {
    flex-direction: column;
  }

  .in-text-media-figure {
    flex-basis: auto;
    width: 100%;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
  }

  .in-text-media-img-left .in-text-media-figure {
    order: -1;
  }
}

.video-embed {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 10px 0 4px;
  aspect-ratio: 16 / 9;
  background: #111;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.video-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* =========================================
   6. HERO SLIDESHOW
   ========================================= */
.hero-band {
  box-sizing: border-box;
  width: 100%;
  padding: 10px 0 0;
}

.hero {
  display: grid;
  place-items: center;
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding-top: 10px;
  padding-bottom: 20px;
  text-align: center;
  container-type: inline-size;
}

#heroRoot {
  position: relative;
}

.hero-slides {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1;
  max-height: min(52vh, 420px);
  border-radius: 5px;
  overflow: hidden;
  background: #e8e8e8;
}

.hero-slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  z-index: 0;
  transition: opacity 1.1s ease-in-out;
  pointer-events: none;
  transform: translateZ(0);
}

.hero-slide.is-visible {
  opacity: 1;
  z-index: 1;
}

.hero-btn {
  position: absolute;
  top: 0;
  height: 100%;
  width: 10%;
  max-width: 100px;
  color: rgba(255, 255, 255, 0.6);
  border: none;
  font-size: 2rem;
  cursor: pointer;
  z-index: 10;
  transition: all 0.3s ease;
  border-radius: 0;
  padding: 0;
  display: flex;
  align-items: center;
}

.hero-prev {
  left: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.5) 0%, transparent 100%);
  justify-content: flex-start;
  padding-left: 15px;
}

.hero-prev:hover {
  background: linear-gradient(to right, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
  color: #ffffff;
}

.hero-next {
  right: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.5) 0%, transparent 100%);
  justify-content: flex-end;
  padding-right: 15px;
}

.hero-next:hover {
  background: linear-gradient(to left, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
  color: #ffffff;
}

.image {
  background: #fdfdfd;
  border: 1px dashed #ccc;
  margin: 20px 0;
  width: 100%;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
}

/* =========================================
   7. FOOTER & ANIMATIONS
   ========================================= */
.main-footer {
  position: fixed;
  bottom: 14px;
  right: 14px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  border-radius: 6px;
  z-index: 50;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 10px 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}

.footer-content {
  text-align: right;
  font-size: 0.82rem;
  line-height: 1.35;
}

.footer-content p {
  margin: 0;
}

.footer-content p + p {
  margin-top: 4px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.mobile-menu-btn {
  display: none;
  width: 100%;
  background: var(--primary-color);
  color: #ffffff;
  border: none;
  padding: 12px 15px;
  font-size: 1.1rem;
  font-family: "Montserrat", sans-serif;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  border-bottom: 1px solid var(--hover-color);
  transition: background-color 0.2s;
}

.mobile-menu-btn:hover {
  background: var(--hover-color);
}

/* =========================================
   8. TABLET VIEW (under 1150px)
   ========================================= */
@media (max-width: 1150px) {
  body {
    padding: 0;
    background: #ffffff;
    height: auto !important;
    overflow: auto !important;
  }

  .main-wrapper {
    flex-direction: column;
    justify-content: flex-start;
    height: auto !important;
    padding: 0;
  }

  .main-wrapper::after {
    display: none;
  }

  .sticky-menu {
    position: sticky;
    top: 0;
    z-index: 200;
    left: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    margin-bottom: 0;
    margin-top: 0;
    flex-shrink: 0;
    overflow: visible;
    border-radius: 0;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    border-bottom: none;
  }

  .sticky-menu-ornament {
    width: 100%;
    height: 60px; /* Fikseerime uue ja ilusa kõrguse */
    object-fit: cover;
    object-position: center top;
    border-radius: 0;
    display: block;
  }

  .mobile-menu-btn {
    display: block;
    padding-right: 120px;
  }

  #main-menu {
    display: none;
  }

  .main-wrapper {
    position: relative;
  }

  .media-figure-right {
    float: right !important;       
    max-width: 60% !important;     
    min-width: 300px !important;   
    margin: 5px 0 15px 20px !important;
    display: block;
  }

  .media-figure-left {
    float: left !important;        
    max-width: 60% !important;
    min-width: 300px !important;   
    margin: 5px 20px 15px 0 !important;
    display: block;
  }

  .media-figure-wide-right {
    float: right !important;
    max-width: 55% !important;
    min-width: 320px !important; /* Forces it to stay readable on tablets */
    margin: 5px 0 15px 20px !important;
    display: block;
  }
  .media-figure-wide-left {
    float: left !important;
    max-width: 55% !important;
    min-width: 320px !important;
    margin: 5px 20px 15px 0 !important;
    display: block;
  }

  .lang-toolbar {
    position: fixed;
    top: 60px; /* SEE NUMBER peab olema täpselt sama, mis ornamendi kõrgus! */
    right: 0;
    height: 47px;
    background: transparent;
    border: none;
    padding: 0 15px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    z-index: 201;
  }

  .lang-link,
  .language-links .lang-sep {
    color: #ffffff;
  }

  .lang-link.active,
  .lang-link:hover {
    color: #ffffff;
    text-decoration: underline;
  }

  .sticky-menu.is-open #main-menu {
    display: block;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.98);
    z-index: 100;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
    max-height: 75vh;
    overflow-y: auto;
    padding-bottom: 15px;
    border-radius: 0 0 5px 5px;
  }
  
  .menu-toc {
    max-height: none;
    overflow-y: visible;
  }

  .content-window {
    min-width: 0;
    max-width: 100%;
    max-height: none;
    flex-grow: 1;
    --content-inline-pad: 20px;
    border-radius: 0;
    box-shadow: none;
    position: static;
    overflow: visible;
    z-index: auto !important;
  }

  .content-window-scroll {
    overflow: visible !important;
  }

  .main-footer {
    position: static;
    width: 100%;
    max-width: 100%;
    background: transparent;
    box-shadow: none;
    padding: 30px 0 10px 0;
    margin-top: 40px;
    border-top: 1px solid #e0e0e0;
    justify-content: center;
  }

  .footer-content {
    text-align: center;
    color: #555;
  }
}

/* =========================================
   9. MOBILE VIEW (600px and below)
   ========================================= */
@media (max-width: 600px) {
  .hero-btn {
    display: none;
  }

  .media-figure-right, 
  .media-figure-left {
    float: none !important;        
    max-width: 100% !important;    
    width: auto !important;        
    margin: 20px auto !important;  
  }
  
  /* Mobile View - Turns off float so images stack in the center */
  .media-figure-right, 
  .media-figure-left,
  .media-figure-wide-right, 
  .media-figure-wide-left {
    float: none !important;        
    max-width: 100% !important;    
    width: auto !important;        
    margin: 20px auto !important;  
  }
}
