:root {
  --bg: #fbf6ef;
  --surface: #ffffff;
  --surface-2: #f5ece1;
  --text: #2b1f22;
  --muted: #7a6a6d;
  --line: #ecdfd2;
  --accent: #b8325a;
  --accent-ink: #ffffff;
  --accent-soft: #fbe3ea;
  --gold: #c98a1b;
  --gold-soft: #fdf0d6;
  --green: #2f7d57;
  --green-soft: #def3e7;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgb(60 30 20 / 6%), 0 4px 16px rgb(60 30 20 / 6%);
  --radius: 16px;
  --font: ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1517;
    --surface: #271e21;
    --surface-2: #31262a;
    --text: #f6ece8;
    --muted: #b3a2a5;
    --line: #3d3135;
    --accent: #f06b93;
    --accent-ink: #2a0c16;
    --accent-soft: #4a2230;
    --gold: #f0b851;
    --gold-soft: #463519;
    --green: #74d3a3;
    --green-soft: #1f3a2d;
    --danger: #ff8a80;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

a {
  color: inherit;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.15rem;
}

p {
  margin: 0;
}

.app {
  min-height: 100dvh;
  padding-bottom: 48px;
}

.loading {
  padding: 40vh 16px 0;
  text-align: center;
  color: var(--muted);
}

.narrow {
  margin: 0 auto;
  padding: 0 16px;
  max-width: 440px;
  padding-top: 8vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.center {
  text-align: center;
  align-items: center;
}

.center .card {
  text-align: left;
  width: 100%;
}

.hero-icon {
  display: block;
  margin: 0 auto 8px;
  border-radius: 18px;
  box-shadow: var(--shadow);
}

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

.small {
  font-size: 0.875rem;
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  margin-bottom: 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--accent);
}

.brand img {
  border-radius: 7px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.who-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

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

.who-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 9em;
}

.who-switch {
  color: var(--muted);
  font-size: 0.75rem;
}

@media (max-width: 420px) {
  .who-switch {
    display: none;
  }
}

/* ---------- Buttons & Formulare ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.875rem;
  border-radius: 10px;
}

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

.btn.primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, black);
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

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

.btn.danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}

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

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

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

.row .push {
  margin-left: auto;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 480px) {
  .two {
    grid-template-columns: 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.label {
  font-size: 0.875rem;
  font-weight: 650;
}

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

input,
textarea,
select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.birthday {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 8px;
}

/* ---------- Karten ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

a.card {
  text-decoration: none;
}

a.card:hover,
button.card:hover {
  border-color: var(--accent);
}

.avatar {
  --hue: 340;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: hsl(var(--hue) 70% 88%);
  color: hsl(var(--hue) 55% 28%);
  font-weight: 800;
}

@media (prefers-color-scheme: dark) {
  .avatar {
    background: hsl(var(--hue) 35% 30%);
    color: hsl(var(--hue) 80% 88%);
  }
}

.avatar.tiny {
  width: 26px;
  height: 26px;
  font-size: 0.8rem;
}

.avatar.large {
  width: 48px;
  height: 48px;
  font-size: 1.2rem;
}

.avatar.xl {
  width: 64px;
  height: 64px;
  font-size: 1.6rem;
}

/* ---------- Wer bist du ---------- */

.who-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.who-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.who-option:hover {
  border-color: var(--accent);
}

.who-option span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Übersicht ---------- */

.hello {
  padding-top: 12px;
}

.hello p {
  margin-top: 4px;
}

.upcoming {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 2px 2px 6px;
  margin: 0 -2px;
  scrollbar-width: thin;
}

.event {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-decoration: none;
}

.event.soon {
  background: var(--gold-soft);
  border-color: color-mix(in srgb, var(--gold) 40%, transparent);
}

.event-icon {
  font-size: 1.4rem;
}

.event-text {
  display: flex;
  flex-direction: column;
  font-size: 0.875rem;
  line-height: 1.3;
}

.event-text span {
  color: var(--muted);
}

.section-title {
  margin-top: 8px;
  font-size: 1rem;
  font-weight: 750;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- Personenseite ---------- */

.back {
  align-self: flex-start;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  padding-top: 4px;
}

.back:hover {
  color: var(--accent);
}

.person-head {
  display: flex;
  align-items: center;
  gap: 16px;
}

.person-head-body {
  flex: 1;
  min-width: 0;
}

.person-head-body h1 {
  overflow-wrap: anywhere;
}

.notice {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.9rem;
}

.add-btn {
  align-self: flex-start;
}

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

.chip {
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

.chip.active {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.ideas {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  align-items: start;
}

@media (max-width: 360px) {
  .ideas {
    grid-template-columns: 1fr;
  }
}

.idea {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 4px solid var(--line);
}

.idea.wish {
  border-left-color: var(--accent);
}

.idea.reserviert {
  border-left-color: var(--gold);
}

.idea.verschenkt {
  border-left-color: var(--green);
  opacity: 0.8;
}

.idea-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.idea-title {
  flex: 1;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
  padding-top: 4px;
}

.idea-tools {
  display: flex;
  margin: -4px -6px 0 0;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 650;
}

.tag.price {
  background: var(--surface-2);
  color: var(--text);
}

.idea-note {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 0.95rem;
}

.idea-link {
  align-self: flex-start;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.idea-link:hover {
  text-decoration: underline;
}

.idea-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.status {
  font-size: 0.85rem;
  font-weight: 650;
}

.status.reserved {
  color: var(--gold);
}

.status.gifted {
  color: var(--green);
}

.gifted-block summary {
  cursor: pointer;
  margin-bottom: 12px;
}

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.empty-icon {
  font-size: 2.4rem;
}

/* ---------- Layout mit Seitenleiste ---------- */

.layout {
  max-width: 1320px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.sidebar {
  display: none;
}

.content {
  min-width: 0;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 28px;
    padding: 0 20px;
  }

  .sidebar {
    display: block;
    position: sticky;
    top: 62px;
    align-self: start;
    max-height: calc(100dvh - 62px);
    overflow-y: auto;
    padding: 8px 6px 24px 0;
    scrollbar-width: thin;
  }

  .content {
    padding: 0;
    max-width: 900px;
  }

  .tree-inline,
  .back {
    display: none;
  }
}

/* ---------- Personen-Baum ---------- */

.tree {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tree-inline {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tree-label {
  margin: 8px 10px 0;
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Rahmen immer sichtbar; die gerade gewählte Person bekommt zusätzlich eine Füllung. */
.tree-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px 0;
}

.tree-group.current {
  background: var(--surface);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
}

.tree-inline .tree-group.current {
  background: var(--surface-2);
}

.tree-head {
  display: flex;
  align-items: center;
}

.tree-toggle {
  flex: none;
  width: 26px;
  height: 34px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.tree-toggle[aria-expanded='true'] {
  transform: rotate(90deg);
}

.tree-person {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 4px;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 650;
}

.tree-person:hover,
.tree-item:hover {
  background: var(--surface-2);
}

.tree-person.active {
  color: var(--accent);
}

.tree-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-bday {
  flex: none;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--gold);
  white-space: nowrap;
}

.tree-count {
  flex: none;
  min-width: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 20px;
  text-align: center;
}

.tree-add {
  flex: none;
  width: 32px;
  height: 32px;
  margin-right: 2px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.tree-add:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.tree-items {
  list-style: none;
  margin: 0 0 4px;
  padding: 0 6px 0 26px;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 5px 8px;
  border-radius: 9px;
  text-decoration: none;
  font-size: 0.94rem;
}

.tree-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.tree-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-price {
  flex: none;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.tree-item.active .tree-price {
  color: inherit;
}

.tree-thumb {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
}

.tree-thumb img {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: var(--surface-2);
  object-fit: cover;
}

.tree-thumb.has-img .tree-dot {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 10px;
  height: 10px;
  box-shadow: 0 0 0 2px var(--bg);
}

.tree-group.current .tree-thumb.has-img .tree-dot {
  box-shadow: 0 0 0 2px var(--surface);
}

.tree-item.reserviert .tree-title {
  color: var(--muted);
}

.tree-dot {
  flex: none;
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--muted) 55%, transparent);
}

.tree-dot.wish,
.tree-item.wish .tree-dot {
  background: var(--accent);
}

.tree-dot.reserviert,
.tree-item.reserviert .tree-dot {
  background: var(--gold);
}

.tree-empty {
  padding: 3px 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.tree-new {
  min-height: 40px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
}

.tree-new:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tree-form {
  padding: 12px;
  box-shadow: none;
}

.tree-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 4px 10px 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.tree-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

@media (max-width: 899px) {
  /* Größere Tippflächen am Handy */
  .tree-item {
    padding: 6px 8px;
  }

  .tree-person {
    padding: 8px 8px 8px 4px;
  }

  .tree-add {
    width: 40px;
    height: 40px;
  }
}

/* ---------- Startseite: Listen ---------- */

.tip {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
}

.tip > span:first-child {
  font-size: 1.4rem;
  line-height: 1;
}

.idea-rows {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
}

@media (max-width: 360px) {
  .idea-rows {
    grid-template-columns: 1fr;
  }
}

.idea-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  color: var(--text);
}

.idea-row-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.idea-row-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Aus der Seitenleiste angesprungene Idee kurz hervorheben */
.idea.highlight {
  border-color: var(--accent);
  animation: flash 1.6s ease-out 1;
}

@keyframes flash {
  0% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 45%, transparent);
  }
  100% {
    box-shadow: var(--shadow);
  }
}

/* ---------- Bilder ---------- */

img.broken {
  visibility: hidden;
}

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

.idea-thumb {
  flex: none;
  width: 76px;
  height: 76px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  overflow: hidden;
  cursor: zoom-in;
}

.idea-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.row-thumb {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
}

.row-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-picker {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.image-preview {
  flex: none;
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
}

.image-preview.empty {
  border-style: dashed;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-controls {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-btn {
  position: relative;
}

.file-btn:focus-within {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.lightbox {
  max-width: min(92vw, 1100px);
  max-height: 92dvh;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
  cursor: zoom-out;
}

.lightbox::backdrop {
  background: rgb(0 0 0 / 70%);
}

.lightbox img {
  display: block;
  max-width: 100%;
  max-height: calc(92dvh - 52px);
  margin: 0 auto;
  object-fit: contain;
}

.lightbox p {
  padding: 12px 16px;
  font-weight: 650;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 10;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: var(--shadow);
  transform: translate(-50%, 140%);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
}

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

.toast.error {
  background: var(--danger);
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
