:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --primary-dark: #4338ca;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e8eaf3;
  --radius: 16px;
  --shadow: 0 2px 6px rgba(31, 36, 48, 0.05), 0 8px 24px rgba(79, 70, 229, 0.08);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

@keyframes popIn {
  0%   { opacity: 0; transform: scale(0.6); }
  70%  { transform: scale(1.08); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 6px 18px rgba(79, 70, 229, 0.4); }
  50%      { box-shadow: 0 6px 26px rgba(124, 58, 237, 0.65); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  padding: 18px 18px 22px;
  padding-top: calc(18px + env(safe-area-inset-top, 0px));
  border-radius: 0 0 24px 24px;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.3);
  display: flex;
  align-items: center;
  gap: 12px;
}

#topbar h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px;
  padding-bottom: calc(110px + env(safe-area-inset-bottom, 0px));
}

.category {
  margin-bottom: 26px;
}

.category-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px 4px;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.category-title::before {
  content: "";
  width: 4px;
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(var(--primary), var(--primary-2));
}

.subject-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.subject-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  animation: fadeUp 0.45s ease both;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.subject-card:nth-child(2) { animation-delay: 0.06s; }
.subject-card:nth-child(3) { animation-delay: 0.12s; }
.subject-card:nth-child(4) { animation-delay: 0.18s; }
.subject-card:nth-child(5) { animation-delay: 0.24s; }
.subject-card:nth-child(n+6) { animation-delay: 0.3s; }

.subject-card:active {
  transform: scale(0.97);
  box-shadow: 0 1px 3px rgba(31, 36, 48, 0.08);
}

.subject-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.subject-count {
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef0ff;
  color: var(--primary-dark);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 56px 16px;
  animation: fadeIn 0.6s ease both;
}

.empty::before {
  content: "📚";
  display: block;
  font-size: 3.2rem;
  margin-bottom: 14px;
  animation: float 3s ease-in-out infinite;
}

.btn {
  display: inline-block;
  padding: 14px 18px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
}

.btn-secondary {
  background: #e0e7ff;
  color: var(--primary-dark);
}

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  padding: 16px 22px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  animation: popIn 0.5s ease 0.3s both, pulse 2.6s ease-in-out 1s infinite;
  transition: transform 0.12s ease;
}

.fab:active {
  transform: scale(0.94);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(15, 18, 40, 0.5);
  animation: fadeIn 0.2s ease both;
}

.modal[hidden] {
  display: none;
}

.modal-box {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 22px 18px;
  padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  animation: slideUp 0.3s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}

.modal-box h2 {
  margin: 0 0 16px;
  font-size: 1.2rem;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.modal-actions .btn {
  flex: 1;
}

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