/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Microsoft Learn palette */
  --bg:            #1b1b28;
  --card-bg:       #232333;
  --text:          #f0f0f0;
  --text-dim:      #a0a0b0;
  --link:          #0078d4;
  --link-hover:    #115ea3;
  --code-bg:       #1b1b28;
  
  /* Category colors */
  --cat-language:  #107c10;
  --cat-performance: #0078d4;
  --cat-aspnet:    #53d769;
  --cat-bestpractices: #ffb900;
  --cat-linq:      #1b1b28;
  --cat-tooling:   #e100ff;
  
  --radius:        8px;
  --border:        1px solid rgba(255,255,255,0.1);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-decoration: none;
}
a:hover {
  color: var(--link-hover);
}

/* ── App Layout ────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  /* Keep content clear of the notch / home indicator in every orientation.
     Requires viewport-fit=cover (already set in index.html). The env() values
     are 0 on devices without a notch, so existing layouts are unchanged. */
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  position: relative;
}

/* ── Header ────────────────────────────────────────────── */
.app-header {
  flex-shrink: 0;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.app-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--text);
}

/* ── Category Bar ──────────────────────────────────────── */
.category-nav {
  flex-shrink: 0;
  min-width: 0;
}

.category-bar {
  display: flex;
  gap: 12px;
  padding: 12px 24px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.category-bar::-webkit-scrollbar { display: none; }

.category-scroll-btn {
  display: none;
}

.cat-btn {
  flex-shrink: 0;
  padding: 8px 20px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  background: rgba(255,255,255,0.05);
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.cat-btn:hover {
  background: rgba(255,255,255,0.1);
}
.cat-btn.active {
  background: var(--link);
  border-color: var(--link);
  color: #fff;
}

/* ── Reel Container ───────────────────────────────────── */
.reel-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.reel-track {
  height: 100%;
  transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  will-change: transform;
}

/* ── Snack Card ────────────────────────────────────────── */
.snack-card {
  --snack-body-top: 60px;
  --snack-body-bottom: 104px;
  --snack-side-padding: 24px;
  height: 100%;
  padding: 0;
  background: var(--card-bg);
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Decorative subtle gradient */
.snack-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--cat-color, var(--link)), transparent);
}

/* Category badge */
.snack-category {
  position: absolute;
  top: 12px;
  left: 16px;
  padding: 6px 14px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #fff;
  background: var(--cat-color, var(--link));
  z-index: 2;
}

/* Source badge */
.snack-source {
  position: absolute;
  top: 12px;
  right: 16px;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.65rem;
  font-weight: 500;
  background: rgba(0,120,212,0.15);
  color: var(--link);
  font-family: 'Consolas', 'Monaco', monospace;
  z-index: 2;
}

/* Card number */
.snack-number {
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1;
  opacity: 0.08;
  position: absolute;
  top: 12px;
  right: 20px;
  letter-spacing: -2px;
  color: #fff;
  pointer-events: none;
}

/* Scrollable body lane */
.snack-body-viewport {
  position: absolute;
  top: var(--snack-body-top);
  right: var(--snack-side-padding);
  bottom: var(--snack-body-bottom);
  left: var(--snack-side-padding);
  z-index: 1;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.22) transparent;
}
.snack-body-viewport::-webkit-scrollbar {
  width: 6px;
}
.snack-body-viewport::-webkit-scrollbar-track {
  background: transparent;
}
.snack-body-viewport::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255,255,255,0.18);
}
.snack-body-viewport:focus-visible {
  outline: 2px solid rgba(0,120,212,0.65);
  outline-offset: 4px;
  border-radius: 12px;
}

.snack-body-content {
  min-height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 8px 0;
  transition: transform 0.2s ease-out;
}

/* Damped rubber-band pull while overscrolling at a content boundary */
.snack-card[data-overscroll] .snack-body-content {
  transition: none;
  transform: translateY(var(--overscroll-px, 0px));
}

/* ── Overscroll pull-to-navigate hints ────────────────── */
.overscroll-hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-dim);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  white-space: nowrap;
}
.overscroll-hint-next {
  bottom: 78px;
}
.overscroll-hint-prev {
  top: 42px;
}

/* Title */
.snack-title {
  font-size: 1.45rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
  margin-bottom: 20px;
  width: 100%;
  max-width: 340px;
  position: relative;
  z-index: 1;
  color: #fff;
}

/* Content (the fact) */
.snack-content {
  font-size: 1rem;
  line-height: 1.7;
  text-align: center;
  color: var(--text-dim);
  width: 100%;
  max-width: 360px;
  overflow-wrap: anywhere;
  position: relative;
  z-index: 1;
}

/* Generated example */
.snack-example {
  margin-top: 20px;
  max-width: 360px;
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(7, 17, 28, 0.55);
  color: #d7ecff;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
  z-index: 1;
}

/* Feedback action */
.snack-feedback-button {
  position: absolute;
  left: 16px;
  bottom: 44px;
  z-index: 2;
  padding: 7px 12px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  color: var(--text-dim);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.snack-feedback-button:hover,
.snack-feedback-button:focus-visible {
  border-color: rgba(255,255,255,0.36);
  background: rgba(255,255,255,0.12);
  color: #fff;
}

/* ── Swipe Hint ────────────────────────────────────────── */
.swipe-hint {
  position: absolute;
  bottom: 24px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  opacity: 0.6;
  animation: pulse 2s ease-in-out infinite;
  z-index: 10;
  pointer-events: none;
}
.swipe-arrow {
  display: block;
  font-size: 1.2rem;
  animation: bounce 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* ── Counter ───────────────────────────────────────────── */
.snack-counter {
  position: absolute;
  bottom: 52px;
  right: 16px;
  text-align: right;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  z-index: 10;
}

/* ── Feedback dialog ──────────────────────────────────── */
.feedback-dialog {
  width: min(calc(100% - 32px), 430px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  border: var(--border);
  border-radius: 18px;
  background: #28283a;
  color: var(--text);
  box-shadow: 0 24px 70px rgba(0,0,0,0.55);
}
.feedback-dialog::backdrop {
  background: rgba(8, 8, 16, 0.76);
  backdrop-filter: blur(4px);
}
.feedback-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
}
.feedback-heading {
  display: grid;
  gap: 5px;
}
.feedback-eyebrow {
  color: var(--link);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.feedback-heading h2 {
  font-size: 1.35rem;
}
.feedback-heading p {
  color: var(--text-dim);
  font-size: 0.83rem;
  line-height: 1.45;
}
.feedback-form label {
  margin-top: 4px;
  font-size: 0.88rem;
  font-weight: 600;
}
.feedback-form textarea {
  width: 100%;
  min-height: 130px;
  padding: 12px 14px;
  resize: vertical;
  border: 1px solid rgba(255,255,255,0.17);
  border-radius: 10px;
  outline: none;
  background: var(--code-bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
}
.feedback-form textarea:focus {
  border-color: var(--link);
  box-shadow: 0 0 0 3px rgba(0,120,212,0.2);
}
.feedback-form textarea::placeholder {
  color: #777789;
}
.feedback-field-meta {
  min-height: 20px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.72rem;
}
.feedback-error {
  color: #ff8a9b;
}
.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 2px;
}
.feedback-actions button {
  padding: 10px 16px;
  border-radius: 9px;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}
.feedback-actions button:disabled {
  cursor: wait;
  opacity: 0.6;
}
.feedback-cancel {
  border: 1px solid rgba(255,255,255,0.18);
  background: transparent;
  color: var(--text);
}
.feedback-submit {
  border: 1px solid var(--link);
  background: var(--link);
  color: #fff;
}
.feedback-toast {
  position: fixed;
  left: 50%;
  bottom: 82px;
  z-index: 100;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  transform: translateX(-50%);
  border: 1px solid rgba(83,215,105,0.35);
  border-radius: 12px;
  background: #203629;
  color: #c7f8d0;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  font-size: 0.82rem;
  text-align: center;
}

/* ── Install prompt ───────────────────────────────────── */
.install-prompt {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(86px + env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 456px;
  margin: 0 auto;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 14px;
  background: rgba(35,35,51,0.96);
  box-shadow: 0 18px 46px rgba(0,0,0,0.45);
  backdrop-filter: blur(10px);
}
.install-prompt[hidden] {
  display: none;
}
.install-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
  flex: 1;
}
.install-copy strong {
  color: #fff;
  font-size: 0.88rem;
  line-height: 1.25;
}
.install-copy span {
  color: var(--text-dim);
  font-size: 0.76rem;
  line-height: 1.35;
}
.install-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.install-actions button {
  min-height: 36px;
  padding: 8px 11px;
  border-radius: 9px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.install-dismiss {
  border: 1px solid rgba(255,255,255,0.18);
  background: transparent;
  color: var(--text-dim);
}
.install-submit {
  border: 1px solid var(--link);
  background: var(--link);
  color: #fff;
}

/* ── Loading / Error ───────────────────────────────────── */
.loading-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
}
.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--link);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}
.error-screen h2 { color: #fff; font-size: 1.1rem; }
.error-screen p { color: var(--text-dim); font-size: 0.85rem; }
.error-screen button {
  margin-top: 8px;
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  background: var(--link);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

/* ── Category Colors ───────────────────────────────────── */
.cat-language  { --cat-color: var(--cat-language); }
.cat-performance { --cat-color: var(--cat-performance); }
.cat-aspnet    { --cat-color: var(--cat-aspnet); }
.cat-bestpractices { --cat-color: var(--cat-bestpractices); }
.cat-linq      { --cat-color: var(--cat-linq); }
.cat-tooling   { --cat-color: var(--cat-tooling); }

.snack-category.cat-language     { } /* Color from CSS var */
.snack-category.cat-performance  { } /* Color from CSS var */
.snack-category.cat-aspnet       { } /* Color from CSS var */
.snack-category.cat-bestpractices{ } /* Color from CSS var */
.snack-category.cat-linq         { } /* Color from CSS var */
.snack-category.cat-tooling      { } /* Color from CSS var */

/* ── Animations ────────────────────────────────────────── */
.snack-card.entering {
  animation: slideIn 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}
@keyframes slideIn {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ── Compact viewport tuning ──────────────────────────── */
@media (max-height: 640px) {
  .app-header {
    padding: 12px 20px;
  }
  .app-header h1 {
    font-size: 1.3rem;
  }
  .category-bar {
    padding: 10px 20px 12px;
  }
  .snack-card {
    --snack-body-top: 54px;
    --snack-body-bottom: 92px;
    --snack-side-padding: 20px;
  }
  .snack-title {
    margin-bottom: 14px;
    font-size: 1.28rem;
    line-height: 1.25;
  }
  .snack-content {
    font-size: 0.94rem;
    line-height: 1.58;
  }
  .snack-example {
    margin-top: 14px;
    padding: 12px 14px;
    font-size: 0.76rem;
    line-height: 1.45;
  }
  .snack-feedback-button {
    bottom: 38px;
  }
  .snack-counter {
    bottom: 46px;
  }
  .swipe-hint {
    bottom: 18px;
  }
  .overscroll-hint-next {
    bottom: 68px;
  }
  .overscroll-hint-prev {
    top: 36px;
  }
  .install-prompt {
    bottom: calc(72px + env(safe-area-inset-bottom));
    padding: 10px;
  }
  .install-copy strong {
    font-size: 0.82rem;
  }
  .install-copy span,
  .install-actions button {
    font-size: 0.72rem;
  }
}

/* ── Desktop ───────────────────────────────────────────── */
@media (min-width: 481px) {
  #app {
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.3);
  }
  .reel-container {
    border-radius: 12px;
    overflow: hidden;
  }
  .category-nav {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    align-items: stretch;
    border-bottom: 1px solid rgba(255,255,255,0.05);
  }
  .category-bar {
    min-width: 0;
    padding: 12px 8px 16px;
    border-bottom: 0;
    scroll-behavior: smooth;
  }
  .category-scroll-btn {
    display: grid;
    place-items: center;
    border: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s ease, background 0.2s ease;
    z-index: 1;
  }
  .category-scroll-btn:hover:not(:disabled) {
    background: rgba(255,255,255,0.08);
    color: #fff;
  }
  .category-scroll-btn:focus-visible {
    outline: 2px solid var(--link);
    outline-offset: -2px;
  }
  .category-scroll-btn:disabled {
    color: rgba(255,255,255,0.2);
    cursor: default;
  }
}

@media (min-width: 821px) {
  .install-prompt {
    display: none;
  }
}

@media (max-width: 360px) {
  .install-prompt {
    align-items: stretch;
    flex-direction: column;
  }
  .install-actions {
    justify-content: flex-end;
  }
}
