/* ===== Reset & Variables ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --sand: #F4E8C1;
  --terracotta: #D4654A;
  --cactus: #5B7553;
  --midnight: #1A1A2E;
  --heat: #E8A838;
  --dust: #C9B99A;
  --white-hot: #FFF8F0;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--sand);
  color: var(--midnight);
  min-height: 100vh;
  overflow-x: hidden;
}

h1, h2, h3, button, .fab {
  font-family: 'Bangers', cursive;
  letter-spacing: 0.05em;
}

/* ===== View Switching ===== */
.view {
  display: none;
  min-height: 100vh;
}

.view.active {
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* ===== Gate Section ===== */
#gate {
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(0deg,
      rgba(0, 0, 0, 0.7) 0%,
      rgba(0, 0, 0, 0.3) 30%,
      transparent 55%),
    linear-gradient(180deg,
      rgba(26, 26, 46, 0.65) 0%,
      rgba(26, 26, 46, 0.2) 40%,
      transparent 70%),
    url('walk.jpg') center / cover no-repeat;
  color: var(--white-hot);
  text-align: center;
  padding: 2rem 2rem 14rem;
  position: relative;
  overflow: hidden;
  gap: 1.5rem;
}

#gate::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(255, 255, 255, 0.03) 2px,
    rgba(255, 255, 255, 0.03) 4px
  );
  animation: shimmer-drift 3s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes shimmer-drift {
  from { transform: translateY(0) scaleY(1); }
  to   { transform: translateY(-8px) scaleY(1.02); }
}

/* Gate Title */
#gate-title h1 {
  font-size: clamp(1.8rem, 5vw, 3.5rem);
  text-shadow: 2px 2px 0 var(--terracotta), 4px 4px 0 rgba(0, 0, 0, 0.3);
  animation: title-fade-in 1s ease-out forwards;
  opacity: 0;
  line-height: 1.2;
}

@keyframes title-fade-in {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Gate center group — image + prompts */
#gate-center {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Jef Image */
#jef-container {
  position: relative;
  z-index: 1;
}

#jef-img {
  width: 250px;
  height: 250px;
  object-fit: cover;
  border-radius: 50%;
  border: 4px solid var(--heat);
  box-shadow: 0 0 30px rgba(232, 168, 56, 0.5);
  opacity: 0;
  transform: rotate(-720deg) scale(0);
}

#jef-img.entrance {
  animation: jef-entrance 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes jef-entrance {
  0%   { opacity: 0; transform: rotate(-720deg) scale(0); }
  100% { opacity: 1; transform: rotate(0deg) scale(1); }
}

#jef-img.idle {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

#jef-img.exit {
  animation: jef-exit 1.2s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes jef-exit {
  0%   { opacity: 1; transform: rotate(0deg) scale(1); }
  20%  { opacity: 1; transform: rotate(10deg) scale(1.05); }
  100% { opacity: 0; transform: rotate(720deg) scale(0); }
}

/* Password Prompt */
#password-prompt, #age-prompt {
  position: absolute;
  top: 100%;
  left: 50%;
  translate: -50% 0;
  margin-top: 1.5rem;
  z-index: 1;
  opacity: 0;
  transform: translateY(20px);
  animation: fade-up 0.4s ease-out 0.1s forwards;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

#password-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}

#password-input {
  font-family: 'Inter', sans-serif;
  font-size: 1.2rem;
  padding: 0.8rem 1.2rem;
  border: 2px solid var(--heat);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--white-hot);
  text-align: center;
  outline: none;
  width: 280px;
  max-width: 90vw;
}

#password-input::placeholder {
  color: rgba(255, 248, 240, 0.5);
}

#password-input:focus {
  border-color: var(--terracotta);
  box-shadow: 0 0 15px rgba(212, 101, 74, 0.4);
}

#password-error {
  color: var(--heat);
  font-weight: 600;
  font-size: 0.9rem;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-10px); }
  40%      { transform: translateX(10px); }
  60%      { transform: translateX(-6px); }
  80%      { transform: translateX(6px); }
}

/* Age Prompt */
#age-prompt p {
  font-family: 'Bangers', cursive;
  font-size: 1.5rem;
  margin-bottom: 1rem;
  letter-spacing: 0.05em;
}

.age-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

/* Buttons (Global) */
button {
  font-family: 'Bangers', cursive;
  font-size: 1.2rem;
  padding: 0.8rem 2rem;
  border: none;
  border-radius: 8px;
  background: var(--terracotta);
  color: var(--white-hot);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  letter-spacing: 0.05em;
}

button:hover {
  background: var(--heat);
  transform: scale(1.05);
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ===== Main Grid Section ===== */
#main {
  padding-bottom: 5rem;
}

.main-header {
  text-align: center;
  padding: 2rem 1rem 1rem;
  background:
    linear-gradient(180deg,
      rgba(26, 26, 46, 0.8) 0%,
      rgba(26, 26, 46, 0.6) 60%,
      transparent 100%),
    url('walk.jpg') center top / cover no-repeat;
  color: var(--white-hot);
  position: relative;
}

.main-header h1 {
  font-size: 2.5rem;
  text-shadow: 2px 2px 0 var(--terracotta);
}

.main-header .subtitle {
  font-size: 0.95rem;
  opacity: 0.8;
  margin-top: 0.3rem;
}

.logout-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.logout-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.25);
}

#tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

#empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--cactus);
  font-size: 1.1rem;
  grid-column: 1 / -1;
}

#empty-state span {
  font-family: 'Bangers', cursive;
  font-size: 1.5rem;
  display: block;
  margin-bottom: 0.5rem;
  color: var(--terracotta);
}

/* Tiles */
.tile {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  animation: tile-pop 0.4s ease-out forwards;
  opacity: 0;
}

.tile:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

@keyframes tile-pop {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.tile-image {
  width: 100%;
  height: 180px;
  object-fit: cover;
}

.tile-no-image {
  height: 8px;
  background: linear-gradient(90deg, var(--terracotta), var(--heat), var(--cactus));
}

.tile-info {
  padding: 1rem;
}

.tile-title {
  font-family: 'Bangers', cursive;
  font-size: 1.3rem;
  margin-bottom: 0.3rem;
  letter-spacing: 0.03em;
}

.tile-snippet {
  font-size: 0.85rem;
  color: rgba(26, 26, 46, 0.6);
  margin-bottom: 0.5rem;
  line-height: 1.4;
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-author {
  font-size: 0.85rem;
  color: var(--cactus);
  font-weight: 600;
}

/* FAB */
.fab {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  font-size: 1.4rem;
  padding: 1rem 1.5rem;
  border-radius: 50px;
  background: var(--terracotta);
  color: var(--white-hot);
  box-shadow: 0 4px 16px rgba(212, 101, 74, 0.4);
  z-index: 100;
}

.fab:hover {
  box-shadow: 0 6px 24px rgba(212, 101, 74, 0.6);
}

/* ===== Create Entry Section ===== */
#create {
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

.form-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.form-header h2 {
  font-size: 1.8rem;
}

.back-btn {
  font-size: 1rem;
  padding: 0.5rem 1rem;
  background: transparent;
  color: var(--midnight);
  border: 2px solid var(--dust);
}

.back-btn:hover {
  border-color: var(--terracotta);
  background: transparent;
  color: var(--terracotta);
}

#entry-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#entry-form input[type="text"],
#entry-form textarea {
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  padding: 0.8rem 1rem;
  border: 2px solid var(--dust);
  border-radius: 8px;
  background: var(--white-hot);
  color: var(--midnight);
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}

#entry-form input:focus,
#entry-form textarea:focus {
  border-color: var(--terracotta);
}

#entry-form textarea {
  resize: vertical;
  min-height: 120px;
}

#image-upload-label {
  display: block;
  padding: 2rem;
  border: 2px dashed var(--dust);
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  color: var(--cactus);
  font-weight: 600;
}

#image-upload-label:hover {
  border-color: var(--terracotta);
  background: rgba(212, 101, 74, 0.05);
}

#image-upload-label input[type="file"] {
  display: none;
}

#image-preview {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
}

#preview-img {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: 8px;
}

#remove-image {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.9rem;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  background: rgba(26, 26, 46, 0.7);
}

#submit-btn {
  font-size: 1.4rem;
  padding: 1rem;
  margin-top: 0.5rem;
}

#upload-progress {
  height: 6px;
  background: var(--dust);
  border-radius: 3px;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  background: var(--terracotta);
  width: 0%;
  transition: width 0.3s;
  border-radius: 3px;
}

/* ===== Detail Overlay ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.85);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: overlay-fade 0.3s ease-out;
}

@keyframes overlay-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#detail-content {
  background: var(--white-hot);
  border-radius: 16px;
  max-width: 700px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  position: relative;
  animation: detail-slide-up 0.3s ease-out;
}

@keyframes detail-slide-up {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.close-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 1.5rem;
  padding: 0.3rem 0.7rem;
  background: var(--dust);
  color: var(--midnight);
  border-radius: 50%;
  line-height: 1;
}

.close-btn:hover {
  background: var(--terracotta);
  color: var(--white-hot);
}

#detail-title {
  font-size: 2rem;
  margin-bottom: 0.3rem;
  padding-right: 2.5rem;
}

#detail-author {
  color: var(--cactus);
  font-weight: 600;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

#detail-image-container {
  margin-bottom: 1.5rem;
  border-radius: 8px;
  overflow: hidden;
}

#detail-image {
  width: 100%;
  border-radius: 8px;
}

#detail-body {
  font-size: 1.05rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== Detail Actions ===== */
#detail-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 2.5rem;
}

.detail-action-btn {
  padding: 0.5rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.edit-btn {
  background: var(--dust);
  color: var(--midnight);
}

.edit-btn:hover {
  background: var(--cactus);
  color: var(--white-hot);
}

.delete-btn {
  background: transparent;
  color: var(--terracotta);
  border: 2px solid var(--terracotta);
}

.delete-btn:hover {
  background: var(--terracotta);
  color: var(--white-hot);
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  #gate {
    background-position: right center;
  }

  #jef-img {
    width: 200px;
    height: 200px;
  }

  #tiles-grid {
    grid-template-columns: 1fr;
    padding: 1rem;
    gap: 1rem;
  }

  .fab {
    bottom: 1rem;
    right: 1rem;
    font-size: 1.2rem;
    padding: 0.8rem 1.2rem;
  }

  #detail-content {
    padding: 1.5rem;
    border-radius: 12px 12px 0 0;
    max-height: 95vh;
    align-self: flex-end;
  }

  #create {
    padding: 1rem;
  }
}
