:root {
  --primary-color: #6C63FF;
  --secondary-color: #4FC3F7;
  --accent-color: #FF4081;
  --dark-bg: #121212;
  --card-bg: #1E1E1E;
  --text-light: #FFFFFF;
  --text-muted: #B0B0B0;
  --border-color: #333333;
  --hover-color: #7C4DFF;
  --gradient-start: #6C63FF;
  --gradient-end: #4FC3F7;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Noto Sans TC', 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
  background: var(--dark-bg);
  color: var(--text-light);
  line-height: 1.6;
  min-height: 100vh;
}

main {
  padding-bottom: 60px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

header {
  background: rgba(18, 18, 18, 0.95);
  backdrop-filter: blur(10px);
  padding: 20px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap; 
}

.nav-content {
  display: flex;
  align-items: center;
  flex: 1;
}

.logo {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-light);
  text-decoration: none;
  display: flex;
  align-items: center;
  min-width: 160px;
  letter-spacing: -0.5px;
}

.logo span {
  background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-left: 4px;
}

.search-container {
  display: flex;
  flex: 1;
  max-width: 500px;
  margin-left: 40px;
}

.search-input {
  flex-grow: 1;
  padding: 14px 20px;
  border-radius: 30px 0 0 30px;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-light);
  font-size: 1rem;
  transition: all 0.3s ease;
  min-width: 0; /* Allow input to shrink */
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-color);
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.2);
}

.search-btn {
  padding: 14px 24px;
  border-radius: 0 30px 30px 0;
  border: none;
  background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
  color: white;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s ease;
}

.search-btn:hover {
  background: linear-gradient(45deg, var(--hover-color), var(--secondary-color));
  transform: translateX(2px);
}

.auth-buttons {
  display: flex;
  gap: 15px;
  align-items: center; /* Vertically align items */
}

.btn {
  padding: 10px 20px;
  border-radius: 30px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  border: none;
  white-space: nowrap; /* Prevent button text from wrapping */
}

.btn-login {
  background: transparent;
  border: 1px solid var(--primary-color);
  color: var(--primary-color);
}

.btn-login:hover {
  background: rgba(108, 99, 255, 0.1);
}

.btn-signup {
  background: var(--primary-color);
  color: white;
}

.btn-signup:hover {
  background: var(--hover-color);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(108, 99, 255, 0.3);
}

/* --- THE REST OF YOUR CSS IS UNCHANGED --- */
.stories-preview {
  padding: 10px 0 10px 0;
  background: var(--dark-bg);
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 30px;
  margin-top: 10px;
}

.story-card {
  background: var(--card-bg);
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  border: 1px solid var(--border-color);
  display: block;
  position: relative;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  text-decoration: none;
  aspect-ratio: 892 / 1280;
  cursor: pointer;
}

.story-card:hover {
  transform: translateY(-8px) scale(1.02);
  border-color: var(--primary-color);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.story-image {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  position: relative;
  overflow: hidden;
}

.story-image::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.4) 50%, rgba(0,0,0,0.2) 100%);
  z-index: 1;
  transition: all 0.4s ease;
}

.story-card:hover .story-image::before {
  background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.6) 50%, rgba(0,0,0,0.3) 100%);
}

.story-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 25px;
  z-index: 2;
}

.story-content h3 {
  font-size: 1.6rem;
  margin-bottom: 0;
  color: var(--text-light);
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: #0A0A0A;
  padding: 10px 0;
  border-top: 1px solid var(--border-color);
  text-align: center;
  z-index: 999;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.age-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  flex-direction: column;
  padding: 20px;
  text-align: center;
}

.age-modal-content {
  background: #1E1E1E;
  padding: 30px 40px;
  border-radius: 12px;
  color: var(--text-light);
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 25px rgba(0,0,0,0.4);
  animation: fadeIn 0.5s ease-out;
}

.age-modal-content h2 {
  font-size: 2rem;
  margin-bottom: 16px;
  color: var(--accent-color);
}

.age-modal-content p {
  font-size: 1.1rem;
  margin-bottom: 24px;
}

.age-modal-content button {
  padding: 12px 25px;
  font-size: 1rem;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  font-weight: 700;
  background: var(--primary-color);
  color: white;
  transition: all 0.3s;
}

.age-modal-content button:hover {
  background: var(--hover-color);
  transform: translateY(-2px);
}

/* --- START OF MOBILE LAYOUT CHANGES --- */

/* This media query will cover tablets and phones */
@media (max-width: 968px) {
  /* Allow the nav items to wrap onto the next line */
  nav {
    gap: 15px;
  }

  /* This is the key: It makes the .logo and .search-container act as direct children of <nav> */
  .nav-content {
    display: contents;
  }

  /* 1. The Logo takes up the first row */
  .logo {
    order: 1;               /* Becomes the first item */
    flex-basis: 100%;       /* Takes the full width */
    justify-content: center; /* Centers the text inside */
    margin-bottom: 0;       /* Reset any bottom margin */
  }

  /* 2. The Search container comes next */
  .search-container {
    order: 2;         /* Becomes the second item */
    flex-grow: 1;     /* Takes up the available space */
    margin-left: 0;   /* Remove desktop margin */
    min-width: 0;     /* Allows the search bar to shrink */
  }

  /* 3. The Auth buttons appear last, next to the search bar */
  .auth-buttons {
    order: 3;         /* Becomes the third item */
    margin-top: 0;
  }
}

/* This media query is for smaller mobile phones (non-header styles) */
@media (max-width: 768px) {
  /* --- START: NEW SPACING RULES --- */
  .container {
    padding-left: 8px;
    padding-right: 8px;
  }

  .story-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px; /* Reduced gap from 15px */
  }
  /* --- END: NEW SPACING RULES --- */

  .story-card {
    height: auto;
    aspect-ratio: 892 / 1280;
  }
  
  .story-content {
      padding: 10px;
  }
  
  .story-content h3 {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 6px;
  }

  .story-tags {
      margin-top: 0;
  }

  .tag {
      font-size: 0.6rem;
      padding: 3px 6px;
  }

  .logo {
    font-size: 24px;
    min-width: 140px;
  }

  .btn {
    padding: 8px 16px;
  }
  
  .search-input, .search-btn {
    padding-top: 12px;
    padding-bottom: 12px;
  }
  
  .age-modal-content {
    padding: 20px;
  }

  .age-modal-content h2 {
    font-size: 1.5rem;
  }

  .age-modal-content p {
    font-size: 1rem;
  }

  .age-modal-content button {
    width: 100%;
    padding: 12px 0;
    font-size: 1rem;
  }
}

/* --- KEYFRAMES AND OTHER STYLES (UNCHANGED) --- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.story-card {
  animation: fadeIn 0.6s ease-out;
}

.story-card:nth-child(2) {
  animation-delay: 0.1s;
}

.story-card:nth-child(3) {
  animation-delay: 0.2s;
}

.story-card:nth-child(4) {
  animation-delay: 0.3s;
}

.story-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
  opacity: 0;
  z-index: -1;
  transition: opacity 0.4s ease;
  border-radius: 16px;
}

.story-card:hover::after {
  opacity: 0.1;
}


/* Styles for the "Submit" button and submission form */
.btn-submit {
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
}

.btn-submit:hover {
    background: rgba(255, 64, 129, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 64, 129, 0.2);
}

.submit-container {
    max-width: 800px;
    margin: 40px auto;
    padding: 40px;
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
}

.submit-container h1 {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 15px;
    color: var(--primary-color);
}

.submit-container p {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 40px;
}

.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-light);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-light);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.2);
}

.btn-submit-form {
    display: block;
    width: 100%;
    padding: 15px;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 8px;
    border: none;
    background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-submit-form:hover {
    background: linear-gradient(45deg, var(--hover-color), var(--secondary-color));
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

/* --- Styles for the story tags --- */

.story-tags {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px; /* Space between tags */
}

.tag {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.15);
    white-space: nowrap;
}

