/* KING Vision — Useful Apps
   High-contrast, accessibility-first stylesheet.
   Black background / white text, large legible type, visible focus states. */

:root {
  --bg: #000000;
  --bg-raised: #141414;
  --bg-card: #101010;
  --bg-card-hover: #181818;
  --border: #3a3a3a;
  --border-strong: #ffffff;
  --text: #ffffff;
  --text-dim: #c9c9c9;
  --accent: #ffd400;
  --accent-text: #000000;
  --focus: #ffd400;
  --link: #9fd8ff;
  --link-visited: #d1b3ff;
  --danger: #ff8a80;
  --ok: #8ff0a4;
  --max-width: 1100px;
  --shell-width: 1280px;
  --radius: 10px;
  --radius-sm: 6px;
  --header-height: 76px;
  --gutter: 20px;
  --transition: 0.16s ease;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", Arial, sans-serif;
}

/* Light theme — same structure/contrast targets as the dark theme above,
   swapped for a white background with dark text. Applied via
   [data-theme="light"] on <html>, set by the inline no-flash script in
   index.html and toggled by the theme-toggle button in app.js. */
html[data-theme="light"] {
  --bg: #ffffff;
  --bg-raised: #f2f2f2;
  --bg-card: #f7f7f7;
  --bg-card-hover: #ececec;
  --border: #949494;
  --border-strong: #000000;
  --text: #000000;
  --text-dim: #3d3d3d;
  --accent: #8a6d00;
  --accent-text: #ffffff;
  --focus: #6b5500;
  --link: #0053a6;
  --link-visited: #6a2ba0;
  --danger: #a4001e;
  --ok: #146b2c;
}

html[data-theme="light"] {
  color-scheme: light;
}

/* Fluid content gutter: tighter on phones, roomier on desktop */
@media (min-width: 640px) {
  :root { --gutter: 32px; }
}
@media (min-width: 1024px) {
  :root { --gutter: 40px; }
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.6;
  min-height: 100vh;
}

img {
  max-width: 100%;
}

a {
  color: var(--link);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

a:visited {
  color: var(--link-visited);
}

a:hover {
  color: var(--accent);
}

/* Strong, visible focus for keyboard users everywhere */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  background: var(--accent);
  color: var(--accent-text);
  padding: 12px 18px;
  border-radius: 6px;
  font-weight: 700;
  z-index: 1000;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 8px;
}

/* Header */
.site-header {
  border-bottom: 2px solid var(--border);
  padding: 0 var(--gutter);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

.site-header-inner {
  max-width: var(--shell-width);
  margin: 0 auto;
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}

.brand:hover,
.brand:focus-visible {
  color: var(--accent);
}

.brand-mark {
  color: var(--accent);
  font-size: 1.3rem;
}

/* Dark/light theme toggle — always visible in the header, independent of
   the collapsible nav, so the preference is reachable on every screen size. */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-height: 44px;
  min-width: 44px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

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

.theme-toggle-icon {
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.theme-toggle-icon svg {
  width: 100%;
  height: 100%;
}

/* Show the moon in dark mode (offering to switch to light), the sun in
   light mode (offering to switch to dark). */
.theme-toggle-icon.icon-sun {
  display: none;
}

html[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

html[data-theme="light"] .theme-toggle .icon-sun {
  display: inline-flex;
}

/* Hamburger toggle — visible below the "laptop" breakpoint */
.nav-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  min-height: 44px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

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

.nav-toggle-box {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 20px;
  height: 16px;
}

.nav-toggle-bar {
  display: block;
  height: 2px;
  width: 100%;
  background: currentColor;
  border-radius: 2px;
  transition: transform var(--transition), opacity var(--transition);
}

.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(2) {
  opacity: 0;
}
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.main-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: fixed;
  top: var(--header-height);
  right: 0;
  width: min(320px, 84vw);
  max-height: calc(100vh - var(--header-height));
  overflow-y: auto;
  background: var(--bg-raised);
  border-left: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
  border-bottom-left-radius: var(--radius);
  padding: 14px;
  transform: translateX(100%);
  transition: transform var(--transition);
  z-index: 150;
}

.main-nav.is-open {
  transform: translateX(0);
}

.main-nav a {
  color: var(--text);
  text-decoration: none;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  border: 2px solid transparent;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.main-nav a:hover {
  border-color: var(--border);
}

.main-nav a[aria-current="page"] {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255, 212, 0, 0.08);
}

.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 140;
}

.nav-backdrop[hidden] {
  display: none;
}

/* Laptop and wider: nav becomes an inline horizontal bar, hamburger hides */
@media (min-width: 900px) {
  .nav-toggle {
    display: none;
  }

  .main-nav {
    position: static;
    flex-direction: row;
    width: auto;
    max-height: none;
    overflow: visible;
    background: transparent;
    border: 0;
    padding: 0;
    transform: none;
    gap: 4px;
  }

  .main-nav a {
    min-height: auto;
    padding: 10px 14px;
  }

  .nav-backdrop {
    display: none !important;
  }
}

/* Layout */
main {
  max-width: var(--shell-width);
  margin: 0 auto;
  padding: 32px var(--gutter) 80px;
}

.page-title {
  font-size: 2.2rem;
  margin: 0 0 8px;
}

.page-subtitle {
  color: var(--text-dim);
  font-size: 1.1rem;
  margin: 0 0 32px;
  max-width: 65ch;
}

/* Home hero */
.hero {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 28px;
  margin-bottom: 40px;
  background: linear-gradient(180deg, var(--bg-raised), var(--bg));
}

.hero h1 {
  font-size: clamp(2rem, 4vw, 2.8rem);
  margin: 0 0 14px;
}

.hero p {
  color: var(--text-dim);
  font-size: 1.15rem;
  max-width: 60ch;
  margin: 0 0 24px;
}

.hero-actions {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.btn {
  display: inline-block;
  padding: 12px 22px;
  border-radius: 8px;
  font-weight: 700;
  text-decoration: none;
  border: 2px solid var(--accent);
  cursor: pointer;
  font-size: 1rem;
  font-family: inherit;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-primary:hover {
  background: #ffe14d;
  color: var(--accent-text);
}

.btn-secondary {
  background: transparent;
  color: var(--accent);
}

.btn-secondary:hover {
  background: rgba(255, 212, 0, 0.12);
  color: var(--accent);
}

/* Stat row */
.stat-row {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
  margin: 32px 0;
}

.stat {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
}

.stat-number {
  font-size: 2rem;
  font-weight: 800;
  display: block;
}

.stat-label {
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* Category grid on home */
.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 48px 0 18px;
  flex-wrap: wrap;
}

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

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.category-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: var(--text);
  display: block;
  background: var(--bg-card);
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

.category-card:hover,
.category-card:focus-visible {
  border-color: var(--accent);
  color: var(--text);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}

.category-card-name {
  font-weight: 700;
  font-size: 1.05rem;
  display: block;
  margin-bottom: 6px;
}

.category-card-count {
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* Controls: search + filter */
.controls {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 24px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--bg-raised);
}

.control-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 220px;
}

.control-field label {
  font-weight: 700;
  font-size: 0.95rem;
}

.control-field input,
.control-field select {
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
}

.control-field input:focus-visible,
.control-field select:focus-visible {
  border-color: var(--accent);
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrap .search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-dim);
  pointer-events: none;
}

.search-input-wrap input#search-input {
  padding-left: 40px;
  width: 100%;
}

.results-summary {
  margin: 0 0 20px;
  color: var(--text-dim);
}

/* App grid / list */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.app-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg-card);
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

.app-card:hover,
.app-card:focus-within {
  border-color: var(--accent);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}

.app-card h3 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.app-card h3 a {
  color: var(--text);
  text-decoration: none;
}

.app-card h3 a:hover,
.app-card h3 a:focus-visible {
  color: var(--accent);
}

.app-card-category {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 2px 10px;
  margin-bottom: 10px;
}

.app-card-overview {
  color: var(--text-dim);
  font-size: 0.96rem;
  margin: 0 0 14px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.platform-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  color: var(--text-dim);
}

.badge.yes {
  border-color: var(--ok);
  color: var(--ok);
}

.no-results {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  color: var(--text-dim);
}

/* Breadcrumb */
.breadcrumb {
  margin: 0 0 20px;
  color: var(--text-dim);
  font-size: 0.95rem;
}

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

.breadcrumb a:hover {
  color: var(--accent);
}

/* App detail page */
.app-detail-header {
  border-bottom: 2px solid var(--border);
  padding-bottom: 24px;
  margin-bottom: 28px;
}

.app-detail-header .app-card-category {
  margin-bottom: 12px;
}

.app-detail-header h1 {
  margin: 0 0 14px;
}

.app-detail-header .overview {
  color: var(--text-dim);
  font-size: 1.1rem;
  max-width: 70ch;
}

.detail-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.detail-section {
  margin-bottom: 36px;
}

.detail-section h2 {
  font-size: 1.35rem;
  border-left: 4px solid var(--accent);
  padding-left: 12px;
  margin: 0 0 14px;
}

.detail-section ul {
  padding-left: 24px;
  margin: 0;
}

.detail-section li {
  margin-bottom: 8px;
}

.feature-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 12px;
}

.feature-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}

.feature-item h3 {
  margin: 0 0 4px;
  font-size: 1.02rem;
}

.feature-item p {
  margin: 0;
  color: var(--text-dim);
}

.pros-cons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.pros-cons-grid > div {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.pros-cons-grid h3 {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.availability-table {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 20px;
  max-width: 480px;
}

.availability-table dt {
  font-weight: 700;
}

.availability-table dd {
  margin: 0;
  color: var(--text-dim);
}

.recommendation-box {
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 22px;
  background: rgba(255, 212, 0, 0.06);
}

.recommendation-verdict {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--accent);
  display: block;
  margin-bottom: 8px;
}

.link-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.link-list .btn {
  border-color: var(--border);
  color: var(--text);
}

.link-list .btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.link-list .unavailable {
  color: var(--text-dim);
  border: 2px solid var(--border);
  padding: 12px 22px;
  border-radius: 8px;
  font-weight: 600;
}

/* Store / download buttons — icon + label, 44px minimum touch target */
.btn-store,
.detail-actions .unavailable {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 20px;
}

.btn-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.detail-actions .unavailable {
  display: inline-flex;
}

.detail-actions .unavailable .btn-icon {
  color: var(--text-dim);
}

/* About page */
.about-content section {
  margin-bottom: 28px;
}

.about-content h2 {
  font-size: 1.3rem;
}

.contact-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Footer */
.site-footer {
  border-top: 2px solid var(--border);
  padding: 48px var(--gutter) 28px;
  margin-top: 60px;
  background: var(--bg-raised);
}

.site-footer-inner {
  max-width: var(--shell-width);
  margin: 0 auto;
  color: var(--text-dim);
  font-size: 0.95rem;
}

.footer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 32px;
}

.footer-col {
  min-width: 0;
}

.footer-about p {
  max-width: 42ch;
  margin: 12px 0 0;
}

.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
}

.footer-logo {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  margin-bottom: 12px;
}

.footer-brand:hover,
.footer-brand:focus-visible {
  color: var(--accent);
}

.footer-heading {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--text);
  margin: 0 0 14px;
}

.footer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.footer-list a {
  color: var(--text-dim);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.footer-list a:hover,
.footer-list a:focus-visible {
  color: var(--accent);
}

.footer-bottom {
  border-top: 1px solid var(--border);
  margin-top: 36px;
  padding-top: 20px;
}

.footer-bottom p {
  margin: 0;
}

@media (min-width: 640px) {
  .footer-grid {
    grid-template-columns: 1.4fr 1fr 1fr;
    gap: 24px;
  }
}

@media (min-width: 900px) {
  .footer-grid {
    grid-template-columns: 1.6fr 1fr 1fr;
    gap: 48px;
  }
}

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

/* Phones: tighten type and stack controls */
@media (max-width: 480px) {
  body {
    font-size: 16.5px;
  }
  .hero {
    padding: 28px 20px;
  }
  .stat-row {
    gap: 20px;
  }
  .controls {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Very narrow phones: drop the hamburger's text label so the header
   has room to breathe (the button keeps an aria-label for screen readers). */
@media (max-width: 400px) {
  .brand {
    font-size: 1.25rem;
  }
  .nav-toggle-label {
    display: none;
  }
  .nav-toggle {
    padding: 8px 10px;
  }
  .theme-toggle-label {
    display: none;
  }
  .theme-toggle {
    padding: 8px 10px;
  }
}

/* Tablets: two-column card grids feel roomier than auto-fill's default */
@media (min-width: 640px) and (max-width: 899px) {
  .app-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Laptop and up: wider shell already applies (see --shell-width); give
   card grids a bit more breathing room and cap column count so cards
   don't stretch too wide on very large monitors. */
@media (min-width: 1024px) {
  .app-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
  .category-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
  .hero {
    padding: 56px 48px;
  }
}

@media (min-width: 1440px) {
  :root {
    --shell-width: 1360px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
