/* Mobile-first flashcard styles */
:root {
  --bg: #0d1220;
  --card: #17203a;
  --card-edge: #26335c;
  --text: #eef2ff;
  --muted: #96a1c0;
  --accent: #6c8cff;
  --accent-deep: #4a63d8;
  --easy: #34d399;
  --medium: #fbbf24;
  --hard: #f87171;
  --radius: 20px;
  --code-bg: #0a0f1e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1100px 520px at 50% -8%, #1c2650 0%, rgba(28, 38, 80, 0) 70%) fixed,
    var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  animation: pageIn .3s ease;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid; place-items: center;
  width: 42px; height: 42px; border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  font-weight: 800; font-size: 17px; color: #fff;
  box-shadow: 0 6px 18px rgba(108, 140, 255, .35);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.brand h1 { margin: 0; font-size: 19px; letter-spacing: .2px; }
.subtitle { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--card-edge);
  background: rgba(255, 255, 255, .04);
  color: var(--text); font-size: 20px; cursor: pointer;
  transition: transform .25s ease, background .2s;
}
.icon-btn:active { transform: scale(.94); }
#shuffleBtn:active { transform: rotate(120deg) scale(.94); }

/* Stage */
.stage {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 6px 16px;
  width: 100%; max-width: 560px; margin: 0 auto;
}
.counter { font-size: 13px; color: var(--muted); letter-spacing: 1.5px; font-variant-numeric: tabular-nums; }

/* Card + 3D flip */
.card {
  width: min(94vw, 480px);
  height: min(62vh, 560px);
  height: min(62dvh, 560px);
  min-height: 400px;
  perspective: 1400px;
  cursor: pointer;
  outline: none;
  touch-action: pan-y;
}
.card:focus-visible .card-inner { box-shadow: 0 0 0 3px var(--accent); border-radius: var(--radius); }
.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.25, .8, .3, 1.15);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  background: linear-gradient(160deg, #1d2745 0%, var(--card) 55%, #141c33 100%);
  border: 1px solid var(--card-edge);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .06);
  overflow: hidden;
}
.face-back { transform: rotateY(180deg); overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Front face */
.face-front {
  display: flex; flex-direction: column; align-items: stretch;
  text-align: left; padding: 24px 22px; gap: 10px;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.face-front > * { position: relative; }
.face-front::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(420px 220px at 50% 0%, rgba(108, 140, 255, .16), transparent 70%);
  pointer-events: none;
}
.p-num {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px; color: var(--muted); letter-spacing: 2px;
}
.p-diff {
  font-size: 12px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase;
  padding: 6px 14px; border-radius: 999px;
  border: 1px solid currentColor;
}
.diff-easy { color: var(--easy); background: rgba(52, 211, 153, .1); }
.diff-medium { color: var(--medium); background: rgba(251, 191, 36, .1); }
.diff-hard { color: var(--hard); background: rgba(248, 113, 113, .1); }
.p-top { display: flex; align-items: center; justify-content: space-between; }
.p-title { margin: 2px 0; font-size: clamp(21px, 5.6vw, 27px); line-height: 1.2; letter-spacing: -.3px; }
.p-desc { margin: 4px 0 2px; font-size: 14.5px; line-height: 1.62; color: #cdd6ef; }
.p-example {
  background: var(--code-bg);
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: 12px; padding: 12px 14px;
}
.ex-label {
  display: block; font-size: 10.5px; font-weight: 700;
  letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 6px;
}
.p-example pre {
  margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; line-height: 1.6; color: #dbe2f7; white-space: pre-wrap;
}
.tags { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.tag {
  font-size: 12px; color: var(--muted);
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .08);
  padding: 5px 11px; border-radius: 999px;
}
.flip-hint {
  margin-top: auto; padding-top: 12px;
  font-size: 12.5px; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 7px;
  animation: hint-pulse 2.4s ease-in-out infinite;
}
@keyframes hint-pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* Back face */
.face-back { padding: 24px 22px 28px; text-align: left; }
.b-label {
  font-size: 11px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase;
  color: var(--accent); margin-bottom: 6px;
}
.b-approach { margin: 0 0 10px; font-size: 21px; letter-spacing: -.2px; }
.b-intuition { margin: 0 0 16px; font-size: 14.5px; line-height: 1.6; color: #cdd6ef; }
.b-sec {
  font-size: 11.5px; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--muted); margin: 16px 0 8px;
  padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .08);
}
.b-steps { margin: 0; padding-left: 20px; font-size: 14px; line-height: 1.55; color: #dbe2f7; }
.b-steps li { margin-bottom: 7px; }
.b-steps li::marker { color: var(--accent); font-weight: 700; }
.complexity { display: flex; gap: 10px; margin-top: 4px; }
.cx {
  flex: 1; background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 12px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.cx span { font-size: 11px; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }
.cx strong { font-size: 16px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.code {
  margin: 0; background: var(--code-bg);
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: 12px; padding: 14px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.65; color: #dbe2f7;
}
.tok-k { color: #8fa6ff; }   /* keyword */
.tok-s { color: #7ee2a8; }   /* string */
.tok-n { color: #f5b96b; }   /* number */
.tok-c { color: #5f6b8a; font-style: italic; } /* comment */
.b-note {
  margin-top: 14px; font-size: 12.5px; line-height: 1.55; color: var(--muted);
  border-left: 3px solid var(--accent); padding-left: 10px;
}

/* Dots */
.dots { display: flex; gap: 9px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  border: none; background: rgba(255, 255, 255, .18);
  cursor: pointer; padding: 0; transition: all .25s;
}
.dot.active { background: var(--accent); transform: scale(1.35); box-shadow: 0 0 10px rgba(108, 140, 255, .7); }

/* Controls */
.controls {
  display: flex; gap: 12px; justify-content: center;
  padding: 12px 18px calc(16px + env(safe-area-inset-bottom));
  width: 100%; max-width: 560px; margin: 0 auto;
}
.btn {
  flex: 1; padding: 15px 0; border-radius: 16px;
  border: 1px solid var(--card-edge);
  background: rgba(255, 255, 255, .05);
  color: var(--text); font-size: 16px; font-weight: 600;
  cursor: pointer; transition: transform .12s, background .2s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.96); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  border: none; color: #fff; flex: 1.25;
  box-shadow: 0 8px 22px rgba(108, 140, 255, .35);
}

.kbd-hint { display: none; text-align: center; color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }
@media (hover: hover) and (pointer: fine) {
  .kbd-hint { display: block; }
  .card { height: 540px; }
}

/* Question picker bottom sheet */
.header-actions { display: flex; gap: 10px; }
.icon-btn-sm { width: 36px; height: 36px; font-size: 22px; line-height: 1; }

.sheet-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(4, 7, 16, .62);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .25s ease, visibility .25s ease;
}
.sheet-overlay.show { opacity: 1; visibility: visible; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: 560px; margin: 0 auto;
  max-height: 78vh; max-height: 78dvh;
  background: #141b31;
  border: 1px solid var(--card-edge); border-bottom: none;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -18px 50px rgba(0, 0, 0, .5);
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; flex-direction: column;
  transform: translateY(105%); visibility: hidden;
  transition: transform .32s cubic-bezier(.2, .8, .3, 1), visibility .32s;
}
.sheet.open { transform: translateY(0); visibility: visible; }

.sheet-handle {
  width: 44px; height: 5px; border-radius: 999px;
  background: rgba(255, 255, 255, .18);
  margin: 10px auto 2px; flex: none;
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 18px 10px; flex: none;
}
.sheet-header h2 { margin: 0; font-size: 18px; letter-spacing: -.2px; }
.sheet-list {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 2px 12px 16px;
}

.q-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  background: rgba(255, 255, 255, .03);
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: 14px; padding: 13px 14px; margin-bottom: 8px;
  color: var(--text); cursor: pointer; font-size: 15px;
  transition: background .15s, border-color .15s, transform .1s;
  touch-action: manipulation;
}
.q-row:active { transform: scale(.98); }
.q-row.current { border-color: var(--accent); background: rgba(108, 140, 255, .12); }
.q-num {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--muted); min-width: 30px;
}
.q-title { flex: 1; font-weight: 600; }
.q-diff {
  font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px; border: 1px solid currentColor; flex: none;
}
.q-chev { color: var(--muted); font-size: 18px; flex: none; }

/* Shared cross-project nav (identical on leetcode/jobs/stocks) */
.ww-nav {
  position: sticky;
  top: 0;
  z-index: 200;
  flex: none;
  display: flex;
  justify-content: center;
  padding: calc(8px + env(safe-area-inset-top)) 0 8px;
  background: rgba(10, 14, 26, .9);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.ww-nav-inner {
  width: 100%;
  max-width: 680px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 10px;
}
.ww-nav a {
  color: #96a1c0;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: 999px;
  white-space: nowrap;
  touch-action: manipulation;
  transition: background .2s ease, color .2s ease, transform .12s ease;
}
.ww-nav a:active { transform: scale(.96); }
.ww-nav a.active {
  color: #fff;
  background: rgba(108, 140, 255, .2);
}
.ww-nav .ww-home {
  font-size: 17px;
  padding: 8px 12px;
  color: #c9d2ec;
}

/* Page-load + entrance motion */
@keyframes pageIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes riseIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
