/* SPDX-License-Identifier: AGPL-3.0-or-later */
/* Nameward: one stylesheet, no external fonts (privacy), system font stacks.
   Theme = genre (html[data-genre]) x color scheme (prefers-color-scheme). */

:root {
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", P052, Georgia, serif;
  --font-mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 14px;
  --radius-small: 999px;
  --gap: 16px;
  --action-bar-height: 0px;

  /* Fantasy, light */
  --bg: #f5efe3;
  --surface: #fffaf0;
  --surface-2: #ede3d1;
  --border: #d8c9b0;
  --text: #231b12;
  --muted: #6b5d49;
  --accent: #8c5a10;
  --accent-ink: #ffffff;
  --accent-soft: rgb(140 90 16 / 0.1);
  --glow: none;
  --font-display: var(--font-serif);
  --display-transform: none;
  --display-spacing: 0;
  color-scheme: light;
}

:root[data-genre="modern"] {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #e7ecf2;
  --border: #cfd8e3;
  --text: #121a24;
  --muted: #536173;
  --accent: #1d5fae;
  --accent-soft: rgb(29 95 174 / 0.1);
  --font-display: var(--font-body);
}

:root[data-genre="cyberpunk"] {
  --bg: #f6f3fb;
  --surface: #ffffff;
  --surface-2: #ece6f6;
  --border: #d6cde8;
  --text: #1a1426;
  --muted: #5e5674;
  --accent: #b5136a;
  --accent-soft: rgb(181 19 106 / 0.1);
  --font-display: var(--font-mono);
  --display-transform: none;
  --display-spacing: -0.01em;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16120e;
    --surface: #211b15;
    --surface-2: #2c241c;
    --border: #3f3428;
    --text: #f1e8da;
    --muted: #b3a48e;
    --accent: #e3b35e;
    --accent-ink: #1c1407;
    --accent-soft: rgb(227 179 94 / 0.13);
    color-scheme: dark;
  }

  :root[data-genre="modern"] {
    --bg: #0f1318;
    --surface: #171d24;
    --surface-2: #1f2731;
    --border: #2e3946;
    --text: #e6ebf1;
    --muted: #9eabba;
    --accent: #6cb0f5;
    --accent-ink: #08121d;
    --accent-soft: rgb(108 176 245 / 0.13);
  }

  :root[data-genre="cyberpunk"] {
    --bg: #0b0a12;
    --surface: #14121f;
    --surface-2: #1d1a2d;
    --border: #322c4c;
    --text: #ece9ff;
    --muted: #a7a2c8;
    --accent: #ff4fb0;
    --accent-ink: #16020d;
    --accent-soft: rgb(255 79 176 / 0.13);
    --glow: 0 0 12px rgb(255 79 176 / 0.35);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 500px at 50% -200px, var(--accent-soft), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  padding-bottom: calc(var(--action-bar-height) + env(safe-area-inset-bottom));
  transition: background-color 0.25s ease, color 0.25s ease;
}

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

button {
  cursor: pointer;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.visually-hidden,
.clipboard-fallback {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  z-index: 100;
}

.skip-link:focus {
  top: 12px;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.05em 0.4em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.noscript {
  max-width: 1160px;
  margin: 12px auto;
  padding: 14px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

/* ---- Header ------------------------------------------------------------------------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1160px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  flex: none;
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 2.6vw, 1.35rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: var(--display-spacing);
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---- Buttons ------------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  font-weight: 600;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.07);
}

.btn-ghost {
  background: transparent;
}

.btn-small {
  min-height: 36px;
  padding: 0 14px;
  font-size: 0.88rem;
}

.btn-danger.armed {
  background: #b3261e;
  border-color: #b3261e;
  color: #fff;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---- View tabs (narrow screens only) -------------------------------------------------- */

.view-tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 4px;
  max-width: 1160px;
  margin: 0 auto;
  padding: 8px 16px;
  background: color-mix(in srgb, var(--bg) 96%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.view-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
}

.view-tab[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border-color: var(--accent);
  color: var(--text);
}

.count-badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.6em;
  height: 1.6em;
  padding: 0 0.45em;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---- Layout ------------------------------------------------------------------------- */

.layout {
  max-width: 1160px;
  margin: 0 auto;
  padding: 8px 16px 24px;
}

body[data-view="generator"] .panel-saved,
body[data-view="saved"] .panel-generator {
  display: none;
}

@media (min-width: 960px) {
  .view-tabs {
    display: none;
  }

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

  body[data-view] .panel-saved,
  body[data-view] .panel-generator {
    display: block;
  }

  /* The saved box is never taller than the generator column. Size containment stops the
     saved column from adding height to the grid row (the generator column alone sets it);
     stretch hands that height to the column, and the box caps itself at 100% of it. */
  .panel-saved {
    align-self: stretch;
    contain: size;
  }

  .saved-box {
    display: flex;
    flex-direction: column;
    max-height: 100%;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
  }

  .saved-box > * {
    flex: none;
  }


  /* Only the list scrolls; the heading and buttons stay in view. */
  .saved-box > #saved-list {
    flex: 0 1 auto;
    min-height: 0;
    margin-right: -6px;
    padding-right: 6px;
    overflow-y: auto;
    scrollbar-color: var(--border) transparent;
  }

  .panel-saved .name-copy {
    background: var(--bg);
  }
}

/* ---- Controls ----------------------------------------------------------------------- */

.controls {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.field {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.field legend,
.field .legend {
  display: block;
  margin-bottom: 6px;
  padding: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  position: relative;
  display: inline-flex;
}

.chip input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.chip span {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--bg);
  font-size: 0.95rem;
  font-weight: 500;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chip:hover span {
  border-color: var(--accent);
}

.chip input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  box-shadow: var(--glow);
}

.chip input[type="checkbox"] + span::before {
  content: "";
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border: 1.5px solid currentColor;
  border-radius: 4px;
}

.chip input[type="checkbox"]:checked + span::before {
  width: 6px;
  height: 11px;
  margin: -3px 12px 0 4px;
  border-width: 0 2px 2px 0;
  border-radius: 0;
  transform: rotate(45deg);
}

.chip input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

select {
  width: 100%;
  max-width: 340px;
  min-height: 44px;
  padding: 0 40px 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 20px) 50% / 6px 6px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 14px) 50% / 6px 6px no-repeat,
    var(--bg);
  appearance: none;
}

/* ---- Generate button ---------------------------------------------------------------- */

.action-bar {
  margin: 16px 0 6px;
}

.btn-generate {
  width: 100%;
  min-height: 52px;
  font-size: 1.05rem;
  font-family: var(--font-display);
  letter-spacing: var(--display-spacing);
}

.btn-generate svg {
  width: 22px;
  height: 22px;
}

@media (max-width: 959px) {
  :root {
    --action-bar-height: 84px;
  }

  body[data-view="generator"] .action-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    margin: 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
  }

  body[data-view="saved"] {
    --action-bar-height: 0px;
  }
}

/* ---- Name lists --------------------------------------------------------------------- */

.results {
  margin-top: 18px;
  scroll-margin-top: 64px;
}

.results:focus {
  outline: none;
}

.results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0 2px 10px;
  scroll-margin-top: 64px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: var(--display-spacing);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.results-head {
  align-items: center;
}

.results-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin: -4px 2px 10px;
}

.save-target {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.save-target select {
  width: auto;
  max-width: 220px;
  min-height: 34px;
  padding: 0 34px 0 10px;
  font-size: 0.88rem;
  color: var(--text);
}

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

.results-actions svg {
  width: 16px;
  height: 16px;
}

@media (hover: none) {
  .key-hint {
    display: none;
  }
}

.name-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.name-item {
  display: flex;
  align-items: stretch;
  gap: 6px;
  animation: rise 0.22s ease both;
}

.name-list .name-item:nth-child(2) { animation-delay: 0.02s; }
.name-list .name-item:nth-child(3) { animation-delay: 0.04s; }
.name-list .name-item:nth-child(4) { animation-delay: 0.06s; }
.name-list .name-item:nth-child(5) { animation-delay: 0.08s; }
.name-list .name-item:nth-child(n + 6) { animation-delay: 0.1s; }

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.name-copy {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.name-copy:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.name-copy:active {
  transform: translateY(1px);
}

.name-text {
  max-width: 100%;
  font-family: var(--font-display);
  font-size: 1.16rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: var(--display-spacing);
  overflow-wrap: anywhere;
}

.name-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.name-meta:empty {
  display: none;
}

.name-item .icon-btn {
  align-self: center;
}

.star-btn[aria-pressed="true"] {
  color: var(--accent);
}

.star-btn[aria-pressed="true"] svg {
  fill: currentColor;
}

.remove-btn:hover {
  color: #d9534f;
}

.saved-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

/* ---- Saved lists: picker, name form ---------------------------------------------------- */

.saved-box .saved-tools,
.saved-box .list-actions {
  gap: 6px;
}

.saved-box .btn-small {
  padding: 0 12px;
}

.list-picker {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.list-picker select {
  max-width: none;
}

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

.list-name-form {
  margin: 0 0 12px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.list-name-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.list-name-row input {
  flex: 1 1 180px;
}

input[type="text"],
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: 150px;
  resize: vertical;
  line-height: 1.45;
}

input[type="text"]::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.form-error {
  margin: 8px 0 0;
  color: #d9534f;
  font-size: 0.88rem;
  font-weight: 600;
}

.form-error:empty {
  display: none;
}

.backup-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.backup-label {
  margin-right: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---- Import dialog --------------------------------------------------------------------- */

.import-dialog .legend {
  display: block;
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.import-dialog select {
  max-width: none;
}

.import-file {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.import-file-name {
  color: var(--muted);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.import-summary {
  margin: 12px 0 0;
  color: var(--muted);
}

.import-hint {
  margin: 8px 0 0;
  font-size: 0.92rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.empty {
  margin: 8px 2px;
  color: var(--muted);
  font-size: 0.92rem;
}

/* ---- Footer ------------------------------------------------------------------------- */

.app-footer {
  max-width: 1160px;
  margin: 0 auto;
  padding: 8px 16px 28px;
  color: var(--muted);
  font-size: 0.84rem;
}

.app-footer p {
  margin: 4px 0;
}

.version {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  opacity: 0.8;
}

/* ---- Toast & update banner ---------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--action-bar-height) + 20px + env(safe-area-inset-bottom));
  z-index: 40;
  width: max-content;
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 18px;
  border-radius: 18px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

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

.update-banner {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 16px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.25);
  transform: translateX(-50%);
  white-space: nowrap;
}

/* ---- About dialog ------------------------------------------------------------------- */

.about {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.35);
  scrollbar-color: var(--border) transparent;
}

.about::backdrop {
  background: rgb(0 0 0 / 0.55);
}

.about-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 10px 4px 22px;
}

.about-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.3rem;
}

.about-body {
  padding: 0 22px 20px;
  font-size: 0.95rem;
}

.about-body h3 {
  margin: 18px 0 6px;
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.about-body p {
  margin: 0 0 6px;
}

.about-body ul {
  margin: 0;
  padding-left: 1.2em;
}

.about-body li + li {
  margin-top: 6px;
}

/* ---- Motion ------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
