/* CommCard V3 - Styles */
/* Estus Health Brand: Warm palette, never cool grey */

/* =============================================
   CSS Custom Properties
   ============================================= */
:root {
  --background: hsl(35, 30%, 92%);
  --foreground: hsl(20, 25%, 15%);
  --card: hsl(0, 0%, 100%);
  --primary: hsl(25, 35%, 35%);
  --primary-foreground: hsl(35, 30%, 92%);
  --secondary: hsl(35, 20%, 82%);
  --border: hsl(25, 20%, 75%);
  --muted-foreground: hsl(20, 15%, 40%);
  --tan: #BFA88E;
  --cream: #E5DCCC;
  --cream-light: #F5F0E8;

  --font-display: 'Oswald', sans-serif;
  --font-serif: 'Libre Baskerville', serif;
  --font-body: 'Inter', sans-serif;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(118, 84, 62, 0.10);
  --shadow-md: 0 4px 16px rgba(118, 84, 62, 0.14);
  --transition: 0.15s ease;
}

/* Dark theme */
[data-theme="dark"] {
  --background: hsl(20, 15%, 10%);
  --foreground: hsl(35, 25%, 88%);
  --card: hsl(20, 12%, 15%);
  --primary: hsl(25, 40%, 60%);
  --primary-foreground: hsl(20, 15%, 10%);
  --secondary: hsl(20, 12%, 20%);
  --border: hsl(20, 15%, 28%);
  --muted-foreground: hsl(35, 15%, 60%);
  --cream: hsl(20, 12%, 20%);
  --cream-light: hsl(20, 12%, 18%);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
}

/* High-contrast theme */
[data-theme="high-contrast"] {
  --background: #000000;
  --foreground: #FFFFFF;
  --card: #111111;
  --primary: #FFD700;
  --primary-foreground: #000000;
  --secondary: #222222;
  --border: #FFFFFF;
  --muted-foreground: #CCCCCC;
  --shadow: none;
  --shadow-md: none;
}

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

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

body {
  font-family: var(--font-body);
  background-color: var(--background);
  color: var(--foreground);
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

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

/* =============================================
   Focus Styles
   ============================================= */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

[data-theme="high-contrast"] :focus-visible {
  outline-color: #FFD700;
  outline-width: 4px;
}

/* =============================================
   Top Bar
   ============================================= */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 56px;
  background-color: var(--primary);
  color: var(--primary-foreground);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.top-bar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-bar__brand-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.top-bar__title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary-foreground);
}

.top-bar__brand-link {
  font-family: var(--font-body);
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  letter-spacing: 0.03em;
}

.top-bar__brand-link:hover {
  color: var(--primary-foreground);
  text-decoration: underline;
}

.top-bar__actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--primary-foreground);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.2rem;
  transition: background-color var(--transition);
  flex-shrink: 0;
}

.icon-btn:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

.icon-btn:active {
  background-color: rgba(255, 255, 255, 0.25);
}

/* =============================================
   Layout: App Container
   ============================================= */
.app-container {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* =============================================
   Desktop Sidebar
   ============================================= */
.sidebar {
  display: none;
  flex-direction: column;
  width: 220px;
  flex-shrink: 0;
  background-color: var(--card);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  position: sticky;
  top: 56px;
  height: calc(100dvh - 56px);
  overflow-y: auto;
}

@media (min-width: 768px) {
  .sidebar {
    display: flex;
  }
}

.sidebar__label {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  padding: 0 16px 8px;
}

.sidebar__nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--foreground);
  background: none;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background-color var(--transition), border-color var(--transition);
}

.sidebar__nav-item:hover {
  background-color: var(--secondary);
}

.sidebar__nav-item.active {
  border-left-color: var(--primary);
  background-color: var(--secondary);
  color: var(--primary);
}

.sidebar__nav-item .cat-emoji {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar__divider {
  margin: 8px 16px;
  border: none;
  border-top: 1px solid var(--border);
}

.sidebar__action {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: color var(--transition), background-color var(--transition);
}

.sidebar__action:hover {
  color: var(--primary);
  background-color: var(--secondary);
}

/* =============================================
   Main Content
   ============================================= */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
}

/* =============================================
   Category Tabs (Mobile)
   ============================================= */
.category-tabs {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 0;
  background-color: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 56px;
  z-index: 90;
}

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

@media (min-width: 768px) {
  .category-tabs {
    display: none;
  }
}

.cat-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  height: 48px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition), border-color var(--transition);
  flex-shrink: 0;
}

.cat-tab:hover {
  color: var(--foreground);
}

.cat-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* =============================================
   Section Header
   ============================================= */
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 8px;
}

@media (min-width: 768px) {
  .section-header {
    padding: 24px 24px 12px;
  }
}

.section-header__emoji {
  font-size: 1.5rem;
}

.section-header__title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--foreground);
}

.section-header__bar {
  height: 4px;
  border-radius: 2px;
  margin: 0 0 4px;
}

/* =============================================
   Phrase Grid
   ============================================= */
.phrase-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 0 12px 12px;
}

@media (min-width: 600px) {
  .phrase-grid {
    grid-template-columns: repeat(2, 1fr);
    padding: 0 16px 16px;
    gap: 14px;
  }
}

@media (min-width: 768px) {
  .phrase-grid {
    padding: 0 24px 24px;
    gap: 16px;
  }
}

@media (min-width: 1100px) {
  .phrase-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* =============================================
   Phrase Card
   ============================================= */
.phrase-card {
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow var(--transition), transform var(--transition);
}

.phrase-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

@media (prefers-reduced-motion: reduce) {
  .phrase-card:hover {
    transform: none;
  }
}

.phrase-card__accent {
  height: 4px;
  flex-shrink: 0;
}

.phrase-card__text {
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.45;
  color: var(--foreground);
  padding: 16px 16px 12px;
  flex: 1;
  min-height: 80px;
}

@media (min-width: 768px) {
  .phrase-card__text {
    font-size: 1.1rem;
    padding: 18px 20px 14px;
  }
}

.phrase-card__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 12px;
  flex-shrink: 0;
}

.phrase-card__actions .spacer {
  flex: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 44px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition), opacity var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}

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

.btn-speak:hover {
  opacity: 0.88;
}

.btn-speak:active {
  opacity: 0.75;
}

.btn-show {
  background-color: var(--secondary);
  color: var(--foreground);
  border: 1px solid var(--border);
}

.btn-show:hover {
  background-color: var(--cream);
}

.btn-download {
  width: 44px;
  height: 44px;
  padding: 0;
  background-color: transparent;
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  transition: color var(--transition), background-color var(--transition);
}

.btn-download:hover {
  color: var(--primary);
  background-color: var(--secondary);
}

.btn-copy {
  width: 44px;
  height: 44px;
  padding: 0;
  background-color: transparent;
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  transition: color var(--transition), background-color var(--transition);
}

.btn-copy:hover {
  color: var(--primary);
  background-color: var(--secondary);
}

/* Hide speak buttons when voice not available */
.no-voice .btn-speak {
  display: none;
}

/* =============================================
   Full-Screen Display Mode
   ============================================= */
#fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 40px;
  cursor: pointer;
  transition: opacity 0.1s;
}

#fullscreen-overlay.hidden {
  display: none;
}

#fullscreen-overlay__text {
  font-family: var(--font-body);
  font-size: clamp(2rem, 7vw, 4.5rem);
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  color: inherit;
  max-width: 90%;
}

#fullscreen-overlay__dismiss {
  position: absolute;
  bottom: 24px;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.5;
}

.fullscreen-copy-btn {
  position: absolute;
  bottom: 60px;
  background-color: rgba(0, 0, 0, 0.12);
  color: inherit;
  border: 2px solid currentColor;
  border-radius: var(--radius-sm);
  padding: 10px 22px;
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  opacity: 0.65;
  transition: opacity var(--transition), background-color var(--transition);
}

.fullscreen-copy-btn:hover {
  opacity: 1;
  background-color: rgba(0, 0, 0, 0.2);
}

/* =============================================
   Card Builder
   ============================================= */
.builder-section {
  display: none;
  flex-direction: column;
  padding: 0 12px 24px;
  max-width: 700px;
}

.builder-section.active {
  display: flex;
}

@media (min-width: 600px) {
  .builder-section {
    padding: 0 16px 24px;
  }
}

@media (min-width: 768px) {
  .builder-section {
    padding: 0 24px 24px;
  }
}

.builder-card {
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.builder-card label {
  display: block;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  margin-bottom: 6px;
}

.builder-card textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--foreground);
  background-color: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  transition: border-color var(--transition);
}

.builder-card textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(118, 84, 62, 0.15);
}

.color-picker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.color-swatch:hover {
  transform: scale(1.1);
}

.color-swatch.selected {
  border-color: var(--foreground);
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.builder-preview {
  background-color: var(--secondary);
  border-radius: var(--radius-sm);
  padding: 20px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.builder-preview__text {
  font-family: var(--font-body);
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
  color: var(--foreground);
  line-height: 1.45;
  font-style: italic;
  opacity: 0.5;
}

.builder-preview__text:not(:empty) {
  font-style: normal;
  opacity: 1;
}

.builder-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-primary {
  background-color: var(--primary);
  color: var(--primary-foreground);
  padding: 0 20px;
  height: 48px;
  font-size: 0.85rem;
}

.btn-primary:hover {
  opacity: 0.88;
}

.btn-secondary {
  background-color: var(--secondary);
  color: var(--foreground);
  border: 1px solid var(--border);
  padding: 0 20px;
  height: 48px;
  font-size: 0.85rem;
}

.btn-secondary:hover {
  background-color: var(--cream);
}

/* =============================================
   Make Your Own Bar
   ============================================= */
.make-own-bar {
  padding: 12px;
}

@media (min-width: 600px) {
  .make-own-bar {
    padding: 12px 16px;
  }
}

@media (min-width: 768px) {
  .make-own-bar {
    padding: 12px 24px;
  }
}

.make-own-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 400px;
  height: 52px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted-foreground);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background-color var(--transition);
}

.make-own-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background-color: var(--secondary);
}

/* =============================================
   Settings Panel
   ============================================= */
#settings-panel {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}

#settings-panel.hidden {
  display: none;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 15, 10, 0.4);
}

.settings-drawer {
  position: relative;
  width: min(380px, 100vw);
  max-height: 100dvh;
  overflow-y: auto;
  background-color: var(--card);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .settings-drawer {
    animation: none;
  }
}

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

.settings-header h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.settings-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  flex: 1;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-group__title {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.settings-group select,
.settings-group input[type="range"] {
  width: 100%;
}

.settings-group select {
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--foreground);
  background-color: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.settings-group select:focus {
  outline: none;
  border-color: var(--primary);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
  height: 6px;
  cursor: pointer;
}

.slider-value {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted-foreground);
  min-width: 36px;
  text-align: right;
}

.theme-options {
  display: flex;
  gap: 8px;
}

.theme-btn {
  flex: 1;
  padding: 10px 8px;
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background-color: var(--secondary);
  color: var(--foreground);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition), background-color var(--transition);
  text-align: center;
}

.theme-btn:hover {
  background-color: var(--cream);
}

.theme-btn.active {
  border-color: var(--primary);
  color: var(--primary);
}

.settings-link {
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.settings-link:hover {
  text-decoration: underline;
}

.privacy-note {
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--muted-foreground);
  line-height: 1.55;
  padding: 12px;
  background-color: var(--secondary);
  border-radius: var(--radius-sm);
}

/* =============================================
   Footer
   ============================================= */
.footer {
  background-color: var(--card);
  border-top: 1px solid var(--border);
  padding: 16px;
  text-align: center;
  flex-shrink: 0;
}

.footer__text {
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--muted-foreground);
  line-height: 1.6;
}

.footer__link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.footer__link:hover {
  text-decoration: underline;
}

/* =============================================
   All Categories View (Desktop: show all)
   ============================================= */
.category-section {
  display: none;
}

.category-section.active {
  display: block;
}

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

.icon {
  font-size: 1em;
  line-height: 1;
  display: inline-block;
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background-color: var(--primary);
  color: var(--primary-foreground);
  padding: 8px 16px;
  font-family: var(--font-display);
  font-size: 0.85rem;
  text-decoration: none;
  z-index: 9999;
  border-radius: 0 0 var(--radius-sm) 0;
}

.skip-link:focus {
  top: 0;
}

/* Loading state */
.loading-msg {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted-foreground);
  font-family: var(--font-body);
  font-size: 0.95rem;
}

/* Page view toggle */
#page-phrases { display: block; }
#page-builder { display: none; }

body.view-builder #page-phrases { display: none; }
body.view-builder #page-builder { display: block; }
