body {
  margin: 0;
  background-color: #f4f1e7;
  color: #222;

  font-family: Montserrat, sans-serif;
}



.navbar {
  background-color: #160b24;
  color: white;

  width: 100%;

  height: 90px;

  padding: 0;

  box-sizing: border-box;

  box-shadow: none;

  position: relative;

  z-index: 1000;
  
}

.navbaritms {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 50%;
  margin-left: 25%;
  
}

.headerleft {
  height: auto;
  flex: 1
}

.headerright {
  height: auto;
}

.navitms {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.LZ {
  font-family: Garamond, serif;
  text-decoration: none;
  color: #fcfcfc; 
}

.LZ:visited {
  color: #fcfcfc; 
}

.LZ:hover {
  color: #fcfcfc; 
  text-decoration: underline;
}

.navitm {
  text-decoration: none;
  color: #fcfcfc; 
}

.navitm:visited {
  color: #fcfcfc; 
}

.navitm:hover {
  color: #fcfcfc; 
  text-decoration: underline;
}

.topcards {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 30px;
}

.card {
  background-color: #ffffff;
  width: 30%;
  height: 225px;
  margin-left: 20%;
  margin-top: 10px;
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.7);
}

.card h2 {
  font-family: Garamond, serif;
  margin: 2%;
  font-size: 30px;
  color: #858172;
}

.card p {
  margin: 2%;
  font-size: 18px;
}

.cardwotd {
  background-color: #ffffff;
  width: 30%;
  height: 225px;
  margin-right: 20%;
  margin-top: 10px;
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.7);
}

.wotdtext {
  margin: 2%;
}

.wotdtext h2 {
  font-size: 14px;
}

.wotdtext h3 {
  font-family: Garamond, serif;
  font-size: 35px;
  color: #160b24;
  
}

.wotdtext p {
  font-style: italic;
  
}

.midcards {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 30px;
}

.midcards h2 {
  font-size: 14px;
  margin: 2%;
}

.midcards p {
  font-size: 15px;
  margin: 2%;
}

.lcard {
  background-color: #ffffff;
  width: 30%;
  height: 225px;
  margin-left: 20%;
  margin-top: 10px;
  position: relative;
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.7);
}

.mcard {
  background-color: #ffffff;
  width: 30%;
  height: 225px;
  margin-top: 10px;
  position: relative;
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.7);
}

.rcard {
  background-color: #ffffff;
  width: 30%;
  height: 225px;
  margin-right: 20%;
  margin-top: 10px;
  position: relative;
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.7);
}

.cardbtn {
  position: absolute;
  bottom: 0;
  left: 0;
  padding: 7px 15px;
  color: #160b24;
  background-color: #ffffff;
  border: 2px solid #160b24;
  margin: 2%;
  text-decoration: none;
  font-size: 15px;
  font-weight: bold;
}

.cardbtn:hover {
  position: absolute;
  bottom: 0;
  left: 0;
  padding: 7px 15px;
  color: #ffffff;
  background-color: #160b24;
  border: 2px solid #160b24;
  margin: 2%;
  text-decoration: none;
  font-size: 15px;
  font-weight: bold;
}

.divider {
  margin-left: 19%;
  margin-top: 2.5%;
  font-family: Garamond, serif;
  font-size: 18px;
  color: #858172;
}

/*------------------------------*/

.navbar {
  height: auto;
  padding-bottom: 18px;
}

.navbaritms,
.searchbar,
.dictionary {
  width: 90%;
  max-width: 1000px;
  margin: 0 auto;
}

.navbaritms {
  gap: 20px;
  flex-wrap: wrap;
}

.searchbar {
  margin-top: 12px;
}

#dictionary-form {
  display: flex;
  gap: 5px;
  padding: 5px;
  background: white;
  border-radius: 3px;
}

#dictionary-query {
  flex: 1;
  min-width: 0;
  padding: 12px;
  border: none;
  background: white;
  color: #222;
  font: inherit;
}

#dictionary-direction,
#dictionary-submit {
  padding: 12px;
  border: none;
  border-radius: 2px;
  background: #160b24;
  color: white;
  font: inherit;
  cursor: pointer;
}

#dictionary-submit {
  background: #d4af37;
  color: #160b24;
}

#dictionary-submit:disabled {
  opacity: 0.5;
  cursor: wait;
}

#dictionary-alphabet {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin-top: 8px;
}

#dictionary-alphabet button {
  border: none;
  background: transparent;
  color: white;
  padding: 6px 8px;
  font: inherit;
  cursor: pointer;
}

#dictionary-alphabet button:hover {
  color: #d4af37;
  text-decoration: underline;
}

.searchbar :focus-visible {
  outline: 2px solid #d4af37;
  outline-offset: 2px;
}

.dictionary {
  padding: 24px 0;
}

.dictionary-entry {
  margin-bottom: 12px;
  padding: 20px;
  background: white;
  border-left: 4px solid #d4af37;
  border-radius: 3px;
}

.dictionary-entry h2 {
  margin: 0 0 8px;
}

.dictionary-entry p {
  margin: 6px 0;
}

.dictionary-entry .word-type {
  color: #666;
  font-style: italic;
}

@media (max-width: 600px) {
  #dictionary-form {
    flex-wrap: wrap;
  }

  #dictionary-query {
    flex-basis: 100%;
  }

  #dictionary-direction {
    flex: 1;
    min-width: 0;
  }
}


/* --------------------------------- */

.grammar-table-wrapper {
  margin-top: 20px;
  overflow-x: auto;
}

.grammar-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  font-size: 0.95rem;
}

.grammar-table caption {
  padding: 12px;
  border: 1px solid #ddd;
  border-bottom: none;
  background: #f3f0f6;
  color: #160b24;
  text-align: left;
  font-weight: bold;
}

.grammar-table th,
.grammar-table td {
  border: 1px solid #ddd;
  padding: 12px;
  text-align: left;
  vertical-align: top;
}

.grammar-table thead th {
  background: #faf8fc;
  color: #160b24;
}

.grammar-table tbody th {
  font-weight: 600;
}

.grammar-table-wrapper:focus-visible {
  outline: 2px solid #d4af37;
  outline-offset: 2px;
}

.grammar-table thead th {
  text-align: center;
  vertical-align: middle;
}

/* ---------- Responsive layout ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

.headerleft,
.headerright,
.card,
.cardwotd,
.lcard,
.mcard,
.rcard {
  min-width: 0;
}

.card,
.cardwotd,
.lcard,
.mcard,
.rcard {
  height: auto;
  min-height: 225px;
  overflow-wrap: anywhere;
}

/* Reserve space for the buttons at the bottom. */
.lcard,
.mcard,
.rcard {
  padding-bottom: 65px;
}

.cardbtn {
  max-width: calc(100% - 4%);
}

.dictionary-entry {
  overflow-wrap: anywhere;
}

.grammar-table-wrapper {
  max-width: 100%;
}

/* Tablets and smaller screens */
@media (max-width: 1000px) {
  .topcards,
  .midcards {
    width: 90%;
    max-width: 1000px;
    margin: 16px auto 0;
    display: grid;
    align-items: stretch;
    gap: 16px;
  }

  .topcards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .midcards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .card,
  .cardwotd,
  .lcard,
  .mcard,
  .rcard {
    width: 100%;
    margin: 0;
    padding: 16px;
  }

  /* Keep buttons in normal flow so text cannot overlap them. */
  .lcard,
  .mcard,
  .rcard {
    display: flex;
    flex-direction: column;
  }

  .cardbtn,
  .cardbtn:hover {
    position: static;
    align-self: flex-start;
    max-width: 100%;
    margin: auto 0 0;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  .midcards p {
    margin-bottom: 20px;
  }

  .divider {
    width: 90%;
    margin: 28px auto 12px;
  }
}

/* Phones */
@media (max-width: 600px) {
  .navbar {
    padding: 16px 0;
  }

  .navbaritms {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .headerleft,
  .headerright {
    width: 100%;
  }

  .headerleft {
    flex: none;
  }

  .headerleft h1 {
    margin: 0;
    font-size: clamp(1.5rem, 7vw, 2rem);
    overflow-wrap: anywhere;
  }

  .navitms {
    gap: 4px 16px;
  }

  .navitm {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  .searchbar {
    margin-top: 16px;
  }

  #dictionary-form {
    flex-wrap: wrap;
    gap: 6px;
  }

  #dictionary-query {
    flex: 1 1 100%;
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  #dictionary-direction {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    font-size: 16px;
  }

  #dictionary-submit {
    flex: 0 0 auto;
    min-height: 44px;
    font-size: 16px;
  }

  #dictionary-alphabet {
    gap: 2px;
  }

  #dictionary-alphabet button {
    min-width: 44px;
    min-height: 44px;
    padding: 8px;
  }

  .topcards,
  .midcards {
    grid-template-columns: minmax(0, 1fr);
  }

  .card,
  .cardwotd,
  .lcard,
  .mcard,
  .rcard {
    min-height: 0;
    padding: 18px;
  }

  .card h2 {
    font-size: 28px;
  }

  .card p {
    font-size: 16px;
    line-height: 1.6;
  }

  .wotdtext {
    margin: 0;
  }

  .wotdtext h3 {
    margin: 16px 0;
    font-size: 32px;
  }

  .midcards p,
  .wotdtext p {
    line-height: 1.6;
  }

  .dictionary {
    padding: 20px 0;
  }

  .dictionary-entry {
    padding: 16px;
  }

  .dictionary-entry h2 {
    font-size: 1.4rem;
  }

  .grammar-table {
    font-size: 0.875rem;
  }

  .grammar-table th,
  .grammar-table td {
    padding: 10px;
  }
}