:root {
  --bg-color: #f0f2f5;
  --sheet-bg: #ffffff;
  --text-color: #1a1a1a;
  --border-color: #58180d; /* Dark Red/Brown D&D Color */
  --red-accent: #922610;

  --page-width: 215.9mm;
  --page-height: 279.4mm;
  
  --font-heading: "Cinzel", serif;
  --font-body: "Libre Baskerville", serif;
  --font-ui: system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
  font-family: var(--font-body);
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 60px;
  padding-bottom: 40px;
}

#controls {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  background: #2c3e50;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  z-index: 1000;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn {
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: transform 0.1s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background-color: var(--red-accent);
  color: white;
}

.btn.secondary {
  background-color: #ecf0f1;
  color: #2c3e50;
}

/* Donation Button */
.donation-btn {
    background-color: #ff9f43;
    color: #2c3e50;
    border: 1px solid #d35400;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: bold;
    font-family: var(--font-ui);
    font-size: 0.9rem; /* Match other buttons */
}

.donation-btn:hover {
    background-color: #ffb773; /* Lighter amber */
    transform: translateY(-1px);
}

.beer-icon {
    display: inline-block;
    animation: bounce-mini 1.5s infinite ease-in-out;
}

@keyframes bounce-mini {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

#help-btn {
    border-radius: 50%;
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    background: #34495e;
    color: #ffd700;
    border: 1px solid #7f8c8d;
}
#help-btn:hover {
    background: #2c3e50;
    color: #fff;
    border-color: #fff;
}

/* --- MODAL --- */
.modal {
    display: none; /* Hidden by default */
    position: fixed; 
    z-index: 2000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.6); 
    backdrop-filter: blur(2px);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: #fff;
    padding: 2rem;
    border: 1px solid #888;
    width: 90%;
    max-width: 500px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    position: relative;
    font-family: var(--font-body);
    animation: slide-in 0.3s ease-out;
}

@keyframes slide-in {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
}

.close-modal:hover,
.close-modal:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.modal-content h2 {
    margin-top: 0;
    font-family: var(--font-heading);
    color: var(--border-color);
}

.modal-content ul {
    margin: 1rem 0;
    padding-left: 1.2rem;
}

.modal-content li {
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.pro-tip {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    padding: 10px;
    font-size: 0.9rem;
    margin: 1.5rem 0;
}

#close-help-btn {
    display: block;
    width: 100%;
    margin-top: 1rem;
    text-align: center;
    font-size: 1.1rem;
}

#lang-select {
  padding: 4px 8px;
  border-radius: 4px;
}

/* --- SHEET LAYOUT --- */
.sheet-page {
  width: var(--page-width);
  height: var(--page-height);
  background-color: var(--sheet-bg);
  margin-bottom: 2rem;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
  position: relative;
  
  /* Print logic: strictly flex column */
  display: flex;
  flex-direction: column;
  padding: 10mm;
  gap: 4mm;
  overflow: hidden;
}

.sheet-page::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url("assets/Marca_de_agua.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 80%;
  opacity: 0.12; 
  pointer-events: none;
  z-index: 0;
}

/* --- MONSTER CARD --- */
.monster-card {
  height: 135mm; /* Strict fixed height per user request */
  max-height: 135mm;
  /* flex: 1 removed to prevent stretching */
  border: 4px double var(--border-color);
  padding: 12px;
  background: transparent;
  position: relative;
  z-index: 1;
  
  /* FLAT LAYOUT: Block display for floats */
  display: block; 
  overflow: hidden; 
}

/* IMAGE CONTAINER - FLOAT RIGHT */
.monster-image-container {
  float: right;
  /* Fixed 3:4 aspect, 6cm x 8cm */
  width: 6cm; 
  height: 8cm; 
  margin-left: 15px;
  margin-bottom: 10px;
  
  border: 3px double var(--border-color);
  background: #fdfdfd;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
  
  shape-outside: inset(0 0 0 0); /* Helps wrapping */
}

.image-placeholder {
  padding: 10px;
  text-align: center;
  font-size: 0.8rem;
  color: #999;
}

.monster-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}


/* HEADER */
.monster-header {
  width: 100%;
  margin-bottom: 6px;
  width: 100%;
  margin-bottom: 6px;
  /* clear: both; REMOVED to allow image to float next to it */
}

.monster-titling {
  display: flex;
  flex-direction: column;
  gap: 0px;
}

.monster-name {
  font-family: var(--font-heading);
  font-size: 1.8rem;
  font-variant: small-caps;
  font-weight: 900;
  color: var(--red-accent);
  border: none;
  width: 100%;
  padding: 0;
  background: transparent;
  line-height: 1.1;
}
.monster-name:focus {
  outline: none;
  background: rgba(0,0,0,0.02);
}

.monster-meta {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.95rem;
  border: none;
  width: 100%;
  background: transparent;
  color: #333;
}

/* Red Divider */
.red-divider {
  border: 0;
  height: 2px;
  background-image: linear-gradient(to right, rgba(146, 38, 16, 0), rgba(146, 38, 16, 1), rgba(146, 38, 16, 0));
  margin: 5px 0 10px 0;
  clear: none; /* Don't clear float */
}

/* STATS SECTION (Wrapper for stats) */
.monster-stats-section {
    /* Block level, will flow next to floated image */
    display: block; 
    margin-bottom: 10px;
}

/* Attributes Row */
.monster-attributes-row {
  display: flex;
  justify-content: space-between;
  gap: 2px;
  margin-bottom: 8px;
  /* Flexbox forms BFC, so it might not wrap *tightly* if it's too wide.
     But since it's just one row, it should sit next to image.
  */
}

.attr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(146, 38, 16, 0.3);
  border-radius: 4px;
  padding: 2px 2px;
  background: rgba(255,255,255,0.6);
  flex: 1;
  min-width: 30px;
}

.attr-box label {
  font-weight: bold;
  font-size: 0.65rem;
  color: var(--red-accent);
  margin-bottom: 1px;
}

.stat-input {
  width: 100%;
  text-align: center;
  border: none;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: bold;
  color: var(--text-color);
  background: transparent;
  padding: 0;
}

.stat-mod {
  font-size: 0.7rem;
  color: #555;
}

/* Combat Grid */
.monster-combat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  /* Grid also sets BFC. */
}

.combat-box {
  border: 2px solid var(--border-color);
  border-radius: 2px;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2px;
  position: relative;
  min-height: 45px;
}

.hp-box {
    grid-column: span 2;
    padding: 0; /* Remove padding from container */
    align-items: flex-start; /* Align input left */
}

.combat-box label {
    font-family: var(--font-ui);
    font-size: 0.6rem;
    font-weight: bold;
    text-transform: uppercase;
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    color: #444;
    white-space: nowrap;
}

.combat-input-main {
    border: none;
    background: transparent;
    text-align: center;
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: bold;
    width: 100%;
    margin-top: 10px;
    color: var(--red-accent);
}

/* HP Input Specifics */
.hp-box .combat-input-main {
    text-align: left;
    padding-left: 4px;
    width: 100%; 
    height: 100%;
    box-sizing: border-box;
}

/* BODY TEXT */
.monster-body {
  font-size: 0.85rem;
  line-height: 1.35;
  padding: 5px;
  border: 1px dashed #ccc;
  border-radius: 4px;
  background: rgba(255,255,255,0.3);
  
  /* IMPORTANT: Block display to allow wrapping under float */
  display: block; 
}
.monster-body:focus {
    outline: none;
    border-color: #999;
}

.monster-body p {
  margin: 0.4em 0;
}


/* --- PRINT CONFIGURATION --- */
@page {
  size: letter;
  margin: 0;
}

@media print {
  @page {
    margin: 0;
    size: letter;
  }

  body {
    margin: 0;
    padding: 0;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    background: none;
    display: block;
  }

  #controls {
    display: none;
  }

  .sheet-page {
    width: 216mm;
    height: 279mm;
    
    /* SAFE ZONE: 15mm top padding */
    padding-top: 15mm;
    padding-right: 0;
    padding-bottom: 0;
    padding-left: 0;
    
    /* CRITICAL: Include padding in total height */
    box-sizing: border-box; 
    
    /* SCALE TRICK ADJUSTED: 0.92 to fit with padding */
    transform: scale(0.92);
    transform-origin: top center;
    
    margin: 0;
    
    overflow: hidden;
    page-break-after: always;
    display: flex;
    flex-direction: column;
    justify-content: start;
    align-items: center;
    gap: 0;
  }
  
  .sheet-page::before {
      /* Watermark on print */
      opacity: 0.1;
  }
  
  .monster-card {
      /* Ensure no external margins break the scale logic */
      margin: 0;
      /* Optional: border adjustment if needed, but keeping double border */
      border-color: #000;
  }
  
  .monster-image-container {
      border-color: #000;
  }
  
  .combat-box {
      border-color: #000 !important;
      background: white;
  }
  
  .attr-box {
      border-color: #666;
  }

  .monster-body {
      border: none;
      background: transparent;
  }

  input {
      background: transparent !important;
  }
  
  .red-divider {
      background: #922610 !important;
      -webkit-print-color-adjust: exact;
  }
}
