:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #172124;
  --muted: #667274;
  --soft: #f5f8f8;
  --line: #dce6e5;
  --panel: #ffffff;
  --accent: #0f9f9a;
  --accent-strong: #087b78;
  --accent-soft: #dff6f3;
  --coral: #ff735c;
  --yellow: #ffcb5b;
  --shadow: 0 18px 45px rgba(30, 50, 48, 0.1);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(15, 159, 154, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(15, 159, 154, 0.04) 1px, transparent 1px),
    var(--bg);
  background-size: 36px 36px;
  color: var(--ink);
  font-family: var(--font);
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: 100vh;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--yellow);
  box-shadow: 5px 5px 0 var(--ink);
  color: var(--ink);
  font-weight: 900;
}

.brand h1,
.brand p,
.panel-heading h2,
.panel-heading p,
.dialog-head h2,
.dialog-head p,
.empty-state h3,
.empty-state p {
  margin: 0;
}

.brand h1 {
  font-size: 22px;
  line-height: 1.15;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.category-list {
  display: grid;
  gap: 8px;
}

.category-btn {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.category-btn:hover {
  background: var(--soft);
}

.category-btn.active {
  border-color: rgba(15, 159, 154, 0.35);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.cat-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: #eef4f4;
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 800;
}

.cat-name {
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-count {
  min-width: 26px;
  padding: 3px 7px;
  border-radius: 99px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
}

.storage-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(15, 159, 154, 0.12);
}

.workspace {
  min-width: 0;
  padding: 22px 24px 28px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) auto auto auto;
  align-items: center;
  gap: 12px;
}

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

.search-wrap {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 8px 24px rgba(31, 54, 52, 0.05);
  color: var(--muted);
}

.search-wrap input {
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  font-size: 15px;
}

.search-wrap input::placeholder {
  color: #8b9799;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.icon-btn,
.mini-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: var(--radius);
  font-weight: 800;
  line-height: 1;
}

.primary-btn {
  border: 1px solid var(--accent-strong);
  background: var(--accent);
  color: white;
  padding: 0 15px;
  box-shadow: 0 9px 18px rgba(15, 159, 154, 0.22);
}

.primary-btn:hover {
  background: var(--accent-strong);
}

.primary-btn svg,
.ghost-btn svg,
.danger-btn svg,
.icon-btn svg,
.mini-action svg {
  width: 18px;
  height: 18px;
}

.ghost-btn {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  padding: 0 14px;
}

.ghost-btn:hover,
.danger-btn:hover,
.icon-btn:hover,
.mini-action:hover {
  border-color: rgba(15, 159, 154, 0.45);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.danger-btn {
  border: 1px solid #ffd5cf;
  background: #fff7f5;
  color: #b84231;
  padding: 0 14px;
}

.danger-btn:hover {
  border-color: #ff9c8c;
  background: #ffe8e3;
  color: #942d20;
}

.filter-band {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin: 22px 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
}

.section-label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-chip {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: white;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.tag-chip.active,
.tag-chip:hover {
  border-color: rgba(15, 159, 154, 0.45);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.library-count {
  align-self: flex-start;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  align-items: start;
  gap: 20px;
}

.library-panel,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.library-panel {
  min-height: 640px;
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-heading h2 {
  font-size: 24px;
  line-height: 1.2;
}

.panel-heading p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.sort-control {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.sort-control select {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

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

.meme-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.meme-card:hover {
  transform: translateY(-2px);
  border-color: rgba(15, 159, 154, 0.45);
  box-shadow: 0 12px 28px rgba(31, 54, 52, 0.12);
}

.meme-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 159, 154, 0.16);
}

.thumb-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.thumb {
  position: relative;
  aspect-ratio: 1 / 0.78;
  overflow: hidden;
  background: var(--soft);
}

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

.category-badge {
  position: absolute;
  top: 9px;
  left: 9px;
  max-width: calc(100% - 18px);
  padding: 5px 8px;
  border: 1px solid rgba(23, 33, 36, 0.12);
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-body {
  padding: 12px;
}

.card-title {
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.35;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
  margin: 8px 0 12px;
}

.tiny-tag {
  padding: 4px 7px;
  border-radius: 99px;
  background: #f0f5f5;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mini-action {
  min-height: 34px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  font-size: 12px;
}

.detail-panel {
  position: sticky;
  top: 22px;
  padding: 16px;
}

.detail-image {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
}

.detail-image img {
  display: block;
  width: 100%;
  max-height: 330px;
  object-fit: contain;
}

.detail-title {
  margin: 14px 0 7px;
  overflow-wrap: anywhere;
  font-size: 22px;
  line-height: 1.2;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.meta-pill {
  padding: 6px 9px;
  border-radius: 99px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.detail-note {
  margin: 0 0 16px;
  padding: 12px;
  border-left: 3px solid var(--coral);
  background: #fff6f3;
  color: #5e3530;
  font-size: 13px;
  line-height: 1.6;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.detail-actions .wide-action {
  grid-column: 1 / -1;
}

.detail-empty {
  display: grid;
  place-items: center;
  min-height: 500px;
  color: var(--muted);
  text-align: center;
}

.detail-empty svg {
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  color: var(--accent);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  padding: 36px;
  color: var(--muted);
  text-align: center;
}

.empty-state[hidden],
[hidden] {
  display: none !important;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin-bottom: 14px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--yellow);
  box-shadow: 5px 5px 0 var(--ink);
  color: var(--ink);
  font-size: 34px;
  font-weight: 900;
}

.empty-state h3 {
  color: var(--ink);
  font-size: 21px;
}

.empty-state p {
  max-width: 380px;
  margin: 8px 0 18px;
  line-height: 1.6;
}

.upload-dialog {
  width: min(720px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(23, 33, 36, 0.26);
}

.upload-dialog::backdrop {
  background: rgba(23, 33, 36, 0.42);
  backdrop-filter: blur(2px);
}

.upload-card {
  padding: 22px;
  background: white;
}

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

.dialog-head h2 {
  font-size: 24px;
}

.dialog-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  padding: 0;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 165px;
  margin-bottom: 16px;
  padding: 22px;
  border: 1.5px dashed rgba(15, 159, 154, 0.52);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-strong);
  text-align: center;
}

.drop-zone.dragging {
  background: #cef0ec;
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.drop-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  background: white;
}

.drop-icon svg {
  width: 25px;
  height: 25px;
}

.drop-zone strong {
  margin-bottom: 5px;
  color: var(--ink);
  font-size: 16px;
}

.drop-zone small {
  color: var(--muted);
}

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

.form-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.wide-field {
  grid-column: 1 / -1;
}

.form-grid input,
.form-grid textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  background: white;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

.form-grid input {
  height: 42px;
  padding: 0 11px;
}

.form-grid textarea {
  resize: vertical;
  min-height: 84px;
  padding: 11px;
}

.form-grid input:focus,
.form-grid textarea:focus,
.sort-control select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 159, 154, 0.14);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid rgba(15, 159, 154, 0.25);
  border-radius: var(--radius);
  background: #152324;
  color: white;
  font-size: 14px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .content-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .category-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    padding: 16px;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .filter-band,
  .panel-heading {
    display: grid;
  }

  .library-count {
    white-space: normal;
  }

  .meme-grid {
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

.maker-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 14px 0 4px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-soft), #ffffff 70%);
  color: var(--ink);
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.maker-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.maker-eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.maker-card strong {
  font-size: 16px;
}

.maker-note {
  font-size: 12px;
  color: var(--muted);
}

.maker-cta {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-strong);
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.page-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

.page-btn:hover:not(:disabled):not(.active) {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.page-btn.active {
  border-color: var(--accent-strong);
  background: var(--accent);
  color: #fff;
  cursor: default;
}

.page-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.page-ellipsis {
  color: var(--muted);
  padding: 0 2px;
}

.page-info {
  margin-left: 6px;
  font-size: 13px;
  color: var(--muted);
}

/* 登入 / 會員狀態 */
.auth-control {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.google-btn:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.google-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  color: #4285f4;
  font-weight: 900;
  font-size: 13px;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px 5px 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft) center / cover no-repeat;
  color: var(--accent-strong);
  font-weight: 900;
  font-size: 14px;
  flex: none;
}

.user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.user-name {
  font-weight: 800;
  font-size: 13px;
  color: var(--ink);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  font-size: 11px;
  color: var(--muted);
}

.user-role.is-admin {
  color: var(--accent-strong);
  font-weight: 800;
}

.logout-btn {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}
