/* Root Variables */
:root {
  --primary: #9B4321;
  --primary-dark: #8A3D20;
  --primary-light: #C85A35;
  --bg-light: #FFF8F5;
  --bg-lighter: #FFF4EC;
  --bg-accent: #F1EAE5;
  --text-dark: #251817;
  --text-medium: #5A4742;
  --text-light: #7A4A3D;
  --border: #E6D8D1;
  --border-light: #E2D4CC;
  --content-width: 980px;
  
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
  --spacing-xl: 20px;
  --spacing-2xl: 24px;
  
  --border-radius-sm: 10px;
  --border-radius-md: 12px;
  --border-radius-lg: 16px;
  --border-radius-xl: 18px;
  
  --transition: 220ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-light);
  color: var(--text-dark);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 100%;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 900;
  line-height: 1.2;
}

p {
  line-height: 1.6;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--primary-dark);
}

.icon-xs {
  width: 20px;
  height: 20px;
}

.playstore-icon {
  width: 22px;
  height: 22px;
}
/* Hero Card */
.hero-card {
  background: linear-gradient(180deg, rgba(155, 67, 33, 0.12) 0%, rgba(255, 248, 245, 1) 100%);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 24px 20px;
  margin: 20px auto 0;
  max-width: calc(100% - 32px);
  width: var(--content-width);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.08);
}

.hero-heading {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: var(--spacing-xl);
}

.hero-book-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 66px;
  height: 66px;
  background: var(--primary);
  color: white;
  border-radius: 18px;
  flex-shrink: 0;
  transition: transform var(--transition), background var(--transition);
}

.hero-book-icon:hover,
.hero-book-icon:focus-visible {
  color: white;
  background: var(--primary-dark);
  transform: translateY(-1px);
  outline: none;
}

.hero-book-icon svg {
  width: 38px;
  height: 38px;
}

.hero-kicker {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-light);
  margin-bottom: 4px;
}

.hero-title {
  font-size: clamp(28px, 7vw, 40px);
  line-height: 1.05;
  color: var(--text-dark);
}

.hero-actions {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(180px, 1.4fr) minmax(140px, 1fr);
  gap: var(--spacing-md);
}

.hero-main-btn,
.hero-action-btn {
  min-height: 52px;
  justify-content: center;
}

.hero-main-btn {
  box-shadow: 0 10px 18px rgba(155, 67, 33, 0.18);
}
/* Search */
.search-container {
  position: relative;
  padding: 12px 0 10px;
  background: transparent;
  max-width: calc(100% - 32px);
  margin: 0 auto;
  width: var(--content-width);
}

.search-container::before {
  content: '';
  position: absolute;
  left: 18px;
  top: 50%;
  width: 15px;
  height: 15px;
  border: 2px solid var(--text-medium);
  border-radius: 50%;
  transform: translateY(-58%);
  pointer-events: none;
}

.search-container::after {
  content: '';
  position: absolute;
  left: 33px;
  top: 50%;
  width: 10px;
  height: 2px;
  background: var(--text-medium);
  border-radius: 999px;
  transform: translateY(8px) rotate(45deg);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 16px 16px 16px 50px;
  font-size: 16px;
  border: 2px solid var(--primary);
  border-radius: 16px;
  background: white;
  color: var(--text-dark);
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: none;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-dark);
  box-shadow: 0 0 0 3px rgba(155, 67, 33, 0.1);
}

.search-input::placeholder {
  color: var(--text-light);
}

.search-clear {
  position: absolute;
  right: calc(var(--spacing-lg) + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition);
}

.search-clear:hover {
  color: var(--primary);
}

.search-clear.hidden,
.results-info.hidden,
.hidden {
  display: none !important;
}

/* Results Info */
.results-info {
  padding: var(--spacing-md) 0 var(--spacing-lg);
  background: transparent;
  color: var(--text-light);
  font-size: 15px;
  font-weight: 800;
  text-align: left;
  max-width: calc(100% - 32px);
  margin: 0 auto;
  width: var(--content-width);
}

/* Main Content */
.app-content {
  flex: 1;
  padding: var(--spacing-lg) 0 calc(var(--spacing-xl) * 1.2);
  max-width: calc(100% - 32px);
  margin: 0 auto;
  width: var(--content-width);
}

.center-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  gap: var(--spacing-lg);
  color: var(--text-light);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(155, 67, 33, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Section Groups */
.section-group {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(155, 67, 33, 0.08);
}

.section-group + .section-group {
  border-top: 0;
}

.section-group-header {
  background: var(--bg-accent);
  padding: 16px 18px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: background-color var(--transition);
}

.section-group-header:hover {
  background: rgba(255, 255, 255, 0.7);
}

.section-group-header:active {
  background: rgba(255, 255, 255, 0.85);
}

.section-title {
  font-size: clamp(15px, 4vw, 18px);
  font-weight: 800;
  letter-spacing: 0;
  color: var(--text-dark);
  flex: 1;
  text-transform: uppercase;
}

.section-count {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--primary);
  min-width: 22px;
  text-align: center;
}

.section-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--primary);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition);
}

.section-toggle.open {
  transform: rotate(180deg);
}

/* Items */
.section-items {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
}

.section-item {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px;
  border-radius: 0;
  background: white;
  border-top: 1px solid rgba(230, 216, 209, 0.65);
  box-shadow: none;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, background-color 0.2s;
  text-decoration: none;
  color: inherit;
}

.section-item:hover {
  transform: none;
  box-shadow: none;
  background: #fffdfb;
}

.section-item:last-child {
  border-bottom: none;
}

.section-item:active {
  background: rgba(155, 67, 33, 0.05);
}

.section-item-icon {
  width: 20px;
  height: 20px;
  color: var(--primary);
  flex-shrink: 0;
  margin-top: 3px;
}

.section-item-content {
  flex: 1;
}

.section-item-title {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.3;
  color: var(--text-dark);
  margin-bottom: 4px;
}

.section-item-snippet {
  font-size: 14px;
  line-height: 1.45;
  color: #5a4742;
  word-break: break-word;
  margin-top: 8px;
  background: transparent;
  border-left: 0;
  padding: 0;
  border-radius: 0;
  font-family: inherit;
  white-space: pre-wrap;
  max-height: 92px;
  overflow: hidden;
}

.section-item-snippet pre {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

.highlight {
  background-color: rgba(248, 175, 94, 0.48);
  color: var(--primary);
  font-weight: 800;
  padding: 0 2px;
  border-radius: 2px;
}

.section-item-chevron {
  width: 18px;
  height: 18px;
  color: #ccc;
  flex-shrink: 0;
  margin-top: 2px;
}

/* Content Detail */
.content-detail {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--border-radius-md);
  padding: var(--spacing-lg);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
}

.content-category {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--primary);
  text-transform: uppercase;
}

.content-title {
  font-size: clamp(18px, 5vw, 24px);
  font-weight: 900;
  line-height: 1.2;
  color: var(--text-dark);
}

.content-subtitle {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  font-size: clamp(14px, 3vw, 16px);
  font-weight: 700;
  color: var(--primary);
}

.content-body {
  flex: 1;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-dark);
  white-space: pre-wrap;
  word-break: break-word;
}

.related-section {
  border-top: 1px solid var(--border);
  padding-top: var(--spacing-lg);
}

.related-title {
  color: var(--primary);
  font-size: 14px;
  font-weight: 900;
  margin-bottom: var(--spacing-md);
  text-transform: uppercase;
}

.related-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.related-list .section-item {
  border-top: 0;
  border-bottom: 1px solid rgba(230, 216, 209, 0.75);
}

.related-list .section-item:last-child {
  border-bottom: 0;
}

.content-body mark.highlight,
.search-results-list mark.highlight,
.section-item-title mark.highlight,
.section-item-snippet mark.highlight,
.content-title mark.highlight,
.content-subtitle mark.highlight {
  background-color: rgba(248, 175, 94, 0.48);
  color: var(--primary);
  font-weight: 800;
  padding: 0 2px;
  border-radius: 2px;
}

.content-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--spacing-md);
  padding-top: var(--spacing-md);
  border-top: 1px solid var(--border);
}

.btn {
  padding: 12px 16px;
  border: none;
  border-radius: var(--border-radius-md);
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  color: white;
}

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

.btn-secondary:hover {
  background: rgba(155, 67, 33, 0.05);
}

/* Search Results Panel */
.search-results-panel {
  background: transparent;
  border: 0;
  border-radius: 0;
  overflow: visible;
  display: flex;
  flex-direction: column;
  max-height: none;
}

.search-results-header {
  padding: var(--spacing-lg);
  background: var(--bg-accent);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-dark);
  letter-spacing: 0.5px;
}

.search-results-list {
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

/* PDF Reader */
.pdf-panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.pdf-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-md);
  padding: var(--spacing-lg);
  background: var(--bg-accent);
  border-bottom: 1px solid var(--border);
}

.pdf-panel-title {
  color: var(--text-dark);
  font-size: 18px;
  font-weight: 900;
}

.pdf-frame {
  display: block;
  width: 100%;
  height: min(78vh, 920px);
  border: 0;
  background: white;
}

.pdf-note {
  padding: 10px var(--spacing-lg);
  border-top: 1px solid var(--border);
  color: var(--text-light);
  font-size: 12px;
}

/* iOS Shortcut Help */
.shortcut-panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--spacing-xl);
}

.shortcut-title {
  color: var(--text-dark);
  font-size: 22px;
  margin-bottom: var(--spacing-lg);
}

.shortcut-steps {
  display: grid;
  gap: var(--spacing-md);
}

.install-help-text {
  color: var(--text-medium);
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: var(--spacing-lg);
}

.shortcut-step {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  color: var(--text-dark);
  font-size: 16px;
  line-height: 1.4;
}

.shortcut-step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-weight: 900;
  flex-shrink: 0;
}

/* Footer */
.app-footer {
  background: var(--bg-accent);
  border-top: 1px solid var(--border-light);
  padding: var(--spacing-lg) max(var(--spacing-lg), env(safe-area-inset-left));
  text-align: center;
  padding-bottom: max(var(--spacing-lg), env(safe-area-inset-bottom));
}

.app-footer p {
  font-size: 13px;
  color: var(--text-light);
  margin: 2px 0;
}

.app-footer p:first-child {
  font-weight: 700;
  color: var(--text-dark);
}

/* Responsive */
@media (max-width: 600px) {
  :root {
    --spacing-lg: 12px;
    --spacing-xl: 16px;
  }

  .hero-card {
    max-width: 100%;
    width: 100%;
    margin-top: 12px;
    padding: 18px 10px 18px;
    border: 1px solid var(--border);
    border-radius: 28px;
    background: linear-gradient(145deg, #fff7f2 0%, #f2e1d7 100%);
    box-shadow: none;
  }

  body.search-mode .hero-card {
    position: sticky;
    top: 0;
    z-index: 30;
    display: block;
    width: 100%;
    max-width: 100%;
    margin-top: 0;
    padding: 8px 10px 6px;
    border: 0;
    border-radius: 0;
    background: var(--bg-light);
    box-shadow: none;
  }

  body.search-mode .hero-heading {
    margin-bottom: 0;
  }

  body.search-mode .hero-heading > div {
    display: none;
  }

  body.search-mode .hero-book-icon {
    display: flex;
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }

  body.search-mode .hero-book-icon svg {
    width: 26px;
    height: 26px;
  }

  body.search-mode .hero-actions {
    display: none;
  }

  .hero-heading {
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
  }

  .hero-book-icon {
    width: 58px;
    height: 58px;
    border-radius: 16px;
  }

  .hero-book-icon svg {
    width: 34px;
    height: 34px;
  }

  .hero-kicker {
    font-size: 18px;
    line-height: 1.1;
  }

  .hero-title {
    font-size: 34px;
    line-height: 1;
  }

  .hero-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .hero-main-btn,
  .hero-action-btn {
    min-height: 48px;
    justify-content: center;
    border-radius: 16px;
    font-size: 15px;
    font-weight: 800;
    padding: 10px 12px;
  }

  .hero-main-btn,
  .hero-action-btn {
    flex: none;
    width: 100%;
  }

  .hero-main-btn {
    grid-column: 1 / -1;
    min-height: 54px;
    order: 1;
  }

  .hero-action-btn {
    min-height: 46px;
    order: 2;
  }

  .search-container {
    max-width: 100%;
    width: 100%;
    padding: 14px 0 10px;
  }

  body.search-mode .search-container {
    position: sticky;
    top: 58px;
    z-index: 20;
    padding-top: 8px;
    background: var(--bg-light);
    border-bottom: 1px solid var(--border-light);
  }

  .search-container::before {
    left: 20px;
    width: 22px;
    height: 22px;
    border-width: 4px;
  }

  .search-container::after {
    left: 43px;
    width: 16px;
    height: 4px;
    transform: translateY(12px) rotate(45deg);
  }

  .search-input {
    min-height: 54px;
    padding-left: 64px;
    padding-right: 52px;
    border-radius: 20px;
    font-size: 16px;
  }

  .search-clear {
    right: 18px;
  }

  .results-info {
    max-width: 100%;
    width: 100%;
  }

  .app-content {
    max-width: none;
    width: 100%;
    padding-top: 0;
    padding-bottom: 0;
  }

  .section-group {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    margin-bottom: 0;
    box-shadow: none;
  }

  .section-group-header {
    min-height: 64px;
    padding: 18px 22px;
    background: var(--bg-accent);
  }

  .section-title {
    font-size: 20px;
    letter-spacing: 1px;
  }

  .section-count {
    display: none;
  }

  .section-toggle svg {
    width: 24px !important;
    height: 24px !important;
  }

  .section-item {
    min-height: 76px;
    align-items: center;
    gap: 16px;
    padding: 18px 22px;
  }

  .section-item-icon {
    width: 22px;
    height: 22px;
    margin-top: 0;
  }

  .section-item-title {
    font-size: 16px;
    line-height: 1.32;
    margin-bottom: 0;
  }

  .section-item-chevron {
    width: 20px;
    height: 20px;
    color: var(--text-medium);
    margin-top: 0;
  }

  .section-item-snippet {
    font-size: 14px;
  }

  .content-title {
    font-size: 18px;
  }

  .app-footer {
    padding-top: 24px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .app-footer p {
    font-size: 14px;
    line-height: 1.5;
  }
}

@media (min-width: 601px) {
  .app-content {
    padding-top: 16px;
    padding-bottom: 24px;
  }

}

/* Print */
@media print {
  .search-container,
  .results-info,
  .app-footer,
  .content-actions {
    display: none;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-light: #1a1a1a;
    --bg-lighter: #2a2a2a;
    --bg-accent: #333333;
    --text-dark: #f5f5f5;
    --text-medium: #e0e0e0;
    --text-light: #c0c0c0;
    --border: #444444;
    --border-light: #555555;
  }

  html, body {
    background-color: var(--bg-light);
  }

  .search-input {
    background: #2a2a2a;
    color: var(--text-dark);
  }

  .section-group {
    background: #2a2a2a;
  }

  .section-item:hover {
    background: rgba(155, 67, 33, 0.2);
  }

  .content-detail {
    background: #2a2a2a;
  }

  .search-input::placeholder {
    color: var(--text-light);
  }
}
