/* Dark theme baseline */
:root {
  color-scheme: dark;
  --bg: #0f1117;
  --panel: #161925;
  --surface: #1d2130;
  --border: #2a3042;
  --accent: #4cc3ff;
  --accent-strong: #1ea7ff;
  --text: #f4f6fb;
  --muted: #9aa1b5;
  --danger: #ff4d6d;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Roboto", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

img {
  max-width: 100%;
  display: block;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.hero__branding {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  align-items: center;
}

.hero__search {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  padding: 0 12px;
}

.hero__search input {
  width: min(640px, 100%);
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.hero h1 {
  margin: 0 0 4px;
  font-size: 20px;
}

.hero p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.logo {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  object-fit: cover;
}

.hero__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.ghost-button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
}

.ghost-button:hover {
  background: #252c3d;
  border-color: var(--accent);
}

.square-button,
.primary-button,
.secondary-button,
.danger-button,
.button-group button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
}

.square-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  font-weight: 700;
  text-transform: uppercase;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-color: transparent;
  color: #0b0c10;
  font-weight: 700;
}

.secondary-button {
  background: transparent;
}

.danger-button {
  background: rgba(255, 77, 109, 0.08);
  border-color: rgba(255, 77, 109, 0.4);
  color: #ffc8d4;
}

.button-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.button-group button {
  border: none;
  border-right: 1px solid var(--border);
  background: transparent;
  padding: 10px 12px;
}

.button-group button:last-child {
  border-right: none;
}

.button-group .active {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--accent);
}

.square-button:hover,
.primary-button:hover,
.secondary-button:hover,
.danger-button:hover,
.button-group button:hover {
  background: #252c3d;
  border-color: var(--accent);
}

.square-button:active,
.primary-button:active,
.secondary-button:active,
.danger-button:active,
.button-group button:active {
  transform: translateY(1px);
}

.content {
  flex: 1;
  padding: 16px;
}

.view {
  display: none;
}

.view--active {
  display: block;
}

.field {
  display: block;
  color: var(--text);
}

.field__label {
  display: inline-block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.field textarea {
  resize: vertical;
  min-height: 60px;
}

.field input[type="color"] {
  padding: 0;
  height: 42px;
  border-radius: 10px;
}

.field__hint {
  color: var(--muted);
  font-size: 12px;
}

.field--inline {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: center;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
}

.card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.card__thumb {
  background: #0c0f18;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
  padding-top: 75%;
}

.card__thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  opacity: 0;
  transition: opacity 180ms ease-out;
}

.card__thumb img.is-loaded {
  opacity: 1;
}

.card__title {
  margin: 0;
  font-weight: 600;
  font-size: 15px;
  text-align: center;
}

.empty-state {
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px dashed var(--border);
  color: var(--muted);
  text-align: center;
}

.gallery-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
}

.results-row {
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.load-more-row {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

.editor {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

.editor__canvas-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  height: 100%;
}

.dropzone {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.02);
  text-align: center;
}

.dropzone.is-hidden {
  display: none;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  background: rgba(76, 195, 255, 0.07);
}

.dropzone__title {
  margin: 0 0 4px;
  font-weight: 600;
}

.dropzone__hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.link-button {
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  font-weight: 600;
}

.canvas-wrapper {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#meme-canvas {
  display: block;
  border-radius: 8px;
  background: #0c0f18;
  margin: 0 auto;
  transform: none;
}

.canvas-overlay {
  position: absolute;
  inset: 12px;
  pointer-events: none;
}

.canvas-actions {
  display: none;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel__section {
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.panel__section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.panel__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.panel__section h3 {
  margin: 0;
  font-size: 16px;
}

.text-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.text-list__item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.text-list__item.active {
  border-color: var(--accent);
  background: rgba(76, 195, 255, 0.08);
}

.text-list__label {
  font-weight: 600;
}

.text-list__meta {
  display: none;
}

.panel__section--footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel__section--footer .primary-button,
#add-text {
  width: 100%;
}

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: var(--panel);
  border: 1px solid var(--accent);
  padding: 12px 14px;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

@media (max-width: 960px) {
  .hero {
    grid-template-columns: 1fr;
    align-items: flex-start;
    gap: 12px;
  }

  .hero__actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .editor {
    grid-template-columns: 1fr;
  }

  .panel {
    order: 2;
  }

  .editor__canvas-column {
    order: 1;
  }
}

@media (max-width: 768px) {
  body.editor-active .hero {
    position: static;
  }
  body.editor-active .hero__search {
    display: none;
  }
  body.editor-active .hero__actions {
    width: 100%;
    justify-content: flex-start;
    gap: 10px;
    flex-wrap: nowrap;
  }
  body.editor-active.header-hidden .hero__branding,
  body.editor-active.header-hidden .hero__actions {
    display: none;
  }
  body.editor-active .hero__actions .ghost-button {
    display: none;
  }
  body:not(.editor-active) .hero__actions {
    justify-content: flex-start;
    gap: 10px;
    flex-wrap: nowrap;
  }
  body:not(.editor-active) .hero__search {
    width: 100%;
  }
  body:not(.editor-active) .hero__search input {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .content {
    padding: 12px;
  }

  .square-button {
    width: 42px;
    height: 42px;
  }

  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .field--inline {
    grid-template-columns: 1fr;
  }
}

