/* ===== ROOT & VARIABLES ===== */
:root {
  --primary: #333;
  --muted: #999;
  --bg: #f9f9f9;
  --border: #ddd;
  --spacing: 1rem;
}

/* ===== RESET & BASE ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--primary);
  background: var(--bg);
}

/* ===== WRAPPER ===== */
.wrap {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 100%;
  overflow-x: hidden;
}

/* ===== HEADER ===== */
header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: var(--spacing);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

header h1 {
  font-size: 1.5rem;
  margin-bottom: var(--spacing);
  text-align: center;
}

/* ===== SEARCH / CONTROLS ===== */
.search {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
}

input[type="search"],
button {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.95rem;
  cursor: pointer;
  background: white;
  color: var(--primary);
  transition: all 0.2s ease;
  min-height: 44px; /* Touch-friendly */
}

input[type="search"] {
  flex: 1;
  min-width: 200px;
  border: 1px solid var(--border);
  padding: 0.6rem;
}

input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(51, 51, 51, 0.1);
}

button {
  background: var(--primary);
  color: white;
  border: none;
  font-weight: 500;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  background: #555;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== VARIABLES ===== */
:root {
  --primary: #333;       /* Default button bg */
  --primary-hover: #555; /* Hover/Active bg */
  --active-bg: #e91e63;  /* Color when 'Checked' (Heart color) */
  --text-white: #fff;
  --spacing: 1rem;
}

/* Hide the default checkbox input entirely */
.favourite-item input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Make the label look like a button */
.favourite-item label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  
  /* Button Styling from your example */
  background: var(--primary);
  color: var(--text-white);
  border: none;
  font-weight: 500;
  font-size: 1rem;
  white-space: nowrap;
  
  /* Shape & Spacing */
  padding: 0.6rem 1.2rem;
  border-radius: 6px; /* Slightly rounded corners */
  cursor: pointer;

  /* Safety: Ensure pseudo-elements aren't clipped by the button itself */
  overflow: visible; 
  position: relative;
  
  /* Interaction */
  transition: background 0.2s ease, transform 0.1s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent; /* Remove mobile tap highlight */
}

/* The Heart Icon (Inside the button) */
.favourite-item label::before {
  content: '';
  width: 1.6rem;
  height: 1.6rem;
  transform-origin: center;
  
  /* Heart Shape */
  background-color: currentColor; /* Inherits text color */
  vertical-align: middle;
  clip-path: path('M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z');  
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  flex-shrink: 0;
}

/* --- UNCHECKED STATE (Default) --- */
/* Text is white, bg is dark (var(--primary)) */
.favourite-item label {
  background: var(--primary);
  color: var(--text-white);
}

/* --- HOVER / ACTIVE (Desktop & Touch) --- */
/* Darken the button slightly to show interaction */
.favourite-item label:hover {
  background: var(--primary-hover);
}

/* Press effect (mousedown or tap) */
.favourite-item label:active {
  transform: scale(0.98); /* Tiny press down effect */
}

/* --- CHECKED STATE (The "Active" Button) --- */
/* Change background to the "Heart" color (Pink/Red) */
.favourite-item input:checked ~ label {
  background: var(--active-bg);
  color: var(--text-white);
}

/* Make the heart pulse slightly when checked */
.favourite-item input:checked ~ label::before {
  transform: scale(1.2);
}

/* ===== MAIN CONTENT ===== */
#results {
  flex: 1;
  padding: var(--spacing);
  display: flex;
  flex-direction: column;
  gap: var(--spacing);
}

.item {
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: var(--spacing);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 50px;
  display: flex;
  align-items: center;
}

.item:hover,
.item:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  background: #fafafa;
}

.item .title {
  font-weight: 500;
  font-size: 0.95rem;
}

/* ===== CONTROLS ===== */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing);
  padding: var(--spacing);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

#count {
  font-size: 0.9rem;
  color: var(--muted);
}

/* ===== FOOTER ===== */
footer {
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: var(--spacing);
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ===== MODAL ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 1000;
  padding: var(--spacing);
  overflow-y: auto;
}

.modal.open {
  opacity: 1;
  pointer-events: all;
}

.card {
  background: white;
  border-radius: 8px;
  padding: 2rem;
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.poem-title {
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
  color: var(--primary);
}

.poem-text {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--primary);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 1.5rem;
  font-family: 'Georgia', 'Garamond', serif;
}

.meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 1rem;
}

.close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close:hover {
  color: var(--primary);
}

/* ===== MOBILE (max-width: 600px) ===== */
@media (max-width: 600px) {
  :root {
    --spacing: 0.75rem;
  }

  body {
    font-size: 0.95rem;
  }

  header h1 {
    font-size: 1.3rem;
    margin-bottom: 0.75rem;
  }

  .search {
    flex-direction: column;
    width: 100%;
  }

  input[type="search"],
  button {
    width: 100%;
    padding: 0.7rem;
    font-size: 0.95rem;
  }

  #results {
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .item {
    padding: 0.75rem;
    min-height: 48px;
  }

  .item .title {
    font-size: 0.9rem;
  }

  .card {
    padding: 1.2rem;
    max-height: 90vh;
    margin: auto;
    width: 95%;
    border-radius: 6px;
  }

  .poem-title {
    font-size: 1.4rem;
    margin-bottom: 1rem;
  }

  .poem-text {
    font-size: 0.95rem;
    line-height: 1.7;
  }

  .close {
    width: 36px;
    height: 36px;
    font-size: 1.3rem;
    top: 0.75rem;
    right: 0.75rem;
  }

  .controls {
    flex-direction: column;
    gap: 0.5rem;
  }

  #count {
    order: -1;
    width: 100%;
  }

  #loadMore {
    width: 100%;
  }

  footer {
    font-size: 0.8rem;
    padding: 0.75rem;
  }
}

/* ===== TABLET (600px - 900px) ===== */
@media (min-width: 601px) and (max-width: 900px) {
  .card {
    max-width: 90%;
  }

  .search {
    justify-content: space-around;
  }

  input[type="search"] {
    min-width: 250px;
  }
}

/* ===== DESKTOP (900px+) ===== */
@media (min-width: 901px) {
  .wrap {
    max-width: 1200px;
    margin: 0 auto;
  }

  header h1 {
    font-size: 2rem;
  }

  .search {
    justify-content: center;
    gap: 1rem;
  }

  input[type="search"] {
    min-width: 300px;
  }

  .card {
    padding: 2.5rem;
  }
}
