/* ========================================
   KATHA — Styles
   Mobile-first storytelling platform
   ======================================== */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  transition: background 0.4s ease, color 0.4s ease;
  padding-bottom: 80px;
}

/* ========================================
   THEME: Warm & Earthy
   ======================================== */
[data-theme="warm"] {
  --bg: #FDF6EC;
  --bg-card: #FFFFFF;
  --bg-card-hover: #FFF8F0;
  --bg-nav: #FFFAF3;
  --bg-modal: #FDF6EC;
  --text: #3D2B1F;
  --text-secondary: #7A6555;
  --text-muted: #A89585;
  --accent: #C4652A;
  --accent-light: #F5DCC8;
  --accent-hover: #A8531F;
  --border: #E8DDD0;
  --border-light: #F0E6D8;
  --badge-bg: #C4652A;
  --badge-text: #FFFFFF;
  --tab-active: #C4652A;
  --tab-inactive: #A89585;
  --shadow: 0 2px 12px rgba(61, 43, 31, 0.08);
  --shadow-lg: 0 8px 30px rgba(61, 43, 31, 0.12);
  --hero-gradient: linear-gradient(135deg, #F5DCC8 0%, #FCEBD4 100%);
  --topic-bg: linear-gradient(135deg, #FFF3E4 0%, #FDE8D0 100%);
  --nav-shadow: 0 -1px 12px rgba(61, 43, 31, 0.08);
  --placeholder-bg: linear-gradient(135deg, #F5DCC8, #FCE4CC);
  --swatch-colors: linear-gradient(135deg, #C4652A, #D4956A, #FDF6EC);
}

/* ========================================
   THEME: Dark & Modern
   ======================================== */
[data-theme="dark"] {
  --bg: #0F0F14;
  --bg-card: #1A1A24;
  --bg-card-hover: #22222E;
  --bg-nav: #14141C;
  --bg-modal: #1A1A24;
  --text: #EAEAF0;
  --text-secondary: #A0A0B8;
  --text-muted: #6A6A82;
  --accent: #7C6AFF;
  --accent-light: #2A2548;
  --accent-hover: #9B8CFF;
  --border: #2A2A38;
  --border-light: #222230;
  --badge-bg: #7C6AFF;
  --badge-text: #FFFFFF;
  --tab-active: #7C6AFF;
  --tab-inactive: #6A6A82;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
  --hero-gradient: linear-gradient(135deg, #1E1A3A 0%, #2A2040 100%);
  --topic-bg: linear-gradient(135deg, #1E1A3A 0%, #252040 100%);
  --nav-shadow: 0 -1px 12px rgba(0, 0, 0, 0.4);
  --placeholder-bg: linear-gradient(135deg, #2A2548, #1E1A3A);
  --swatch-colors: linear-gradient(135deg, #7C6AFF, #3A3060, #0F0F14);
}

/* ========================================
   THEME: Light & Minimal
   ======================================== */
[data-theme="light"] {
  --bg: #FAFAFA;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F8F8F8;
  --bg-nav: #FFFFFF;
  --bg-modal: #FFFFFF;
  --text: #1A1A1A;
  --text-secondary: #555555;
  --text-muted: #999999;
  --accent: #1A1A1A;
  --accent-light: #F0F0F0;
  --accent-hover: #333333;
  --border: #E8E8E8;
  --border-light: #F0F0F0;
  --badge-bg: #1A1A1A;
  --badge-text: #FFFFFF;
  --tab-active: #1A1A1A;
  --tab-inactive: #999999;
  --shadow: 0 1px 8px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.06);
  --hero-gradient: linear-gradient(135deg, #F5F5F5 0%, #EFEFEF 100%);
  --topic-bg: linear-gradient(135deg, #F5F5F5 0%, #EEEEEE 100%);
  --nav-shadow: 0 -1px 8px rgba(0, 0, 0, 0.04);
  --placeholder-bg: linear-gradient(135deg, #F0F0F0, #E8E8E8);
  --swatch-colors: linear-gradient(135deg, #FFFFFF, #CCCCCC, #1A1A1A);
}

/* ========================================
   THEME: Colorful & Bold
   ======================================== */
[data-theme="colorful"] {
  --bg: #FFF8F0;
  --bg-card: #FFFFFF;
  --bg-card-hover: #FFFAF5;
  --bg-nav: #FFFAF5;
  --bg-modal: #FFF8F0;
  --text: #1A1035;
  --text-secondary: #4A3D60;
  --text-muted: #8A7DA0;
  --accent: #E8365D;
  --accent-light: #FFE0E8;
  --accent-hover: #D02A4E;
  --border: #F0E0F0;
  --border-light: #F8F0F8;
  --badge-bg: #E8365D;
  --badge-text: #FFFFFF;
  --tab-active: #E8365D;
  --tab-inactive: #8A7DA0;
  --shadow: 0 2px 16px rgba(232, 54, 93, 0.08);
  --shadow-lg: 0 8px 30px rgba(232, 54, 93, 0.12);
  --hero-gradient: linear-gradient(135deg, #FFE0E8 0%, #E8D0FF 50%, #D0F0FF 100%);
  --topic-bg: linear-gradient(135deg, #FFE8EE 0%, #F0E0FF 100%);
  --nav-shadow: 0 -1px 12px rgba(232, 54, 93, 0.08);
  --placeholder-bg: linear-gradient(135deg, #FFE0E8, #E8D0FF);
  --swatch-colors: linear-gradient(135deg, #E8365D, #A855F7, #3B82F6);
}

/* ========================================
   Header
   ======================================== */
.header {
  padding: 20px 20px 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  transition: background 0.4s ease;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  transition: color 0.4s ease;
}

.logo-en {
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 6px;
  letter-spacing: 0.05em;
}

.tagline {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
  font-style: italic;
  transition: color 0.4s ease;
}

.theme-toggle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.theme-toggle:active {
  transform: scale(0.92);
}

/* ========================================
   Theme Modal
   ======================================== */
.theme-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.theme-modal.open {
  pointer-events: auto;
  opacity: 1;
}

.theme-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.theme-modal-content {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg-modal);
  border-radius: 24px 24px 0 0;
  padding: 28px 24px 36px;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1), background 0.4s ease;
}

.theme-modal.open .theme-modal-content {
  transform: translateY(0);
}

.theme-modal-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.25rem;
  color: var(--text);
  text-align: center;
  margin-bottom: 20px;
  transition: color 0.4s ease;
}

.theme-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  transition: all 0.25s ease;
  text-align: left;
}

.theme-option:active {
  transform: scale(0.98);
}

.theme-option.active {
  border-color: var(--accent);
  background: var(--accent-light);
}

.theme-swatch {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
}

.warm-swatch { background: linear-gradient(135deg, #C4652A, #D4956A, #FDF6EC); }
.dark-swatch { background: linear-gradient(135deg, #7C6AFF, #3A3060, #0F0F14); }
.light-swatch { background: linear-gradient(135deg, #FFFFFF, #CCCCCC, #1A1A1A); border: 1px solid #E0E0E0; }
.colorful-swatch { background: linear-gradient(135deg, #E8365D, #A855F7, #3B82F6); }

.theme-label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  display: block;
  transition: color 0.4s ease;
}

.theme-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
  margin-top: 1px;
  transition: color 0.4s ease;
}

.theme-modal-close {
  display: block;
  width: 100%;
  padding: 14px;
  margin-top: 20px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: var(--badge-text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
}

.theme-modal-close:active {
  transform: scale(0.98);
  opacity: 0.9;
}

/* ========================================
   Navigation Tabs
   ======================================== */
.nav-tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--bg);
  position: sticky;
  top: 82px;
  z-index: 90;
  transition: background 0.4s ease;
}

.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tab {
  padding: 8px 18px;
  border-radius: 20px;
  border: none;
  background: transparent;
  color: var(--tab-inactive);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.25s ease;
  font-family: 'Inter', sans-serif;
}

.nav-tab.active {
  background: var(--accent);
  color: var(--badge-text);
}

/* ========================================
   Main Content
   ======================================== */
.main-content {
  padding: 0 16px;
  max-width: 480px;
  margin: 0 auto;
}

.section {
  display: none;
}

.section.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-header {
  margin-bottom: 16px;
}

.section-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.2rem;
  color: var(--text);
  font-weight: 600;
  transition: color 0.4s ease;
}

/* ========================================
   Story Cards
   ======================================== */
.story-card {
  background: var(--bg-card);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  cursor: pointer;
}

.story-card:active {
  transform: scale(0.985);
  background: var(--bg-card-hover);
}

.hero-card {
  margin-bottom: 18px;
}

.story-card-row {
  display: flex;
  gap: 14px;
  padding: 16px;
}

/* Story Images */
.story-image {
  position: relative;
}

.image-placeholder {
  background: var(--placeholder-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.4s ease;
}

.hero-image {
  width: 100%;
}

.hero-placeholder {
  width: 100%;
  height: 180px;
  border-radius: 0;
}

.thumb-image {
  flex-shrink: 0;
}

.thumb-placeholder {
  width: 88px;
  height: 88px;
  border-radius: 12px;
}

.placeholder-icon {
  font-size: 2rem;
}

.thumb-placeholder .placeholder-icon {
  font-size: 1.6rem;
}

.story-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 8px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* Story Body */
.story-body {
  flex: 1;
  min-width: 0;
}

.hero-card .story-body {
  padding: 16px 16px 14px;
}

.story-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  transition: color 0.4s ease;
}

.story-author {
  font-weight: 500;
  color: var(--text-secondary);
  transition: color 0.4s ease;
}

.meta-dot {
  opacity: 0.5;
}

.story-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  margin-bottom: 6px;
  transition: color 0.4s ease;
}

.hero-title {
  font-size: 1.3rem;
}

.story-excerpt {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color 0.4s ease;
}

.story-excerpt-short {
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color 0.4s ease;
}

.story-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.read-time {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 500;
  transition: color 0.4s ease;
}

.bookmark-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.25s ease;
}

.bookmark-btn:active {
  transform: scale(0.85);
}

.bookmark-btn.bookmarked {
  color: var(--accent);
}

.bookmark-btn.bookmarked svg {
  fill: var(--accent);
}

/* ========================================
   Topics Grid
   ======================================== */
.topics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.topic-card {
  background: var(--topic-bg);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.25s ease;
  text-align: center;
}

.topic-card:active {
  transform: scale(0.96);
}

.topic-emoji {
  font-size: 1.8rem;
}

.topic-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  transition: color 0.4s ease;
}

.topic-count {
  font-size: 0.76rem;
  color: var(--text-muted);
  transition: color 0.4s ease;
}

/* ========================================
   Empty State
   ======================================== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 16px;
}

.empty-text {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 8px;
  transition: color 0.4s ease;
}

.empty-subtext {
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: color 0.4s ease;
}

/* ========================================
   Bottom Navigation
   ======================================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-nav);
  border-top: 1px solid var(--border-light);
  box-shadow: var(--nav-shadow);
  z-index: 100;
  max-width: 100%;
  transition: all 0.4s ease;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--tab-inactive);
  font-size: 0.65rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
  font-family: 'Inter', sans-serif;
}

.bottom-nav-item.active {
  color: var(--accent);
}

.bottom-nav-item:active {
  transform: scale(0.9);
}

/* ========================================
   Emoji Reactions
   ======================================== */
.story-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.emoji-reactions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.reaction-btn {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
}

.reaction-btn:active {
  transform: scale(0.9);
}

.reaction-btn.reacted {
  border-color: var(--accent);
  background: var(--accent-light);
}

.reaction-emoji {
  font-size: 0.85rem;
  line-height: 1;
}

.reaction-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  min-width: 8px;
  transition: color 0.4s ease;
}

.reaction-btn.reacted .reaction-count {
  color: var(--accent);
  font-weight: 600;
}

.add-reaction {
  border-style: dashed;
  padding: 4px 8px;
  opacity: 0.6;
}

.add-reaction:hover,
.add-reaction:active {
  opacity: 1;
}

.add-reaction .reaction-emoji {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Emoji Picker Popup */
.emoji-picker {
  position: fixed;
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 500;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 200px;
}

.emoji-picker.open {
  display: flex;
}

.emoji-pick {
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.emoji-pick:active {
  transform: scale(0.85);
  background: var(--accent-light);
}

/* ========================================
   Utilities & Animations
   ======================================== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Smooth theme transitions for all elements */
* {
  transition-property: background-color, color, border-color, box-shadow;
  transition-duration: 0.4s;
  transition-timing-function: ease;
}

/* Override for transform transitions */
.story-card, .bookmark-btn, .theme-toggle, .bottom-nav-item, .topic-card, .theme-option, .nav-tab {
  transition: all 0.25s ease;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 200;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Max width wrapper for larger screens */
@media (min-width: 481px) {
  body {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--border-light);
    border-right: 1px solid var(--border-light);
    min-height: 100vh;
  }

  .bottom-nav {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
  }
}
