:root {
  --bg: #f5f4f2;
  --surface: #ffffff;
  --inset-bg: #f0efec;
  --border: #e2e0dc;
  --text: #1c1c1c;
  --text-dim: #6f6d69;
  --accent: #2f7fb8;
  --accent-text: #ffffff;
  --accent-soft: #e4f2fa;
  --img-bg: #ffffff;
  --radius: 10px;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 20px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #202124;
    --inset-bg: #2a2b2e;
    --border: #3a3c40;
    --text: #f2f2f0;
    --text-dim: #a6a5a1;
    --accent: #2f7fb8;
    --accent-text: #ffffff;
    --accent-soft: #1e3a4d;
    --img-bg: #ffffff;
    --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.55), 0 0 24px rgba(47, 127, 184, 0.12);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Segoe UI", system-ui, sans-serif;
  line-height: 1.6;
}

.header {
  position: relative;
  padding: 32px 24px 16px;
  text-align: center;
}

.header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.lang-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.lang-toggle:hover {
  border-color: var(--accent);
  color: var(--text);
}

.subtitle {
  margin: 6px 0 0;
  color: var(--text-dim);
  font-size: 14px;
}

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

.theme-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 10;
}

.theme-nav-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 13px;
  font-family: inherit;
  padding: 12px 6px;
  cursor: pointer;
}

.theme-nav-btn.active {
  color: var(--accent);
  font-weight: 700;
}

.search-section {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 12px 0;
  z-index: 5;
}

.search-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
}

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

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

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

.result-count {
  color: var(--text-dim);
  font-size: 13px;
  margin: 4px 2px 12px;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.card-img-wrap {
  aspect-ratio: 1 / 1;
  background: var(--img-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.card-img-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.card-body {
  padding: 10px 12px 12px;
}

.card-name {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.card-category {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 0;
  font-size: 14px;
  grid-column: 1 / -1;
}

.detail-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.detail-overlay[hidden] {
  display: none;
}

@media (min-width: 640px) {
  .detail-overlay {
    align-items: center;
  }
}

.detail-panel {
  background: var(--surface);
  color: var(--text);
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  position: relative;
}

@media (min-width: 640px) {
  .detail-panel {
    border-radius: var(--radius);
  }
}

.detail-header {
  display: flex;
  justify-content: flex-end;
  position: sticky;
  top: 0;
  background: var(--surface);
  padding-bottom: 8px;
  margin: -20px -20px 0;
  padding: 20px 20px 8px;
}

.detail-close {
  background: var(--inset-bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}

.detail-img-wrap {
  background: var(--img-bg);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  clear: both;
}

.detail-img-wrap img {
  max-width: 100%;
  max-height: 260px;
  object-fit: contain;
}

.detail-name {
  margin: 16px 0 0;
  font-size: 20px;
  font-weight: 700;
}

.detail-name-en {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

.detail-category {
  display: inline-block;
  margin-top: 10px;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
}

.detail-section {
  margin-top: 16px;
}

.detail-section-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.detail-section-body {
  font-size: 14px;
  white-space: pre-wrap;
}

.detail-tip {
  margin-top: 16px;
  background: var(--inset-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.detail-tip-label {
  font-weight: 700;
  margin-bottom: 3px;
}

.detail-source {
  margin-top: 16px;
  font-size: 12px;
}

.detail-source a {
  color: var(--text-dim);
}
