:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #202124;
  --muted: #777d86;
  --line: #d8dce2;
  --accent: #6657d9;
  --accent-soft: #eeebff;
  --topbar: #24242b;
  --topbar-text: #ffffff;
  --danger: #d74545;
  --shadow: 0 2px 12px rgba(0,0,0,.06);
}

:root.dark {
  --bg: #17181c;
  --surface: #222329;
  --surface-2: #2b2d34;
  --text: #eceef2;
  --muted: #a9aeb8;
  --line: #3a3d46;
  --accent: #a99cff;
  --accent-soft: #302d4d;
  --topbar: #111217;
  --topbar-text: #ffffff;
  --shadow: none;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  background: var(--topbar);
  color: var(--topbar-text);
  box-shadow: 0 1px 8px rgba(0,0,0,.18);
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 190px;
  font-weight: 800;
}
.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--accent);
}
.topbar-title { flex: 1; color: #c9cad1; font-size: 13px; }
.top-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.top-link { color: #ececf1; font-size: 13px; }
.icon-button { border: 0; background: transparent; color: inherit; font-size: 20px; }

.layout {
  min-height: calc(100vh - 58px);
  display: grid;
  grid-template-columns: 240px minmax(0,1fr);
}
.sidebar {
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.sidebar-section + .sidebar-section { margin-top: 26px; }
.sidebar-title {
  margin: 0 10px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .6px;
}
.sidebar-link, .sidebar-info {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 14px;
}
.sidebar-link:hover { background: var(--surface-2); }
.sidebar-link.active { color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.sidebar-info { color: var(--muted); font-size: 12px; line-height: 1.55; }
.sidebar-back {
  margin-top: auto;
  padding: 11px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 700;
}

.content { min-width: 0; padding: 28px; }
.article {
  max-width: 1480px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.article-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  padding: 26px 30px 18px;
  border-bottom: 1px solid var(--line);
}
.eyebrow, .detail-kicker {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
}
.article-head h1 { margin: 0; font-size: 38px; letter-spacing: -.7px; }
.subtitle { margin: 8px 0 0; color: var(--accent); font-size: 20px; font-weight: 700; }
.article-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.primary-button, .secondary-button, .danger-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 13px;
  font-weight: 700;
}
.primary-button { background: var(--accent); color: white; }
.secondary-button { background: var(--surface); color: var(--text); border-color: var(--line); }
.danger-button { background: var(--surface); color: var(--danger); border-color: #efb4b4; }

#adminButton.admin-active {
  color: #fff !important;
  border-color: #22c76f !important;
  background: #19a95b !important;
  box-shadow: 0 0 18px rgba(34,199,111,.48);
}

.submission-notice {
  margin: 22px 30px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
}
.submission-notice strong { font-size: 14px; }
.submission-notice p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.suggest-button {
  flex: 0 0 auto;
  padding: 9px 12px;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 800;
}

.gallery-tools {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 24px 30px 14px;
}
.date-filter { display: grid; gap: 7px; font-size: 12px; font-weight: 800; color: var(--muted); }
.date-filter input {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
}
.sort-note { margin-left: auto; color: var(--muted); font-size: 12px; }

.gallery-wrap { padding: 0 30px 60px; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 24px 16px;
}
.gallery-card {
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}
.gallery-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}
.gallery-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform .2s ease;
}
.gallery-card:hover .gallery-thumb img { transform: scale(1.025); }
.gallery-card:hover .gallery-title { color: var(--accent); }
.gallery-title {
  margin-top: 10px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-date { margin-top: 5px; color: var(--muted); font-size: 12px; }
.loading, .empty-state { grid-column: 1 / -1; padding: 60px 20px; text-align: center; color: var(--muted); }
.empty-state { display: grid; gap: 6px; }
.empty-state strong { color: var(--text); }

.detail-dialog, .upload-dialog {
  width: min(980px, calc(100vw - 30px));
  max-height: calc(100vh - 30px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0,0,0,.28);
}
.detail-dialog::backdrop, .upload-dialog::backdrop { background: rgba(0,0,0,.58); }
.detail-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  max-height: calc(100dvh - 30px);
}
.detail-image-wrap {
  display: grid;
  place-items: center;
  min-height: 300px;
  padding: 24px;
  background: #111216;
}
.detail-image-wrap img {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  object-fit: contain;
}
.detail-info { padding: 20px 24px 26px; }
.detail-info h2 { margin: 0 0 14px; font-size: 26px; }
.detail-info dl { margin: 0 0 18px; border-top: 1px solid var(--line); }
.detail-info dl div {
  display: grid;
  grid-template-columns: 120px minmax(0,1fr);
  border-bottom: 1px solid var(--line);
}
.detail-info dt, .detail-info dd { margin: 0; padding: 10px 8px; font-size: 13px; }
.detail-info dt { color: var(--muted); font-weight: 800; }
.detail-info a { color: var(--accent); font-weight: 700; }
.close-button {
  position: sticky;
  float: right;
  top: 10px;
  margin: 10px 10px -44px 0;
  z-index: 5;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(0,0,0,.62);
  color: white;
  font-size: 25px;
}

.upload-dialog { width: min(620px, calc(100vw - 30px)); padding: 22px; }
.upload-dialog form { margin: 0; }
.modal-head { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-head .close-button { position: static; float: none; margin: 0; background: transparent; color: var(--muted); }
.upload-dialog label { display: grid; gap: 7px; margin: 15px 0; font-size: 13px; font-weight: 800; }
.upload-dialog input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--surface);
  color: var(--text);
}
.form-note, .upload-progress { color: var(--muted); font-size: 12px; line-height: 1.55; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 18px);
  padding: 9px 14px;
  border-radius: 7px;
  background: #111;
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
  font-size: 13px;
}
.toast.show { opacity: 1; transform: translate(-50%,0); }
.mobile-only { display: none; }

@media (max-width: 1100px) {
  .gallery-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 25;
    left: 0;
    top: 58px;
    width: 270px;
    transform: translateX(-102%);
    transition: transform .2s ease;
    box-shadow: 6px 0 20px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-block; }
  .brand { min-width: auto; }
  .brand span:last-child, .topbar-title, .top-link { display: none; }
  .content { padding: 14px; }
  .article-head { align-items: flex-start; flex-direction: column; padding: 22px 20px 16px; }
  .submission-notice { margin: 18px 20px 0; align-items: stretch; flex-direction: column; }
  .suggest-button { width: fit-content; }
  .gallery-tools { padding: 20px 20px 12px; }
  .gallery-wrap { padding: 0 20px 50px; }
}
@media (max-width: 680px) {
  .gallery-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px 10px; }
  .article-head h1 { font-size: 30px; }
  .article-actions { width: 100%; }
  .article-actions button { flex: 1; }
  .sort-note { width: 100%; margin-left: 0; }
  .detail-info dl div { grid-template-columns: 100px minmax(0,1fr); }
}


.top-admin-button {
  height: 32px;
  padding: 0 11px;
  border: 1px solid #51535d;
  border-radius: 7px;
  background: rgba(255,255,255,.05);
  color: #e8e9ee;
  font-size: 12px;
  font-weight: 800;
}
.top-admin-button.admin-active {
  color: #fff !important;
  border-color: #35df87 !important;
  background: #169a50 !important;
  box-shadow: 0 0 15px rgba(53,223,135,.42);
}


/* Fanart source embed mode */
.removal-notice {
  margin: 12px 30px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  border: 1px solid color-mix(in srgb, var(--danger) 28%, var(--line));
  border-left: 4px solid var(--danger);
  background: color-mix(in srgb, var(--danger) 7%, var(--surface));
}

.removal-notice strong {
  font-size: 14px;
}

.removal-notice p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.removal-request-button {
  flex: 0 0 auto;
  padding: 9px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 55%, transparent);
  border-radius: 7px;
  background: var(--surface);
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
}

.gallery-card {
  display: flex;
  flex-direction: column;
}

.gallery-card-meta {
  min-width: 0;
}

.gallery-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
}

.gallery-detail-button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 9px;
  background: var(--surface);
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
}

.gallery-detail-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.embed-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 900;
}

.gallery-embed-media {
  min-height: 260px;
  display: grid;
  align-items: start;
  justify-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 8px;
}

.gallery-embed-media > div,
.gallery-embed-media iframe,
.detail-embed > div,
.detail-embed iframe {
  max-width: 100% !important;
}

.gallery-embed-media .twitter-tweet,
.gallery-embed-media .twitter-tweet-rendered,
.detail-embed .twitter-tweet,
.detail-embed .twitter-tweet-rendered {
  width: 100% !important;
  margin: 0 auto !important;
}

.embed-loading,
.embed-fallback {
  width: 100%;
  min-height: 180px;
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 24px 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.embed-fallback a {
  color: var(--accent);
  font-weight: 800;
}

.detail-embed {
  width: min(560px, 100%);
  margin: 0 auto;
}

.detail-image-wrap:has(.detail-embed:not([hidden])) {
  background: var(--surface-2);
}

.gallery-display-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0 4px;
  padding: 0;
  border: 0;
}

.gallery-display-mode legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.display-mode-option {
  position: relative;
  margin: 0 !important;
  cursor: pointer;
}

.display-mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.display-mode-option > span {
  min-height: 72px;
  display: grid;
  align-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  transition: .15s ease;
}

.display-mode-option strong {
  font-size: 12px;
}

.display-mode-option small {
  color: var(--muted);
  font-size: 10px;
}

.display-mode-option input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 10%, transparent);
}

@media (max-width: 900px) {
  .removal-notice {
    margin: 12px 20px 0;
    align-items: stretch;
    flex-direction: column;
  }

  .removal-request-button {
    width: fit-content;
  }
}

@media (max-width: 680px) {
  .gallery-display-mode {
    grid-template-columns: 1fr;
  }

  .gallery-embed-media {
    min-height: 220px;
  }
}


.detail-admin-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}


/* Floating admin upload button */
.floating-upload-button {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 120;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid color-mix(in srgb, var(--accent) 72%, #fff 10%);
  border-radius: 999px;
  padding: 0 16px 0 12px;
  background: color-mix(in srgb, var(--accent) 92%, #000 8%);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  box-shadow:
    0 12px 30px rgba(0, 0, 0, .28),
    0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
  cursor: pointer;
  transform: translateY(0);
  opacity: 1;
  transition:
    opacity .16s ease,
    transform .16s ease,
    box-shadow .16s ease;
}

.floating-upload-button:hover {
  transform: translateY(-2px);
  box-shadow:
    0 15px 34px rgba(0, 0, 0, .34),
    0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
}

.floating-upload-button:active {
  transform: translateY(0);
}

.floating-upload-button[hidden] {
  display: none !important;
}

.floating-upload-icon {
  width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(255,255,255,.17);
  font-size: 18px;
  font-weight: 700;
}

@media (max-width: 700px) {
  .floating-upload-button {
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
    min-height: 46px;
    padding: 0 15px 0 11px;
    font-size: 12px;
  }
}

/* Unsaved media editor warning */
.media-unsaved-dialog {
  width: min(440px, calc(100vw - 32px));
  max-width: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .42);
}

.media-unsaved-dialog::backdrop {
  background: rgba(8, 9, 13, .72);
  backdrop-filter: blur(3px);
}

.media-unsaved-shell {
  padding: 24px;
}

.media-unsaved-shell h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.35;
}

.media-unsaved-shell p {
  margin: 9px 0 22px;
  color: var(--muted);
  font-size: 14px;
}

.media-unsaved-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.media-unsaved-actions button {
  min-width: 78px;
  height: 38px;
  border-radius: 7px;
  padding: 0 16px;
  font-weight: 900;
  cursor: pointer;
}

.media-unsaved-no {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.media-unsaved-yes {
  border: 1px solid rgba(223, 93, 93, .65);
  background: #b83f4a;
  color: #fff;
}

.media-unsaved-no:hover {
  border-color: var(--accent);
}

.media-unsaved-yes:hover {
  filter: brightness(1.08);
}

/* Keep media detail modal pinned to the current viewport */
.detail-dialog[open] {
  position: fixed;
  inset: 15px;
  width: min(980px, calc(100vw - 30px));
  max-width: calc(100vw - 30px);
  height: fit-content;
  max-height: calc(100dvh - 30px);
  margin: auto;
  overflow: auto;
  overscroll-behavior: contain;
}

@media (max-width: 680px) {
  .detail-dialog[open] {
    inset: 10px;
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
  }
}

/* Archive title counts + restricted X preview */
.archive-title-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.archive-title-row h1 {
  margin-right: 0;
}

.archive-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}

.x-restricted-preview {
  position: relative;
  isolation: isolate;
  width: 100%;
  min-height: 250px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--line) 82%, #fff 8%);
  border-radius: 8px;
  background: #171a20;
  color: #fff;
  text-decoration: none;
}

.x-restricted-preview-blur {
  position: absolute;
  inset: -28px;
  z-index: -2;
  background:
    radial-gradient(circle at 24% 28%, rgba(143, 112, 255, .78), transparent 26%),
    radial-gradient(circle at 72% 34%, rgba(67, 174, 255, .55), transparent 28%),
    radial-gradient(circle at 55% 78%, rgba(245, 112, 175, .48), transparent 30%),
    linear-gradient(135deg, #20242c, #111319 70%);
  filter: blur(22px) saturate(.75);
  transform: scale(1.12);
}

.x-restricted-preview::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: rgba(12, 14, 18, .60);
  backdrop-filter: blur(9px);
}

.x-restricted-preview-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 50%;
  background: rgba(0,0,0,.42);
  font-size: 18px;
  font-weight: 900;
}

.x-restricted-preview-copy {
  width: min(310px, calc(100% - 44px));
  display: grid;
  justify-items: center;
  gap: 7px;
  padding: 22px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 12px;
  background: rgba(14, 16, 21, .58);
  box-shadow: 0 14px 34px rgba(0,0,0,.28);
  text-align: center;
}

.x-restricted-preview-copy strong {
  font-size: 16px;
}

.x-restricted-preview-copy > span:not(.x-restricted-preview-open) {
  color: rgba(255,255,255,.72);
  font-size: 11px;
  line-height: 1.55;
}

.x-restricted-preview-open {
  margin-top: 4px;
  color: #b9a4ff;
  font-size: 12px;
  font-weight: 900;
}

.x-restricted-preview:hover .x-restricted-preview-open {
  text-decoration: underline;
}

.detail-embed .x-restricted-preview {
  min-height: min(420px, 58vh);
}

@media (max-width: 680px) {
  .archive-title-row {
    gap: 7px 10px;
  }

  .archive-count {
    font-size: 12px;
  }

  .x-restricted-preview {
    min-height: 220px;
  }
}

.x-restricted-preview.is-neutral .x-restricted-preview-blur {
  background: linear-gradient(135deg, #242833, #171a20 72%);
  filter: none;
  transform: none;
}

.x-restricted-preview.is-neutral::after {
  background: rgba(12, 14, 18, .35);
  backdrop-filter: none;
}

.x-restricted-preview.is-neutral .x-restricted-preview-open {
  color: var(--accent);
}
