:root {
  --bg: #f5f2ea;
  --surface: #ffffff;
  --surface-soft: #faf8f1;
  --text: #172019;
  --muted: #667060;
  --primary: #244b32;
  --primary-dark: #18251c;
  --border: #ddd6c8;
  --shadow: 0 14px 40px rgba(20, 32, 24, .08);
  --radius: 22px;
  --sidebar-w: 220px;
  --sidebar-collapsed-w: 64px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

.app-header {
  display: flex;
  flex-flow: column;
  align-items: center;
  justify-content: center;
  background: rgba(245, 242, 234, .88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

/* Sidebar elements — hidden on mobile, styled on desktop */
.sidebar-brand {
  display: contents;
  /* brand visible inline in header on mobile */
}

.brand-icon {
  width: 35px;
  height: 35px;
  flex-shrink: 0;
  color: var(--primary);
}

.sidebar-header {
  display: none;
}

.sidebar-footer {
  display: none;
}

.sidebar-toggle {
  display: none;
}

.nav-item {
  display: flex;
  align-items: center;
}

.login-card {
  max-width: 420px;
  margin: 8vh auto;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: 1.6rem;
  text-align: center;
}

.nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 80px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.page-head h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.6rem);
  letter-spacing: -0.06em;
}

.page-head p {
  margin: 8px 0 0;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn-secondary {
  background: var(--surface-soft);
}

.search-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 32px;
}

.search-bar input {
  flex: 1;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.card,
.panel,
.sheet,
.side-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card {
  padding: 24px;
  position: relative;
  cursor: pointer;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 1.4rem;
}

.card-link {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
}

.card-name {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.card-name h2 {
  margin: 0;
  flex: 1;
}

.card-edit {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  padding: 4px;
  margin-top: 2px;
  border-radius: 8px;
  color: var(--muted);
  flex-shrink: 0;
  transition: color .13s, background .13s;
}

.card-edit svg {
  width: 16px;
  height: 16px;
}

.card-edit:hover {
  color: var(--primary);
  background: var(--surface-soft);
}

.latin {
  color: var(--primary);
  font-style: italic;
}

.muted {
  color: var(--muted);
}

.detail-cover {
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  border-radius: 24px;
  margin: 24px 0;
}

.media-list {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.media-item {
  position: relative;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface-soft);
}

.media-item img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 14px;
  margin-bottom: 12px;
}

.badge {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  font-size: .8rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.btn-danger {
  background: #8f1d1d;
  color: white;
  border-color: #8f1d1d;
}

.card-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.sheet {
  padding: clamp(24px, 5vw, 56px);
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 36px;
}

.sheet-head .name-container {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 16px;
}

.sheet h1 {
  margin: 0;
  font-size: clamp(2.5rem, 3vw, 3.5rem);
  letter-spacing: 1;
}

.sheet section {
  padding-top: 28px;
  margin-top: 28px;
  border-top: 1px solid var(--border);
}

.sheet h2 {
  margin: 0 0 14px;
  font-size: 1.25rem;
}

.subcard {
  padding: 18px;
  background: var(--surface-soft);
  border-radius: 16px;
  margin-bottom: 14px;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  align-items: start;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.panel,
.side-panel {
  padding: 24px;
}

.side-panel {
  position: sticky;
  top: 92px;
}

details {
  border: 1px solid var(--border);
  border-radius: 16px;
  margin-bottom: 8px;
  background: var(--surface);
  overflow: hidden;
}

summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 18px;
  cursor: pointer;
  font-weight: 700;
  font-size: .9rem;
  list-style: none;
  user-select: none;
  transition: color .15s;
}

summary::-webkit-details-marker {
  display: none;
}

details[open] > summary {
  color: var(--primary);
  border-bottom: 1px solid var(--border);
}

.chevron {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--muted);
  transition: transform .25s cubic-bezier(.4, 0, .2, 1), color .15s;
}

.summary-end {
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  line-height: 1;
}

details[open] > summary .chevron {
  transform: rotate(180deg);
  color: var(--primary);
}

.details-body {
  overflow: hidden;
  transition: height .28s cubic-bezier(.4, 0, .2, 1);
}

.details-body-inner {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.add-form {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}


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

.item-title {
  margin: 0 0 8px;
  font-weight: 600;
  font-size: .9rem;
}

.item-title a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-sm {
  min-height: 34px;
  padding: 0 14px;
  font-size: .85rem;
}

form p {
  margin: 0 0 18px;
}

label {
  display: block;
  margin-bottom: 7px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  background: white;
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: unset;
  height: 46px;
  resize: none;
  overflow: hidden;
}

input:focus,
textarea:focus,
select:focus {
  outline: 3px solid rgba(36, 75, 50, .16);
  border-color: var(--primary);
}

/* ── Mobile ────────────────────────────────────────────────── */

.bottom-nav {
  display: none;
}

@media (max-width: 860px) {

  .app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    flex-direction: row;
    justify-content: center;
    padding: 14px clamp(18px, 5vw, 56px);
    gap: 0;
  }

  .nav {
    display: none;
  }


  .page-head,
  .sheet-head,
  .search-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .editor-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }


  .app-main {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    background: rgba(245, 242, 234, .96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .bottom-nav-form {
    flex: 1;
    display: flex;
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 4px;
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
    color: var(--muted);
    background: none;
    border: none;
    border-radius: 0;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
    transition: color .15s;
    min-height: unset;
  }

  .bottom-nav-item svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }

  .bottom-nav-item.active,
  .bottom-nav-item:active {
    color: var(--primary);
  }
}

/* ── Desktop sidebar ───────────────────────────────────────── */

@media (min-width: 861px) {

  html {
    height: 100%;
  }

  body {
    display: flex;
    align-items: stretch;
    min-height: 100%;
  }

  /* Sidebar */
  .app-header {
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    width: var(--sidebar-w);
    flex-shrink: 0;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    padding: 0;
    border-bottom: none;
    border-right: 1px solid var(--border);
    background: var(--bg);
    backdrop-filter: none;
    overflow: hidden;
    transition: width .22s cubic-bezier(.4, 0, .2, 1);
    z-index: 20;
  }

  .sidebar-collapsed .app-header {
    width: var(--sidebar-collapsed-w);
  }

  /* Brand */
  .sidebar-brand {
    display: block;
    padding: 24px 14px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  .brand {
    font-size: 1.15rem;
    white-space: nowrap;
  }

  .brand-text {
    transition: opacity .15s;
    overflow: hidden;
  }

  .sidebar-collapsed .brand-text {
    opacity: 0;
  }

  /* Nav */
  .nav {
    flex-direction: column;
    gap: 2px;
    padding: 14px 10px;
    flex: 1;
    overflow: hidden;
    align-items: stretch;
  }

  .nav-item {
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    font-size: .93rem;
    font-weight: 600;
    white-space: nowrap;
    color: var(--text);
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    width: 100%;
    text-decoration: none;
    transition: background .13s, color .13s;
    min-height: unset;
  }

  .nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--muted);
    transition: color .13s;
  }

  .nav-item span {
    transition: opacity .15s;
    overflow: hidden;
  }

  .sidebar-collapsed .nav-item span {
    opacity: 0;
  }

  .nav-item:hover {
    background: var(--surface-soft);
    color: var(--primary);
  }

  .nav-item:hover svg {
    color: var(--primary);
  }

  .nav-item.active {
    background: var(--primary);
    color: #fff;
  }

  .nav-item.active svg {
    color: #fff;
  }

  .sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 10px 10px;
    flex-shrink: 0;
  }

  /* Footer */
  .sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 10px 18px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }

  .sidebar-footer form {
    display: flex;
  }

  .sidebar-footer .nav-item {
    flex: 1;
    color: var(--muted);
  }

  .sidebar-footer .nav-item:hover {
    color: var(--text);
  }

  /* Toggle button */
  .sidebar-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: .93rem;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
    text-align: left;
    transition: background .13s, color .13s;
    min-height: unset;
  }

  .sidebar-toggle:hover {
    background: var(--surface-soft);
    color: var(--text);
  }

  .sidebar-toggle svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    transition: transform .22s cubic-bezier(.4, 0, .2, 1);
  }

  .sidebar-collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
  }

  .sidebar-toggle span {
    transition: opacity .15s;
    overflow: hidden;
  }

  .sidebar-collapsed .sidebar-toggle span {
    opacity: 0;
  }

  /* Main content */
  .app-main {
    flex: 1;
    min-width: 0;
    width: auto;
    margin: 0;
    padding: 36px clamp(24px, 4vw, 56px) 80px;
  }
}

/* ── Wiki Accordion ────────────────────────────────────────── */

.wiki-accordion {
  margin-top: 8px;
}

.wiki-section {
  border: none;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  margin-bottom: 0;
  overflow: visible;
}

.wiki-accordion > .wiki-section:first-child {
  border-top: 1px solid var(--border);
}

.wiki-section > summary {
  padding: 13px 2px;
  font-size: .975rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  border-bottom: none;
}

.wiki-section[open] > summary {
  color: var(--text);
  border-bottom: none;
}

.wiki-section > summary .chevron {
  width: 15px;
  height: 15px;
  color: var(--muted);
  opacity: .7;
}

.wiki-section[open] > summary .chevron {
  color: var(--muted);
}

.wiki-body {
  padding: 4px 2px 22px;
}

.wiki-subhead {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 20px 0 5px;
}

.wiki-body > .wiki-subhead:first-child {
  margin-top: 2px;
}

.wiki-content {
  font-size: .95rem;
  line-height: 1.75;
  color: var(--text);
}

.wiki-content p {
  margin: 0 0 6px;
}

.wiki-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.wiki-figure {
  margin: 0;
}

.wiki-figure img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}

.wiki-figure figcaption {
  font-size: .73rem;
  color: var(--muted);
  margin-top: 5px;
  text-align: center;
  line-height: 1.4;
}

.wiki-docs {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wiki-docs li a {
  font-size: .95rem;
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}