/* --- THEME & RESPONSIVE VARIABLES --- */
:root {
  --gold: #FFC857;
  --black: #222;
  --white: #fff;
  --shadow: rgba(44,44,44,0.15);
  --shadow-light: rgba(44,44,44,0.08);
  --shadow-dark: rgba(44,44,44,0.2);
  
  /* Responsive scaling */
  --scale: 1;
  --header-padding: 1.2rem 2.5rem;
  --title-size: 2.2rem;
  --search-height: 48px;
  --search-width: 280px;
  --main-padding: 1.5rem;
  --main-margin: 2rem auto;
  --border-radius: 20px;
  --button-padding: 0.8rem 1.8rem;
  --button-size: 1.1rem;
  --hamburger-size: 2.2rem;
  --sidebar-width: 340px;
}

/* --- GLOBAL STYLES --- */
* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', 'Roboto', Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: var(--white);
  color: var(--black);
  min-height: 100vh;
}

/* --- HEADER & NAVIGATION --- */
header {
  background: var(--black);
  color: var(--gold);
  box-shadow: 0 4px 16px var(--shadow);
  border-bottom: 4px solid var(--gold);
  position: sticky;
  top: 0;
  z-index: 10;
  width: 100vw;
  left: 0;
  margin: 0;
  padding: 0;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(1.2rem * var(--scale)) calc(0.5rem * var(--scale));
  gap: calc(1rem * var(--scale));
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

/* --- INTERACTIVE ELEMENTS --- */
.hamburger, #close-sidebar {
  background: none;
  border: none;
  font-size: var(--hamburger-size);
  color: var(--gold);
  cursor: pointer;
  padding: calc(0.3rem * var(--scale)) calc(0.7rem * var(--scale));
  border-radius: calc(8px * var(--scale));
  transition: background 0.2s;
}

.hamburger {
  margin-right: calc(0.5rem * var(--scale));
  margin-left: 0;
  flex-shrink: 0;
}

#close-sidebar {
  font-size: calc(2rem * var(--scale));
  padding: calc(0.2rem * var(--scale)) calc(0.7rem * var(--scale));
}

.hamburger:focus, .hamburger:hover, #close-sidebar:hover {
  background: var(--gold);
  color: var(--black);
}

.site-title {
  margin: 0;
  color: var(--gold);
  font-size: var(--title-size);
  font-weight: 800;
  letter-spacing: calc(1.5px * var(--scale));
  white-space: nowrap;
  flex: 1;
  text-align: center;
  text-shadow: 0 2px 8px var(--shadow);
  padding-bottom: calc(0.2rem * var(--scale));
}

/* --- SEARCH & FORM ELEMENTS --- */
#search-form {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0;
  background: var(--white);
  border-radius: 999px;
  padding: 0;
  box-shadow: 0 2px 8px var(--shadow-light);
  height: var(--search-height);
  min-width: calc(200px * var(--scale));
  max-width: var(--search-width);
  width: 100%;
  overflow: hidden;
  border: 2px solid var(--gold);
  flex-shrink: 0;
}

#search-input {
  padding: calc(0.6rem * var(--scale)) calc(1rem * var(--scale));
  font-size: var(--button-size);
  border: none;
  border-radius: 999px 0 0 999px;
  outline: none;
  width: 100%;
  background: var(--white);
  color: var(--black);
  height: var(--search-height);
  transition: border 0.2s;
  margin: 0;
}

#search-input:focus {
  outline: 2px solid var(--black);
}

#search-form button {
  background: var(--gold);
  color: var(--black);
  border: none;
  padding: 0 calc(1.2rem * var(--scale));
  margin: 0;
  cursor: pointer;
  font-size: var(--button-size);
  border-radius: 0 999px 999px 0;
  font-weight: 600;
  height: var(--search-height);
  display: flex;
  align-items: center;
  transition: background 0.2s, color 0.2s;
}

#search-form button:hover {
  background: var(--black);
  color: var(--gold);
}

/* --- MAIN CONTENT --- */
main {
  max-width: 800px;
  margin: var(--main-margin);
  padding: var(--main-padding);
  background: var(--white);
  box-shadow: 0 4px 20px var(--shadow-light);
  border-radius: var(--border-radius);
  border: 2px solid var(--gold);
}

h2 {
  margin-top: calc(0.3rem * var(--scale));
  color: var(--black);
  font-weight: 700;
  font-size: calc(1.8rem * var(--scale));
}

/* --- CONTENT BOXES & BUTTONS --- */
.joke-box, #search-results .search-result {
  border: 2px solid var(--gold);
  padding: var(--main-padding);
  margin: calc(1.5rem * var(--scale)) 0;
  background: var(--white);
  border-radius: calc(16px * var(--scale));
  box-shadow: 0 4px 12px var(--shadow-light);
  font-size: calc(1.2rem * var(--scale));
  line-height: 1.6;
  transition: all 0.3s ease;
}

.joke-box {
  min-height: calc(80px * var(--scale));
}

#search-results .search-result {
  border-bottom: 2px solid var(--gold);
  padding: calc(1rem * var(--scale));
  border-radius: calc(12px * var(--scale));
  margin-bottom: calc(0.8rem * var(--scale));
}

.joke-box:hover, #search-results .search-result:hover {
  box-shadow: 0 6px 20px var(--shadow);
  transform: translateY(-3px) scale(1.02);
}

button, #random-joke-btn, #show-more-btn {
  background: var(--gold);
  color: var(--black);
  border: none;
  padding: var(--button-padding);
  margin-top: calc(1rem * var(--scale));
  margin-bottom: calc(1.5rem * var(--scale));
  cursor: pointer;
  font-size: var(--button-size);
  border-radius: calc(25px * var(--scale));
  font-weight: 600;
  box-shadow: 0 4px 12px var(--shadow);
  transition: all 0.3s ease;
}

button:hover, #random-joke-btn:hover, #show-more-btn:hover {
  background: var(--black);
  color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--shadow-dark);
}

label {
  font-size: calc(1rem * var(--scale));
  color: var(--black);
  margin-left: calc(0.5rem * var(--scale));
  display: inline-flex;
  align-items: center;
  gap: calc(0.4rem * var(--scale));
  white-space: nowrap;
  flex-wrap: nowrap;
}

input[type="checkbox"] {
  accent-color: var(--gold);
  width: calc(1.2em * var(--scale));
  height: calc(1.2em * var(--scale));
  margin: 0;
  flex-shrink: 0;
}

/* --- SIDEBAR --- */
#favorites-sidebar {
  position: fixed;
  top: 0;
  left: -100%;
  width: 100vw;
  height: 100vh;
  background: var(--white);
  box-shadow: 4px 0 20px var(--shadow-dark);
  z-index: 1000;
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
  color: var(--black);
  border-top-right-radius: var(--border-radius);
  border-bottom-right-radius: var(--border-radius);
  border-right: 3px solid var(--gold);
  transform: translateX(0);
}

#favorites-sidebar.open {
  left: 0;
}

.sidebar-header {
  background: var(--black);
  color: var(--gold);
  font-family: 'Segoe UI', 'Roboto', Arial, sans-serif;
  font-size: var(--title-size);
  font-weight: 800;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--header-padding);
  border-top-right-radius: var(--border-radius);
  width: 100%;
}

#favorites-sidebar-list {
  background: var(--white);
  color: var(--black);
  font-family: 'Segoe UI', 'Roboto', Arial, sans-serif;
  font-size: var(--button-size);
  font-weight: 400;
  flex: 1;
  overflow-y: auto;
  padding: var(--main-padding);
  border-bottom-right-radius: var(--border-radius);
}

.favorite-item .favorited {
  color: var(--gold) !important;
  text-shadow: 0 1px 4px var(--shadow-light);
}

.favorite-item span {
  color: var(--black);
}

/* --- RESPONSIVE DESIGN --- */

/* Mobile Header Stacking */
@media (max-width: 900px) {
  :root {
    --scale: 0.85;
    --header-padding: 1rem 1rem;
    --title-size: 1.4rem;
    --search-height: 44px;
    --search-width: 250px;
    --main-padding: 1rem;
    --main-margin: 0.8rem;
    --border-radius: 16px;
    --button-padding: 0.6rem 1.2rem;
    --button-size: 0.9rem;
    --hamburger-size: 1.8rem;
    --sidebar-width: 100vw;
  }
  
  .header-content {
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  
  .site-title {
    order: 2;
    line-height: 1.2;
    flex: none;
  }
  
  .hamburger {
    order: 1;
    align-self: flex-start;
    margin-right: 0;
    position: absolute;
    top: 1rem;
    left: 1rem;
  }
  
  #search-form {
    order: 3;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 0.3rem;
  }
  
  #favorites-sidebar {
    border-radius: 0;
    border-right: none;
    border-bottom: 4px solid var(--gold);
  }
  
  .sidebar-header {
    border-radius: 0;
    font-size: 1.6rem;
  }
}

/* Small phones */
@media (max-width: 375px) {
  :root {
    --scale: 0.7;
    --header-padding: 0.8rem 0.6rem;
    --title-size: 1.2rem;
    --search-height: 40px;
    --search-width: 220px;
    --main-padding: 0.8rem;
    --main-margin: 0.6rem;
    --border-radius: 12px;
    --button-padding: 0.5rem 1rem;
    --button-size: 0.8rem;
    --hamburger-size: 1.6rem;
  }
  
  .hamburger {
    top: 0.8rem;
    left: 0.8rem;
  }
}

/* Medium phones */
@media (min-width: 376px) and (max-width: 414px) {
  :root {
    --scale: 0.8;
    --header-padding: 1.2rem 1rem;
    --title-size: 1.6rem;
    --search-height: 48px;
    --search-width: 300px;
    --main-padding: 1.4rem;
    --main-margin: 1.2rem;
    --border-radius: 16px;
    --button-padding: 0.8rem 1.6rem;
    --button-size: 1rem;
    --hamburger-size: 2.2rem;
  }
}

/* Large phones */
@media (min-width: 415px) and (max-width: 600px) {
  :root {
    --scale: 0.9;
    --header-padding: 1.4rem 1.2rem;
    --title-size: 1.8rem;
    --search-height: 52px;
    --search-width: 320px;
    --main-padding: 1.6rem;
    --main-margin: 1.4rem;
    --border-radius: 18px;
    --button-padding: 0.9rem 1.8rem;
    --button-size: 1.1rem;
    --hamburger-size: 2.4rem;
  }
}

/* Large phones and tablets */
@media (min-width: 600px) and (max-width: 900px) {
  :root {
    --scale: 0.95;
    --header-padding: 1.8rem 2.5rem;
    --title-size: 2rem;
    --search-height: 56px;
    --search-width: 350px;
    --main-padding: 2rem;
    --main-margin: 2rem auto;
    --border-radius: 22px;
    --button-padding: 1rem 2rem;
    --button-size: 1.2rem;
    --hamburger-size: 2.6rem;
    --sidebar-width: 85vw;
  }
  
  #favorites-sidebar {
    max-width: 450px;
  }
}

/* Landscape orientation */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --scale: 0.75;
    --header-padding: 0.8rem 1.5rem;
    --title-size: 1.4rem;
    --main-padding: 1.2rem;
    --main-margin: 0.8rem auto;
    --button-padding: 0.6rem 1.4rem;
    --button-size: 0.9rem;
    --sidebar-width: 80vw;
  }
  
  #favorites-sidebar {
    max-width: 400px;
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .joke-box, #search-results .search-result {
    box-shadow: 0 2px 6px var(--shadow-light);
  }
  
  button, #random-joke-btn, #show-more-btn {
    box-shadow: 0 2px 8px var(--shadow);
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  button, #random-joke-btn, #show-more-btn, #search-form button, .hamburger, #close-sidebar {
    min-height: 44px;
    min-width: 44px;
  }
  
  #search-input {
    min-height: 44px;
  }
  
  .favorite-item span {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}
