:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1b18;
  --text-dim: #8a877e;
  --border: #e6e4de;
  --accent: #e0564a;
  --accent-ink: #ffffff;
  --shadow: 0 1px 2px rgba(20, 18, 12, 0.05), 0 6px 20px -8px rgba(20, 18, 12, 0.12);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --surface: #211f1c;
    --text: #ece9e2;
    --text-dim: #969288;
    --border: #35322c;
    --accent: #e8695e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -10px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.header { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.header-inner { max-width: 1080px; margin: 0 auto; padding: 14px 20px; display: flex; align-items: center; gap: 12px; }
.logo { font-size: 24px; text-decoration: none; }
.list-title { font-size: 18px; font-weight: 700; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; border-radius: 8px; padding: 2px 8px; }
.list-title:hover { background: var(--border); }
.list-title[contenteditable="true"] { outline: 2px solid var(--accent); background: var(--surface); cursor: text; }

.main { max-width: 1080px; margin: 0 auto; padding: 24px 20px 80px; }

.add-form { display: flex; gap: 10px; margin-bottom: 20px; }
.add-form input {
  flex: 1; font-size: 16px; padding: 14px 18px; border-radius: var(--radius);
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text); outline: none;
  transition: border-color 0.15s;
}
.add-form input:focus { border-color: var(--accent); }

.btn {
  font-size: 15px; font-weight: 600; padding: 12px 22px; border-radius: var(--radius);
  border: 1.5px solid transparent; cursor: pointer; transition: opacity 0.15s, background 0.15s;
  font-family: inherit;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { opacity: 0.88; }
.btn.primary:disabled { opacity: 0.5; cursor: wait; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface); }
.btn.small { padding: 6px 14px; font-size: 13px; border-radius: 9px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; }
.tab { font-size: 13px; font-weight: 600; padding: 6px 14px; border: none; background: transparent; color: var(--text-dim); border-radius: 9px; cursor: pointer; font-family: inherit; }
.tab.active { background: var(--accent); color: var(--accent-ink); }
.summary { font-size: 13px; color: var(--text-dim); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
}
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

.card {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.card:hover { transform: translateY(-2px); }
.card.purchased { opacity: 0.55; }
.card.purchased .title { text-decoration: line-through; }

.thumb { display: block; aspect-ratio: 1 / 1; background: var(--bg); position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-fallback {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 48px; background: linear-gradient(135deg, var(--bg), var(--border));
}
.hidden { display: none !important; }

.card-body { padding: 10px 12px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.brand { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); min-height: 14px; }
.title {
  font-size: 13.5px; font-weight: 600; color: var(--text); text-decoration: none; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.title:hover { text-decoration: underline; }
.price { font-size: 15px; font-weight: 700; margin-top: 2px; }
.price:empty { display: none; }
.site { font-size: 11px; color: var(--text-dim); margin-top: auto; padding-top: 4px; display: flex; align-items: center; gap: 5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.site img { width: 13px; height: 13px; border-radius: 3px; }

.card-actions {
  display: flex; gap: 4px; padding: 0 8px 10px; justify-content: flex-end;
}
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  width: 30px; height: 30px; border-radius: 9px; cursor: pointer; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; transition: all 0.12s;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-dim); }
.buy-btn.on { background: #2e9e5b; border-color: #2e9e5b; color: #fff; }
.del-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.edit-form { padding: 10px 12px 12px; border-top: 1px dashed var(--border); display: flex; flex-direction: column; gap: 8px; }
.edit-form input {
  /* 16px未満だと iOS Safari がフォーカス時に自動ズームするため16pxを維持する */
  font-size: 16px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); outline: none; font-family: inherit;
}
.edit-form input:focus { border-color: var(--accent); }
.edit-form-actions { display: flex; gap: 8px; }

.empty { text-align: center; color: var(--text-dim); padding: 70px 20px; }
.empty-emoji { font-size: 56px; margin-bottom: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 600;
  padding: 12px 22px; border-radius: 12px; box-shadow: var(--shadow); z-index: 100;
  max-width: 90vw;
}

.card.loading .thumb { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
