:root {
  --bg: #f7f7f4;
  --panel: #ffffff;
  --ink: #232522;
  --muted: #6b706a;
  --line: #d9ddd5;
  --accent: #146c64;
  --accent-strong: #0d4f49;
  --danger: #b42318;
  --shadow: 0 10px 28px rgba(26, 31, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

a {
  color: var(--accent);
}

.topbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  height: 58px;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  color: var(--ink);
  font-size: 18px;
  font-weight: 750;
  text-decoration: none;
}

.page {
  margin: 0 auto;
  max-width: 1420px;
  padding: 24px;
}

.workspace {
  display: grid;
  gap: 24px;
  grid-template-columns: 340px 1fr;
}

.upload-panel,
.library-panel,
.auth-panel,
.edit-layout {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.upload-panel {
  align-self: start;
  padding: 20px;
  position: sticky;
  top: 82px;
}

.library-panel {
  min-width: 0;
  padding: 18px;
}

h1 {
  font-size: 22px;
  line-height: 1.15;
  margin: 0 0 18px;
}

h2 {
  font-size: 14px;
  line-height: 1.25;
  margin: 0;
  overflow-wrap: anywhere;
}

.form-stack {
  display: grid;
  gap: 14px;
}

label,
.tag-field > label {
  color: var(--muted);
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 650;
}

input[type="text"],
input[type="url"],
input[type="password"],
input[type="search"],
input[type="file"],
.tag-field [data-tag-input] {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 40px;
  padding: 8px 10px;
  width: 100%;
}

input:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(20, 108, 100, 0.18);
}

.button,
button {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  min-height: 36px;
  padding: 7px 11px;
  text-decoration: none;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

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

.button.ghost {
  background: transparent;
}

.button.secondary {
  background: #f8faf7;
  border-color: #dfe4dc;
  color: #34423e;
  font-weight: 700;
}

.button.secondary:hover {
  background: #eef5f2;
  border-color: #cbdcd5;
}

.search-row {
  align-items: center;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(180px, 1fr) auto;
  margin-bottom: 18px;
}

.search-row span {
  color: var(--muted);
  font-size: 13px;
}

.meme-grid {
  align-items: stretch;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  min-width: 0;
  overflow: hidden;
  width: 100%;
}

@media (max-width: 520px) {
  .meme-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.meme-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  contain: layout paint;
  display: flex;
  flex-direction: column;
  justify-self: stretch;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
  width: 100%;
}

.meme-card > * {
  min-width: 0;
  max-width: 100%;
}

.meme-card * {
  min-width: 0;
}

.meme-card:hover {
  border-color: #bdc7bf;
  box-shadow: 0 8px 20px rgba(26, 31, 28, 0.1);
  transform: translateY(-1px);
}

.thumb-button {
  aspect-ratio: 1 / 1;
  background: #ecefe9;
  border: 0;
  border-radius: 0;
  display: block;
  max-width: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  position: relative;
  width: 100%;
}

.thumb-button img {
  display: block;
  inset: 0;
  height: 100%;
  max-width: 100%;
  object-fit: cover;
  overflow: hidden;
  position: absolute;
  width: 100%;
}

.meme-meta {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 9px;
  max-width: 100%;
  min-height: max-content;
  min-width: 0;
  padding: 12px;
  width: 100%;
}

.tag-list,
.tag-chips,
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-chips button,
.tag-cloud button {
  background: #eaf2ef;
  border: 1px solid #cfe2dc;
  border-radius: 999px;
  color: #23413d;
  font-size: 12px;
  min-height: 26px;
  padding: 3px 8px;
}

.tag-list {
  min-height: 20px;
}

.tag-list span {
  align-items: center;
  background: #edf4f1;
  border: 1px solid #d3e2dc;
  border-radius: 999px;
  color: #23413d;
  display: inline-flex;
  font-size: 11px;
  font-weight: 650;
  height: 20px;
  line-height: 1;
  max-width: 100%;
  overflow: hidden;
  padding: 0 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-cloud {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 16px;
}

.card-actions {
  align-items: center;
  border-top: 1px solid #edf0ea;
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: auto;
  max-width: 100%;
  min-width: 0;
  padding-top: 10px;
  width: 100%;
}

.card-action {
  align-items: center;
  background: #f8faf7;
  border: 1px solid #dfe4dc;
  border-radius: 6px;
  color: #34423e;
  display: inline-flex;
  height: 34px;
  justify-content: center;
  min-height: 34px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  padding: 0;
  text-decoration: none;
  width: 100%;
}

.card-action:hover {
  background: #eef5f2;
  border-color: #cbdcd5;
  color: var(--accent-strong);
}

.card-action svg {
  fill: none;
  flex: 0 0 17px;
  height: 17px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 17px;
}

.card-action.copied {
  background: #eaf2ef;
  border-color: #b9d5cc;
  color: var(--accent-strong);
}

.card-action.danger {
  color: var(--danger);
}

.card-action.danger:hover {
  background: #fff2f1;
  border-color: #f0c5c0;
  color: #8f1b12;
}

.card-actions form {
  display: contents;
  margin: 0;
}

.card-actions form .card-action {
  display: flex;
  width: 100%;
}

.tag-field {
  display: grid;
  gap: 8px;
  position: relative;
}

.suggestions {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  display: none;
  left: 0;
  max-height: 190px;
  overflow: auto;
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 10;
}

.suggestions button {
  background: #fff;
  border: 0;
  border-radius: 0;
  display: block;
  text-align: left;
  width: 100%;
}

.suggestions button:hover {
  background: #f1f4ef;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.message {
  background: #eef6f0;
  border: 1px solid #cfe6d5;
  border-radius: 6px;
  padding: 10px 12px;
}

.message.error {
  background: #fff0ef;
  border-color: #ffd0cc;
}

.auth-panel {
  margin: 60px auto;
  max-width: 380px;
  padding: 24px;
}

.edit-layout {
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(220px, 380px) minmax(280px, 1fr);
  padding: 20px;
}

.edit-preview {
  background: #ecefe9;
  border-radius: 8px;
  display: block;
  width: 100%;
}

.action-row {
  display: flex;
  gap: 10px;
}

.edit-actions {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  margin-top: 4px;
  padding-top: 16px;
}

.edit-actions .button {
  min-height: 42px;
  width: 100%;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 32px;
  text-align: center;
}

.load-sentinel {
  color: var(--muted);
  font-size: 13px;
  min-height: 44px;
  padding: 18px 0 4px;
  text-align: center;
}

.load-sentinel[hidden] {
  display: none;
}

.image-modal {
  background: #111;
  border: 0;
  border-radius: 8px;
  max-height: 92vh;
  max-width: 92vw;
  padding: 0;
}

.image-modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.image-modal img {
  display: block;
  max-height: calc(92vh - 52px);
  max-width: 92vw;
}

.modal-toolbar {
  align-items: center;
  background: #fff;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 8px;
}

.icon-button {
  font-weight: 800;
  width: 36px;
}

@media (max-width: 860px) {
  .page {
    padding: 14px;
  }

  .workspace,
  .edit-layout {
    grid-template-columns: 1fr;
  }

  .upload-panel {
    position: static;
  }

  .card-actions {
    gap: 5px;
  }
}
