:root {
  --bg: #fbf5f2;
  --surface: #ffffff;
  --text: #2d2126;
  --muted: #86727a;
  --accent: #e0567a;
  --line: #ead9d5;
  --green: #22c55e;
  --blue: #3b82f6;
  --red: #ef4444;
  --ring: 5px;
  --radius: 24px;
  --shadow: 0 10px 30px rgba(70, 30, 45, 0.12);
  --cheese: #ffc93c;
  --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140' viewBox='0 0 140 140'%3E%3Cg fill='%23e0567a14'%3E%3Cg transform='translate(28 32) rotate(-18)'%3E%3Cellipse cy='7' rx='8' ry='6.5'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-7' r='3'/%3E%3Ccircle cx='3' cy='-7' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3Cg transform='translate(98 102) rotate(24)'%3E%3Cellipse cy='7' rx='8' ry='6.5'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-7' r='3'/%3E%3Ccircle cx='3' cy='-7' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17121a;
    --surface: #221b26;
    --text: #f4ecef;
    --muted: #a594a0;
    --accent: #f27497;
    --line: #3a2f3f;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140' viewBox='0 0 140 140'%3E%3Cg fill='%23f2749712'%3E%3Cg transform='translate(28 32) rotate(-18)'%3E%3Cellipse cy='7' rx='8' ry='6.5'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-7' r='3'/%3E%3Ccircle cx='3' cy='-7' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3Cg transform='translate(98 102) rotate(24)'%3E%3Cellipse cy='7' rx='8' ry='6.5'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-7' r='3'/%3E%3Ccircle cx='3' cy='-7' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #17121a;
  --surface: #221b26;
  --text: #f4ecef;
  --muted: #a594a0;
  --accent: #f27497;
  --line: #3a2f3f;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140' viewBox='0 0 140 140'%3E%3Cg fill='%23f2749712'%3E%3Cg transform='translate(28 32) rotate(-18)'%3E%3Cellipse cy='7' rx='8' ry='6.5'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-7' r='3'/%3E%3Ccircle cx='3' cy='-7' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3Cg transform='translate(98 102) rotate(24)'%3E%3Cellipse cy='7' rx='8' ry='6.5'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-7' r='3'/%3E%3Ccircle cx='3' cy='-7' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--pattern), var(--bg);
  background-size: 140px 140px, auto;
  color: var(--text);
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
}

.top {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.top h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.top__title {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: 18px;
  box-shadow: var(--shadow);
  animation: wiggle 6s ease-in-out infinite;
  transform-origin: 50% 80%;
}

@keyframes wiggle {
  0%, 88%, 100% { transform: rotate(0); }
  91% { transform: rotate(-8deg); }
  94% { transform: rotate(7deg); }
  97% { transform: rotate(-4deg); }
}

.top__sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.top__side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.dot--requested { background: var(--green); }
.dot--in_progress { background: var(--blue); }
.dot--cancelled { background: var(--red); }

.top__buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.pill {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.pill[hidden] {
  display: none;
}

.pill:disabled {
  cursor: default;
  opacity: 0.7;
}

.grid {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 24px 64px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 28px;
}

.card {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  outline: none;
  transition: box-shadow 0.3s ease, transform 0.2s ease;
}

@media (hover: hover) {
  .card:hover {
    transform: translateY(-3px);
  }
}

.card:focus-visible {
  box-shadow: 0 0 0 3px var(--accent), var(--shadow);
}

.card.status-requested {
  box-shadow: 0 0 0 var(--ring) var(--green), var(--shadow);
}

.card.status-in_progress {
  box-shadow: 0 0 0 var(--ring) var(--blue), var(--shadow);
}

.card.is-cancelled {
  animation: cancelled-glow 2.4s ease-in-out infinite;
}

@keyframes cancelled-glow {
  0%, 100% { box-shadow: 0 0 0 var(--ring) var(--red), 0 0 18px 4px rgba(239, 68, 68, 0.45); }
  50% { box-shadow: 0 0 0 var(--ring) var(--red), 0 0 36px 12px rgba(239, 68, 68, 0.7); }
}

.card__img,
.card__ph {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.card__img {
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.5s ease, transform 0.6s ease;
}

.card__img.is-loaded {
  opacity: 1;
}

@media (hover: hover) {
  .card:hover .card__img {
    transform: scale(1.04);
  }
}

.card__ph {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-bottom: 22%;
  font-size: 64px;
  background: linear-gradient(135deg, hsl(var(--h1) 80% 78%), hsl(var(--h2) 75% 70%));
}

.card__ph small {
  font-size: 14px;
  font-weight: 700;
  color: rgba(40, 20, 30, 0.7);
}

.card__ph.is-generating small::after {
  content: "…";
  animation: dots 1.2s steps(4) infinite;
  display: inline-block;
  width: 1.2em;
  overflow: hidden;
  vertical-align: bottom;
}

@keyframes dots {
  from { width: 0; }
  to { width: 1.2em; }
}

.card__caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 48px 18px 16px;
  background: linear-gradient(to top, rgba(15, 5, 10, 0.78), rgba(15, 5, 10, 0));
  color: #fff;
  font-weight: 800;
  font-size: 19px;
  line-height: 1.2;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.card__count[hidden] {
  display: none;
}

.card__count {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0.8;
}

.badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.badge[hidden] {
  display: none;
}

.badge--requested { background: var(--green); }
.badge--in_progress { background: var(--blue); }
.badge--cancelled { background: var(--red); }

.card__overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  background: rgba(20, 8, 14, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

@media (hover: hover) {
  .card:hover .card__overlay,
  .card:focus-within .card__overlay {
    opacity: 1;
    visibility: visible;
  }
}

.card.show-actions .card__overlay {
  opacity: 1;
  visibility: visible;
}

.card__note {
  max-width: 220px;
  line-height: 1.35;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
}

.card__tools {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
}

.tool {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #2d2126;
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease;
}

.tool:hover {
  transform: scale(1.1);
}

.tool:disabled {
  opacity: 0.5;
  cursor: progress;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 11px 22px;
  min-width: 160px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn--request { background: var(--green); }
.btn--start { background: var(--blue); }
.btn--complete { background: var(--green); }
.btn--cancel { background: #fff; color: var(--red); }
.btn--danger { background: var(--red); }
.btn--ghost {
  background: transparent;
  color: var(--text);
  box-shadow: none;
  border: 1px solid var(--line);
}

.card--add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed var(--line);
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-weight: 800;
  font-size: 17px;
}

.card--add span {
  font-size: 56px;
  line-height: 1;
  font-weight: 400;
}

.card--add small {
  font-size: 30px;
}

@media (hover: hover) {
  .card--add:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
}

.footer {
  padding: 0 16px 40px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.toast::before {
  content: "🐾 ";
}

.toasts {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  width: 100%;
  padding: 14px 18px;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-weight: 700;
  animation: toast-in 0.3s ease;
  pointer-events: auto;
}

.toast.is-leaving {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(12px); }
}

.dialog {
  border: 0;
  border-radius: 22px;
  padding: 0;
  width: min(400px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(20, 8, 14, 0.5);
  backdrop-filter: blur(2px);
}

.dialog__form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.dialog__text {
  margin: 0;
  white-space: pre-line;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.35;
}

.dialog__input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 17px;
}

.dialog__input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog__actions .btn {
  min-width: 0;
}

@media (max-width: 560px) {
  .top {
    padding: 22px 16px 4px;
  }

  .top__side {
    align-items: flex-start;
  }

  .top__buttons {
    justify-content: flex-start;
  }

  .card__note {
    font-size: 13px;
  }

  .logo {
    width: 48px;
    height: 48px;
    border-radius: 14px;
  }

  .grid {
    padding: 16px 16px 48px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
  }

  :root {
    --ring: 4px;
    --radius: 18px;
  }

  .card__caption {
    padding: 36px 12px 10px;
    font-size: 15px;
  }

  .btn {
    min-width: 0;
    width: 100%;
    padding: 9px 12px;
    font-size: 14px;
  }

  .card__overlay {
    padding: 12px;
    gap: 8px;
  }

  .card__ph {
    font-size: 44px;
  }

  .tool {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }

  .badge {
    top: 8px;
    left: 8px;
    font-size: 11px;
    padding: 4px 8px;
  }
}
