:root {
  color-scheme: light;
  --bg: #f7f5f0;
  --panel: #ffffff;
  --panel-2: #f0eee8;
  --field: #ffffff;
  --ink: #202020;
  --muted: #67635d;
  --line: #d8d3c9;
  --accent: #f05a3d;
  --accent-ink: #ffffff;
  --green: #2f8d67;
  --blue: #3577a8;
  --topbar-bg: rgba(247, 245, 240, 0.94);
  --active-ink: #ffffff;
  --error: #b42318;
  --canvas-bg: #23201e;
  --shadow: 0 18px 50px rgba(32, 32, 32, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121416;
  --panel: #191c20;
  --panel-2: #252a30;
  --field: #101214;
  --ink: #f2eee8;
  --muted: #ada79f;
  --line: #363c44;
  --accent: #ff765d;
  --accent-ink: #1a0c08;
  --green: #55b889;
  --blue: #6ca7d6;
  --topbar-bg: rgba(18, 20, 22, 0.94);
  --active-ink: #101214;
  --error: #ff897f;
  --canvas-bg: #090a0c;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.42);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121416;
    --panel: #191c20;
    --panel-2: #252a30;
    --field: #101214;
    --ink: #f2eee8;
    --muted: #ada79f;
    --line: #363c44;
    --accent: #ff765d;
    --accent-ink: #1a0c08;
    --green: #55b889;
    --blue: #6ca7d6;
    --topbar-bg: rgba(18, 20, 22, 0.94);
    --active-ink: #101214;
    --error: #ff897f;
    --canvas-bg: #090a0c;
    --shadow: 0 18px 55px rgba(0, 0, 0, 0.42);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  min-height: 100vh;
}

.boot {
  margin: 0;
  padding: 24px;
  color: var(--muted);
}

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 900;
  letter-spacing: 0;
}

.brand h1,
.brand h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.1;
}

.muted {
  color: var(--muted);
}

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

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 11px 12px;
  outline: 0;
}

.field textarea {
  min-height: 132px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240, 90, 61, 0.17);
}

.btn {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-weight: 800;
}

.btn.primary {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.btn.ghost {
  background: transparent;
}

.btn.good {
  color: var(--active-ink);
  background: var(--green);
  border-color: var(--green);
}

.notice {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.notice.error {
  color: var(--error);
}

.notice.ok {
  color: var(--green);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nav button {
  min-height: 36px;
  border-radius: 8px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.nav button.active {
  background: var(--ink);
  color: var(--active-ink);
}

.workspace {
  width: min(1380px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.meme-layout {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.tool-panel,
.preview-panel,
.settings-panel,
.admin-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tool-panel,
.settings-panel,
.admin-panel {
  padding: 16px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title h2,
.section-title h3 {
  margin: 0;
  font-size: 1rem;
}

.people-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.person-card {
  min-width: 0;
  border-radius: 8px;
  border: 2px solid transparent;
  padding: 6px;
  background: var(--panel-2);
  color: var(--ink);
  text-align: left;
}

.person-card.active {
  border-color: var(--accent);
  background: var(--field);
}

.person-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
}

.person-card span {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 800;
  font-size: 0.85rem;
}

.segments {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.segments button {
  min-height: 38px;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 800;
}

.segments button.active {
  color: var(--active-ink);
  background: var(--blue);
  border-color: var(--blue);
}

.stack {
  display: grid;
  gap: 16px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.preview-panel {
  padding: 14px;
}

.canvas-wrap {
  display: grid;
  place-items: center;
  min-height: 420px;
  border-radius: 8px;
  background: var(--canvas-bg);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100vh - 150px);
  object-fit: contain;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.table th,
.table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 18px;
}

.shortcut-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.empty-state {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.small {
  font-size: 0.86rem;
  margin: 0 0 4px;
}

.brand p {
  margin: 4px 0 0;
  font-size: 0.9rem;
}

.auth-lang {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.lang-btn {
  min-height: 34px;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 800;
}

.lang-btn.active {
  color: var(--active-ink);
  background: var(--ink);
  border-color: var(--ink);
}

.lang-segments button.active {
  color: var(--active-ink);
  background: var(--ink);
  border-color: var(--ink);
}

.theme-segments button.active {
  color: var(--active-ink);
  background: var(--ink);
  border-color: var(--ink);
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .meme-layout,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .canvas-wrap {
    min-height: 280px;
  }
}

@media (max-width: 520px) {
  .workspace,
  .topbar {
    padding-left: 12px;
    padding-right: 12px;
  }

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

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

  .shortcut-row {
    grid-template-columns: 1fr;
  }
}
