@scope (.card-layout) {
  /* 0. Scoped Variables for DRY property management */
  :scope {
    --card-border-color: #817164;
    --font-serif-body: 'Times New Roman', serif;
    --font-serif-header: 'Georgia', 'Times New Roman', serif;
    
    position: relative;
    width: 350px;
    height: 490px; /* Classic 5:7 MTG ratio */
    background: #2b2521; 
    border: 12px solid #000;
    border-radius: 18px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    box-sizing: border-box;
    padding: 16px;
    
    /* Stack internal elements vertically */
    display: flex;
    flex-direction: column;
    gap: 8px; 
    flex-shrink: 0;
  }

  /* Shared full-bleed image styling */
  .border-art img,
  .main-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* 1. Border art frame */
  .border-art {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none; 
  }
  .border-art img {
    border-radius: 10px;
  }

  /* 2. Layering for internal card elements */
  .card-header, 
  .main-art, 
  .date-line, 
  .text-box, 
  .year-line, 
  .set-logo {
    position: relative;
    z-index: 2; 
  }

  /* 3. Headers & Title */
  .card-header {
    background: rgba(240, 230, 210, 0.75);
    border: 2px solid var(--card-border-color);
    border-left: none;
    border-right: none;
    border-radius: 0; 
    
    /* Stretch to left and right outer edges */
    margin: 0 -16px;
    padding: 4px 16px;
    box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.2);
    text-align: center;
  }

  .title {
    font-weight: bold;
    color: #111;
    font-size: 1.36rem;
    font-family: 'MatrixBold', var(--font-serif-header);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    width: 100%;
    margin: 0;
  }

  /* 4. Main Art Window */
  .main-art {
    width: 100%;
    height: 200px;
    border: 2.1px solid var(--card-border-color); 
    border-radius: 7px;
    overflow: hidden;
    box-sizing: border-box;
    flex-shrink: 0;
  }

  .main-art-blur {
    filter: blur(19px) contrast(0.9);
  }

  /* 5. Text Box, Description, and Flavor Text */
  .text-box {
    background: rgba(245, 238, 225, 0.88);
    border: 2px solid var(--card-border-color);
    border-radius: 7px;
    padding: 10px 12px;
    height: 145px !important; 
    box-sizing: border-box;
    flex: 0 0 auto !important;
    
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 10px;
    overflow: hidden; 
  }

  .description {
    font-family: var(--font-serif-body) !important;
    font-weight: normal;
    margin: 0;
    font-size: 14px !important;
    line-height: 1.25 !important;  /* Strictly enforced line-height for JS calculation */
    color: #111;
    flex: 0 1 auto;
    overflow: visible;
  }

  .flavor-text {
    font-family: var(--font-serif-body) !important;
    margin-top: 0;
    font-style: italic;
    font-size: 0.78rem;
    line-height: 1.18 !important;
    color: #444;
    padding-top: 0;
    flex: 0 0 auto; 
  }

  /* 6. Date & Era Line */
  .date-line {
    background: rgba(240, 230, 210, 0.85);
    border: 2px solid var(--card-border-color);
    border-radius: 4px;
    padding: 4px 12px;
    box-shadow: inset 0 0 4px rgba(0,0,0,0.2);
    
    display: flex;
    justify-content: space-between; 
    align-items: center;
  }

  .date, .era {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    width: auto;
    font-family: var(--font-serif-header);
    font-size: 0.9rem;
    font-weight: 600;
    color: #222;
  }

  .date { text-align: left; }
  .era { text-align: right; }
}

.card-link {
  text-decoration: none;
  color: inherit;
  display: block;
}