.gallery-shell {
  width: min(1200px, calc(100% - 40px));
  margin: 0 auto;
  padding: 48px 0 40px;
  position: relative;
  z-index: 1;
}

.gallery-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding-bottom: 28px;
  border-bottom: 3px dashed #ffd9a8;
}

.gallery-title { margin-bottom: 10px; }
.gallery-home {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  margin-top: 8px;
  padding: 8px 15px;
  border: 2px solid #ffd166;
  border-radius: 999px;
  background: linear-gradient(135deg, #fff3c9, #ffe08a);
  color: #7a3d0a;
  box-shadow: 0 4px 0 #f2c14e;
  text-decoration: none;
  font-size: .8rem;
  font-weight: 800;
  white-space: nowrap;
  transition: transform .15s ease, box-shadow .15s ease;
}
.gallery-home:hover { transform: translateY(-1px); box-shadow: 0 5px 0 #f2c14e, 0 10px 18px rgba(240, 165, 0, .2); }
.gallery-home:active { transform: translateY(2px); box-shadow: 0 2px 0 #f2c14e; }

.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 22px 0 16px;
}
.gallery-info { color: var(--muted); font-size: .78rem; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 18px;
}
.gallery-grid .gallery-empty { grid-column: 1 / -1; padding: 34px; color: var(--muted); text-align: center; font-size: .85rem; }

.gallery-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  border: 3px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(165deg, #fffefa, #fff8ea);
  color: inherit;
  text-align: left;
  box-shadow: 0 6px 0 -2px #ffe6b8;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.gallery-card:hover {
  transform: translateY(-3px);
  border-color: var(--red-soft);
  box-shadow: 0 9px 0 -2px #ffe6b8, 0 20px 30px rgba(226, 116, 58, .16);
}
.gallery-card-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: zoom-in;
  font: inherit;
}
.gallery-card-open:hover { transform: none; }
.gallery-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #fff7e4;
}
.gallery-card-missing {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  background: #fff7e4;
  color: var(--muted);
  font-size: .78rem;
}
.gallery-card-body { display: grid; gap: 4px; padding: 12px 14px 14px; }
.gallery-card-name { color: #58302a; font-size: .88rem; font-weight: 800; overflow-wrap: anywhere; }
.gallery-card-author { color: var(--muted); font-size: .74rem; overflow-wrap: anywhere; }
.gallery-card-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 0 12px 12px; }
.gallery-like {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 4px 11px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fffefa;
  color: #8a6a55;
  font-size: .75rem;
  font-weight: 800;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.gallery-like:hover { border-color: var(--red-soft); background: #fff0f1; color: var(--danger); }
.gallery-like.active { border-color: #ffb3b8; background: #fff0f1; color: var(--danger); }
.gallery-like:disabled { opacity: .6; cursor: wait; }
.gallery-icon-host { display: inline-flex; align-items: center; justify-content: center; width: 1rem; height: 1rem; flex: 0 0 auto; }
.gallery-icon { display: block; width: 1rem; height: 1rem; }
.gallery-like.active .gallery-icon { fill: currentColor; }
.gallery-like-count, .gallery-comment-count, .gallery-view-count { min-width: 12px; text-align: center; }
.gallery-comment-stat { cursor: pointer; }
.gallery-view-stat { cursor: default; }
span.gallery-view-stat:hover { border-color: var(--line); background: #fffefa; color: #8a6a55; }
button.gallery-view-stat { cursor: pointer; }

.gallery-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 24px;
}

.gallery-viewer { position: fixed; inset: 0; z-index: 120; display: grid; place-items: center; padding: 24px; }
.gallery-viewer-backdrop { position: absolute; inset: 0; background: rgba(74, 42, 36, .62); backdrop-filter: blur(3px); }
.gallery-viewer-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1120px, 100%);
  max-height: calc(100vh - 48px);
  overflow: hidden;
  border: 3px solid var(--line);
  border-radius: 26px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.gallery-viewer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 2px dashed var(--line);
}
.gallery-viewer-head-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; flex: 0 0 auto; }
.gallery-viewer-head h2 { font-size: 1rem; overflow-wrap: anywhere; }
.gallery-viewer-body {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, .8fr);
  gap: 18px;
  padding: 18px 20px 20px;
  overflow: auto;
}
.gallery-viewer-body img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 240px);
  object-fit: contain;
  background: #fff7e4;
  border: 2px solid var(--line);
  border-radius: 18px;
}
.gallery-viewer-meta { min-width: 0; }
.gallery-kv { display: grid; grid-template-columns: 1fr; gap: 0; margin: 0 0 14px; }
.gallery-kv > div { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px dashed rgba(255, 213, 140, .75); }
.gallery-kv dt { flex: 0 0 92px; color: var(--muted); font-size: .74rem; }
.gallery-kv dd { flex: 1; margin: 0; color: #6b4433; font-size: .78rem; overflow-wrap: anywhere; }
.gallery-text-block { margin-top: 14px; }
.gallery-text-block h3 { margin: 0 0 8px; color: #8a5a2b; font-size: .82rem; }
.gallery-long-text {
  margin: 0;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--panel-2);
  color: #6b4433;
  font-size: .8rem;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.gallery-comments {
  grid-column: 1 / -1;
  margin-top: 6px;
  padding-top: 18px;
  border-top: 2px dashed var(--line);
}
.gallery-comments-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.gallery-comments-head h3 { margin: 0; color: #58302a; font-size: .95rem; }
.gallery-comments-head h3 span { color: var(--muted); font-size: .78rem; font-weight: 700; }
.gallery-comments-list { display: grid; gap: 10px; }
.gallery-comment {
  padding: 11px 13px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--panel-2);
}
.gallery-comment-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.gallery-comment-name { color: #58302a; font-size: .8rem; font-weight: 800; overflow-wrap: anywhere; }
.gallery-comment-time { color: var(--muted); font-size: .68rem; white-space: nowrap; }
.gallery-comment-content { margin: 0; color: #6b4433; font-size: .8rem; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.gallery-comments-empty { color: var(--muted); font-size: .8rem; padding: 4px 0; }
.gallery-comments-more { display: block; width: 100%; margin: 12px 0 0; }
.gallery-comments-more.hidden { display: none; }
.comment-form { margin-top: 18px; padding-top: 16px; border-top: 2px dashed var(--line); }
.comment-textarea { min-height: 110px; margin-bottom: 8px; }
.comment-form-row { display: flex; justify-content: flex-end; margin: 0 0 8px; }
.comment-length { color: var(--muted); font-size: .72rem; font-weight: 700; }
.comment-length.over { color: var(--danger); }
.comment-mode { display: flex; flex-wrap: wrap; gap: 18px; margin: 0 0 12px; }
.comment-radio { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: #6b4433; font-size: .82rem; font-weight: 700; cursor: pointer; }
.comment-radio::before { content: none; }
.comment-radio input { width: 16px; height: 16px; margin: 0; padding: 0; box-shadow: none; accent-color: var(--accent); }
.comment-nickname-wrap { margin: 0 0 12px; }
.comment-nickname-wrap input { margin-bottom: 0; }
.comment-form .primary-button { margin-top: 4px; }
.comment-form .message { margin-top: 10px; }
body.viewer-open { overflow: hidden; }

@media (max-width: 820px) {
  .gallery-viewer { padding: 12px; }
  .gallery-viewer-card { max-height: calc(100vh - 24px); }
  .gallery-viewer-body { grid-template-columns: 1fr; }
  .gallery-viewer-body img { max-height: 52vh; }
}

@media (max-width: 760px) {
  .gallery-shell { width: min(100% - 24px, 620px); padding-top: 30px; }
  .gallery-topbar { flex-direction: column; }
  .gallery-home { margin-top: 0; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
}
