/* ============================================================
   CeliacTools — Design System
   Single source of truth for all pages.
   ============================================================ */

/* ── Design Tokens ── */
:root {
  --color-primary:       #0D7C76;
  --color-primary-dark:  #0A6661;
  --color-primary-light: #E6F4F3;

  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --font-size-xs:   0.75rem;
  --font-size-sm:   0.875rem;
  --font-size-base: 1rem;
  --font-size-lg:   1.125rem;
  --font-size-xl:   1.25rem;
  --font-size-2xl:  1.5rem;
  --font-size-3xl:  1.875rem;

  --border-radius-sm: 8px;
  --border-radius:    12px;
  --border-radius-lg: 16px;
  --border-radius-xl: 24px;
  --max-width:        680px;

  --transition-fast:   120ms ease;
  --transition-base:   200ms ease;
  --transition-slow:   300ms ease;

  /* Light mode (default) */
  --color-bg:           #F3F4F6;
  --color-surface:      #F9F8F6;
  --color-surface-alt:  #FFFFFF;
  --color-text:         #1A1A2E;
  --color-text-muted:   #6B7280;
  --color-text-light:   #9CA3AF;
  --color-border:       #E5E7EB;
  --color-border-light: #F3F4F6;
  --color-star:          #FCD34D;
  --color-star-active:   #F59E0B;
  --color-emergency:     #DC2626;
  --color-emergency-bg:  #FEF2F2;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-card:  0 4px 16px rgba(0,0,0,0.08);
  --shadow-card-hover: 0 8px 28px rgba(0,0,0,0.12), 0 0 0 1px rgba(13,124,118,0.09);
  --shadow-modal: 0 24px 64px rgba(0,0,0,0.2);
}

/* Dark mode overrides */
[data-theme="dark"] {
  --color-bg:           #090c13;
  --color-surface:      #1A1D27;
  --color-surface-alt:  #242838;
  --color-text:         #F9FAFB;
  --color-text-muted:   #9CA3AF;
  --color-text-light:   #6B7280;
  --color-border:       #323a4e;
  --color-border-light: #1E2535;
  --color-primary-light: rgba(13,124,118,0.22);
  --color-emergency:     #FCA5A5;
  --color-emergency-bg:  rgba(220,38,38,0.15);
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.3);
  --shadow-card:  0 4px 20px rgba(0,0,0,0.45), 0 0 0 1px rgba(13,124,118,0.04);
  --shadow-card-hover: 0 8px 28px rgba(0,0,0,0.5), 0 0 0 1px rgba(13,124,118,0.2);
  --shadow-modal: 0 24px 64px rgba(0,0,0,0.6);
}

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

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

/* ── Body ── */
body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background:
    radial-gradient(ellipse 70% 55% at 0% 0%,   rgba(13,124,118,0.16) 0%, transparent 65%),
    radial-gradient(ellipse 55% 45% at 100% 0%,  rgba(13,124,118,0.10) 0%, transparent 60%),
    radial-gradient(ellipse 65% 55% at 100% 100%, rgba(13,124,118,0.13) 0%, transparent 65%),
    radial-gradient(ellipse 55% 45% at 0% 100%,  rgba(13,124,118,0.08) 0%, transparent 60%),
    #f7fafa;
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
[data-theme="dark"] body {
  background:
    radial-gradient(ellipse 70% 55% at 0% 0%,   rgba(13,124,118,0.30) 0%, transparent 65%),
    radial-gradient(ellipse 55% 45% at 100% 0%,  rgba(13,124,118,0.20) 0%, transparent 60%),
    radial-gradient(ellipse 65% 55% at 100% 100%, rgba(13,124,118,0.25) 0%, transparent 65%),
    radial-gradient(ellipse 55% 45% at 0% 100%,  rgba(13,124,118,0.18) 0%, transparent 60%),
    #090c13;
  background-attachment: fixed;
}

/* ── Base elements ── */
button { font-family: inherit; cursor: pointer; border: none; background: none; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
input, textarea, select { font-family: inherit; font-size: var(--font-size-base); }

/* ── Layout ── */
.container { width: 100%; max-width: var(--max-width); margin: 0 auto; padding: 0 16px; }

/* ============================================================
   Header
   ============================================================ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .site-header {
  background: rgba(8,12,20,0.88);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  max-width: var(--max-width);
  margin: 0 auto;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--color-text);
  flex-shrink: 0;
}
.wordmark:hover { text-decoration: none; }

.wordmark-icon {
  width: 30px;
  height: 30px;
  background: var(--color-primary);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wordmark-icon svg { width: 16px; height: 16px; color: white; }

.wordmark-text {
  font-size: var(--font-size-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
}
.wordmark-text span { color: var(--color-primary); }

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

/* ============================================================
   Tools Tab Bar
   ============================================================ */

.tools-tab-bar {
  display: flex;
  justify-content: center;
  background: rgba(255,255,255,0.80);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: 57px;
  z-index: 90;
}
[data-theme="dark"] .tools-tab-bar {
  background: rgba(8,12,20,0.85);
}
.tools-tab-bar::-webkit-scrollbar { display: none; }

.tools-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 13px 16px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  font-family: var(--font-family);
  color: var(--color-text-muted);
  border: none;
  border-bottom: 3px solid transparent;
  background: none;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--transition-base), border-color var(--transition-base);
  margin-bottom: -1px;
  line-height: 1;
}
.tools-tab svg { flex-shrink: 0; }
.tools-tab:hover { color: var(--color-text); text-decoration: none; }
.tools-tab--active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: 600;
}

/* ============================================================
   Language Bar
   ============================================================ */

.lang-bar {
  background: transparent;
  padding: 36px 0 28px;
}

.lang-bar-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 16px;
  max-width: var(--max-width);
  margin: 0 auto;
}

.lang-selector-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  max-width: 200px;
}

.lang-selector-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
}

.lang-select-pill {
  appearance: none;
  width: 100%;
  background: var(--color-surface-alt);
  border: 1.5px solid var(--color-border);
  border-radius: 100px;
  padding: 7px 28px 7px 14px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  text-align: center;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.lang-select-pill:hover,
.lang-select-pill:focus { border-color: var(--color-primary); outline: none; box-shadow: 0 0 0 3px var(--color-primary-light); }

.lang-select-pill--output {
  background-color: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary-dark);
}
[data-theme="dark"] .lang-select-pill--output { color: #5dd6d0; }
.lang-select-pill--output:hover,
.lang-select-pill--output:focus { border-color: var(--color-primary-dark); }

.lang-bar-arrow { flex-shrink: 0; color: var(--color-text-light); margin-top: 14px; }
.lang-bar-arrow svg { width: 20px; height: 20px; display: block; }

/* Legacy single-selector */
.lang-select {
  appearance: none;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  padding: 7px 28px 7px 10px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  transition: border-color var(--transition-fast);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  min-width: 130px;
  max-width: 180px;
}
.lang-select:hover, .lang-select:focus { border-color: var(--color-primary); outline: none; }

/* ============================================================
   Theme Toggle
   ============================================================ */

.theme-toggle-wrapper { position: relative; }

.btn-theme {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 9px;
  width: auto;
  min-width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  transition: all var(--transition-fast);
  flex-shrink: 0;
  cursor: pointer;
}
.btn-theme:hover { color: var(--color-text); border-color: var(--color-primary); }
.btn-theme svg { width: 16px; height: 16px; pointer-events: none; flex-shrink: 0; }
.btn-theme .icon-chevron { width: 10px; height: 10px; transition: transform var(--transition-fast); margin-left: 1px; }
.btn-theme[aria-expanded="true"] .icon-chevron { transform: rotate(180deg); }
.btn-theme .icon-sun,
.btn-theme .icon-moon,
.btn-theme .icon-monitor { display: none; }
.btn-theme[data-theme-mode="light"]   .icon-sun     { display: block; }
.btn-theme[data-theme-mode="dark"]    .icon-moon    { display: block; }
.btn-theme[data-theme-mode="system"]  .icon-monitor { display: block; }

.theme-picker {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-card);
  padding: 4px;
  min-width: 136px;
  max-width: calc(100vw - 16px); /* never bleeds off narrow screens */
  z-index: 200;
  opacity: 0;
  transform: translateY(-6px) scale(0.97);
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
}
.theme-picker.open { opacity: 1; transform: none; pointer-events: all; }

.theme-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-family);
  transition: background var(--transition-fast), color var(--transition-fast);
  text-align: left;
}
.theme-option:hover { background: var(--color-bg); color: var(--color-text); }
.theme-option.active { color: var(--color-primary); font-weight: 600; }
.theme-option svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ── My Card button ── */
.btn-my-card {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--border-radius-sm);
  height: 34px;
  padding: 0 12px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
  white-space: nowrap;
  cursor: pointer;
  font-family: var(--font-family);
  text-decoration: none;
}
.btn-my-card:hover { background: var(--color-primary-dark); text-decoration: none; color: white; box-shadow: 0 4px 18px rgba(13,124,118,0.45); }
.btn-my-card svg { width: 14px; height: 14px; }
@media (max-width: 440px) { .btn-my-card .btn-my-card-label { display: none; } }

/* tTG nav button */
.btn-ttg-nav {
  display: flex; align-items: center; gap: 6px;
  background: var(--color-surface-alt);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  padding: 6px 11px;
  font-size: var(--font-size-sm); font-weight: 600;
  transition: all var(--transition-fast); white-space: nowrap; text-decoration: none;
}
.btn-ttg-nav:hover { border-color: var(--color-primary); color: var(--color-primary); text-decoration: none; }
.btn-ttg-nav svg { width: 14px; height: 14px; }
@media (max-width: 400px) { .btn-ttg-nav span { display: none; } }

/* ============================================================
   Main Content
   ============================================================ */

.main-content { padding: 0 0 80px; max-width: var(--max-width); margin: 0 auto; }
#app-content { padding: 0 16px; }

/* Loading */
.loading-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 60px 16px;
  color: var(--color-text-muted); font-size: var(--font-size-sm);
}
.loading-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Favourites Section
   ============================================================ */

.favourites-section { margin-bottom: 32px; }

.favourites-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

.favourites-title {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--font-size-sm); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--color-primary);
}
.favourites-title svg { width: 14px; height: 14px; }

.btn-copy-all {
  display: flex; align-items: center; gap: 5px;
  font-size: var(--font-size-xs); font-weight: 600;
  color: var(--color-text-muted);
  padding: 4px 8px; border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  transition: all var(--transition-fast);
}
.btn-copy-all:hover { color: var(--color-text); border-color: var(--color-primary); }
.btn-copy-all svg { width: 12px; height: 12px; }

.btn-collapse {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  transition: all var(--transition-fast); flex-shrink: 0;
}
.btn-collapse:hover { color: var(--color-text); border-color: var(--color-primary); }
.btn-collapse svg { width: 14px; height: 14px; transition: transform var(--transition-base); pointer-events: none; }
.btn-collapse[aria-expanded="false"] svg { transform: rotate(-90deg); }

.favourites-body { overflow: hidden; max-height: 2000px; opacity: 1; transition: max-height var(--transition-slow), opacity var(--transition-slow); }
.favourites-body.collapsed { max-height: 0; opacity: 0; }

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

.fav-count-badge {
  display: none; font-size: var(--font-size-xs); font-weight: 600;
  color: var(--color-text-muted); background: var(--color-border-light);
  padding: 2px 7px; border-radius: 20px;
}
.favourites-body.collapsed ~ .favourites-header .fav-count-badge,
.fav-count-badge.visible { display: inline-block; }

.favourites-empty {
  padding: 20px;
  background: var(--color-surface-alt);
  border-radius: var(--border-radius);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  border: 1px dashed var(--color-border);
}

#favourites-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding-bottom: 8px; }

/* Fav card */
.phrase-card--fav {
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start;
  padding: 14px; min-height: 90px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}
.phrase-card--fav:hover { box-shadow: var(--shadow-card); border-color: var(--color-primary); }
.phrase-fav-text { font-size: var(--font-size-sm); font-weight: 500; color: var(--color-text); line-height: 1.45; flex: 1; }
.phrase-card--fav .btn-star { align-self: flex-end; flex-shrink: 0; }

/* ============================================================
   Category Sections
   ============================================================ */

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

.category-section--emergency .category-header {
  background: var(--color-emergency-bg);
  border-color: #FECACA;
}
.category-section--emergency .category-title { color: var(--color-emergency); }

.category-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  cursor: pointer; user-select: none;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}
.category-header:hover { border-color: var(--color-primary); box-shadow: var(--shadow-card); }
.category-header.open {
  border-bottom-left-radius: 0; border-bottom-right-radius: 0;
  border-bottom-color: var(--color-border-light);
}
/* When an open section's header is hovered, glow the whole section together */
.category-header.open:hover { box-shadow: var(--shadow-sm); }
.category-section:has(.category-header.open:hover) .category-header.open {
  border-color: var(--color-primary);
  border-bottom-color: var(--color-border-light);
}
.category-section:has(.category-header.open:hover) .category-body.open {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-card);
}

.category-title { font-size: var(--font-size-base); font-weight: 600; color: var(--color-text); }
.category-meta { display: flex; align-items: center; gap: 8px; }
.category-count {
  font-size: var(--font-size-xs); font-weight: 600;
  color: var(--color-text-muted); background: var(--color-bg);
  padding: 2px 8px; border-radius: 20px;
}
.category-chevron { width: 16px; height: 16px; color: var(--color-text-muted); transition: transform var(--transition-base); flex-shrink: 0; }
.category-header.open .category-chevron { transform: rotate(180deg); }

.category-body {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-top: none;
  border-bottom-left-radius: var(--border-radius);
  border-bottom-right-radius: var(--border-radius);
  overflow: hidden;
  display: none;
  box-shadow: var(--shadow-sm);
}
.category-body.open { display: block; }

/* ============================================================
   Phrase Cards
   ============================================================ */

.phrase-card {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 16px;
  background: transparent;
  border-bottom: 1px solid var(--color-border-light);
  cursor: pointer;
  transition: background var(--transition-fast);
  position: relative;
}
.phrase-card:last-child { border-bottom: none; }
.phrase-card:hover { background: var(--color-bg); }
.phrase-card:active { background: var(--color-primary-light); }

.phrase-card-body { flex: 1; min-width: 0; }
.phrase-input-text { font-size: var(--font-size-lg); font-weight: 500; color: var(--color-text); line-height: 1.45; margin-bottom: 4px; }
.phrase-output-text { font-size: var(--font-size-sm); color: var(--color-text-muted); line-height: 1.4; font-style: italic; }
.phrase-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }

.btn-icon {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  transition: all var(--transition-fast);
  color: var(--color-text-light);
}
.btn-icon:hover { background: var(--color-bg); color: var(--color-text); }
.btn-icon svg { width: 16px; height: 16px; pointer-events: none; }
.btn-star svg { width: 14px; height: 14px; fill: none; pointer-events: none; }
.btn-star[data-starred="true"] { color: #F59E0B; }
.btn-star[data-starred="true"] svg { fill: #FCD34D; color: #F59E0B; }
.btn-copy.copied { color: var(--color-primary); }

/* Star pop-and-glow animation — fires when .starring class is added via JS */
@keyframes star-pop {
  0%   { transform: scale(1);    filter: drop-shadow(0 0 0px  rgba(245,158,11,0)); }
  35%  { transform: scale(1.55); filter: drop-shadow(0 0 8px  rgba(245,158,11,0.85)); }
  65%  { transform: scale(0.88); filter: drop-shadow(0 0 4px  rgba(245,158,11,0.4)); }
  100% { transform: scale(1);    filter: drop-shadow(0 0 0px  rgba(245,158,11,0)); }
}
.btn-star.starring {
  animation: star-pop 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.phrase-output-text.rtl { direction: rtl; text-align: right; }

/* ============================================================
   Phrase Expanded Overlay
   ============================================================ */

.phrase-overlay {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background: rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition-slow);
}
.phrase-overlay.active { opacity: 1; pointer-events: all; }

.phrase-overlay-card {
  width: 100%; max-width: 540px;
  border-radius: var(--border-radius-xl);
  overflow: hidden;
  transform: translateY(20px);
  transition: transform var(--transition-slow);
  box-shadow: 0 8px 48px rgba(0,0,0,0.25);
}
.phrase-overlay.active .phrase-overlay-card { transform: translateY(0); }

.phrase-overlay-output {
  background: linear-gradient(135deg, #0e8a84 0%, #0D7C76 45%, #075652 100%);
  padding: 20px 20px 24px;
  position: relative;
}
.phrase-overlay-actions-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.overlay-star-btn { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; color: rgba(255,255,255,0.7); transition: color var(--transition-fast); }
.overlay-star-btn:hover { color: white; }
.overlay-star-btn svg { width: 20px; height: 20px; fill: none; pointer-events: none; }
.overlay-star-btn[data-starred="true"] { color: #FCD34D; }
.overlay-star-btn[data-starred="true"] svg { fill: #FCD34D; }

.overlay-close-btn { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; color: rgba(255,255,255,0.8); transition: color var(--transition-fast), background var(--transition-fast); }
.overlay-close-btn:hover { color: white; background: rgba(255,255,255,0.15); }
.overlay-close-btn svg { width: 20px; height: 20px; pointer-events: none; }

.overlay-output-text { font-size: clamp(1.5rem, 4vw, 2.25rem); font-weight: 700; color: white; line-height: 1.35; text-align: center; }
.overlay-output-text.rtl { direction: rtl; }

.phrase-overlay-reference {
  background: var(--color-surface-alt);
  padding: 20px;
}
.overlay-input-text { font-size: var(--font-size-base); color: var(--color-text-muted); line-height: 1.5; margin-bottom: 16px; font-style: italic; }
.phrase-overlay-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.overlay-lang-group { display: flex; align-items: center; gap: 6px; flex: 1; }
.overlay-lang-label { font-size: var(--font-size-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--color-text-muted); white-space: nowrap; }
.overlay-lang-select {
  flex: 1; appearance: none;
  background: var(--color-primary-light);
  border: 1.5px solid var(--color-primary);
  border-radius: 100px; padding: 7px 28px 7px 12px;
  font-size: var(--font-size-sm); font-weight: 600;
  color: var(--color-primary-dark); cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%230D7C76' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  transition: border-color var(--transition-fast);
}
[data-theme="dark"] .overlay-lang-select { color: #5dd6d0; }
.overlay-lang-select:focus { outline: none; border-color: var(--color-primary-dark); }

.overlay-copy-btn { display: flex; align-items: center; gap: 6px; padding: 7px 14px; background: var(--color-bg); border: 1.5px solid var(--color-border); border-radius: var(--border-radius-sm); font-size: var(--font-size-sm); font-weight: 600; color: var(--color-text); transition: all var(--transition-fast); white-space: nowrap; }
.overlay-copy-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }
.overlay-copy-btn svg { width: 14px; height: 14px; pointer-events: none; }
.overlay-hint { font-size: var(--font-size-xs); color: var(--color-text-light); text-align: center; }

/* ============================================================
   Modal (Build My Card)
   ============================================================ */

.modal-backdrop { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); opacity: 0; pointer-events: none; transition: opacity var(--transition-base); }
.modal-backdrop.active { opacity: 1; pointer-events: all; }

.modal {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  width: 100%; max-width: 520px; max-height: 80vh; max-height: 80dvh; overflow-y: auto;
  border-radius: var(--border-radius-xl);
  transform: translateY(20px);
  transition: transform var(--transition-slow);
  box-shadow: var(--shadow-modal);
}
.modal-backdrop.active .modal { transform: translateY(0); }

.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 20px 0; position: sticky; top: 0; background: var(--color-surface-alt); z-index: 1; border-bottom: 1px solid var(--color-border); padding-bottom: 16px; }
.modal-title { font-size: var(--font-size-xl); font-weight: 700; color: var(--color-text); }
.btn-modal-close { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; color: var(--color-text-muted); transition: all var(--transition-fast); }
.btn-modal-close:hover { background: var(--color-bg); color: var(--color-text); }
.btn-modal-close svg { width: 20px; height: 20px; pointer-events: none; }

.modal-body { padding: 20px; }
.modal-section { margin-bottom: 20px; }

.form-label { display: block; font-size: var(--font-size-sm); font-weight: 600; color: var(--color-text); margin-bottom: 6px; }

.form-input {
  width: 100%;
  background: var(--color-surface-alt);
  border: 1.5px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  padding: 10px 12px;
  color: var(--color-text); font-size: var(--font-size-base);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-input::placeholder { color: var(--color-text-light); }
.form-input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }

.form-textarea { width: 100%; min-height: 80px; resize: vertical; background: var(--color-surface-alt); border: 1.5px solid var(--color-border); border-radius: var(--border-radius-sm); padding: 10px 12px; color: var(--color-text); font-size: var(--font-size-base); font-family: var(--font-family); transition: border-color var(--transition-fast), box-shadow var(--transition-fast); }
.form-textarea::placeholder { color: var(--color-text-light); }
.form-textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.form-hint { font-size: var(--font-size-xs); color: var(--color-text-muted); margin-top: 4px; }

.phrase-selector { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; border: 1px solid var(--color-border); border-radius: var(--border-radius-sm); padding: 4px; background: var(--color-bg); }
.phrase-selector-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; cursor: pointer; transition: background var(--transition-fast); font-size: var(--font-size-sm); color: var(--color-text-muted); }
.phrase-selector-item:hover { background: var(--color-surface-alt); color: var(--color-text); }
.phrase-selector-item input[type="checkbox"] { accent-color: var(--color-primary); width: 15px; height: 15px; flex-shrink: 0; }
.phrase-selector-item.selected { color: var(--color-text); }

/* ── Buttons ── */
.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 12px 20px;
  background: var(--color-primary);
  color: white; border: none; border-radius: var(--border-radius-sm);
  font-size: var(--font-size-base); font-weight: 600; font-family: var(--font-family);
  cursor: pointer; transition: background var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: 0 2px 8px rgba(13,124,118,0.3);
  margin-top: 8px;
}
.btn-primary:hover { background: var(--color-primary-dark); box-shadow: 0 4px 18px rgba(13,124,118,0.45); }
.btn-primary svg { width: 16px; height: 16px; }

.btn-secondary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; background: var(--color-surface-alt); color: var(--color-text); border: 1.5px solid var(--color-border); border-radius: var(--border-radius-sm); font-size: var(--font-size-sm); font-weight: 600; font-family: var(--font-family); cursor: pointer; transition: all var(--transition-fast); text-decoration: none; }
.btn-secondary:hover { border-color: var(--color-primary); color: var(--color-primary); text-decoration: none; }
.btn-secondary svg { width: 16px; height: 16px; }

/* ── URL Output ── */
.url-output { margin-top: 16px; padding: 14px; background: var(--color-primary-light); border: 1px solid var(--color-primary); border-radius: var(--border-radius-sm); display: none; }
.url-output.visible { display: block; }
.url-output-label { font-size: var(--font-size-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--color-primary); margin-bottom: 8px; }
.url-output-text { font-size: var(--font-size-sm); font-family: monospace; color: var(--color-text); word-break: break-all; line-height: 1.5; background: var(--color-surface-alt); padding: 8px 10px; border-radius: 6px; border: 1px solid var(--color-border); }
.btn-copy-url { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; background: var(--color-primary); border: none; border-radius: 6px; cursor: pointer; font-size: var(--font-size-sm); font-weight: 600; color: white; transition: background var(--transition-fast); font-family: var(--font-family); }
.btn-copy-url:hover { background: var(--color-primary-dark); }
.btn-copy-url svg { width: 14px; height: 14px; }

/* ── Build Card legacy button ── */
.btn-build-card { display: flex; align-items: center; gap: 6px; background: var(--color-primary); color: white; border-radius: var(--border-radius-sm); padding: 7px 12px; font-size: var(--font-size-sm); font-weight: 600; transition: background var(--transition-fast); white-space: nowrap; }
.btn-build-card:hover { background: var(--color-primary-dark); }
.btn-build-card svg { width: 14px; height: 14px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--color-text);
  color: var(--color-surface-alt);
  padding: 10px 18px; border-radius: 100px;
  font-size: var(--font-size-sm); font-weight: 500;
  box-shadow: var(--shadow-card);
  z-index: 9999; opacity: 0; pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
/* ttg.js uses .visible class */
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   Site Footer
   ============================================================ */

.site-footer {
  margin-top: 40px;
  background: var(--color-surface-alt);
  border-top: 1px solid var(--color-border);
  padding: 36px 16px;
}

.site-footer-inner { max-width: var(--max-width); margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.site-footer-love { font-size: var(--font-size-base); font-weight: 500; color: var(--color-text); }
.heart { font-style: normal; color: #fb7185; }
.site-footer-support { font-size: var(--font-size-sm); color: var(--color-text-muted); line-height: 1.6; max-width: 420px; }
.site-footer-donate { color: var(--color-primary); font-weight: 600; text-decoration: none; }
.site-footer-donate:hover { text-decoration: underline; }
.site-footer-meta { font-size: var(--font-size-xs); color: var(--color-text-light); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.site-footer-sep { opacity: 0.5; }
.site-footer-meta a { color: var(--color-text-light); }
.site-footer-meta a:hover { color: var(--color-primary); }
.site-footer-meta-btn {
  background: none; border: none; padding: 0;
  font: inherit; font-size: var(--font-size-xs);
  color: var(--color-text-light); cursor: pointer;
}
.site-footer-meta-btn:hover { color: var(--color-primary); }
.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;
}
.coming-soon {
  font-size: var(--font-size-xs); color: var(--color-text-light);
  opacity: 0.65; font-weight: 400;
}

/* ============================================================
   tTG Tracker — header aliases
   ============================================================ */

.ttg-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.ttg-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  max-width: var(--max-width);
  margin: 0 auto;
}

/* ── tTG Tracker main layout ── */

.ttg-main { max-width: var(--max-width); margin: 0 auto; padding: 24px 16px 80px; }

.ttg-intro { margin-bottom: 20px; }
.ttg-intro h1 { font-size: var(--font-size-2xl); font-weight: 800; color: var(--color-text); margin-bottom: 6px; letter-spacing: -0.02em; }
.ttg-intro p { font-size: var(--font-size-sm); color: var(--color-text-muted); line-height: 1.6; }

/* Encouragement message */
.ttg-encourage {
  display: none;
  padding: 12px 16px;
  background: var(--color-primary-light);
  border: 1px solid var(--color-primary);
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-primary-dark);
  margin-bottom: 16px;
  line-height: 1.5;
}
[data-theme="dark"] .ttg-encourage { color: #5dd6d0; }
.ttg-encourage.visible { display: block; }

/* Add result card */
.ttg-add-card {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.ttg-add-card h2 {
  font-size: var(--font-size-lg); font-weight: 700;
  color: var(--color-text); margin-bottom: 16px;
}

.ttg-add-row {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
}
.ttg-field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
.ttg-field label { font-size: var(--font-size-xs); font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.ttg-input {
  padding: 9px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  background: var(--color-surface-alt);
  color: var(--color-text);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.ttg-input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }

.ttg-add-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 18px;
  background: var(--color-primary); color: white;
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-sm); font-weight: 600; font-family: var(--font-family);
  transition: background var(--transition-fast);
  white-space: nowrap;
}
.ttg-add-btn:hover { background: var(--color-primary-dark); }
.ttg-add-btn svg { width: 16px; height: 16px; }

/* Info box */
.ttg-info-box {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  background: #EFF6FF;
  border: 1px solid #BFDBFE;
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-xs);
  color: #1E40AF;
  line-height: 1.55;
  margin-bottom: 16px;
}
[data-theme="dark"] .ttg-info-box { background: rgba(30,64,175,0.15); border-color: rgba(96,165,250,0.3); color: #93C5FD; }
.ttg-info-box svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }

/* Chart card */
.ttg-chart-card {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.ttg-chart-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.ttg-chart-header h2 { font-size: var(--font-size-lg); font-weight: 700; color: var(--color-text); margin: 0; }
.ttg-ref-note { display: flex; align-items: center; gap: 4px; font-size: var(--font-size-xs); color: var(--color-text-muted); flex-wrap: wrap; }
.ttg-chart-wrap { overflow-x: auto; }

#ttg-chart-container { min-height: 140px; }

.ttg-empty-chart {
  display: flex; align-items: center; justify-content: center;
  min-height: 140px;
  font-size: var(--font-size-sm); color: var(--color-text-muted);
  border: 2px dashed var(--color-border);
  border-radius: var(--border-radius-sm);
}

#ttg-chart { width: 100%; display: block; }

/* SVG chart classes */
.ttg-chart-line { fill: none; stroke: var(--color-primary); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.ttg-chart-area { fill: var(--color-primary-light); opacity: 0.5; }
[data-theme="dark"] .ttg-chart-area { fill: rgba(13,124,118,0.2); }

/* Stats widgets */
.ttg-widgets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
@media (min-width: 480px) { .ttg-widgets { grid-template-columns: repeat(4, 1fr); } }

.ttg-widget {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.ttg-widget-label { font-size: var(--font-size-xs); font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.ttg-widget-value { font-size: 1.6rem; font-weight: 800; color: var(--color-text); line-height: 1.1; margin-bottom: 4px; letter-spacing: -0.02em; }
.ttg-widget-sub { font-size: var(--font-size-xs); color: var(--color-text-muted); line-height: 1.45; }

.ttg-widget-badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: var(--font-size-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}
.ttg-widget-badge.normal     { background: #D1FAE5; color: #065F46; }
.ttg-widget-badge.borderline { background: #FEF3C7; color: #92400E; }
.ttg-widget-badge.positive   { background: #FEE2E2; color: #991B1B; }
[data-theme="dark"] .ttg-widget-badge.normal     { background: rgba(6,78,59,0.4);   color: #6EE7B7; }
[data-theme="dark"] .ttg-widget-badge.borderline { background: rgba(120,83,0,0.4);  color: #FCD34D; }
[data-theme="dark"] .ttg-widget-badge.positive   { background: rgba(127,29,29,0.4); color: #FCA5A5; }

.positive-trend  { color: #059669; }
.negative-trend  { color: #DC2626; }
.neutral-trend   { color: var(--color-text-muted); }

/* Test history list */
.ttg-list-card {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.ttg-list-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
}
.ttg-list-header h2 { font-size: var(--font-size-base); font-weight: 700; color: var(--color-text); margin: 0; }
.ttg-actions { display: flex; gap: 8px; }

.ttg-action-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 10px; border-radius: 6px;
  font-size: var(--font-size-xs); font-weight: 600; font-family: var(--font-family);
  color: var(--color-text-muted); border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  transition: all var(--transition-fast);
}
.ttg-action-btn:hover { color: var(--color-text); border-color: var(--color-primary); }
.ttg-action-btn svg { width: 13px; height: 13px; }

.ttg-list-empty { padding: 32px 16px; text-align: center; font-size: var(--font-size-sm); color: var(--color-text-muted); }

.ttg-entry {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-light);
  font-size: var(--font-size-sm);
}
.ttg-entry:last-child { border-bottom: none; }

.ttg-entry-date { color: var(--color-text-muted); flex: 1; }
.ttg-entry-value { font-weight: 700; color: var(--color-text); white-space: nowrap; }
.ttg-entry-value.normal { color: #059669; }
.ttg-entry-value.above-normal { color: #DC2626; }
[data-theme="dark"] .ttg-entry-value.normal { color: #6EE7B7; }
[data-theme="dark"] .ttg-entry-value.above-normal { color: #FCA5A5; }

.ttg-entry-badge {
  display: inline-block; padding: 2px 7px; border-radius: 12px;
  font-size: var(--font-size-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap;
}
.ttg-entry-badge.normal { background: #D1FAE5; color: #065F46; }
.ttg-entry-badge.above  { background: #FEE2E2; color: #991B1B; }
[data-theme="dark"] .ttg-entry-badge.normal { background: rgba(6,78,59,0.4);   color: #6EE7B7; }
[data-theme="dark"] .ttg-entry-badge.above  { background: rgba(127,29,29,0.4); color: #FCA5A5; }

.ttg-edit-btn, .ttg-delete-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 6px;
  color: var(--color-text-light);
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.ttg-edit-btn svg, .ttg-delete-btn svg { width: 14px; height: 14px; pointer-events: none; }
.ttg-edit-btn:hover { color: var(--color-primary); border-color: var(--color-primary); background: var(--color-primary-light); }
.ttg-delete-btn:hover { color: #DC2626; border-color: #FECACA; background: #FEF2F2; }
[data-theme="dark"] .ttg-delete-btn:hover { border-color: rgba(252,165,165,0.3); background: rgba(220,38,38,0.15); }

/* Edit row */
.ttg-entry-edit-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border-light);
  background: var(--color-bg);
}
.ttg-edit-input {
  padding: 7px 10px;
  border: 1.5px solid var(--color-primary);
  border-radius: 6px;
  background: var(--color-surface-alt);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
}
.ttg-edit-input:focus { outline: none; box-shadow: 0 0 0 3px var(--color-primary-light); }
.ttg-edit-save {
  padding: 6px 12px; background: var(--color-primary); color: white;
  border-radius: 6px; font-size: var(--font-size-sm); font-weight: 600; font-family: var(--font-family);
  transition: background var(--transition-fast);
}
.ttg-edit-save:hover { background: var(--color-primary-dark); }
.ttg-edit-cancel {
  padding: 6px 12px; background: var(--color-surface-alt); color: var(--color-text-muted);
  border: 1px solid var(--color-border); border-radius: 6px;
  font-size: var(--font-size-sm); font-weight: 600; font-family: var(--font-family);
  transition: all var(--transition-fast);
}
.ttg-edit-cancel:hover { border-color: var(--color-primary); color: var(--color-text); }

/* ============================================================
   Handbook styles
   ============================================================ */

.handbook-main { max-width: var(--max-width); margin: 0 auto; padding: 24px 16px 60px; }

.handbook-section {
  margin-bottom: 16px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.handbook-section-title {
  font-size: var(--font-size-sm); font-weight: 700;
  color: var(--color-text); padding: 12px 14px 0;
}

.handbook-header-row { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--color-border); }
.handbook-header-col { font-size: var(--font-size-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-text-muted); padding: 10px 14px; }
.handbook-header-col--avoid { border-right: 1px solid var(--color-border); }

.handbook-row { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--color-border-light); }
.handbook-row:last-child { border-bottom: none; }
.handbook-col { padding: 10px 14px; font-size: var(--font-size-sm); color: var(--color-text); line-height: 1.45; }
.handbook-col--avoid { color: #DC2626; border-right: 1px solid var(--color-border-light); }
.handbook-col--safe  { color: #059669; }
[data-theme="dark"] .handbook-col--avoid { color: #FCA5A5; }
[data-theme="dark"] .handbook-col--safe  { color: #86EFAC; }

@media (max-width: 480px) {
  .handbook-row { grid-template-columns: 1fr; }
  .handbook-col--avoid { border-right: none; border-bottom: 1px solid var(--color-border-light); }
}

/* ============================================================
   Card page (card.html)
   ============================================================ */

.card-page {
  background: var(--color-bg);
  padding-bottom: 80px; /* space for download bar */
}

/* ── Card header ── */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.card-header-link {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
}
.card-header-link:hover { text-decoration: underline; }

/* ── PWA banner ── */
.pwa-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--color-primary-light);
  border-bottom: 1px solid var(--color-primary);
}
.pwa-banner.visible { display: flex; }
.pwa-banner-text { font-size: var(--font-size-xs); color: var(--color-primary-dark); line-height: 1.5; }
[data-theme="dark"] .pwa-banner-text { color: var(--color-text); }
.btn-pwa-dismiss {
  font-size: var(--font-size-xs); font-weight: 600; font-family: var(--font-family);
  color: var(--color-primary); white-space: nowrap;
  padding: 4px 8px; border-radius: 4px;
  border: 1px solid var(--color-primary);
  transition: all var(--transition-fast);
}
.btn-pwa-dismiss:hover { background: var(--color-primary); color: white; }

/* ── Card main content ── */
.card-main {
  max-width: 600px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

/* ── Identity block ── */
.card-identity {
  background: var(--color-primary);
  color: white;
  border-radius: var(--border-radius-lg);
  padding: 24px 20px;
  margin-bottom: 20px;
}

.card-tagline {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.7);
  margin-bottom: 6px;
}

.card-name {
  font-size: var(--font-size-3xl);
  font-weight: 800;
  color: white;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 12px;
}

.card-note {
  background: rgba(255,255,255,0.15);
  border-left: 3px solid rgba(255,255,255,0.6);
  padding: 10px 14px;
  border-radius: 0 var(--border-radius-sm) var(--border-radius-sm) 0;
  font-size: var(--font-size-sm);
  font-style: italic;
  color: rgba(255,255,255,0.9);
  line-height: 1.5;
  margin-bottom: 12px;
}

.card-contact {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--font-size-sm);
  color: rgba(255,255,255,0.8);
  margin-bottom: 12px;
}
.card-contact svg { width: 14px; height: 14px; flex-shrink: 0; }

.card-lang-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 100px;
  padding: 4px 12px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: rgba(255,255,255,0.9);
}
.card-lang-badge svg { width: 13px; height: 13px; }

/* ── Category sections ── */
.card-category {
  margin-bottom: 16px;
}

.card-category-title {
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-primary);
  margin-bottom: 8px;
  padding-left: 2px;
}

/* ── Phrase entries ── */
.card-phrase {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}

.card-phrase--emergency {
  border-color: #FECACA;
  background: var(--color-emergency-bg);
}

.card-note--emergency {
  border-color: #FECACA;
  background: var(--color-emergency-bg);
}

.card-phrase-translation {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.4;
  margin-bottom: 4px;
}

.card-phrase-english {
  font-size: var(--font-size-sm);
  color: var(--color-primary);
  font-weight: 600;
  line-height: 1.4;
}
.card-phrase-english.rtl { direction: rtl; text-align: right; }

/* ── Card footer ── */
.card-footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  text-align: center;
  line-height: 1.6;
}
.card-footer a { color: var(--color-primary); }
.card-footer a:hover { text-decoration: underline; }

/* ── Download bar ── */
.card-download-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 12px 16px;
  background: var(--color-surface-alt);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
  z-index: 100;
}

.btn-download {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
}

.btn-download--wallet {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border: 1.5px solid var(--color-border);
}
.btn-download--wallet:hover { border-color: var(--color-primary); color: var(--color-primary); }

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

.btn-download svg { width: 15px; height: 15px; }

/* ============================================================
   Mobile Overrides
   All responsive fixes consolidated here — keep layout-breaking
   fixes first (P1), then usability (P2), then touch targets (P3).
   ============================================================ */

/* ── P1 · Global: prevent any element from causing horizontal scroll ── */
html, body { overflow-x: hidden; max-width: 100%; }

/* ── P1 · Language selector bar — tighter on narrow screens ── */
@media (max-width: 479px) {
  .lang-bar-inner {
    gap: 8px;
    padding: 0 12px;
  }
  /* Let each selector group shrink freely to fill available width */
  .lang-selector-group {
    max-width: none; /* remove the 200px cap — flex:1 handles sizing */
  }
  .lang-select-pill {
    padding-left: 10px;
    padding-right: 22px;
    font-size: var(--font-size-xs);
  }
  .lang-bar-arrow svg { width: 16px; height: 16px; }
}

/* ── P1 · TTG add-entry form — stack fields on very narrow screens ── */
@media (max-width: 420px) {
  .ttg-field    { min-width: 0; width: 100%; }
  .ttg-add-btn  { width: 100%; justify-content: center; }
}

/* ── P1 · Card hero name — scale down on mobile ── */
@media (max-width: 479px) {
  .card-name { font-size: var(--font-size-2xl); } /* 24px instead of 30px */
}

/* ── P2 · Card download bar — stack buttons on very narrow screens ── */
@media (max-width: 380px) {
  .card-download-bar {
    flex-direction: column;
    padding: 10px 12px;
    gap: 8px;
  }
  .btn-download {
    width: 100%;
    justify-content: center;
  }
}

/* ── P3 · Touch targets — increase interactive element sizes on touch devices ── */
@media (hover: none) and (pointer: coarse) {
  /* Accordion collapse/expand button */
  .btn-collapse { width: 36px; height: 36px; }

  /* Phrase star & copy buttons */
  .btn-icon { width: 36px; height: 36px; }

  /* Overlay close and star in fullscreen phrase view */
  .overlay-close-btn,
  .overlay-star-btn  { width: 40px; height: 40px; }

  /* Navigation tabs */
  .tools-tab { padding: 15px 16px; }

  /* TTG edit/delete row buttons */
  .ttg-edit-btn,
  .ttg-delete-btn { width: 36px; height: 36px; }
}
