/**
 * financeforest - Tree & Forest Visualization Styles
 * Abstract geometric tree system with 5 growth states
 */

/* ==========================================================================
   CSS Variables for Forest System
   ========================================================================== */

:root {
  /* Tree colors */
  --tree-leaf-primary: #22C55E;
  --tree-leaf-secondary: #16A34A;
  --tree-leaf-light: #4ADE80;
  --tree-trunk: #1E293B;
  --tree-trunk-light: #334155;
  --tree-glow: #F59E0B;
  --tree-glow-soft: rgba(245, 158, 11, 0.3);

  /* Growth state scales */
  --growth-seed-scale: 0.25;
  --growth-sprout-scale: 0.45;
  --growth-young-scale: 0.7;
  --growth-mature-scale: 1;
  --growth-flourishing-scale: 1;

  /* Growth state opacities */
  --growth-seed-opacity: 0.5;
  --growth-sprout-opacity: 0.7;
  --growth-young-opacity: 0.85;
  --growth-mature-opacity: 1;
  --growth-flourishing-opacity: 1;
}

html.theme-dark {
  --tree-trunk: #94A3B8;
  --tree-trunk-light: #A9B9CD;
}

/* ==========================================================================
   Base Tree Styles
   ========================================================================== */

.tree {
  display: inline-block;
  position: relative;
  transition: transform 0.4s ease, opacity 0.3s ease;
  transform-origin: bottom center;
}

.tree svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Tree parts */
.tree-trunk {
  fill: var(--tree-trunk);
  transition: fill 0.3s ease;
}

.tree-canopy {
  fill: var(--tree-leaf-primary);
  transition: fill 0.3s ease, filter 0.3s ease;
}

.tree-canopy-shadow {
  fill: var(--tree-leaf-secondary);
}

.tree-roots {
  fill: var(--tree-trunk-light);
  transition: fill 0.3s ease;
}

.tree-highlight {
  fill: var(--tree-leaf-light);
  opacity: 0.5;
}

.tree-glow {
  opacity: 0;
  fill: var(--tree-glow);
  filter: blur(8px);
  transition: opacity 0.5s ease;
}

/* ==========================================================================
   Growth States
   ========================================================================== */

/* Seed State - Minimal dot/sprout */
.tree[data-growth="seed"] {
  transform: scale(var(--growth-seed-scale));
  opacity: var(--growth-seed-opacity);
}

.tree[data-growth="seed"] .tree-canopy {
  fill: var(--tree-leaf-secondary);
}

/* Sprout State - Thin stem with leaves */
.tree[data-growth="sprout"] {
  transform: scale(var(--growth-sprout-scale));
  opacity: var(--growth-sprout-opacity);
}

.tree[data-growth="sprout"] .tree-canopy {
  fill: var(--tree-leaf-light);
}

/* Young State - Defined trunk and canopy */
.tree[data-growth="young"] {
  transform: scale(var(--growth-young-scale));
  opacity: var(--growth-young-opacity);
}

/* Mature State - Full canopy, rich color */
.tree[data-growth="mature"] {
  transform: scale(var(--growth-mature-scale));
  opacity: var(--growth-mature-opacity);
}

.tree[data-growth="mature"] .tree-canopy {
  filter: saturate(1.1);
}

/* Flourishing State - Gold highlights, glow */
.tree[data-growth="flourishing"] {
  transform: scale(var(--growth-flourishing-scale));
  opacity: var(--growth-flourishing-opacity);
}

.tree[data-growth="flourishing"] .tree-canopy {
  filter: saturate(1.2) brightness(1.05);
}

.tree[data-growth="flourishing"] .tree-glow {
  opacity: 0.6;
  animation: tree-glow-pulse 3s ease-in-out infinite;
}

.tree[data-growth="flourishing"] .tree-highlight {
  fill: var(--tree-glow);
  opacity: 0.8;
}

/* ==========================================================================
   Tree Hover & Focus States
   ========================================================================== */

.tree-interactive {
  cursor: pointer;
}

.tree-interactive:hover {
  transform: scale(calc(var(--growth-mature-scale) * 1.05));
}

.tree-interactive:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 4px;
  border-radius: var(--radius-md);
}

.tree-interactive:hover .tree-canopy {
  filter: brightness(1.1);
}

/* Growth state hover adjustments */
.tree[data-growth="seed"].tree-interactive:hover {
  transform: scale(calc(var(--growth-seed-scale) * 1.1));
}

.tree[data-growth="sprout"].tree-interactive:hover {
  transform: scale(calc(var(--growth-sprout-scale) * 1.1));
}

.tree[data-growth="young"].tree-interactive:hover {
  transform: scale(calc(var(--growth-young-scale) * 1.08));
}

/* ==========================================================================
   Forest Container (Progress Page)
   ========================================================================== */

.forest {
  position: relative;
  width: 100%;
  min-height: 400px;
  padding: 2rem;
  background: linear-gradient(180deg,
    var(--color-bg) 0%,
    var(--color-primary-bg) 100%
  );
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.forest-ground {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: linear-gradient(180deg,
    transparent 0%,
    var(--tree-leaf-secondary) 50%,
    var(--tree-leaf-primary) 100%
  );
  opacity: 0.3;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Forest grid layout */
.forest-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 1rem;
  position: relative;
  z-index: 1;
  min-height: 320px;
  align-items: end;
  padding-bottom: 40px;
}

@media (max-width: 768px) {
  .forest-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(4, 1fr);
    min-height: 500px;
  }
}

@media (max-width: 480px) {
  .forest-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }
}

/* Individual tree container in forest */
.forest-tree {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  text-align: center;
  padding: 0.5rem;
}

.forest-tree .tree {
  width: 80px;
  height: 120px;
  margin-bottom: 0.5rem;
}

@media (max-width: 480px) {
  .forest-tree .tree {
    width: 60px;
    height: 90px;
  }
}

.forest-tree-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 500;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.forest-tree-status {
  font-size: 0.65rem;
  color: var(--color-text-light);
  margin-top: 2px;
}

/* ==========================================================================
   Hero Tree (Landing Page)
   ========================================================================== */

.hero-tree {
  position: relative;
  width: 200px;
  height: 280px;
  margin: 0 auto;
}

.hero-tree .tree {
  width: 100%;
  height: 100%;
}

@media (max-width: 768px) {
  .hero-tree {
    width: 150px;
    height: 210px;
  }
}

/* ==========================================================================
   Module Tree (Module Pages)
   ========================================================================== */

.module-tree {
  width: 100px;
  height: 140px;
  margin: 0 auto 1rem;
}

.module-tree .tree {
  width: 100%;
  height: 100%;
}

/* ==========================================================================
   Tree Tooltip
   ========================================================================== */

.tree-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  min-width: 160px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  pointer-events: none;
}

.tree-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: var(--color-surface);
}

.forest-tree:hover .tree-tooltip,
.forest-tree:focus-within .tree-tooltip {
  opacity: 1;
  visibility: visible;
}

.tree-tooltip-title {
  font-weight: 600;
  font-size: var(--text-sm);
  margin-bottom: 0.25rem;
}

.tree-tooltip-progress {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.tree-tooltip-state {
  display: inline-block;
  font-size: 0.65rem;
  padding: 2px 6px;
  background: var(--color-primary-bg);
  color: var(--color-primary);
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
  text-transform: capitalize;
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes tree-glow-pulse {
  0%, 100% {
    opacity: 0.4;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(1.05);
  }
}

@keyframes tree-sway {
  0%, 100% {
    transform: rotate(-1deg);
  }
  50% {
    transform: rotate(1deg);
  }
}

@keyframes tree-grow-in {
  0% {
    transform: scale(0) translateY(20px);
    opacity: 0;
  }
  60% {
    transform: scale(1.1) translateY(-5px);
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* Apply sway animation to mature/flourishing trees on hover */
.tree[data-growth="mature"]:hover .tree-canopy,
.tree[data-growth="flourishing"]:hover .tree-canopy {
  animation: tree-sway 2s ease-in-out infinite;
  transform-origin: bottom center;
}

/* Grow-in animation for trees */
.tree.animate-grow {
  animation: tree-grow-in 0.6s ease-out forwards;
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .tree,
  .tree-canopy,
  .tree-glow,
  .tree-tooltip {
    animation: none !important;
    transition: none !important;
  }

  .tree[data-growth="flourishing"] .tree-glow {
    opacity: 0.5;
  }
}

/* ==========================================================================
   Tree Images
   ========================================================================== */

.tree-image {
  width: 100%;
  height: 100%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center bottom;
  transition: filter 0.3s ease;
}

/* Tree type images */
.tree-image[data-type="foundation"] {
  background-image: url('../images/trees/foundation.svg');
}

.tree-image[data-type="broadleaf"] {
  background-image: url('../images/trees/broadleaf.svg');
}

.tree-image[data-type="willow"] {
  background-image: url('../images/trees/willow.svg');
}

.tree-image[data-type="evergreen"] {
  background-image: url('../images/trees/evergreen.svg');
}

.tree-image[data-type="oak"] {
  background-image: url('../images/trees/oak.svg');
}

.tree-image[data-type="roots"] {
  background-image: url('../images/trees/roots.svg');
}

.tree-image[data-type="symmetrical"] {
  background-image: url('../images/trees/symmetrical.svg');
}

.tree-image[data-type="shield"] {
  background-image: url('../images/trees/shield.svg');
}

/* 201 Tree type images */
.tree-image[data-type="sapling-coins"] {
  background-image: url('../images/trees/201/sapling-coins.svg');
}

.tree-image[data-type="fruit-tree"] {
  background-image: url('../images/trees/201/fruit-tree.svg');
}

.tree-image[data-type="bridge-tree"] {
  background-image: url('../images/trees/201/bridge-tree.svg');
}

.tree-image[data-type="cluster"] {
  background-image: url('../images/trees/201/cluster.svg');
}

.tree-image[data-type="sunset-canopy"] {
  background-image: url('../images/trees/201/sunset-canopy.svg');
}

.tree-image[data-type="house-canopy"] {
  background-image: url('../images/trees/201/house-canopy.svg');
}

.tree-image[data-type="layered-canopy"] {
  background-image: url('../images/trees/201/layered-canopy.svg');
}

.tree-image[data-type="bonsai"] {
  background-image: url('../images/trees/201/bonsai.svg');
}

/* Growth state visual effects on tree images */
.tree[data-growth="seed"] .tree-image {
  filter: grayscale(70%) brightness(0.7);
}

.tree[data-growth="sprout"] .tree-image {
  filter: grayscale(40%) brightness(0.85);
}

.tree[data-growth="young"] .tree-image {
  filter: grayscale(10%) brightness(0.95);
}

.tree[data-growth="mature"] .tree-image {
  filter: saturate(1.1) brightness(1);
}

.tree[data-growth="flourishing"] .tree-image {
  filter: saturate(1.3) brightness(1.1);
}

/* Dark mode tree visibility */
html.theme-dark .tree-image {
  filter: brightness(1.12) contrast(1.08);
}

html.theme-dark .tree[data-growth="seed"] .tree-image {
  filter: grayscale(65%) brightness(1.05) contrast(1.06);
}

html.theme-dark .tree[data-growth="sprout"] .tree-image {
  filter: grayscale(36%) brightness(1.1) contrast(1.06);
}

html.theme-dark .tree[data-growth="young"] .tree-image {
  filter: grayscale(10%) brightness(1.12) contrast(1.08);
}

html.theme-dark .tree[data-growth="mature"] .tree-image {
  filter: saturate(1.15) brightness(1.12) contrast(1.08);
}

html.theme-dark .tree[data-growth="flourishing"] .tree-image {
  filter: saturate(1.28) brightness(1.18) contrast(1.1);
}

/* Fallback placeholder for missing images */
.tree-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg,
    var(--tree-leaf-primary) 0%,
    var(--tree-leaf-secondary) 100%
  );
  border-radius: 50% 50% 5% 5%;
  position: relative;
}

.tree-placeholder::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20%;
  height: 30%;
  background: var(--tree-trunk);
  border-radius: 2px;
}

/* ==========================================================================
   Forest Stats Panel
   ========================================================================== */

.forest-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.forest-stat {
  text-align: center;
  padding: 1rem;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.forest-stat-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-primary);
}

.forest-stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

/* ==========================================================================
   Mini Forest (Course Overview)
   ========================================================================== */

.mini-forest {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
}

.mini-forest .tree {
  width: 40px;
  height: 60px;
}

@media (max-width: 480px) {
  .mini-forest .tree {
    width: 30px;
    height: 45px;
  }
}
