:root {
  --bg: #f5f1e8;
  --bg-elev: #fdfaf3;
  --ink: #1a1814;
  --ink-soft: #54504a;
  --ink-muted: #8a857c;
  --line: #e3ddd0;
  --line-soft: #ede7d8;
  --accent: #b54520;
  --accent-soft: #f4dbcf;
  --accent-ink: #6a230d;
  --success: #2f6a3e;
  --danger: #9c2b1c;
  --radius: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(26, 24, 20, 0.04), 0 1px 3px rgba(26, 24, 20, 0.06);
  --shadow-md: 0 4px 12px rgba(26, 24, 20, 0.07), 0 2px 4px rgba(26, 24, 20, 0.04);
  --shadow-lg: 0 12px 32px rgba(26, 24, 20, 0.14), 0 4px 8px rgba(26, 24, 20, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { min-height: 100dvh; }

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ============ Topbar ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
  padding-top: max(18px, env(safe-area-inset-top));
}

.brand {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 28px;
  margin: 0;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.brand-italic {
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.005em;
  transition: transform 0.06s ease, background 0.15s ease, color 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--ink);
  color: var(--bg-elev);
}
.btn-primary:hover:not(:disabled) { background: #2c2823; }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  padding: 10px 12px;
}
.btn-ghost:hover { background: rgba(26,24,20,0.06); color: var(--ink); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: rgba(26,24,20,0.06); color: var(--ink); }

@media (max-width: 540px) {
  .btn-label { display: none; }
  .btn-primary { padding: 10px; width: 40px; height: 40px; justify-content: center; }
}

/* ============ Tagbar ============ */
.tagbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 22px 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
.tag-chip {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.tag-chip:hover { border-color: var(--ink-muted); color: var(--ink); }
.tag-chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg-elev);
  border-color: var(--ink);
}
.tag-chip .tag-count {
  font-size: 11px;
  opacity: 0.6;
  margin-left: 4px;
}

/* ============ Grid ============ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
  padding: 22px;
  padding-bottom: max(22px, env(safe-area-inset-bottom));
}

.card {
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s cubic-bezier(0.2, 0.7, 0.3, 1), box-shadow 0.18s ease;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-img {
  aspect-ratio: 4 / 3;
  background: var(--line-soft);
  background-size: cover;
  background-position: center;
  position: relative;
}
.card-img.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-muted);
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 32px;
}

.card-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-title {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.35;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 38px;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  gap: 8px;
}

.card-price {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 20px;
  color: var(--accent-ink);
  letter-spacing: -0.01em;
}
.card-price.no-price {
  color: var(--ink-muted);
  font-style: italic;
  font-size: 14px;
  font-family: 'Manrope', sans-serif;
  font-weight: 500;
}

.card-domain {
  font-size: 11px;
  color: var(--ink-muted);
  text-transform: lowercase;
  letter-spacing: 0.02em;
  max-width: 110px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.card-tag {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

/* ============ Empty ============ */
.empty {
  text-align: center;
  padding: 80px 22px;
  max-width: 420px;
  margin: 0 auto;
}
.empty-title {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 28px;
  color: var(--ink);
  margin: 0 0 8px;
}
.empty-sub {
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.5;
}

/* ============ Modal ============ */
.modal[hidden] { display: none !important; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 24, 20, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeIn 0.18s ease;
}
.modal-panel {
  position: relative;
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  max-width: 440px;
  width: 100%;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: rise 0.22s cubic-bezier(0.2, 0.7, 0.3, 1);
}
.modal-panel-wide { max-width: 640px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 22px 0;
}
.modal-head h2 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 22px;
  margin: 0;
  letter-spacing: -0.01em;
}

#addForm, .detail-body {
  padding: 18px 22px 22px;
}

#addForm label {
  display: block;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}
#addForm .muted { color: var(--ink-muted); font-weight: 400; }

#addForm input,
#addForm textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 15px;
  color: var(--ink);
  transition: border-color 0.15s ease, background 0.15s ease;
}
#addForm input:focus,
#addForm textarea:focus {
  outline: none;
  border-color: var(--ink);
  background: var(--bg-elev);
}
#addForm textarea { resize: vertical; min-height: 60px; }

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

.status {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
}
.status.error { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); }
.status.warn { background: #fdf3d6; color: #6b4d00; }
.status.success { background: color-mix(in srgb, var(--success) 12%, transparent); color: var(--success); }

.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: var(--bg-elev);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Detail ============ */
.detail-image {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--line-soft);
  background-size: cover;
  background-position: center;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.detail-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.detail-price {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 32px;
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}
.detail-price.no-price { font-size: 16px; color: var(--ink-muted); font-style: italic; }

.detail-domain a {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1px;
}
.detail-domain a:hover { color: var(--ink); border-color: var(--ink-soft); }

.detail-section {
  margin: 18px 0;
}
.detail-section h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  margin: 0 0 8px;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.detail-tags .card-tag {
  cursor: default;
}

.editable-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 14px;
  color: var(--ink);
}
.editable-input:focus {
  outline: none;
  border-color: var(--ink);
  background: var(--bg-elev);
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}
.history-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid var(--line-soft);
}
.history-row .history-price { font-weight: 600; }
.history-row.up .history-price { color: var(--danger); }
.history-row.down .history-price { color: var(--success); }
.history-row .history-date { color: var(--ink-muted); }

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
}
.detail-actions .btn { flex: 1 1 auto; justify-content: center; }

/* ============ Login ============ */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 22px;
}
.login-card {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
  max-width: 360px;
  width: 100%;
  border: 1px solid var(--line-soft);
}
.login-card .brand { font-size: 32px; }
.login-sub {
  color: var(--ink-soft);
  margin: 4px 0 24px;
  font-size: 14px;
}
.login-card input[type="password"] {
  width: 100%;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 16px;
  margin-bottom: 12px;
}
.login-card input:focus { outline: none; border-color: var(--ink); background: var(--bg-elev); }
.login-card button {
  width: 100%;
  padding: 13px;
  background: var(--ink);
  color: var(--bg-elev);
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
}
.login-card button:hover { background: #2c2823; }
.error {
  margin-top: 12px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
  border-radius: 10px;
  font-size: 13px;
}

@media (max-width: 540px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; padding: 16px; }
  .topbar { padding: 14px 16px; }
  .tagbar { padding: 12px 16px 0; }
  .brand { font-size: 24px; }
  .card-title { font-size: 13px; min-height: 36px; }
  .card-price { font-size: 17px; }
  .card-body { padding: 12px; }
  .toolbar { padding: 12px 16px 0; flex-direction: column; align-items: stretch; gap: 10px; }
  .toolbar-views { justify-content: flex-start; overflow-x: auto; }
  .sort-label { justify-content: space-between; }
  .drop-banner { margin: 12px 16px 0; padding: 10px 12px; font-size: 13px; }
  .drop-banner-action { padding: 4px 10px; font-size: 12px; }
}

/* ============ Drop-Banner ============ */
.drop-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 22px 0;
  padding: 12px 16px;
  background: linear-gradient(135deg, #f3e3d3 0%, #ecd5be 100%);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: var(--radius);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 500;
  animation: rise 0.25s cubic-bezier(0.2, 0.7, 0.3, 1);
}
.drop-banner-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  flex-shrink: 0;
}
.drop-banner-text { flex: 1; }
.drop-banner-action {
  background: var(--accent-ink);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: background 0.15s ease;
}
.drop-banner-action:hover { background: var(--ink); }
.drop-banner-close {
  background: transparent;
  border: none;
  color: var(--accent-ink);
  opacity: 0.6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 50%;
  cursor: pointer;
}
.drop-banner-close:hover { opacity: 1; background: rgba(0,0,0,0.05); }

/* ============ Toolbar ============ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 22px 0;
}
.toolbar-views {
  display: flex;
  gap: 6px;
  align-items: center;
}
.view-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.005em;
  transition: all 0.15s ease;
  cursor: pointer;
}
.view-chip:hover { border-color: var(--ink-muted); color: var(--ink); }
.view-chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg-elev);
  border-color: var(--ink);
}
.view-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--accent);
  color: white;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.view-chip[aria-pressed="true"] .view-count { background: var(--accent-soft); color: var(--accent-ink); }

.sort-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-muted);
  font-weight: 500;
}
.sort-label-text { white-space: nowrap; }
.sort-select {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 30px 7px 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2354504a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.sort-select:hover { border-color: var(--ink-muted); }
.sort-select:focus { outline: none; border-color: var(--ink); }

/* ============ Drop-Badge auf Karten ============ */
.card-price-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.card-price.is-drop { color: var(--accent); }
.drop-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: -2px;
}
.card-price-old {
  font-size: 12px;
  color: var(--ink-muted);
  text-decoration: line-through;
  font-family: 'Manrope', sans-serif;
  font-weight: 500;
}
.card.is-purchased { opacity: 0.65; }
.card.is-purchased .card-title { text-decoration: line-through; }

/* ============ Sparkline ============ */
.sparkline-wrap {
  margin: 6px 0 18px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--line-soft);
}
.sparkline {
  display: block;
  width: 100%;
  height: 60px;
}
.sparkline-line {
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sparkline-area { opacity: 0.18; }
.sparkline.trend-down .sparkline-line { stroke: var(--success); }
.sparkline.trend-down .sparkline-area { fill: var(--success); }
.sparkline.trend-down .sparkline-dot { fill: var(--success); }
.sparkline.trend-up .sparkline-line { stroke: var(--danger); }
.sparkline.trend-up .sparkline-area { fill: var(--danger); }
.sparkline.trend-up .sparkline-dot { fill: var(--danger); }
.sparkline.trend-flat .sparkline-line { stroke: var(--ink-muted); }
.sparkline.trend-flat .sparkline-area { fill: var(--ink-muted); }
.sparkline.trend-flat .sparkline-dot { fill: var(--ink-muted); }

.sparkline-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.muted-text {
  font-size: 13px;
  color: var(--ink-muted);
  margin: 0;
}
