:root {
  color-scheme: dark;
  --bg: #0b1733;
  --bg-soft: #0f1e3c;
  --panel: #142444;
  --panel-strong: #1a2c52;
  --ink: #f4f8ff;
  --muted: #aebbd2;
  --quiet: #7888a8;
  --line: #2a416c;
  --line-soft: rgba(174, 187, 210, 0.18);
  --gold: #f3d47d;
  --mint: #8ad9aa;
  --sky: #9ecbff;
  --coral: #ffaaa2;
  --violet: #c9c0ff;
  --lime: #cbefb1;
  --peach: #ffd5ae;
  --shadow: 0 22px 58px rgba(3, 8, 23, 0.36);
  --soft-shadow: 0 16px 36px rgba(4, 9, 26, 0.28);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #101f3f 0%, #0b1733 38%, #08132d 100%);
}

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

button {
  cursor: pointer;
}

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

a {
  color: inherit;
}

.app-shell {
  width: min(1240px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 56px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 3px solid rgba(138, 217, 170, 0.92);
  border-radius: 50%;
  background: #e8ecff;
  box-shadow: 0 0 0 5px rgba(138, 217, 170, 0.14), var(--soft-shadow);
}

.brand-mark::before {
  content: "P";
  color: #27304a;
  font-size: 1.35rem;
  font-weight: 950;
  line-height: 1;
}

.brand-mark span {
  position: absolute;
  right: 8px;
  top: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #7b78ff;
  box-shadow: -12px 16px 0 #ffb24f, 10px 15px 0 #89d9aa;
}

.brand-name {
  font-size: 1.52rem;
  font-weight: 950;
  letter-spacing: 0;
}

.topbar-actions,
.toolbar-row,
.form-actions,
.detail-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button,
.sync-button,
.tab-button,
.icon-button,
.link-button {
  border: 0;
  color: var(--ink);
}

.button,
.sync-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: var(--radius);
  padding: 0 14px;
  font-weight: 800;
}

.primary-button {
  background: #e9edff;
  color: #17213d;
  box-shadow: var(--soft-shadow);
}

.secondary-button {
  background: #1b2b50;
  border: 1px solid var(--line);
}

.danger-action-button {
  background: var(--coral);
  color: #241015;
  box-shadow: var(--soft-shadow);
}

.sync-button {
  background: #12223f;
  border: 1px solid var(--line);
  color: var(--muted);
}

.sync-dot {
  width: 8px;
  height: 8px;
  background: var(--quiet);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.05);
}

.sync-button.synced .sync-dot {
  background: var(--mint);
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin: 30px 0 14px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 36, 68, 0.86);
  box-shadow: var(--soft-shadow);
}

.search-field input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.search-field input::placeholder {
  color: var(--quiet);
}

.view-tabs {
  display: inline-flex;
  min-height: 42px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(14, 29, 57, 0.88);
}

.tab-button {
  min-width: 90px;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab-button.active {
  background: #e8ecff;
  color: #17213d;
}

.tab-button:hover,
.icon-button:hover,
.button:hover {
  transform: translateY(-1px);
}

.tab-button,
.icon-button,
.button {
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.select-wrap {
  position: relative;
}

.select-wrap select,
.prompt-form input,
.prompt-form textarea,
.prompt-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0f1e3c;
  color: var(--ink);
  outline: 0;
}

.select-wrap select {
  min-height: 42px;
  padding: 0 34px 0 12px;
  font-weight: 800;
}

.library-meta {
  display: flex;
  align-items: center;
  min-height: 24px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(205px, 1fr));
  gap: 22px;
}

.prompt-card {
  position: relative;
  display: flex;
  min-width: 0;
  aspect-ratio: 5 / 7;
  border: 0;
  padding: 9px;
  border-radius: var(--radius);
  background: var(--card-accent, var(--sky));
  box-shadow: var(--soft-shadow);
  isolation: isolate;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.prompt-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.5), transparent 32% 74%, rgba(11, 23, 51, 0.08)),
    var(--card-accent, var(--gold));
  z-index: -1;
}

.prompt-card:hover,
.prompt-card:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 24px 50px rgba(3, 8, 23, 0.42);
}

.prompt-card:focus-visible,
.button:focus-visible,
.sync-button:focus-visible,
.tab-button:focus-visible,
.icon-button:focus-visible,
.link-button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}

.card-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(15, 30, 60, 0.24);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(246, 249, 255, 0.66);
  backdrop-filter: blur(6px);
}

.card-image {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 10px 10px 0;
  border: 1px solid rgba(17, 32, 61, 0.18);
  border-radius: 6px;
  overflow: hidden;
  background: #172846;
}

.card-image img,
.detail-image img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.image-placeholder,
.empty-card,
.image-preview.placeholder {
  background:
    linear-gradient(135deg, rgba(158, 203, 255, 0.34), transparent 42%),
    linear-gradient(45deg, transparent 0 46%, rgba(138, 217, 170, 0.46) 46% 54%, transparent 54%),
    repeating-linear-gradient(0deg, #e6ebff 0 12px, #dce4fb 12px 24px);
}

.image-placeholder {
  position: relative;
  width: 100%;
  height: 100%;
}

.image-placeholder::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 72px;
  height: 72px;
  border: 6px solid rgba(138, 217, 170, 0.72);
  border-radius: 50%;
  background: rgba(246, 249, 255, 0.48);
  transform: translate(-50%, -50%);
}

.image-placeholder::after {
  content: "P";
  position: absolute;
  left: 50%;
  top: 50%;
  width: auto;
  height: auto;
  color: #27304a;
  font-size: 3.2rem;
  font-weight: 950;
  line-height: 1;
  transform: translate(-50%, -50%);
}

.card-footer {
  display: grid;
  grid-template-columns: 1fr 38px;
  gap: 8px;
  align-items: center;
  min-height: 58px;
  padding: 10px;
}

.card-title {
  min-width: 0;
  margin: 0;
  color: #15203d;
  font-size: 0.98rem;
  line-height: 1.18;
  overflow-wrap: anywhere;
  font-weight: 900;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: var(--radius);
  background: #1d315a;
  color: var(--ink);
}

.copy-button {
  background: #17213d;
  border: 1px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 8px 18px rgba(18, 33, 61, 0.22);
}

.ghost-button {
  background: transparent;
  color: var(--muted);
}

.action-button {
  background: #1d315a;
}

.danger-button {
  background: rgba(255, 170, 162, 0.14);
  color: #ffc2bd;
}

.icon,
[data-icon] svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.button-icon {
  display: inline-grid;
  place-items: center;
}

.empty-state {
  min-height: 330px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  color: var(--muted);
}

.empty-state h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 900;
}

.empty-card {
  width: 118px;
  height: 162px;
  border: 7px solid #e8ecff;
  border-radius: var(--radius);
  box-shadow: var(--soft-shadow);
}

.modal {
  width: min(760px, calc(100% - 24px));
  max-height: min(860px, calc(100vh - 24px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(4, 10, 25, 0.72);
  backdrop-filter: blur(6px);
}

.prompt-form,
.detail-card,
.confirm-card {
  padding: 20px;
}

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

.modal-head h2 {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 950;
  overflow-wrap: anywhere;
}

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

.prompt-form label,
.image-field {
  display: grid;
  gap: 7px;
}

.prompt-form label span,
.field-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.prompt-form input,
.prompt-form select {
  min-height: 44px;
  padding: 0 12px;
}

.prompt-form textarea {
  min-height: 180px;
  padding: 12px;
  line-height: 1.5;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 12px;
}

.image-uploader {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 13px;
  min-height: 124px;
  padding: 12px;
  border: 1px dashed #536990;
  border-radius: var(--radius);
  background: #0f1e3c;
  cursor: pointer;
}

.image-uploader input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.image-preview {
  display: block;
  width: 96px;
  height: 96px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background-position: center;
  background-size: cover;
}

.upload-copy {
  color: var(--ink);
  font-weight: 900;
}

.link-button {
  justify-self: start;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.form-actions {
  justify-content: flex-end;
  margin-top: 6px;
}

.detail-modal {
  width: min(900px, calc(100% - 24px));
}

.confirm-modal {
  width: min(430px, calc(100% - 24px));
}

.confirm-card p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(220px, 330px) minmax(0, 1fr);
  gap: 18px;
}

.detail-image {
  aspect-ratio: 5 / 6;
  min-height: 260px;
  border: 6px solid #e8ecff;
  border-radius: var(--radius);
  overflow: hidden;
  background: #172846;
  box-shadow: var(--soft-shadow);
}

.detail-body {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.detail-description {
  margin: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.detail-meta,
.detail-source {
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.detail-source {
  color: var(--sky);
}

.prompt-text {
  max-height: 390px;
  margin: 0;
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0d1a35;
  color: #eef4ff;
  line-height: 1.48;
}

.detail-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  transform: translate(-50%, 18px);
  min-width: 120px;
  max-width: calc(100% - 28px);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #e8ecff;
  color: var(--ink);
  color: #17213d;
  box-shadow: var(--soft-shadow);
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.cat-art { --card-accent: #ffe6e2; }
.cat-website { --card-accent: #dfe8ff; }
.cat-writing { --card-accent: #eeeaff; }
.cat-code { --card-accent: #dff6e9; }
.cat-marketing { --card-accent: #fff0cf; }
.cat-video { --card-accent: #ffe3f2; }
.cat-music { --card-accent: #edf8d5; }
.cat-business { --card-accent: #ffe8d6; }
.cat-research { --card-accent: #ddf4ff; }
.cat-other { --card-accent: #e9eef8; }

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

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

  .toolbar-row {
    justify-content: space-between;
    align-items: stretch;
  }

  .view-tabs,
  .select-wrap,
  .select-wrap select {
    width: 100%;
  }

  .tab-button {
    flex: 1;
    min-width: 0;
  }

  .form-grid,
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .detail-image {
    min-height: 0;
    height: min(58vw, 330px);
    aspect-ratio: auto;
  }
}

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

  .brand-name {
    font-size: 1.28rem;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

.topbar-actions {
  gap: 8px;
  min-width: 0;
}

.sync-button {
  max-width: 42vw;
  min-width: 0;
  padding: 0 10px;
}

.button-label {
  display: none;
}

.sync-button #syncLabel {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions .primary-button {
  width: 52px;
  min-width: 52px;
  padding: 0;
}

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

  .prompt-card {
    padding: 5px;
    box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.5);
  }

  .card-image {
    margin: 6px 6px 0;
  }

  .card-footer {
    grid-template-columns: 1fr 34px;
    gap: 6px;
    min-height: 52px;
    padding: 6px;
  }

  .card-title {
    font-size: 0.78rem;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .image-uploader {
    grid-template-columns: 1fr;
  }

  .form-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .form-actions .button {
    width: 100%;
  }
}
