@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');

/* Universal Box Sizing & Visually Hidden Class */
*, *::before, *::after {
  box-sizing: border-box;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:root {
  --primary-color: #3367D6;
  --primary-hover-color: #2a56b9;
  --background-color: #f0f2f5;
  --container-background: #ffffff;
  --text-color: #333;
  --subtle-text-color: #555;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --glow-color: rgba(51, 103, 214, 0.5);
  --border-color: #e0e0e0;
  --like-color: #ff4d4d;
}

body {
  font-family: 'Roboto', sans-serif;
  background-color: var(--background-color);
  margin: 0;
  padding: 20px;
}

/* Enhanced Focus States */
:focus-visible {
  outline: 3px solid var(--primary-color);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Main Layout */
main {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

/* Loader Styles */
.loader {
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  animation: spin 1s linear infinite;
  display: none; /* Hidden by default */
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}


/* Login Container */
#login-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  min-height: 80vh;
  background-color: var(--container-background);
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 8px 25px var(--shadow-color);
}

#login-container h1 {
  font-size: 2.5rem;
  color: var(--text-color);
  margin-bottom: 10px;
}

#login-container p {
  font-size: 1.1rem;
  color: var(--subtle-text-color);
  margin-bottom: 30px;
}

.login-button {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 15px 30px;
  font-size: 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
  box-shadow: 0 4px 10px var(--shadow-color);
}

.login-button:hover {
  background-color: var(--primary-hover-color);
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
}

#login-loader {
    margin-top: 20px;
}


/* Welcome / Main Content Container */
#welcome-container {
  display: none;
  flex-direction: column;
  gap: 30px;
}

#user-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  padding-bottom: 15px; /* Adjust for the divider */
  background-color: var(--container-background);
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 5px 15px var(--shadow-color);
}

#user-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

#user-info img {
  width: 50px;
  height: 50px;
  border-radius: 50%;
}

#user-info h2 {
  margin: 0;
  font-size: 1.5rem;
}

#user-info p {
  margin: 0;
  color: var(--subtle-text-color);
}

#logout-btn {
  background-color: transparent;
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

#logout-btn:hover {
  background-color: var(--primary-color);
  color: white;
}


/* Post Creation Form */
#post-creation-container {
  background-color: var(--container-background);
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 5px 15px var(--shadow-color);
}

#create-post-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

#game-title-group {
    position: relative;
}

.floating-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--container-background);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 8px 16px var(--shadow-color);
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    display: none; /* Hidden by default */
}

.floating-results .result-item {
    padding: 12px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.floating-results .result-item:hover {
    background-color: #f7f7f7;
}

.floating-results .result-name {
    font-weight: 500;
}

.floating-results .result-year {
    color: var(--subtle-text-color);
    font-size: 0.9rem;
}


.form-group label {
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-color);
}

#create-post-form input[type="text"],
#create-post-form input[type="url"],
#create-post-form textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#create-post-form input:focus, #create-post-form textarea:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--glow-color);
}

#create-post-form textarea {
    min-height: 100px;
    resize: vertical;
}

/* File Upload Button Styling */
.file-upload-group {
  display: flex;
  flex-direction: column;
}

#photo-upload {
  display: none; /* Hide the actual file input */
}

.file-upload-label {
  display: inline-block;
  background-color: #f0f2f5;
  color: #333;
  border: 1px solid #e0e0e0;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.3s ease, border-color 0.3s ease;
  text-align: center;
  margin-bottom: 10px; /* Add space between button and filename */
}

.file-upload-label:hover {
  background-color: #e9ecef;
  border-color: #ccc;
}

#photo-upload-filename {
  font-size: 0.9rem;
  color: #555;
  margin-top: 5px; /* Adjust spacing */
}

#rating-slider {
    width: 100%;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

#create-post-form button[type="submit"] {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 12px 25px;
  font-size: 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

#create-post-form button[type="submit"]:hover {
  background-color: var(--primary-hover-color);
}


/* Post Card Styling */
#posts-list .post, #profile-checkins-list .post {
  background-color: #fff;
  border-radius: 12px;
  margin-bottom: 30px;
  border: 1px solid var(--border-color);
  box-shadow: 0 5px 15px var(--shadow-color);
  overflow: hidden; /* To keep the image corners rounded */
}

.post .game-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background-color: #eee;
  display: block; /* Remove space under image */
}

.post-content {
 padding: 20px;
}

.post-content h4 a {
    color: var(--text-color);
    text-decoration: none;
}

.post-content h4 a:hover,
.post-content h4 a:focus {
    text-decoration: underline;
}

.post-author {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  cursor: pointer;
  border-radius: 8px;
  padding: 5px;
  transition: background-color 0.2s ease-in-out;
}

.post-author:hover {
  background-color: var(--background-color)
}

.post-author img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 15px;
}

.post-author span {
  font-weight: 500;
  color: var(--text-color);
}

.post-notes {
  margin: 15px 0;
  color: var(--subtle-text-color);
}

.post-rating .stars {
  --percent: calc(var(--rating) / 10 * 100%);
  display: inline-block;
  font-size: 24px;
  font-family: Times; /* We can use a custom star icon font later */
  line-height: 1;
}

.post-rating .stars::before {
  content: '★★★★★★★★★★';
  letter-spacing: 3px;
  background: linear-gradient(90deg, #ffcc00 var(--percent), #c7c7c7 var(--percent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.post-actions {
    display: flex;
    align-items: center;
    margin-top: 20px;
    gap: 16px;
}

.like-button, .comment-button {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--subtle-text-color);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.like-button:hover, .like-button:focus {
    border-color: var(--like-color);
    color: var(--like-color);
}

.comment-button:hover, .comment-button:focus {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.like-button.liked {
    background-color: var(--like-color);
    color: white;
    border-color: var(--like-color);
}

.like-button.exploding {
  animation: explode 0.6s ease-out;
}

@keyframes explode {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.7);
  }
  40% {
    transform: scale(1.5);
    box-shadow: 0 0 0 20px rgba(255, 77, 77, 0);
  }
  70% {
      transform: scale(0.9);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 77, 77, 0);
  }
}

.like-count {
    font-size: 0.9rem;
    color: var(--subtle-text-color);
}


#posts-list .post .post-meta, #profile-checkins-list .post .post-meta {
  font-size: 0.8rem;
  color: #999;
  margin-top: 15px;
}

/* Comment Section */
.comment-section {
  margin-top: 20px;
  border-top: 1px solid #eee;
  padding-top: 20px;
}

.comment-form {
  display: none; /* Initially hidden */
  margin-bottom: 20px;
}

.comment-form textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  resize: vertical;
  margin-bottom: 10px;
}

.comment-form button {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
}

.comments-list .comment {
  display: flex;
  align-items: flex-start;
  margin-bottom: 15px;
}

.comments-list .comment img {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  margin-right: 10px;
}

.comment-content {
  background-color: #f0f2f5;
  padding: 10px;
  border-radius: 10px;
  width: 100%;
}

.comment-author {
  font-weight: bold;
  font-size: 0.9rem;
  margin: 0 0 5px 0;
}

.comment-content p {
  margin: 0;
  font-size: 0.95rem;
}

.comment-timestamp {
  font-size: 0.75rem;
  color: #888;
  margin-top: 5px;
}

/* Profile Page */
#profile-container {
  display: none;
  flex-direction: column;
  gap: 20px;
}

#profile-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px;
  background-color: var(--container-background);
  border-radius: 12px;
  box-shadow: 0 5px 15px var(--shadow-color);
}

#back-to-main-btn {
  background: none;
  border: 1px solid var(--border-color);
  padding: 10px 15px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

#back-to-main-btn:hover {
  background-color: #f0f2f5;
  border-color: #ccc;
}

#profile-header h1 {
  margin: 0;
  font-size: 1.8rem;
}

#profile-overview {
  text-align: center;
  background-color: var(--container-background);
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 5px 15px var(--shadow-color);
}

#profile-stats {
  display: flex;
  justify-content: space-around;
  text-align: center;
}

.stat .stat-value {
  font-size: 2rem;
  font-weight: 500;
  color: var(--primary-color);
  display: block;
}

.stat .stat-label {
  font-size: 0.9rem;
  color: var(--subtle-text-color);
}

#profile-games-list {
  text-align: center;
  background-color: var(--container-background);
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 5px 15px var(--shadow-color);
}

#profile-checkins-heading {
  text-align: center;
  margin-bottom: 20px;
}

#profile-checkins-section {
  background-color: var(--container-background);
  padding: 6px;
  border-radius: 12px;
  box-shadow: 0 5px 15px var(--shadow-color);
}

#games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 20px;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.game-card img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.game-card .game-title {
  font-size: 0.9rem;
  font-weight: 500;
}

/* Responsive Design */
@media (max-width: 600px) {
  body {
    padding: 10px;
  }

  main {
    gap: 20px;
  }

  #login-container {
    padding: 20px;
  }

  #login-container h1 {
    font-size: 2rem;
  }

  #user-header {
    flex-direction: column;
    gap: 15px;
  }

  #user-info {
    flex-direction: column;
    text-align: center;
  }

  #user-info h2 {
    font-size: 1.3rem;
  }

  #logout-btn {
    width: 100%;
    text-align: center;
  }

  #post-creation-container, .post-content {
    padding: 20px;
  }

  #profile-stats {
    flex-direction: column;
    gap: 20px;
  }

  #games-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}
