:root {
  --bg: #f6f4f4;
  --surface: #ffffff;
  --border: #e6e0e1;
  --text: #262022;
  --text-dim: #6b6062;
  --primary: #9e1b32;
  --primary-dim: #f6e6e8;
  --accent: #9c7a1f;
  --accent-dim: #faf1de;
  --thumb-grad-2: #f0d6da;
  --shadow: 0 1px 3px rgba(30, 20, 22, 0.08), 0 1px 2px rgba(30, 20, 22, 0.06);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1517;
    --surface: #251c1f;
    --border: #3d2e31;
    --text: #f2eaeb;
    --text-dim: #b6a5a8;
    --primary: #e0536e;
    --primary-dim: #3a1f26;
    --accent: #d4ac4e;
    --accent-dim: #3a301a;
    --thumb-grad-2: #2a1c20;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #1c1517;
  --surface: #251c1f;
  --border: #3d2e31;
  --text: #f2eaeb;
  --text-dim: #b6a5a8;
  --primary: #e0536e;
  --primary-dim: #3a1f26;
  --accent: #d4ac4e;
  --accent-dim: #3a301a;
  --thumb-grad-2: #2a1c20;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.55;
}

/* ---------- Header ---------- */
header.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--primary);
  color: #fff;
  padding: 16px 24px;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.header-left {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  height: 30px;
  width: auto;
  display: block;
  background: #fff;
  border-radius: 6px;
  padding: 4px 8px;
}

.header-divider {
  width: 1px;
  height: 22px;
  background: rgba(255,255,255,0.35);
}

.header-team-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.header-logo-fallback {
  display: none;
  align-items: center;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: #fff;
  border: 1.5px solid rgba(255,255,255,0.7);
  border-radius: 999px;
  padding: 6px 14px;
}

.site-title {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  white-space: nowrap;
  text-align: center;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0,0,0,0.18);
  pointer-events: none;
}

.header-right {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  min-width: 0;
}

.search-box {
  flex: none;
  width: 150px;
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border-radius: 999px;
  border: none;
  font-size: 0.95rem;
  background: rgba(255,255,255,0.95);
  color: var(--text);
}

.search-box input:focus {
  outline: 2px solid var(--accent);
}

.search-box::before {
  content: "🔍";
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  opacity: 0.6;
}

.entry-count {
  font-size: 0.85rem;
  opacity: 0.85;
  white-space: nowrap;
}

.btn-add {
  white-space: nowrap;
  border: none;
  background: #fff;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
}

.btn-add:hover { background: var(--primary-dim); }

.btn-quiz {
  white-space: nowrap;
  border: 1.5px solid rgba(255,255,255,0.7);
  background: transparent;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.btn-quiz:hover { background: rgba(255,255,255,0.15); }

.lang-toggle {
  white-space: nowrap;
  border: 1.5px solid rgba(255,255,255,0.7);
  background: transparent;
  color: #fff;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
}

.lang-toggle:hover { background: rgba(255,255,255,0.15); }

.read-only-note {
  white-space: nowrap;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(255,255,255,0.18);
  padding: 5px 12px;
  border-radius: 999px;
}

/* ---------- Mode bar ---------- */
.mode-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.mode-bar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.mode-bar-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.mode-bar .cat-mode-toggle {
  width: 240px;
  margin-bottom: 0;
}

/* ---------- Layout ---------- */
.layout {
  max-width: 1600px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  padding: 24px;
  align-items: start;
}

.layout.with-idiogram {
  grid-template-columns: 220px 1fr;
}

/* ---------- Idiogram panel ---------- */
.idiogram-panel {
  position: sticky;
  top: 88px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.idiogram-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #111;
  color: #fff;
  padding: 10px 12px;
}

.idiogram-close {
  flex: none;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  line-height: 1;
  font-size: 15px;
  font-weight: 700;
}

.idiogram-close:hover { background: rgba(255,255,255,0.3); }

.idiogram-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 260px);
  padding: 16px;
  text-align: center;
}

.idiogram-figure {
  position: relative;
  display: inline-block;
  width: 55%;
  max-width: 130px;
  margin: 0 auto;
}

.idiogram-figure img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.idiogram-band {
  position: absolute;
  left: var(--bar-left, 25%);
  width: var(--bar-width, 32%);
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
}

.idiogram-band:hover,
.idiogram-band:focus-visible {
  background: rgba(158, 27, 50, 0.18);
  outline: 2px solid var(--primary);
}

.idiogram-band.active {
  background: rgba(158, 27, 50, 0.32);
  outline: 2px solid var(--primary);
}

.idiogram-hint {
  flex: 1;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.4;
  color: #fff;
}

.idiogram-placeholder {
  padding: 30px 10px;
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.6;
}

.idiogram-clear-band {
  margin-top: 12px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 0.76rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

.cat-mode-toggle {
  position: relative;
  display: flex;
  background: var(--bg);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 14px;
}

.cat-mode-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  bottom: 3px;
  width: calc(50% - 3px);
  background: var(--primary);
  border-radius: 999px;
  box-shadow: var(--shadow);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 0;
}

.cat-mode-toggle.mode-disease .cat-mode-thumb {
  transform: translateX(100%);
}

.cat-mode-btn {
  position: relative;
  z-index: 1;
  flex: 1;
  text-align: center;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.2s;
}

.cat-mode-btn:hover { color: var(--text); }

.cat-mode-btn.active { color: #fff; }

.category-bar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px 14px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.cat-all-btn {
  flex-shrink: 0;
  border: none;
  background: var(--bg);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.cat-all-btn:hover { background: var(--primary-dim); }

.cat-all-btn.active {
  background: var(--primary);
  color: #fff;
}

.cat-all-btn .count { color: var(--text-dim); font-size: 0.78rem; }
.cat-all-btn.active .count { color: rgba(255,255,255,0.8); }

.category-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.category-list button {
  border: none;
  background: var(--bg);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
}

.category-list button:hover { background: var(--primary-dim); }

.category-list button.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.category-list .count {
  color: var(--text-dim);
  font-size: 0.72rem;
}

.category-list button.active .count { color: rgba(255,255,255,0.8); }

/* ---------- Grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  display: flex;
  flex-direction: column;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(30,20,22,0.12);
}

.card-thumb {
  width: 200px;
  height: 150px;
  margin: 0 auto;
  background: linear-gradient(135deg, var(--primary-dim), var(--thumb-grad-2));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.85rem;
  text-align: center;
  padding: 10px;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card-body { padding: 12px 14px 14px; }

.card-tag {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 6px;
}

.card-karyotype {
  font-family: "Consolas", "SF Mono", monospace;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 2px;
  min-height: 2.6em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-diagname {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.4;
  min-height: 1.4em;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 30, 0.55);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 14px;
  max-width: 720px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  overflow: hidden;
}

.modal-header {
  background: var(--primary);
  color: #fff;
  padding: 20px 24px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.modal-close:hover { background: rgba(255,255,255,0.3); }

.modal-tag {
  display: inline-block;
  font-size: 0.72rem;
  background: rgba(255,255,255,0.2);
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.modal-title { font-size: 1.4rem; font-weight: 700; margin: 0; }

.modal-body { padding: 22px 24px 26px; }

.modal-thumb {
  width: 100%;
  min-height: 160px;
  max-height: 420px;
  background: linear-gradient(135deg, var(--primary-dim), var(--thumb-grad-2));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 18px;
  overflow: hidden;
}

.modal-thumb img {
  width: 100%;
  height: 100%;
  max-height: 420px;
  object-fit: contain;
  cursor: zoom-in;
}

/* ---------- Image lightbox ---------- */
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 9, 0.88);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.lightbox-backdrop.open { display: flex; }

.lightbox-viewport {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  cursor: grab;
}

.lightbox-viewport.dragging { cursor: grabbing; }

.lightbox-viewport img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  transition: transform 0.1s ease-out;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-toolbar {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 2;
}

.lightbox-btn {
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.lightbox-btn:hover { background: rgba(255,255,255,0.3); }

.lightbox-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.7);
  font-size: 0.78rem;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}

.info-item-full {
  grid-column: 1 / -1;
}

.info-item-half {
  grid-column: span 1;
}

.info-item {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
}

.info-item .label {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.info-item .value {
  font-size: 0.92rem;
  font-weight: 600;
  font-family: "Consolas", "SF Mono", monospace;
}

.section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  margin: 20px 0 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary-dim);
}

.description p { margin: 0 0 10px; font-size: 0.93rem; }

.ref-list {
  margin: 0;
  padding-left: 18px;
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* ---------- Footer ---------- */
footer {
  text-align: center;
  padding: 30px 20px 50px;
  color: var(--text-dim);
  font-size: 0.8rem;
}

.data-io {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.78rem;
}

.link-btn {
  border: none;
  background: none;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

/* ---------- Entry Form ---------- */
.modal-form .modal-body { padding-top: 20px; }

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

.field .hint {
  display: block;
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 3px;
}

.field input[type="text"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

.field textarea { resize: vertical; min-height: 64px; }

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.delete-confirm {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.delete-confirm .form-actions {
  margin-top: 14px;
  padding-top: 0;
  border-top: none;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.img-preview-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.img-preview {
  width: 84px;
  height: 64px;
  border-radius: 6px;
  background: var(--primary-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--primary);
  font-size: 0.7rem;
  flex-shrink: 0;
}

.img-preview img { width: 100%; height: 100%; object-fit: cover; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.btn-primary,
.btn-secondary {
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary { background: var(--bg); color: var(--text); }
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: #b3261e;
  margin-right: auto;
}
.btn-danger:hover { background: #fbe9e7; }

.form-error {
  color: #b3261e;
  font-size: 0.82rem;
  margin: -6px 0 14px;
}

/* ---------- Responsive ---------- */
@media (max-width: 780px) {
  .layout,
  .layout.with-idiogram { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .idiogram-panel { position: static; }
  .idiogram-figure { max-width: 220px; }

  .header-inner {
    flex-direction: column;
    gap: 12px;
  }
  .site-title {
    position: static;
    transform: none;
    font-size: 1.4rem;
  }
  .header-right { justify-content: center; flex-wrap: wrap; }
  .search-box { width: 100%; max-width: 260px; }
}
