* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg-1: #e6f4fb;
  --bg-2: #ffffff;
  --accent: #0a7ea4;
  --accent-dark: #075e7c;
  --text: #0c3b4f;
  --text-muted: #5a7d8c;
  --card: #ffffff;
  --chip-bg: #d9eefa;
  --shadow: 0 2px 8px rgba(10, 126, 164, 0.08);
}

html, body {
  margin: 0;
  padding: 0;
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 40%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, var(--bg-1) 70%, rgba(230,244,251,0));
  z-index: 10;
}

.topbar h1 {
  font-size: 22px;
  margin: 0;
  color: var(--accent-dark);
  letter-spacing: -0.5px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.filters {
  padding: 8px 16px 12px;
  position: sticky;
  top: 62px;
  background: linear-gradient(180deg, rgba(230,244,251,0.95) 80%, rgba(230,244,251,0));
  z-index: 9;
  backdrop-filter: blur(6px);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.filter-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  min-width: 62px;
  letter-spacing: 0.5px;
}

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chip.active {
  background: var(--accent);
  color: white;
}

.list {
  padding: 8px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.1s;
  border: 1px solid rgba(10, 126, 164, 0.06);
}

.card:active { transform: scale(0.985); }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  flex: 1;
}

.card-num {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--accent-dark);
  font-weight: 600;
}

.tag.section {
  background: var(--accent);
  color: white;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 14px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 59, 79, 0.5);
  display: flex;
  align-items: flex-end; /* На мобильных прижимаем к низу */
  justify-content: center;
  z-index: 100;
  padding-top: 40px; /* Отступ сверху, чтобы окно не перекрывало статус-бар */
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  width: 100%;
  max-width: 640px;
  height: 100%; /* На мобильных занимает всё доступное место */
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Плавный скролл на iOS */
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 60px; /* Большой отступ снизу, чтобы было куда скроллить */
  position: relative;
  animation: slideUp 0.25s ease-out;
}

/* Для компьютеров (экраны шире 700px) */
@media (min-width: 700px) {
  .modal {
    align-items: center; /* На ПК показываем окно по центру */
  }
  .modal-content {
    height: auto;
    max-height: 85vh; /* Ограничиваем высоту на ПК */
    border-radius: 20px;
    padding-bottom: 32px;
  }
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--chip-bg);
  color: var(--accent-dark);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}

.modal h2 {
  margin: 0 0 4px;
  color: var(--text);
  font-size: 20px;
}

.modal .modal-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
}

.sets {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
}

.set {
  padding: 10px 14px;
  background: #f4fafd;
  border-radius: 10px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
}

.set.total {
  background: var(--accent);
  color: white;
  font-weight: 700;
  text-align: center;
}

.note {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  margin: 12px 0;
  padding-left: 10px;
  border-left: 3px solid var(--chip-bg);
}

.term {
  border-bottom: 1px dashed var(--accent);
  color: var(--accent-dark);
  font-weight: 600;
  cursor: help;
}

/* Reference */
.ref-section {
  margin-bottom: 22px;
}
.ref-section h3 {
  color: var(--accent-dark);
  font-size: 15px;
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ref-item {
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.45;
}
.ref-item b {
  color: var(--accent-dark);
}
.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}
.ref-table th, .ref-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid #e0eef5;
}
.ref-table th {
  color: var(--accent-dark);
  font-weight: 700;
}