/* ========================================
   논어 앱 - 메인 스타일시트
   ======================================== */

:root {
  --primary: #8B4513;
  --primary-dark: #5C2E08;
  --primary-light: #D2691E;
  --accent: #DAA520;
  --bg: #FAF7F2;
  --bg-card: #FFFFFF;
  --bg-secondary: #F5EFE6;
  --text-primary: #2C1810;
  --text-secondary: #6B4C3B;
  --text-muted: #9B7965;
  --border: #E8DDD5;
  --shadow: rgba(139, 69, 19, 0.15);
  --header-h: 56px;
  --tts-h: 0px;
  --font-size-base: 16px;
  --font-size-sm: 14px;
  --font-size-lg: 18px;
  --font-size-xl: 20px;
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --primary: #CD853F;
  --primary-dark: #A0522D;
  --primary-light: #DEB887;
  --accent: #FFD700;
  --bg: #1A1209;
  --bg-card: #2A1F12;
  --bg-secondary: #231810;
  --text-primary: #F5E6D3;
  --text-secondary: #C8A882;
  --text-muted: #8B6A4F;
  --border: #3D2A1A;
  --shadow: rgba(0, 0, 0, 0.4);
}

[data-theme="sepia"] {
  --primary: #795548;
  --primary-dark: #4E342E;
  --primary-light: #A1887F;
  --accent: #8D6E63;
  --bg: #F5ECD7;
  --bg-card: #FBF5E8;
  --bg-secondary: #EDE0C4;
  --text-primary: #3E2723;
  --text-secondary: #5D4037;
  --text-muted: #8D6E63;
  --border: #D7C4A8;
  --shadow: rgba(78, 52, 46, 0.2);
}

/* Font sizes */
[data-fontsize="small"] { --font-size-base: 14px; --font-size-sm: 12px; --font-size-lg: 16px; --font-size-xl: 18px; }
[data-fontsize="large"] { --font-size-base: 18px; --font-size-sm: 16px; --font-size-lg: 20px; --font-size-xl: 24px; }

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

body {
  font-family: 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: var(--font-size-base);
  transition: background 0.3s, color 0.3s;
}

#app { height: 100%; display: flex; flex-direction: column; }

/* ========================================
   Splash Screen
   ======================================== */
.splash {
  position: fixed; inset: 0; z-index: 9999;
  background: linear-gradient(135deg, #8B4513 0%, #5C2E08 50%, #3D1C05 100%);
  display: flex; align-items: center; justify-content: center;
}

.splash-content {
  text-align: center; color: white;
}

.splash-hanja {
  font-family: 'Noto Serif KR', serif;
  font-size: 72px; font-weight: 700;
  letter-spacing: 8px;
  text-shadow: 2px 4px 16px rgba(0,0,0,0.4);
  animation: fadeInUp 0.8s ease;
}

.splash-title {
  font-size: 28px; margin-top: 8px;
  letter-spacing: 6px;
  animation: fadeInUp 0.8s ease 0.2s both;
}

.splash-subtitle {
  font-size: 16px; margin-top: 8px; opacity: 0.7;
  animation: fadeInUp 0.8s ease 0.4s both;
}

.splash-loader {
  width: 200px; height: 3px; background: rgba(255,255,255,0.2);
  border-radius: 2px; margin: 32px auto 0;
  overflow: hidden;
  animation: fadeInUp 0.8s ease 0.6s both;
}

.loader-bar {
  height: 100%; background: white; border-radius: 2px;
  animation: loadProgress 1.5s ease forwards;
}

@keyframes loadProgress { from { width: 0; } to { width: 100%; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* ========================================
   Header
   ======================================== */
.app-header {
  height: var(--header-h);
  background: var(--primary);
  color: white;
  display: flex; align-items: center;
  padding: 0 8px;
  box-shadow: 0 2px 8px var(--shadow);
  flex-shrink: 0;
  position: relative; z-index: 10;
}

.header-title {
  flex: 1; text-align: center;
  font-family: 'Noto Serif KR', serif;
  font-size: 20px; font-weight: 700;
  letter-spacing: 2px;
}

.header-actions {
  display: flex; gap: 4px;
}

.btn-icon {
  width: 40px; height: 40px;
  background: transparent; border: none;
  color: white; font-size: 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}

.btn-icon:hover, .btn-icon:active { background: rgba(255,255,255,0.2); }
.btn-icon.hidden { visibility: hidden; }

/* ========================================
   Search Bar
   ======================================== */
.search-bar {
  background: var(--primary-dark);
  padding: 10px 12px;
  flex-shrink: 0;
  position: relative; z-index: 9;
}

.search-input-wrap {
  display: flex; align-items: center;
  background: white; border-radius: var(--radius);
  padding: 8px 12px; gap: 8px;
}

.search-icon { color: var(--text-muted); font-size: 14px; }

.search-input-wrap input {
  flex: 1; border: none; outline: none;
  font-size: var(--font-size-base);
  font-family: 'Noto Sans KR', sans-serif;
  background: transparent;
  color: var(--text-primary);
}

.btn-clear {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 14px; padding: 2px;
}

.search-results {
  position: absolute; top: 100%; left: 12px; right: 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px var(--shadow);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 100;
}

.search-result-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
}

.search-result-item:hover { background: var(--bg-secondary); }

.search-result-meta {
  font-size: 12px; color: var(--text-muted); margin-bottom: 4px;
}

.search-result-original {
  font-family: 'Noto Serif KR', serif;
  font-size: var(--font-size-sm); color: var(--primary);
  margin-bottom: 2px;
}

.search-result-reading { font-size: var(--font-size-sm); color: var(--text-secondary); }

/* ========================================
   Content Area
   ======================================== */
#main-app {
  display: flex; flex-direction: column; height: 100%;
  overflow: hidden;
}

.content-area {
  flex: 1; overflow: hidden; position: relative;
}

.view {
  position: absolute; inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
}

.view.hidden { display: none; }

/* ========================================
   Book List View
   ======================================== */
.view-intro {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white; padding: 32px 20px; text-align: center;
}

.intro-hanja {
  font-family: 'Noto Serif KR', serif;
  font-size: 56px; font-weight: 700;
  letter-spacing: 8px; line-height: 1;
  margin-bottom: 12px;
}

.intro-text {
  font-size: var(--font-size-sm); line-height: 1.7; opacity: 0.85;
}

.section-label {
  padding: 12px 16px 8px;
  font-size: 13px; font-weight: 700;
  color: var(--text-muted); letter-spacing: 1px;
  text-transform: uppercase;
}

.book-list { padding: 0 12px 12px; }

.book-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 6px var(--shadow);
}

.book-card:active { transform: scale(0.98); }

.book-number {
  width: 44px; height: 44px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}

.book-info { flex: 1; min-width: 0; }

.book-hanja {
  font-family: 'Noto Serif KR', serif;
  font-size: var(--font-size-lg); font-weight: 700;
  color: var(--primary); letter-spacing: 2px;
}

.book-ko {
  font-size: var(--font-size-sm); color: var(--text-secondary);
  margin-top: 2px;
}

.book-subtitle {
  font-size: 12px; color: var(--text-muted); margin-top: 2px;
}

.book-meta {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap;
}

.book-arrow { color: var(--text-muted); font-size: 14px; }

/* ========================================
   Chapter List View
   ======================================== */
.book-info-banner {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white; padding: 24px 20px; text-align: center;
}

.book-info-banner .banner-hanja {
  font-family: 'Noto Serif KR', serif;
  font-size: 42px; font-weight: 700; letter-spacing: 6px;
}

.book-info-banner .banner-ko {
  font-size: 18px; margin-top: 4px; opacity: 0.9;
}

.book-info-banner .banner-subtitle {
  font-size: 13px; opacity: 0.7; margin-top: 4px;
}

.chapter-list { padding: 12px; }

.chapter-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.chapter-card:active { transform: scale(0.98); }

.chapter-icon {
  width: 36px; height: 36px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--primary); font-size: 16px; flex-shrink: 0;
}

.chapter-title { flex: 1; font-size: var(--font-size-base); font-weight: 500; }
.chapter-meta { font-size: 12px; color: var(--text-muted); }
.chapter-arrow { color: var(--text-muted); font-size: 14px; }

/* ========================================
   Verse List View
   ======================================== */
.chapter-info-banner {
  background: var(--bg-secondary);
  padding: 16px 20px; text-align: center;
  border-bottom: 1px solid var(--border);
}

.chapter-info-banner .cib-book {
  font-size: 13px; color: var(--text-muted); margin-bottom: 4px;
}

.chapter-info-banner .cib-title {
  font-size: var(--font-size-lg); font-weight: 700; color: var(--primary);
}

/* TTS Panel */
.tts-panel {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--shadow);
  position: sticky; top: 0; z-index: 5;
}

.tts-top-row {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 8px; gap: 8px;
}

.tts-mode-tabs {
  display: flex; gap: 4px; flex: 1;
}

.tts-mode-tab {
  flex: 1; padding: 5px 2px;
  font-size: 12px; font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.2s;
  font-family: 'Noto Sans KR', sans-serif;
}

.tts-mode-tab.active {
  background: var(--primary); color: white; border-color: var(--primary);
}

.tts-speed-control {
  display: flex; align-items: center; gap: 4px;
}

.speed-label { font-size: 11px; color: var(--text-muted); }
.speed-btn {
  width: 24px; height: 24px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  color: var(--primary); border-radius: 50%;
  cursor: pointer; font-size: 10px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.speed-btn:active { background: var(--border); }
.speed-value {
  font-size: 13px; font-weight: 700; color: var(--primary);
  min-width: 36px; text-align: center;
}

.tts-controls-row {
  display: flex; align-items: center; gap: 8px;
}

.tts-btn {
  border: none; cursor: pointer; border-radius: var(--radius-sm);
  transition: all 0.2s; font-family: 'Noto Sans KR', sans-serif;
}

.btn-prev, .btn-next {
  width: 36px; height: 36px;
  background: var(--bg-secondary); color: var(--primary);
  font-size: 14px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

.btn-play-all {
  flex: 1; height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white; font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}

.btn-play-all.playing {
  background: linear-gradient(135deg, #c0392b, #e74c3c);
}

.btn-repeat {
  width: 36px; height: 36px;
  background: var(--bg-secondary); color: var(--text-muted);
  font-size: 14px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

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

/* Verse List */
.verse-list { padding: 12px; }

.verse-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  transition: all 0.2s;
  box-shadow: 0 2px 6px var(--shadow);
}

.verse-card.playing {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(139,69,19,0.2), 0 4px 12px var(--shadow);
}

.verse-header {
  padding: 12px 14px 8px;
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 8px;
}

.verse-number {
  width: 24px; height: 24px; flex-shrink: 0;
  background: var(--primary); color: white;
  border-radius: 50%; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.verse-original {
  flex: 1;
  font-family: 'Noto Serif KR', serif;
  font-size: var(--font-size-lg); font-weight: 700;
  color: var(--primary); line-height: 1.6;
  letter-spacing: 1px;
}

.verse-actions {
  display: flex; gap: 4px; flex-shrink: 0;
}

.verse-action-btn {
  width: 32px; height: 32px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}

.verse-action-btn:active { background: var(--border); }
.verse-action-btn.speak-btn:active,
.verse-action-btn.speak-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

.verse-body { padding: 0 14px 12px; }

.verse-reading {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  line-height: 1.7; margin-bottom: 6px;
  letter-spacing: 0.5px;
}

.verse-interpretation {
  font-size: var(--font-size-sm);
  color: var(--text-primary); line-height: 1.7;
  padding: 8px 10px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.verse-characters {
  margin-top: 10px;
  display: flex; flex-wrap: wrap; gap: 6px;
}

.hanja-chip {
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px; min-width: 48px;
  cursor: default;
  transition: all 0.2s;
}

.hanja-chip:hover {
  background: var(--primary); color: white; border-color: var(--primary);
}

.hanja-chip:hover .hc-char,
.hanja-chip:hover .hc-sound,
.hanja-chip:hover .hc-meaning { color: white; }

.hc-char {
  font-family: 'Noto Serif KR', serif;
  font-size: var(--font-size-lg); font-weight: 700;
  color: var(--primary); line-height: 1.2;
}

.hc-sound {
  font-size: 11px; color: var(--text-secondary);
  font-weight: 500; margin-top: 2px;
}

.hc-meaning {
  font-size: 10px; color: var(--text-muted);
  text-align: center; line-height: 1.2; margin-top: 1px;
}

.verse-toggle-chars {
  display: flex; align-items: center; gap: 4px;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 12px;
  padding: 6px 0; margin-top: 4px;
  font-family: 'Noto Sans KR', sans-serif;
}

.verse-toggle-chars i { transition: transform 0.2s; }
.verse-toggle-chars.open i { transform: rotate(180deg); }

/* Playing indicator */
.playing-wave {
  display: flex; align-items: flex-end; gap: 2px; height: 20px;
}

.playing-wave span {
  display: inline-block; width: 3px;
  background: var(--primary); border-radius: 2px;
  animation: wave 1.2s ease-in-out infinite;
}

.playing-wave span:nth-child(2) { animation-delay: 0.2s; }
.playing-wave span:nth-child(3) { animation-delay: 0.4s; }
.playing-wave span:nth-child(4) { animation-delay: 0.6s; }

@keyframes wave {
  0%, 100% { height: 4px; }
  50% { height: 16px; }
}

/* ========================================
   Modal
   ======================================== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden { display: none; }

.modal-content {
  width: 100%; max-height: 90vh;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  display: flex; flex-direction: column;
  animation: slideUp 0.3s ease;
}

.settings-modal { max-height: 85vh; }
.verse-modal { max-height: 80vh; }

.modal-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}

.modal-header h2 {
  font-size: var(--font-size-lg); font-weight: 700;
  color: var(--primary);
}

.modal-header .btn-icon { color: var(--text-muted); }

.modal-body {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; flex-shrink: 0;
}

.btn-speak {
  flex: 1; padding: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white; border: none;
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px; font-weight: 700;
  font-family: 'Noto Sans KR', sans-serif;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}

/* Settings */
.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  font-size: 14px; font-weight: 700;
  color: var(--text-muted); letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 12px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.setting-item {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 10px 0; gap: 12px;
}

.setting-item label {
  font-size: var(--font-size-sm); color: var(--text-secondary);
  font-weight: 500; flex-shrink: 0;
}

.setting-select {
  flex: 1; max-width: 180px;
  padding: 6px 10px; font-size: var(--font-size-sm);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text-primary);
  font-family: 'Noto Sans KR', sans-serif;
}

.setting-item input[type="range"] {
  flex: 1; accent-color: var(--primary);
}

.font-size-btns, .theme-btns {
  display: flex; gap: 6px;
}

.font-size-btns button, .theme-btns button {
  padding: 5px 12px; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text-secondary);
  cursor: pointer; transition: all 0.2s;
  font-family: 'Noto Sans KR', sans-serif;
}

.font-size-btns button.active, .theme-btns button.active {
  background: var(--primary); color: white; border-color: var(--primary);
}

.toggle-item { flex-direction: row; }

.toggle-switch {
  position: relative; display: inline-block;
  width: 48px; height: 26px;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border); border-radius: 26px;
  cursor: pointer; transition: 0.3s;
}

.toggle-slider:before {
  content: ''; position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: white; border-radius: 50%;
  transition: 0.3s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

input:checked + .toggle-slider { background: var(--primary); }
input:checked + .toggle-slider:before { transform: translateX(22px); }

.btn-test-voice {
  width: 100%; padding: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--primary); cursor: pointer;
  font-size: 13px; font-weight: 700;
  margin-top: 8px;
  font-family: 'Noto Sans KR', sans-serif;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}

/* Verse Modal */
.vm-original {
  font-family: 'Noto Serif KR', serif;
  font-size: var(--font-size-xl); font-weight: 700;
  color: var(--primary); line-height: 1.6;
  letter-spacing: 1px; margin-bottom: 12px;
}

.vm-reading {
  font-size: var(--font-size-base);
  color: var(--text-secondary); line-height: 1.8;
  margin-bottom: 12px; padding: 10px 12px;
  background: var(--bg-secondary); border-radius: var(--radius-sm);
}

.vm-interpretation {
  font-size: var(--font-size-base);
  line-height: 1.8; color: var(--text-primary);
  padding: 12px; background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--accent);
  margin-bottom: 16px;
}

.vm-chars-title {
  font-size: 13px; font-weight: 700;
  color: var(--text-muted); margin-bottom: 10px;
  text-transform: uppercase; letter-spacing: 1px;
}

.vm-chars {
  display: flex; flex-wrap: wrap; gap: 8px;
}

.vm-hanja-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px; text-align: center;
  min-width: 56px;
}

.vm-hanja-char {
  font-family: 'Noto Serif KR', serif;
  font-size: 24px; font-weight: 700;
  color: var(--primary); display: block;
}

.vm-hanja-sound {
  font-size: 13px; font-weight: 600;
  color: var(--text-secondary); display: block; margin-top: 2px;
}

.vm-hanja-meaning {
  font-size: 11px; color: var(--text-muted);
  display: block; margin-top: 2px; line-height: 1.3;
}

/* Toast */
.toast {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8); color: white;
  padding: 10px 20px; border-radius: 20px;
  font-size: 13px; z-index: 9999;
  animation: fadeIn 0.3s ease;
  white-space: nowrap;
}

.toast.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Hidden */
.hidden { display: none !important; }

/* Responsive */
@media (min-width: 480px) {
  .modal-content { max-width: 480px; margin: 0 auto; border-radius: var(--radius); }
  .modal-overlay { align-items: center; }
}
