/* ===== CSS Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fafaf8;
  --bg-card: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --accent: #d4845a;
  --accent-light: #fdf0e8;
  --accent-dark: #b86d45;
  --border: #e8e4df;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-main: 'Noto Serif KR', 'Georgia', serif;
  --font-ui: 'Noto Sans KR', 'system-ui', sans-serif;
  --header-h: 60px;
  --max-w: 680px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font-ui);
}

input, textarea {
  font-family: var(--font-ui);
}

/* ===== Layout ===== */
.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 16px;
}

/* ===== Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: rgba(250, 250, 248, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}

.site-header .container {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-title {
  font-family: var(--font-main);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.site-title span {
  color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  background: transparent;
  transition: background 0.2s, color 0.2s;
  font-size: 1.1rem;
}

.btn-icon:hover, .btn-icon:active {
  background: var(--accent-light);
  color: var(--accent);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
  font-family: var(--font-ui);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover, .btn-primary:active {
  background: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(212, 132, 90, 0.35);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  color: var(--accent);
}

.btn-danger {
  background: #fee2e2;
  color: #dc2626;
}

.btn-danger:hover {
  background: #fecaca;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1rem;
  border-radius: var(--radius-md);
}

.btn-full {
  width: 100%;
}

/* ===== Login Page ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(145deg, #fdf6f0 0%, #fafaf8 60%, #f0f4ff 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .icon {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.login-logo h1 {
  font-family: var(--font-main);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.login-logo p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text-primary);
  background: var(--bg);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  -webkit-appearance: none;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 132, 90, 0.12);
  background: white;
}

.login-error {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fee2e2;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: #dc2626;
  display: none;
}

.login-error.show {
  display: block;
}

/* ===== Blog Feed ===== */
.page-main {
  padding-top: 24px;
  padding-bottom: 80px;
}

.feed-header {
  margin-bottom: 24px;
}

.feed-date {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
}

.feed-title {
  font-family: var(--font-main);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ===== Post Card ===== */
.post-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.post-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

.post-card:active {
  transform: scale(0.98);
}

.post-card-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: var(--bg);
}

.post-card-thumb-placeholder {
  width: 100%;
  aspect-ratio: 16/9;
  background: linear-gradient(135deg, var(--accent-light), #f0f4ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
}

.post-card-body {
  padding: 16px;
}

.post-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.post-mood-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent-light);
  color: var(--accent-dark);
}

.post-date {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.post-card-title {
  font-family: var(--font-main);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.4;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-card-excerpt {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-state .icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
  opacity: 0.6;
}

.empty-state h3 {
  font-family: var(--font-main);
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== FAB (Floating Action Button) ===== */
.fab {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(212, 132, 90, 0.45);
  z-index: 50;
  transition: transform 0.2s, box-shadow 0.2s;
}

.fab:active {
  transform: scale(0.93);
}

/* ===== Write Page ===== */
.write-page {
  padding-bottom: 100px;
}

.write-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.write-header h2 {
  font-family: var(--font-main);
  font-size: 1.1rem;
  font-weight: 700;
}

.write-form .form-group {
  margin-bottom: 20px;
}

.title-input {
  font-family: var(--font-main);
  font-size: 1.3rem;
  font-weight: 700;
  border: none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  padding: 10px 0;
  background: transparent;
}

.title-input:focus {
  border-color: var(--accent);
  box-shadow: none;
  background: transparent;
}

.title-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.content-textarea {
  width: 100%;
  min-height: 200px;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-card);
  resize: vertical;
  outline: none;
  font-family: var(--font-main);
}

.content-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 132, 90, 0.1);
}

.mood-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mood-chip {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  cursor: pointer;
  transition: all 0.15s;
}

.mood-chip.active, .mood-chip:active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent-dark);
}

/* ===== Image Upload ===== */
.image-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 28px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg);
}

.image-upload-area:hover, .image-upload-area.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.image-upload-area .upload-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.image-upload-area p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.image-upload-area small {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.image-preview-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.image-preview-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.image-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ===== Submit Bar ===== */
.submit-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: rgba(250, 250, 248, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  z-index: 50;
}

/* ===== Post Detail ===== */
.post-detail {
  padding-bottom: 80px;
}

.post-detail-header {
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  cursor: pointer;
}

.back-btn:hover {
  color: var(--accent);
}

.post-detail-title {
  font-family: var(--font-main);
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.post-detail-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.post-detail-author {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.post-detail-date {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.post-detail-content {
  font-family: var(--font-main);
  font-size: 1rem;
  line-height: 1.85;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== Post Images Gallery ===== */
.post-images {
  margin: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.post-images img {
  width: 100%;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.post-images.multi {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.post-images.multi img:first-child:nth-last-child(odd):last-child {
  grid-column: 1 / -1;
}

/* ===== Lightbox ===== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.lightbox.open {
  opacity: 1;
  pointer-events: all;
}

.lightbox img {
  max-width: 95vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  color: white;
  font-size: 1.6rem;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
}

/* ===== Post Actions ===== */
.post-actions {
  display: flex;
  gap: 10px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  margin-top: 28px;
}

/* ===== Loading ===== */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 12px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 18px;
  background: #1a1a1a;
  color: white;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(12px);
  animation: toastIn 0.25s ease forwards, toastOut 0.25s ease 2.5s forwards;
  white-space: nowrap;
}

.toast.success { background: #15803d; }
.toast.error { background: #dc2626; }

@keyframes toastIn {
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(12px); }
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal-sheet {
  width: 100%;
  max-width: var(--max-w);
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-overlay.open .modal-sheet {
  transform: translateY(0);
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.modal-title {
  font-family: var(--font-main);
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 16px;
}

/* ===== Utility ===== */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

/* ===== Responsive ===== */
@media (min-width: 640px) {
  .post-card-body {
    padding: 20px;
  }

  .login-card {
    padding: 48px 40px;
  }
}