/* ============================================================
   CaribFlow — css/main.css
   Layout Foundation, Box Model Reset, Base Typography
   ============================================================ */

@import url("./variables.css");

/* ── UNIVERSAL RESET ──────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  font-family: var(--font-active);
  font-size: var(--text-base);
  color: var(--text-main);
  background-color: var(--bg-primary);
  background-image: var(--gradient-ambient);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  transition: background-color var(--transition-smooth), color var(--transition-smooth);
}

/* ── SELECTION ────────────────────────────────────────────── */
::selection {
  background: var(--accent-subtle);
  color: var(--accent-color);
}

/* ── TYPOGRAPHY HIERARCHY ─────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-active);
  font-weight: var(--fw-bold);
  color: var(--text-main);
  line-height: 1.2;
  letter-spacing: -0.02em;
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); }
h6 { font-size: var(--text-base); }

p {
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: var(--space-4);
}
p:last-child { margin-bottom: 0; }

a {
  color: var(--accent-color);
  text-decoration: none;
  transition: var(--transition-fast);
}
a:hover { opacity: 0.8; }
a:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

strong { font-weight: var(--fw-bold); }
em { font-style: italic; }
small { font-size: var(--text-sm); color: var(--text-muted); }

code, pre {
  font-family: var(--font-family-mono);
  font-size: 0.9em;
}
code {
  background: var(--accent-subtle);
  color: var(--accent-color);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
}
pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-apple);
  padding: var(--space-4);
  overflow-x: auto;
}

/* ── LISTS ────────────────────────────────────────────────── */
ul, ol {
  padding-left: var(--space-6);
  color: var(--text-secondary);
}
li { margin-bottom: var(--space-2); }

/* ── IMAGES & MEDIA ───────────────────────────────────────── */
img, video, canvas, svg {
  display: block;
  max-width: 100%;
}
img { object-fit: cover; }

/* ── FORM ELEMENTS BASE ───────────────────────────────────── */
input, textarea, select, button {
  font-family: var(--font-active);
  font-size: var(--text-base);
  color: var(--text-main);
  border: none;
  outline: none;
  background: none;
}
input::placeholder, textarea::placeholder {
  color: var(--text-placeholder);
}
button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

/* ── PAGE LAYOUT SCAFFOLDING ──────────────────────────────── */
.page-wrapper {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-content {
  flex: 1;
  padding-top: calc(64px + var(--space-4)); /* Island offset */
  padding-bottom: var(--space-20);
}

/* ── CONTAINER SYSTEM ─────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}
.container-sm { max-width: 720px; }
.container-md { max-width: 960px; }
.container-lg { max-width: 1120px; }
.container-full { max-width: 100%; }

/* ── GRID SYSTEM ──────────────────────────────────────────── */
.grid {
  display: grid;
  gap: var(--space-4);
}
.grid-1 { grid-template-columns: 1fr; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-dashboard { grid-template-columns: repeat(12, 1fr); }

/* ── FLEX UTILITIES ───────────────────────────────────────── */
.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.flex-center  { align-items: center; justify-content: center; }
.flex-between { align-items: center; justify-content: space-between; }
.flex-start   { align-items: center; justify-content: flex-start; }
.flex-end     { align-items: center; justify-content: flex-end; }
.flex-wrap    { flex-wrap: wrap; }
.flex-1       { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }
.gap-1  { gap: var(--space-1); }
.gap-2  { gap: var(--space-2); }
.gap-3  { gap: var(--space-3); }
.gap-4  { gap: var(--space-4); }
.gap-6  { gap: var(--space-6); }
.gap-8  { gap: var(--space-8); }

/* ── SPACING UTILITIES ────────────────────────────────────── */
.mt-auto { margin-top: auto; }
.mb-auto { margin-bottom: auto; }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }
.p-4  { padding: var(--space-4); }
.p-6  { padding: var(--space-6); }
.p-8  { padding: var(--space-8); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

/* ── TEXT UTILITIES ───────────────────────────────────────── */
.text-center  { text-align: center; }
.text-left    { text-align: left; }
.text-right   { text-align: right; }
.text-main    { color: var(--text-main); }
.text-muted   { color: var(--text-muted); }
.text-accent  { color: var(--accent-color); }
.text-success { color: var(--color-success); }
.text-error   { color: var(--color-error); }
.text-warning { color: var(--color-warning); }
.font-bold    { font-weight: var(--fw-bold); }
.font-medium  { font-weight: var(--fw-medium); }
.uppercase    { text-transform: uppercase; letter-spacing: 0.08em; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── DISPLAY UTILITIES ────────────────────────────────────── */
.hidden        { display: none !important; }
.visible       { display: block !important; }
.invisible     { visibility: hidden; }
.opacity-0     { opacity: 0; }
.opacity-50    { opacity: 0.5; }
.overflow-hidden { overflow: hidden; }
.overflow-auto   { overflow: auto; }
.relative        { position: relative; }
.absolute        { position: absolute; }
.fixed           { position: fixed; }
.sticky          { position: sticky; }
.inset-0         { top: 0; right: 0; bottom: 0; left: 0; }
.z-modal         { z-index: var(--z-modal); }
.w-full          { width: 100%; }
.h-full          { height: 100%; }
.min-h-screen    { min-height: 100vh; }

/* ── SECTION DIVIDER ──────────────────────────────────────── */
.divider {
  width: 100%;
  height: 1px;
  background: var(--divider);
  margin: var(--space-6) 0;
}
.divider-v {
  width: 1px;
  height: 100%;
  background: var(--divider);
  margin: 0 var(--space-6);
}

/* ── AVATAR SYSTEM ────────────────────────────────────────── */
.avatar {
  border-radius: var(--radius-pill);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--accent-subtle);
  border: 2px solid var(--glass-border);
}
.avatar-sm  { width: 32px;  height: 32px; }
.avatar-md  { width: 48px;  height: 48px; }
.avatar-lg  { width: 72px;  height: 72px; }
.avatar-xl  { width: 96px;  height: 96px; }
.avatar-2xl { width: 128px; height: 128px; }

/* ── BADGE DISPLAY ────────────────────────────────────────── */
.badge-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}
.badge-icon-lg {
  width: 64px;
  height: 64px;
}

/* ── SKELETON LOADERS ─────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--skeleton-base) 25%,
    var(--skeleton-shine) 50%,
    var(--skeleton-base) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: var(--radius-apple);
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── CURRENCY CHIPS ───────────────────────────────────────── */
.currency-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
}
.currency-chip.coins {
  background: rgba(255, 215, 0, 0.15);
  color: var(--coin-color);
  border: 1px solid rgba(255, 215, 0, 0.3);
}
.currency-chip.diamonds {
  background: rgba(0, 212, 255, 0.15);
  color: var(--diamond-color);
  border: 1px solid rgba(0, 212, 255, 0.3);
}
.currency-chip.xp {
  background: rgba(155, 89, 182, 0.15);
  color: var(--xp-color);
  border: 1px solid rgba(155, 89, 182, 0.3);
}

/* ── PROGRESS BAR ─────────────────────────────────────────── */
.progress-track {
  width: 100%;
  height: 8px;
  background: var(--glass-border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--gradient-primary);
  border-radius: var(--radius-pill);
  transition: width var(--transition-smooth);
  position: relative;
}
.progress-fill::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 0 6px var(--accent-glow);
}
.progress-track.thin { height: 4px; }
.progress-track.thick { height: 12px; }

/* ── XP BAR ───────────────────────────────────────────────── */
.xp-bar-container {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.xp-bar-label {
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  color: var(--xp-color);
  flex-shrink: 0;
}

/* ── TOOLTIPS ─────────────────────────────────────────────── */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--island-bg);
  color: var(--island-text);
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-apple);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: var(--transition-fast);
  z-index: var(--z-tooltip, 999);
}
[data-tooltip]:hover::after { opacity: 1; }

/* ── FOCUS RING (ACCESSIBILITY) ───────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* ── SMOOTH PAGE TRANSITIONS ──────────────────────────────── */
.page-enter {
  animation: pageEnter 0.3s var(--ease-smooth) forwards;
}
@keyframes pageEnter {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── GLOW PULSE ANIMATION ─────────────────────────────────── */
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 12px var(--accent-glow); }
  50%       { box-shadow: 0 0 24px var(--accent-glow), 0 0 48px var(--accent-glow); }
}
@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50%       { transform: translateY(-8px); }
}
@keyframes spinIn {
  from { transform: rotate(-180deg) scale(0.5); opacity: 0; }
  to   { transform: rotate(0deg) scale(1); opacity: 1; }
}
@keyframes bounceIn {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.15); }
  80%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideDown {
  from { transform: translateY(-20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes scaleIn {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ── PRINT RESET ──────────────────────────────────────────── */
@media print {
  body { background: white; color: black; }
  .no-print { display: none !important; }
}
