:root {
  --ink: #14201c;
  --ink-soft: #3d4f47;
  --muted: #6b7c74;
  --paper: #f3f6f2;
  --paper-2: #e7eee8;
  --surface: rgba(255, 255, 255, 0.78);
  --line: rgba(20, 32, 28, 0.1);
  --forest: #1a5c45;
  --forest-deep: #0d3a2c;
  --moss: #2f7a5c;
  --gold: #c8922a;
  --gold-soft: #f4e4c0;
  --danger: #a63d3d;
  --ok: #1f7a4d;
  --wait: #9a6b1f;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(13, 58, 44, 0.12);
  --font: "Be Vietnam Pro", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
  overflow-x: hidden;
}

.bg-atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 55% at 12% -10%, rgba(47, 122, 92, 0.22), transparent 55%),
    radial-gradient(ellipse 60% 45% at 95% 8%, rgba(200, 146, 42, 0.16), transparent 50%),
    linear-gradient(165deg, #eef3ec 0%, #f7f8f4 42%, #e4ebe5 100%);
}

.bg-atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(26, 92, 69, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(26, 92, 69, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, black 0%, transparent 78%);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(14px);
  background: rgba(243, 246, 242, 0.82);
  border-bottom: 1px solid var(--line);
}

.save-status {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.25rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.save-status.is-ok {
  color: var(--ok);
}

.save-status.is-error {
  color: var(--danger);
}

.save-status.is-pending {
  color: var(--wait);
}

.save-status[hidden] {
  display: none !important;
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand-mark {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.2rem;
  color: #fff;
  background: linear-gradient(145deg, var(--moss), var(--forest-deep));
  box-shadow: 0 8px 20px rgba(13, 58, 44, 0.25);
  flex-shrink: 0;
}

.brand-school {
  margin: 0;
  font-weight: 650;
  font-size: 0.95rem;
}

.brand-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.header-actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-end;
  align-items: center;
}

.filter-linked {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
  padding: 0.35rem 0.2rem;
}

.filter-linked input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--forest);
}

.load-status {
  margin: 1rem 0 0;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.page-user .hero-user {
  max-width: 40rem;
}

.site-footer code {
  font-size: 0.85em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: rgba(26, 92, 69, 0.08);
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s var(--ease), background 0.2s, border-color 0.2s, color 0.2s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--forest);
  color: #fff;
}

.btn-primary:hover {
  background: var(--forest-deep);
}

.btn-primary.is-active {
  background: var(--gold);
  color: var(--ink);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-soft);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(26, 92, 69, 0.25);
}

.btn-danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: rgba(166, 61, 61, 0.08);
}

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
}

.hero {
  padding: 3.2rem 0 2rem;
  max-width: 38rem;
  animation: rise 0.7s var(--ease) both;
}

.hero-eyebrow {
  margin: 0 0 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--moss);
}

.hero-brand {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(3.2rem, 9vw, 5.4rem);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.03em;
  color: var(--forest-deep);
}

.hero-title {
  margin: 0.85rem 0 0;
  font-size: clamp(1.25rem, 2.6vw, 1.65rem);
  font-weight: 650;
  color: var(--ink);
}

.hero-lead {
  margin: 0.85rem 0 0;
  color: var(--ink-soft);
  font-size: 1.02rem;
  max-width: 34rem;
}

.hero-stats {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.25rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
  animation: rise 0.8s var(--ease) 0.12s both;
}

.hero-stats strong {
  color: var(--forest-deep);
  font-weight: 700;
}

.grades {
  margin: 0.5rem 0 1.25rem;
  animation: rise 0.75s var(--ease) 0.18s both;
}

.grade-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
  padding: 0.4rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.grade-tab {
  appearance: none;
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 1rem 0.5rem;
  font: inherit;
  cursor: pointer;
  text-align: center;
  color: var(--ink-soft);
  transition: background 0.25s var(--ease), color 0.25s, transform 0.25s var(--ease);
}

.grade-tab:hover {
  background: rgba(26, 92, 69, 0.06);
  color: var(--ink);
}

.grade-tab.is-active {
  background: linear-gradient(160deg, var(--moss), var(--forest-deep));
  color: #fff;
  box-shadow: 0 10px 24px rgba(13, 58, 44, 0.28);
  transform: translateY(-1px);
}

.grade-tab .grade-num {
  display: block;
  font-family: var(--display);
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1;
}

.grade-tab .grade-label {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0.85;
}

.grade-tab .grade-count {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.7rem;
  opacity: 0.75;
}

.subjects-panel {
  margin-top: 0.5rem;
  animation: rise 0.8s var(--ease) 0.28s both;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.75rem;
  color: var(--forest-deep);
}

.panel-desc {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.search-wrap input {
  width: min(100%, 240px);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  padding: 0.65rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-wrap input:focus {
  border-color: rgba(47, 122, 92, 0.45);
  box-shadow: 0 0 0 3px rgba(47, 122, 92, 0.12);
}

.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.75rem;
}

.subject-item {
  --accent: var(--moss);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 1.05rem 1.1rem 1rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  transition: transform 0.25s var(--ease), border-color 0.25s, box-shadow 0.25s;
  animation: rise 0.5s var(--ease) both;
}

.subject-item:hover {
  transform: translateY(-2px);
  border-color: rgba(26, 92, 69, 0.22);
  box-shadow: 0 14px 30px rgba(13, 58, 44, 0.08);
}

.subject-item.is-linked {
  --accent: var(--ok);
  border-color: rgba(31, 122, 77, 0.2);
}

.subject-item.is-waiting {
  --accent: var(--wait);
}

.subject-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.subject-group {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.subject-name {
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--ink);
}

.status-pill {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, white);
  color: var(--accent);
}

.subject-note {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subject-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: auto;
  padding-top: 0.25rem;
}

.subject-actions .btn {
  padding: 0.42rem 0.8rem;
  font-size: 0.8rem;
}

.btn-open {
  background: var(--forest);
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-open:hover {
  background: var(--forest-deep);
}

.btn-open.is-disabled {
  pointer-events: none;
  opacity: 0.45;
  background: #8aa397;
}

body.is-editing .subject-item {
  cursor: pointer;
  outline: 1px dashed transparent;
}

body.is-editing .subject-item:hover {
  outline-color: rgba(200, 146, 42, 0.55);
  border-color: rgba(200, 146, 42, 0.35);
}

.edit-hint {
  margin: 0 0 0.85rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: var(--gold-soft);
  color: #6a4a10;
  font-size: 0.9rem;
  font-weight: 500;
}

.edit-hint[hidden] {
  display: none !important;
}

.site-footer {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.25rem 2.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.link-dialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  width: min(92vw, 460px);
  box-shadow: 0 30px 80px rgba(13, 58, 44, 0.28);
  background: #fff;
}

.link-dialog::backdrop {
  background: rgba(13, 32, 26, 0.45);
  backdrop-filter: blur(3px);
}

.dialog-body {
  padding: 1.25rem 1.3rem 1.3rem;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.dialog-head h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  color: var(--forest-deep);
}

.dialog-close {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.15rem 0.4rem;
}

.dialog-meta {
  margin: 0.35rem 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.field input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  font-weight: 400;
  font-size: 0.92rem;
  outline: none;
}

.field input:focus {
  border-color: rgba(47, 122, 92, 0.5);
  box-shadow: 0 0 0 3px rgba(47, 122, 92, 0.12);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-top: 1rem;
}

.dialog-actions-right {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.45);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 720px) {
  .header-inner {
    flex-wrap: wrap;
  }

  .header-actions {
    width: 100%;
    margin-left: 0;
  }

  .hero {
    padding-top: 2.2rem;
  }

  .grade-tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  .grade-tab {
    padding: 0.85rem 0.35rem;
  }

  .grade-tab .grade-num {
    font-size: 1.4rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
