@tailwind base;
@tailwind components;
@tailwind utilities;

/* ═══════════════════════════════════════════════════
   ROOT VARIABLES & BASE
   ═══════════════════════════════════════════════════ */

:root {
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --header-h: 3.25rem;
  color-scheme: dark;
}

/* ═══════════════════════════════════════════════════
   GLOBAL RESETS FOR MOBILE
   ═══════════════════════════════════════════════════ */

*, *::before, *::after {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html {
  overflow: hidden;
  height: 100%;
  height: 100dvh;
}

body {
  overflow: hidden;
  height: 100%;
  height: 100dvh;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
}

#root {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ═══════════════════════════════════════════════════
   SAFE AREA UTILITIES
   ═══════════════════════════════════════════════════ */

.safe-top { padding-top: var(--sat); }
.safe-bottom { padding-bottom: max(var(--sab), 8px); }
.safe-left { padding-left: var(--sal); }
.safe-right { padding-right: var(--sar); }

/* ═══════════════════════════════════════════════════
   SCROLLBAR
   ═══════════════════════════════════════════════════ */

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

/* ═══════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════ */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

@keyframes slideOutLeft {
  from { transform: translateX(0); }
  to   { transform: translateX(-100%); }
}

@keyframes fadeOverlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes fadeOverlayOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.animate-fade-in { animation: fadeIn 0.2s ease-out both; }
.animate-slide-in { animation: slideInLeft 0.25s cubic-bezier(0.16, 1, 0.3, 1) both; }
.animate-slide-out { animation: slideOutLeft 0.2s ease-in both; }
.animate-overlay-in { animation: fadeOverlayIn 0.2s ease-out both; }
.animate-overlay-out { animation: fadeOverlayOut 0.15s ease-in both; }

/* ═══════════════════════════════════════════════════
   MOBILE INPUT FIXES
   ═══════════════════════════════════════════════════ */

textarea, input, select {
  font-size: 16px !important; /* Prevents iOS zoom on focus */
}

@media (min-width: 640px) {
  textarea, input, select {
    font-size: 14px !important;
  }
}

textarea {
  -webkit-appearance: none;
  appearance: none;
}

select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23666' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* ═══════════════════════════════════════════════════
   TOUCH-FRIENDLY RANGE SLIDER
   ═══════════════════════════════════════════════════ */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.08);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e53e3e;
  border: 2px solid #1a1a2e;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(229,62,62,0.3);
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e53e3e;
  border: 2px solid #1a1a2e;
  cursor: pointer;
}

/* ═══════════════════════════════════════════════════
   MARKDOWN PROSE
   ═══════════════════════════════════════════════════ */

.prose-anton {
  color: #e2e2ea;
  line-height: 1.65;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.prose-anton h1, .prose-anton h2, .prose-anton h3,
.prose-anton h4, .prose-anton h5, .prose-anton h6 {
  color: #fff;
  font-weight: 600;
  margin-top: 1.2em;
  margin-bottom: 0.5em;
}

.prose-anton h1 { font-size: 1.4em; }
.prose-anton h2 { font-size: 1.2em; }
.prose-anton h3 { font-size: 1.05em; }

.prose-anton p { margin-bottom: 0.75em; }

.prose-anton ul, .prose-anton ol {
  padding-left: 1.4em;
  margin-bottom: 0.75em;
}

.prose-anton li { margin-bottom: 0.25em; }
.prose-anton li::marker { color: #555; }

.prose-anton code:not(pre code) {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 4px;
  padding: 0.15em 0.35em;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
  color: #ff6b6b;
  word-break: break-all;
}

.prose-anton a {
  color: #e53e3e;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.prose-anton blockquote {
  border-left: 3px solid #e53e3e;
  padding: 0.5em 1em;
  margin: 0.75em 0;
  background: rgba(229,62,62,0.04);
  border-radius: 0 6px 6px 0;
  color: #aaa;
}

.prose-anton hr {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin: 1.5em 0;
}

.prose-anton table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85em;
  margin: 0.75em 0;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.prose-anton th, .prose-anton td {
  border: 1px solid rgba(255,255,255,0.08);
  padding: 0.4em 0.7em;
  text-align: left;
  white-space: nowrap;
}

.prose-anton th {
  background: rgba(255,255,255,0.04);
  font-weight: 600;
}

.prose-anton strong { color: #fff; font-weight: 600; }
.prose-anton em { font-style: italic; }

/* ═══════════════════════════════════════════════════
   THINKING PULSE
   ═══════════════════════════════════════════════════ */

@keyframes thinkPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.thinking-pulse { animation: thinkPulse 1.5s ease-in-out infinite; }

/* ═══════════════════════════════════════════════════
   MOBILE-SPECIFIC OVERRIDES
   ═══════════════════════════════════════════════════ */

@media (max-width: 639px) {
  .prose-anton { font-size: 0.9rem; line-height: 1.6; }
  .prose-anton h1 { font-size: 1.25em; }
  .prose-anton h2 { font-size: 1.15em; }
}

/* Prevent body scroll when modal/drawer is open */
body.drawer-open {
  touch-action: none;
}