:root {
  color-scheme: light dark;

  --bg-light: #f6f7f2;
  --bg-dark: #111b15;
  --surface-light: #ffffff;
  --surface-dark: #1a2920;
  --surface-muted-light: #eef2e6;
  --surface-muted-dark: #22352a;

  --text-light: #1c2820;
  --text-dark: #eef3ee;
  --text-muted-light: #526358;
  --text-muted-dark: #a6b9ad;

  --brand-light: #2f6b48;
  --brand-dark: #6bc48d;
  --brand-contrast-light: #ffffff;
  --brand-contrast-dark: #0e2216;

  --border-light: #dce3d5;
  --border-dark: #2d4235;

  --accent-gold-light: #d99b26;
  --accent-gold-dark: #f2bd4e;

  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --surface-muted: var(--surface-muted-light);
  --text: var(--text-light);
  --text-muted: var(--text-muted-light);
  --brand: var(--brand-light);
  --brand-contrast: var(--brand-contrast-light);
  --border: var(--border-light);
  --accent-gold: var(--accent-gold-light);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --surface-muted: var(--surface-muted-dark);
    --text: var(--text-dark);
    --text-muted: var(--text-muted-dark);
    --brand: var(--brand-dark);
    --brand-contrast: var(--brand-contrast-dark);
    --border: var(--border-dark);
    --accent-gold: var(--accent-gold-dark);
  }
}

@supports (color: light-dark(white, black)) {
  :root {
    --bg: light-dark(var(--bg-light), var(--bg-dark));
    --surface: light-dark(var(--surface-light), var(--surface-dark));
    --surface-muted: light-dark(var(--surface-muted-light), var(--surface-muted-dark));
    --text: light-dark(var(--text-light), var(--text-dark));
    --text-muted: light-dark(var(--text-muted-light), var(--text-muted-dark));
    --brand: light-dark(var(--brand-light), var(--brand-dark));
    --brand-contrast: light-dark(var(--brand-contrast-light), var(--brand-contrast-dark));
    --border: light-dark(var(--border-light), var(--border-dark));
    --accent-gold: light-dark(var(--accent-gold-light), var(--accent-gold-dark));
  }
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  accent-color: var(--brand);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100dvh;
}

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

.honeypot {
  position: absolute;
  left: -9999px;
  opacity: 0;
  pointer-events: none;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
}

.header-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  border-radius: 10px;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.2;
  color: var(--brand);
}

.brand-subtitle {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-portal {
  min-height: 44px;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.btn-portal:hover {
  color: var(--brand);
  border-color: var(--brand);
}

.btn-install {
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--brand);
  background: transparent;
  color: var(--brand);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
}

/* Desktop Navigation */
.desktop-nav {
  display: none;
  max-width: 980px;
  margin: 0.75rem auto 0;
  gap: 0.5rem;
}

.nav-tab {
  min-height: 44px;
  padding: 0.5rem 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-tab:hover {
  background-color: var(--surface-muted);
  color: var(--text);
}

.nav-tab.active {
  background-color: var(--brand);
  color: var(--brand-contrast);
}

.badge {
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background-color: color-mix(in srgb, currentColor 15%, transparent);
}

/* Main Content */
.app-main {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 1rem;
  flex: 1;
}

/* Search Box */
.search-wrapper {
  margin-bottom: 1rem;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 0.75rem;
}

.search-box:focus-within {
  border-color: var(--brand);
  outline: 2px solid color-mix(in srgb, var(--brand) 25%, transparent);
}

.search-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}

#search-input {
  width: 100%;
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  padding: 0.5rem 0.5rem;
  outline: none;
}

.clear-search {
  min-width: 44px;
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
}

.section-heading {
  font-size: 1.1rem;
  margin: 0 0 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Card Grid */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

.item-card {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.item-card:hover {
  border-color: var(--brand);
}

.item-card:active {
  transform: scale(0.99);
}

.item-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background-color: var(--surface-muted);
}

.item-meta {
  flex: 1;
  min-width: 0;
}

.item-title {
  display: block;
  font-weight: 600;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-subtitle {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.item-star {
  color: var(--accent-gold);
  font-size: 1.2rem;
  flex-shrink: 0;
}

.fav-section-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--brand);
  margin: 1.25rem 0 0.5rem;
}

.fav-section-title:first-child {
  margin-top: 0;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  background-color: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 14px;
}

/* Extra Tab */
.extra-group {
  margin-bottom: 1.5rem;
}

.extra-group-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 0.5rem 0.25rem;
}

.extra-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.extra-item {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
}

.extra-item:hover {
  border-color: var(--brand);
}

.extra-icon {
  font-size: 1.4rem;
  width: 36px;
  text-align: center;
  flex-shrink: 0;
}

.extra-text {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.extra-text small {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.chevron {
  font-size: 1.4rem;
  color: var(--text-muted);
}

.app-footer {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.link-btn {
  min-height: 44px;
  background: none;
  border: none;
  color: var(--brand);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.85rem;
}

.ad-container {
  margin-top: 1.5rem;
  min-height: 90px;
  text-align: center;
  overflow: hidden;
}

/* Mobile Bottom Nav */
.mobile-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background-color: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.mobile-tab {
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.mobile-tab svg {
  width: 22px;
  height: 22px;
}

.mobile-tab.active {
  color: var(--brand);
}

/* Native Modal Dialog */
dialog.app-dialog {
  width: min(92vw, 620px);
  max-height: 85dvh;
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background-color: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
}

dialog.app-dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.dialog-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.detail-badge {
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background-color: var(--surface-muted);
  color: var(--brand);
}

.dialog-title {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.3;
}

.icon-close-btn {
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

.dialog-body {
  padding: 1.15rem 1.25rem;
  overflow-y: auto;
  flex: 1;
}

.dialog-body ul {
  padding-left: 1.25rem;
  margin: 0.5rem 0 1rem;
}

.dialog-body li {
  margin-bottom: 0.35rem;
}

.dialog-body h3 {
  margin: 1rem 0 0.4rem;
  font-size: 1rem;
  color: var(--brand);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.65rem;
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--border);
}

.btn-primary, .btn-secondary {
  min-height: 44px;
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-primary {
  border: none;
  background-color: var(--brand);
  color: var(--brand-contrast);
}

.btn-secondary {
  border: 1px solid var(--border);
  background-color: var(--surface-muted);
  color: var(--text);
}

/* Forms & Notes */
.field-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.notes-textarea, .form-field input, .form-field textarea {
  width: 100%;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background-color: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

.form-field {
  margin-bottom: 1rem;
}

.form-field label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.form-feedback {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--brand);
}

/* Cookie Banner */
.cookie-banner {
  position: fixed;
  bottom: calc(68px + env(safe-area-inset-bottom));
  left: 0.75rem;
  right: 0.75rem;
  z-index: 30;
  max-width: 680px;
  margin: 0 auto;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.cookie-content p {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
}

.cookie-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background-color: var(--text);
  color: var(--bg);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

/* Responsive Tablet & Desktop */
@media (min-width: 768px) {
  .app-shell {
    padding-bottom: 0;
  }

  .mobile-nav {
    display: none;
  }

  .desktop-nav {
    display: flex;
  }

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

  .cookie-banner {
    bottom: 1.25rem;
  }

  .toast {
    bottom: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
