.topic-page {
  min-height: 100vh;
}

.topic-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(44px, 8vh, 86px) 0;
}

.topic-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: clamp(32px, 6vw, 58px);
}

.topic-header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.1;
  font-weight: 800;
}

.topic-main-link {
  flex: 0 0 auto;
  padding: 11px 16px;
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  background: var(--ui-surface);
  color: var(--text);
  box-shadow: var(--ui-shadow);
  font-size: 0.95rem;
  text-decoration: none;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.topic-main-link:hover,
.topic-main-link:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(179, 38, 46, 0.3);
  outline: none;
}

.topic-section {
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid rgba(114, 38, 35, 0.12);
  border-radius: 8px;
  background: rgba(255, 252, 250, 0.52);
  box-shadow: 0 24px 60px rgba(102, 26, 31, 0.08);
}

.topic-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(114, 38, 35, 0.12);
}

.topic-section-heading h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
  color: var(--muted);
  font-weight: 700;
}

.topic-section-heading p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.5;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.topic-loading {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.topic-card-shell {
  position: relative;
  min-width: 0;
}

.topic-card {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  width: 100%;
  height: 100%;
  min-height: 132px;
  padding: 24px;
  border: 1px solid rgba(114, 38, 35, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 253, 251, 0.96), rgba(255, 246, 242, 0.84)),
    var(--surface);
  color: var(--text);
  box-shadow: 0 18px 42px rgba(102, 26, 31, 0.1);
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.topic-card-with-image {
  min-height: 190px;
  background:
    linear-gradient(180deg, rgba(52, 22, 22, 0.08), rgba(52, 22, 22, 0.72)),
    var(--topic-card-image) center / cover no-repeat;
  color: #fffdfb;
}

.topic-card-with-image::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(179, 38, 46, 0.18), rgba(52, 22, 22, 0.28));
  pointer-events: none;
}

.topic-card:hover,
.topic-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(179, 38, 46, 0.34);
  box-shadow: 0 24px 54px rgba(102, 26, 31, 0.15);
  outline: none;
}

.topic-card span {
  position: relative;
  z-index: 1;
  display: block;
  font-size: 1.18rem;
  font-weight: 700;
  line-height: 1.35;
}

.topic-card-delete {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(52, 22, 22, 0.58);
  color: #fffdfb;
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
  box-shadow: 0 10px 24px rgba(52, 22, 22, 0.16);
  transition: transform 180ms ease, opacity 180ms ease;
}

.topic-card-delete:hover,
.topic-card-delete:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.topic-card-delete:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.topic-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 28px;
}

.topic-modal.is-hidden {
  display: none;
}

.topic-modal-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(52, 22, 22, 0.46);
  backdrop-filter: blur(9px);
  cursor: pointer;
}

.topic-modal-panel {
  position: relative;
  width: min(860px, 100%);
  max-height: min(82vh, 780px);
  overflow: auto;
  padding: clamp(24px, 4vw, 42px);
  border: 1px solid rgba(114, 38, 35, 0.16);
  border-radius: 8px;
  background: rgba(255, 253, 251, 0.98);
  box-shadow: 0 30px 80px rgba(52, 22, 22, 0.24);
}

.topic-modal-close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(114, 38, 35, 0.16);
  border-radius: 999px;
  background: rgba(255, 252, 250, 0.92);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 1.35rem;
  line-height: 1;
}

.topic-modal-panel h1 {
  margin: 0 52px 34px 0;
  font-size: clamp(1.65rem, 4vw, 2.35rem);
  line-height: 1.2;
}

.topic-timeline {
  position: relative;
  display: grid;
  gap: 26px;
}

.topic-timeline::before {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 5px;
  width: 1px;
  background: rgba(179, 38, 46, 0.24);
}

.topic-timeline-item {
  position: relative;
  padding-left: 30px;
}

.topic-timeline-item::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 0;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 7px rgba(179, 38, 46, 0.12);
}

.topic-timeline-item time {
  display: block;
  margin-bottom: 6px;
  color: var(--accent-deep);
  font-size: 0.9rem;
  font-weight: 700;
}

.topic-timeline-item h2 {
  margin: 0 0 12px;
  font-size: 1.18rem;
  line-height: 1.4;
}

.topic-timeline-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.topic-timeline-title-row h2 {
  margin-bottom: 12px;
}

.topic-remove-button,
.topic-admin-button {
  flex: 0 0 auto;
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  background: var(--ui-surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  transition: transform 180ms ease, border-color 180ms ease, opacity 180ms ease;
}

.topic-remove-button {
  padding: 7px 12px;
}

.topic-remove-button:hover,
.topic-remove-button:focus-visible,
.topic-admin-button:hover,
.topic-admin-button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(179, 38, 46, 0.3);
  outline: none;
}

.topic-remove-button:disabled,
.topic-admin-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.topic-timeline-copy {
  display: grid;
  gap: 12px;
}

.topic-timeline-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.85;
}

.topic-timeline-copy a {
  color: var(--accent-deep);
  text-underline-offset: 3px;
}

.topic-modal-open {
  overflow: hidden;
}

.topic-admin {
  margin-top: 34px;
  padding-top: 22px;
  border-top: 1px solid rgba(114, 38, 35, 0.14);
}

.topic-admin-heading {
  margin-bottom: 14px;
}

.topic-admin-heading h2 {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.topic-admin-picker {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
  min-height: 210px;
  padding: 8px;
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  background: rgba(255, 252, 250, 0.74);
}

.topic-admin-years,
.topic-admin-events {
  display: grid;
  align-content: start;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
}

.topic-admin-events {
  padding-left: 10px;
  border-left: 1px solid rgba(74, 52, 49, 0.12);
}

.topic-admin-year,
.topic-admin-event {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease, transform 180ms ease;
}

.topic-admin-year {
  padding: 10px 12px;
  color: var(--muted);
}

.topic-admin-event {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
}

.topic-admin-event span {
  color: var(--accent-deep);
  font-size: 0.82rem;
  font-weight: 700;
}

.topic-admin-event strong {
  font-size: 0.94rem;
  line-height: 1.35;
}

.topic-admin-year:hover,
.topic-admin-year:focus-visible,
.topic-admin-event:hover,
.topic-admin-event:focus-visible,
.topic-admin-year.is-active,
.topic-admin-event.is-selected {
  background: rgba(179, 38, 46, 0.1);
  color: var(--accent-deep);
  outline: none;
}

.topic-admin-year:hover,
.topic-admin-event:hover {
  transform: translateY(-1px);
}

.topic-admin-empty {
  margin: 0;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.topic-admin-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.topic-admin-button {
  padding: 11px 18px;
  background: var(--accent);
  color: #fff7f4;
}

.topic-create-panel {
  margin-top: 24px;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid rgba(114, 38, 35, 0.12);
  border-radius: 8px;
  background: rgba(255, 252, 250, 0.52);
  box-shadow: 0 24px 60px rgba(102, 26, 31, 0.08);
}

.topic-create-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(140px, 0.45fr) auto;
  gap: 14px;
  align-items: end;
}

.topic-create-form label,
.topic-settings-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
}

.topic-create-form input,
.topic-create-form select,
.topic-settings-form input,
.topic-settings-form select {
  min-width: 0;
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  background: var(--ui-surface-strong);
  color: var(--text);
  font: inherit;
}

.topic-settings-form {
  display: grid;
  grid-template-columns: minmax(140px, 0.42fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.topic-create-feedback {
  min-height: 1.4em;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

@media (max-width: 760px) {
  .topic-grid {
    grid-template-columns: 1fr;
  }

  .topic-shell {
    width: min(100% - 24px, 1180px);
    padding-top: 28px;
  }

  .topic-header {
    align-items: center;
    margin-bottom: 28px;
  }

  .topic-modal {
    padding: 16px;
  }

  .topic-modal-panel {
    max-height: 88vh;
  }

  .topic-timeline-title-row,
  .topic-admin-picker,
  .topic-create-form,
  .topic-settings-form {
    grid-template-columns: 1fr;
  }

  .topic-timeline-title-row {
    display: grid;
  }

  .topic-remove-button {
    justify-self: start;
  }

  .topic-admin-events {
    padding-left: 0;
    padding-top: 8px;
    border-left: 0;
    border-top: 1px solid rgba(74, 52, 49, 0.12);
  }
}
