:root {
  --bg: #f5f7f9;
  --surface: #ffffff;
  --ink: #1f2933;
  --muted: #66788a;
  --line: #d7eadf;
  --primary: #0f6b3f;
  --primary-dark: #0b4f30;
  --primary-soft: #e8f7ee;
  --accent: #29a35d;
  --accent-soft: #f0fbf4;
  --shadow: 0 10px 28px rgba(31, 41, 51, 0.08);
  --content-width: 860px;
  --page-gutter: 18px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
}

html.modal-open,
body.modal-open {
  overflow: hidden;
  overscroll-behavior: none;
}

body.modal-open {
  touch-action: none;
}

body.modal-open .detail-dialog,
body.modal-open .detail-dialog * {
  touch-action: auto;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: 100%;
  margin: 0 auto;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
}

.hero {
  position: relative;
  overflow: hidden;
  width: min(calc(100% - (var(--page-gutter) * 2)), var(--content-width));
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 18px 20px;
  color: #ffffff;
  background:
    linear-gradient(135deg, #0f5132 0%, #1f8f52 55%, #5fd38a 100%),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.08) 0 1px, transparent 1px 18px);
  border-bottom: 4px solid #0b4f30;
}

.hero::after {
  content: "";
  position: absolute;
  right: 32px;
  top: 28px;
  width: 95px;
  height: 95px;
  opacity: 0.24;
  background:
    linear-gradient(#064e2f, #064e2f) center / 30px 95px no-repeat,
    linear-gradient(#064e2f, #064e2f) center / 95px 30px no-repeat;
}

.hero > div {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #e4fff0;
}

h1 {
  margin: 0;
  font-size: clamp(1.75rem, 8vw, 2.5rem);
  line-height: 1.15;
}

.subtitle {
  margin: 6px 0 0;
  font-size: 1rem;
  color: #f0fff6;
}

main {
  width: min(calc(100% - (var(--page-gutter) * 2)), var(--content-width));
  margin: 0 auto;
  padding: 18px 0;
}

.controls {
  display: grid;
  gap: 12px;
  padding: 14px;
  margin-top: -10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.list-controls {
  margin-top: -4px;
}

.search-label,
.filter-row label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.search-input,
#categorySelect {
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid #c6d4df;
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
}

.search-input:focus,
#categorySelect:focus,
button:focus-visible {
  outline: 3px solid rgba(47, 191, 113, 0.35);
  outline-offset: 2px;
}

.filter-row {
  display: grid;
  gap: 6px;
}

.toggle-button,
.primary-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--primary);
  font-weight: 700;
}

.toggle-button[aria-pressed="true"] {
  color: #ffffff;
  background: var(--accent);
}

.secondary-button,
.back-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--primary-dark);
  background: #ffffff;
  font-weight: 800;
}

.intro-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 16px;
  align-items: end;
  width: 100%;
  padding: 15px 16px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #cfe8da;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.intro-card > *:not(.intro-actions) {
  grid-column: 1;
}

.intro-card h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.35;
}

.intro-card p {
  margin: 4px 0 0;
  color: var(--muted);
}

.intro-kicker {
  display: inline-flex;
  padding: 2px 9px;
  margin: 0 0 4px;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.8rem;
  font-weight: 800;
}

.intro-actions {
  grid-column: 2;
  grid-row: 1 / span 3;
  display: grid;
  gap: 8px;
  justify-items: end;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 5px 10px;
  border: 1px solid #b9dbc8;
  border-radius: 8px;
  color: var(--primary-dark);
  background: #f8fffa;
  font-size: 0.9rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 54px;
  height: 30px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #d6e2dc;
  border: 1px solid #bfd6c8;
  border-radius: 999px;
  transition: 0.2s ease;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 24px;
  height: 24px;
  left: 3px;
  top: 2px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  transition: 0.2s ease;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
  border-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(23px);
}

.intro-link {
  min-height: 38px;
  padding: 5px 12px;
  border: 1px solid #b9dbc8;
  border-radius: 8px;
  color: var(--primary-dark);
  background: #f8fffa;
  font-weight: 800;
  white-space: nowrap;
}

.catalog-section {
  width: 100%;
  margin: 24px auto 0;
}

.catalog-note {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.status-row,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-row {
  margin: 14px 2px 10px;
}

#resultCount {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.text-button {
  min-height: 36px;
  padding: 4px 8px;
  border: 0;
  color: var(--primary);
  background: transparent;
  font-weight: 700;
}

.back-button {
  position: sticky;
  top: 0;
  z-index: 20;
  width: 100%;
  justify-content: center;
  margin: 0 0 14px;
  padding: 0 16px;
  background: rgba(248, 255, 250, 0.96);
  border-color: #cfe8da;
  backdrop-filter: blur(8px);
}

.list-heading {
  padding: 14px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 18px rgba(31, 41, 51, 0.06);
}

.list-heading h2 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.3;
}

.eyebrow-dark {
  margin: 0 0 4px;
  color: var(--primary-dark);
  font-size: 0.84rem;
  font-weight: 800;
}

.message {
  padding: 14px;
  margin: 12px 0;
  border-radius: 8px;
  background: var(--accent-soft);
  color: #14532d;
  font-weight: 700;
}

.message.error {
  background: #fff0f0;
  color: #9b1c1c;
}

.card-grid {
  display: grid;
  gap: 12px;
}

.category-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 14px;
}

.category-card {
  position: relative;
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 13px;
  width: 100%;
  min-height: 116px;
  padding: 18px 18px 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  box-shadow: 0 8px 24px rgba(31, 41, 51, 0.08);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.category-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 30px rgba(31, 41, 51, 0.12);
}

.category-card::after {
  content: "";
  position: absolute;
  right: -26px;
  bottom: -34px;
  width: 112px;
  height: 112px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.42);
}

.category-icon {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  color: #116835;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 1px rgba(17, 104, 53, 0.06);
}

.category-icon-svg {
  display: block;
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.category-copy {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 7px;
  padding-right: 42px;
}

.category-copy strong {
  font-size: 1.08rem;
  line-height: 1.35;
}

.category-copy span {
  color: #3d4c5c;
  font-size: 0.93rem;
  line-height: 1.55;
}

.category-count {
  position: absolute;
  z-index: 1;
  right: 15px;
  bottom: 12px;
  color: #263442;
  font-size: 0.82rem;
  font-weight: 900;
}

.category-card-all { background: linear-gradient(135deg, #e9fbf1, #ddf7ec); }
.category-card-concrete { background: linear-gradient(135deg, #edf4ef, #e3f5ee); }
.category-card-wood { background: linear-gradient(135deg, #eef8d7, #fff7df); }
.category-card-board { background: linear-gradient(135deg, #e7fbf3, #fafffc); }
.category-card-metal { background: linear-gradient(135deg, #eef4ef, #e4eee8); }
.category-card-waterproof { background: linear-gradient(135deg, #e4f7f0, #ddfbf6); }
.category-card-paint { background: linear-gradient(135deg, #eef9d9, #fff0d8); }
.category-card-roof { background: linear-gradient(135deg, #edf3dc, #f6efd7); }
.category-card-glass { background: linear-gradient(135deg, #e2faef, #e8fbf6); }
.category-card-insulation { background: linear-gradient(135deg, #e9f8e6, #f2edfb); }
.category-card-equipment { background: linear-gradient(135deg, #e4f8e3, #edf9dd); }
.category-card-temporary { background: linear-gradient(135deg, #e8fbd8, #f5ffe6); }
.category-card-tools { background: linear-gradient(135deg, #e9f8df, #f7eddc); }

.material-card {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--primary);
  border-radius: 8px;
  box-shadow: 0 4px 18px rgba(31, 41, 51, 0.06);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.material-card h2 {
  margin: 0;
  font-size: 1.22rem;
  line-height: 1.35;
}

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

.english-name {
  margin: 10px 0 0;
  background: #eef8f1;
  border-left: 4px solid #0f6b3f;
  padding: 8px 12px;
  border-radius: 10px;
  color: #123524;
}

.english-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 800;
  color: #0f6b3f;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.english-text {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
}

.category-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 9px;
  margin: 0 0 8px;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.82rem;
  font-weight: 700;
}

.short-description {
  margin: 8px 0 14px;
  color: #384957;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: center;
}

.favorite-button,
.icon-button {
  border: 1px solid var(--line);
  color: var(--primary-dark);
  background: #ffffff;
  border-radius: 8px;
  font-weight: 800;
}

.favorite-button {
  min-width: 48px;
  min-height: 48px;
  font-size: 1.25rem;
}

.favorite-button.is-active {
  border-color: #72c792;
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.primary-button {
  width: 100%;
  padding: 0 16px;
}

.recent-section {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.section-heading h2 {
  margin: 0;
  font-size: 1.15rem;
}

.section-heading .muted {
  margin: 0;
  font-weight: 700;
}

.recent-list {
  display: flex;
  gap: 8px;
  padding: 10px 0 2px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.recent-chip {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 700;
}

.muted {
  margin: 8px 0 0;
  color: var(--muted);
}

.detail-dialog {
  position: fixed;
  inset: 12px;
  width: min(calc(100% - 24px), 680px);
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.28);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #f7faf8;
  z-index: 1000;
}

.detail-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.38rem;
  line-height: 1.25;
}

.dialog-header .category-pill {
  min-height: 25px;
  padding: 2px 8px;
  margin-bottom: 6px;
  font-size: 0.76rem;
}

.dialog-header .reading {
  margin: 2px 0 0;
  font-size: 0.86rem;
}

.dialog-header .english-name {
  margin-top: 7px;
  padding: 6px 9px;
  border-radius: 8px;
}

.dialog-header .english-label {
  font-size: 0.68rem;
}

.dialog-header .english-text {
  font-size: 0.84rem;
}

.icon-button {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  font-size: 1.45rem;
  line-height: 1;
}

.detail-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.detail-action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid #b9dfc8;
  border-radius: 8px;
  color: var(--primary-dark);
  background: #effaf3;
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
}

.detail-action-button:active {
  background: #dff3e7;
}

.detail-toast {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  margin: 8px 14px 0;
  border-radius: 999px;
  color: #ffffff;
  background: rgba(11, 79, 48, 0.9);
  font-size: 0.82rem;
  font-weight: 800;
}

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

.detail-body {
  display: grid;
  gap: 12px;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
}

.detail-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.detail-item h3 {
  margin: 0 0 5px;
  color: var(--primary-dark);
  font-size: 0.95rem;
}

.detail-item p {
  margin: 0;
}

.detail-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

@media (min-width: 640px) {
  main {
    padding: 22px 0;
  }

  .controls {
    grid-template-columns: 1fr;
    align-items: end;
  }

  .category-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

}

@media (max-width: 639px) {
  :root {
    --page-gutter: 16px;
  }

  .hero::after {
    right: 16px;
    top: 24px;
    width: 82px;
    height: 82px;
    background:
      linear-gradient(#064e2f, #064e2f) center / 26px 82px no-repeat,
      linear-gradient(#064e2f, #064e2f) center / 82px 26px no-repeat;
  }

  .intro-card {
    grid-template-columns: 1fr;
  }

  .intro-actions {
    grid-column: 1;
    grid-row: auto;
    justify-items: start;
  }

  .intro-link {
    width: fit-content;
  }

  .detail-dialog {
    inset: 8px;
    width: min(calc(100% - 16px), 680px);
    max-height: calc(100dvh - 16px);
  }

  .detail-actions {
    gap: 8px;
    padding: 10px 12px;
  }
}
