:root {
  color-scheme: light;
  --bg: #fff8fc;
  --surface: #ffffff;
  --ink: #21172a;
  --muted: #75697d;
  --line: #eadfed;
  --coral: #ff5d6c;
  --violet: #7d4dff;
  --lime: #b8f24b;
  --cyan: #38c7ff;
  --shadow: 0 18px 50px rgba(68, 38, 85, 0.14);
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-top, 0px), var(--tg-content-safe-top, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-right, 0px), var(--tg-content-safe-right, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom, 0px), var(--tg-content-safe-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-left, 0px), var(--tg-content-safe-left, 0px));
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 18% 0%, rgba(255, 93, 108, 0.20), transparent 30%),
    radial-gradient(circle at 92% 8%, rgba(184, 242, 75, 0.28), transparent 28%),
    linear-gradient(180deg, #fff8fc 0%, #f7fbff 48%, #fffdf3 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

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

.screen {
  width: min(100%, 760px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) calc(16px + var(--safe-right)) calc(94px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.gate,
.boot-state {
  min-height: calc(100vh - 120px);
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 14px;
}

.gate h1,
.boot-state h1,
.topbar h1,
.section-head h2 {
  margin: 0;
  line-height: 1.04;
}

.gate h1,
.boot-state h1 {
  max-width: 11ch;
  font-size: 42px;
}

.gate p,
.boot-state p,
.section-head p,
.detail-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.logo-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(33, 23, 42, 0.10);
  border-radius: 18px;
  background: linear-gradient(135deg, var(--coral), var(--violet) 52%, var(--lime));
  color: white;
  font-size: 32px;
  font-weight: 900;
  box-shadow: var(--shadow);
}

.pulse {
  animation: pulse 1.3s ease-in-out infinite;
}

@keyframes pulse {
  50% { transform: translateY(-3px) scale(1.03); }
}

.primary-link,
.primary-button,
.secondary-button,
.icon-button,
.nav-item,
.category-chip,
.danger-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.primary-link,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  background: var(--ink);
  color: white;
  text-decoration: none;
  font-weight: 800;
}

.secondary-button {
  padding: 12px 16px;
  background: #f1edf4;
  color: var(--muted);
  font-weight: 800;
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.78;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--violet);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.topbar h1 {
  font-size: 36px;
}

.hello {
  min-height: 44px;
  max-width: 46%;
  display: grid;
  align-content: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.notice,
.state-box,
.form-error {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  padding: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.notice {
  margin-bottom: 16px;
  border-color: rgba(255, 93, 108, 0.24);
  background: #fff0f3;
}

.panel {
  display: grid;
  gap: 14px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.icon-button {
  width: 44px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 23px;
  font-weight: 900;
}

.category-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 3px 1px 8px;
  scrollbar-width: none;
}

.category-row::-webkit-scrollbar {
  display: none;
}

.category-chip {
  flex: 0 0 auto;
  padding: 0 14px;
  background: #ffffff;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 850;
}

.category-chip.is-active {
  background: var(--lime);
  border-color: rgba(33, 23, 42, 0.12);
}

.template-grid,
.jobs-list {
  display: grid;
  gap: 14px;
}

.template-card,
.job-card {
  width: 100%;
  border: 1px solid rgba(33, 23, 42, 0.09);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 28px rgba(68, 38, 85, 0.10);
  overflow: hidden;
}

.template-card {
  padding: 0;
  text-align: left;
  color: inherit;
}

.template-card:focus-visible,
.category-chip:focus-visible,
.nav-item:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.icon-button:focus-visible,
.danger-button:focus-visible,
.close-button:focus-visible,
.primary-link:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 2px;
}

.template-card img,
.detail-cover {
  width: 100%;
  display: block;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: #f2eef6;
}

.template-body,
.job-card {
  padding: 13px;
}

.cover-label {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 4px 8px;
  border-radius: 8px;
  background: #fff4bb;
  color: #5d4a00;
  font-size: 12px;
  font-weight: 900;
}

.template-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
}

.template-title-row h3,
.job-card h3 {
  margin: 0;
  font-size: 20px;
  line-height: 1.14;
}

.template-card p,
.job-card p {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.42;
}

.template-icon {
  min-width: 32px;
  min-height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f5f0ff;
  font-weight: 900;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 11px;
}

.meta-row span {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 8px;
  background: #f4f0f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 8;
  width: min(100%, 760px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  border-top: 1px solid rgba(33, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
}

.nav-item {
  display: grid;
  grid-template-columns: 24px auto;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.nav-item.is-active {
  background: var(--ink);
  color: white;
}

.detail-sheet {
  width: min(100% - 20px, 720px);
  max-height: calc(100dvh - 20px);
  border: 0;
  border-radius: 12px;
  padding: 0;
  background: transparent;
}

.detail-sheet::backdrop {
  background: rgba(33, 23, 42, 0.38);
}

.sheet-card {
  position: relative;
  display: grid;
  gap: 14px;
  max-height: calc(100dvh - 20px);
  overflow: auto;
  padding: 12px;
  background: var(--surface);
  border-radius: 12px;
}

.close-button {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.detail-copy {
  display: grid;
  gap: 9px;
  padding: 0 2px;
}

.detail-copy h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.08;
}

.upload-box,
.field {
  display: grid;
  gap: 8px;
}

.upload-box {
  min-height: 132px;
  align-content: center;
  padding: 16px;
  border: 2px dashed rgba(125, 77, 255, 0.36);
  border-radius: 8px;
  background: #fbf8ff;
  cursor: pointer;
}

.upload-box input {
  width: 100%;
  min-height: 44px;
}

.upload-title,
.field span {
  color: var(--ink);
  font-weight: 900;
}

.upload-hint {
  color: var(--muted);
  line-height: 1.4;
}

.preview-card {
  display: grid;
  grid-template-columns: 86px 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.preview-card img {
  width: 86px;
  height: 86px;
  object-fit: cover;
  border-radius: 8px;
  background: #f1edf4;
}

.preview-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

textarea {
  width: 100%;
  min-height: 112px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  resize: vertical;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.job-card {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 12px;
  align-items: start;
}

.job-thumb {
  width: 82px;
  height: 82px;
  border-radius: 8px;
  object-fit: cover;
  background: #f1edf4;
}

.job-main {
  min-width: 0;
}

.job-prompt {
  overflow-wrap: anywhere;
}

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

.danger-button {
  padding: 10px 12px;
  background: #fff0f3;
  color: #b71934;
  font-weight: 900;
}

[hidden] {
  display: none !important;
}

@media (min-width: 360px) and (max-width: 639px) {
  .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .template-body { padding: 10px; }
  .template-title-row h3 { font-size: 16px; overflow-wrap: anywhere; }
  .template-title-row { gap: 4px; }
  .template-icon { min-width: 24px; min-height: 24px; }
  .template-card p { font-size: 12px; }
  .template-card .cover-label { font-size: 10px; padding: 3px 5px; min-height: 24px; }
  .template-card .meta-row { gap: 4px; }
  .template-card .meta-row span { font-size: 10px; padding: 3px 5px; min-height: 23px; }
}

.upload-box input[type="file"] {
  position: absolute; width: 1px; height: 1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.upload-box:focus-within { outline: 3px solid var(--cyan); outline-offset: 3px; }

@media (min-width: 640px) {
  .screen {
    padding-inline: 24px;
  }

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

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

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