/* ─── Silent Words - Aligned with Silent Bell Styling ─────────── */

:root,
[data-theme="dark"] {
  --bg: #1c1b19;
  --surface: #2a2825;
  --surface-hover: #35322d;
  --accent: #c4a77d;
  --text: #f5f0e8;
  --muted: #8b8478;
  --danger: #b85c4f;
  --success: #7a9e7a;
  --border: #3d3830;
  --radius: 12px;
}

[data-theme="light"] {
  --bg: #e8e2d6;
  --surface: #f0ebe3;
  --surface-hover: #f5f2ed;
  --accent: #8b6f4a;
  --text: #5c564d;
  --muted: #9b9185;
  --danger: #b85c4f;
  --success: #5a7a5a;
  --border: #d4ccc0;
  --radius: 12px;
}

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

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

body {
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 32px;
  position: relative;
  transition: background 0.3s, color 0.3s;
  background-color: var(--bg);
  background-image: 
    radial-gradient(ellipse at 50% 30%, rgba(196, 167, 125, 0.06) 0%, transparent 50%),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.03'/%3E%3C/svg%3E");
  background-attachment: fixed;
}

[data-theme="light"] body {
  background-image: 
    radial-gradient(ellipse at 50% 20%, rgba(139, 111, 74, 0.08) 0%, transparent 60%),
    linear-gradient(to bottom, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 50%),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.04'/%3E%3C/svg%3E");
  background-color: #e8e2d6;
}

/* ─── Offline Indicator ───────────────────────────────────────── */

.offline-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--accent);
  color: var(--bg);
  text-align: center;
  padding: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transform: translateY(-100%);
  animation: slideDown 0.3s forwards;
}

@keyframes slideDown {
  to { transform: translateY(0); }
}

.offline-dot {
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
  display: inline-block;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ─── Header ───────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, var(--bg), rgba(196, 167, 125, 0.05));
}

[data-theme="light"] header {
  background: linear-gradient(to bottom, #e8e2d6, rgba(139, 111, 74, 0.04));
  border-bottom-color: rgba(139, 111, 74, 0.15);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-icon {
  width: 32px;
  height: 32px;
  color: var(--accent);
  opacity: 0.95;
  border-radius: 6px;
}

.header-title {
  font-size: 1.15rem;
  font-weight: 400;
  letter-spacing: 0.5px;
  color: var(--accent);
  opacity: 0.95;
  font-family: Georgia, 'Times New Roman', serif;
}

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

#btn-theme, .btn-install {
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-install {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  border-color: var(--accent);
}

.btn-install:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

[data-theme="light"] #btn-theme {
  background: rgba(255, 255, 255, 0.5);
  border-color: rgba(139, 111, 74, 0.2);
}

#btn-theme:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(196, 167, 125, 0.08);
}

/* ─── Main View ───────────────────────────────────────────────── */

.view {
  flex: 1;
  display: none;
  padding: 24px 20px;
  flex-direction: column;
  gap: 16px;
  position: relative;
  z-index: 1;
}

.view.active {
  display: flex;
}

/* ─── Quote Card ──────────────────────────────────────────────── */

.quote-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  transition: background 0.3s, border-color 0.3s;
}

[data-theme="light"] .quote-card {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(10px);
}

/* Loading State */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Quote Content */
.quote-content {
  transition: opacity 0.3s ease;
}

.quote-text {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.25rem;
  line-height: 1.7;
  color: var(--text);
  text-align: center;
  margin-bottom: 24px;
  position: relative;
}

.quote-text::before {
  content: open-quote;
  font-size: 2.5rem;
  color: var(--accent);
  opacity: 0.3;
  position: absolute;
  top: -15px;
  left: -5px;
  font-family: Georgia, serif;
  line-height: 1;
}

.quote-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.quote-author {
  font-size: 1rem;
  color: var(--accent);
  font-weight: 500;
  font-family: Georgia, serif;
  font-style: italic;
}

.quote-source {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
  text-align: center;
}

.quote-tradition {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-top: 4px;
  padding: 4px 12px;
  background: var(--bg);
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* ─── Controls ─────────────────────────────────────────────────── */

.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 8px;
}

.btn-primary {
  flex: 1;
  padding: 16px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-size: 1.05rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.9;
}

.btn-primary:disabled {
  opacity: 0.35;
  pointer-events: none;
  cursor: wait;
}

.btn-secondary {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
}

[data-theme="light"] .btn-secondary {
  background: rgba(255, 255, 255, 0.6);
  border-color: rgba(139, 111, 74, 0.2);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(196, 167, 125, 0.08);
}

/* ─── Source Controls ──────────────────────────────────────────── */

.source-controls {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.source-label {
  font-size: 0.9rem;
  color: var(--muted);
  font-family: Georgia, 'Times New Roman', serif;
  letter-spacing: 0.5px;
}

.source-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.source-btn {
  padding: 10px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.source-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.source-btn.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 500;
}

/* ─── Stats ────────────────────────────────────────────────────── */

.stats {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
  font-style: italic;
  min-height: 20px;
}

/* ─── Footer & Credits ────────────────────────────────────────── */

.footer {
  margin-top: auto;
  padding: 20px;
  text-align: center;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  transition: opacity 0.4s ease;
}

[data-theme="light"] .footer {
  border-top-color: rgba(139, 111, 74, 0.12);
}

.footer .container {
  max-width: 100%;
}

.footer-row {
  margin-bottom: 8px;
  line-height: 1.5;
}

.footer-row:last-child {
  margin-bottom: 0;
}

.footer-row a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.2s;
}

.footer-row a:hover {
  color: var(--accent);
}

/* Details Toggle Button */
.btn-details {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.2s;
}

.btn-details:hover {
  color: var(--accent);
}

.btn-details[aria-expanded="true"] {
  color: var(--accent);
  font-weight: 500;
}

/* Credits Panel */
.credits-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s ease-out;
}

.credits-panel:not([hidden]) {
  grid-template-rows: 1fr;
}

.credits-content {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  opacity: 0;
  transition: opacity 0.3s ease-out 0.1s;
}

.credits-panel:not([hidden]) .credits-content {
  opacity: 1;
}

.credits-item {
  padding: 12px;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.credits-item strong {
  color: var(--accent);
  display: block;
  margin-bottom: 4px;
  font-size: 0.85rem;
  font-weight: 600;
}

.credits-item p {
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--muted);
  margin: 0;
}

.credits-item a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(196, 167, 125, 0.3);
}

[data-theme="light"] .credits-item {
  background: rgba(255, 255, 255, 0.4);
  border-color: rgba(139, 111, 74, 0.15);
}

/* ─── Toast ────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface);
  color: var(--text);
  padding: 14px 28px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 100;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

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

[data-theme="light"] .toast {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(139, 111, 74, 0.2);
}

/* ─── Responsive ───────────────────────────────────────────────── */

@media (max-width: 480px) {
  .view {
    padding: 24px 16px;
  }
  
  .quote-card {
    padding: 24px 20px;
    min-height: 220px;
  }
  
  .quote-text {
    font-size: 1.1rem;
  }
  
  .quote-text::before {
    font-size: 2rem;
    top: -10px;
    left: -2px;
  }
  
  .controls {
    gap: 8px;
  }
  
  .btn-primary, .btn-secondary {
    padding: 14px;
  }
  
  .source-btn {
    padding: 8px 12px;
    font-size: 0.75rem;
  }

  .credits-item {
    padding: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible for accessibility */
button:focus-visible,
.source-btn:focus-visible,
.btn-details:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Selection color to match theme */
::selection {
  background: rgba(196, 167, 125, 0.3);
  color: var(--text);
}

[data-theme="light"] ::selection {
  background: rgba(139, 111, 74, 0.2);
}

/* Safe Area Support */
@supports (padding-top: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
  }
  
  header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }
}
