/* ============================================
   JT's Bitcoin Price Watch - Styles
   Dark theme with Bitcoin orange accents
   ============================================ */

/* CSS Variables */
:root {
    --bg-primary: #0d0d0d;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --border-color: #2a2a2a;
    
    --bitcoin-orange: #f7931a;
    --bitcoin-gold: #ffb347;
    
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --text-muted: #666666;
    
    --positive: #00ff88;
    --negative: #ff4444;
    
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

/* ============================================
   3D Spinning Bitcoin Coins Background
   ============================================ */
#coins-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
    perspective: 1000px;
}

.bitcoin-coin {
    position: absolute;
    width: 60px;
    height: 60px;
    transform-style: preserve-3d;
    animation: spin3d var(--spin-duration, 5s) linear infinite;
    opacity: var(--coin-opacity, 0.15);
    filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.4))
            drop-shadow(0 0 30px rgba(247, 147, 26, 0.2));
}

/* Front face of coin */
.coin-front,
.coin-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 50%;
}

.coin-front img,
.coin-back img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.coin-front {
    transform: rotateY(0deg);
}

.coin-back {
    transform: rotateY(180deg);
}

/* Coin edge (thickness) - creates 3D depth illusion */
.bitcoin-coin::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, 
        #654321 0%, 
        #8B6914 10%, 
        #B8860B 25%,
        #DAA520 50%,
        #B8860B 75%,
        #8B6914 90%,
        #654321 100%
    );
    transform: translateY(-50%) rotateX(90deg) translateZ(0px);
    border-radius: 2px;
    opacity: 0.8;
}

/* Alternative edge segments for more realistic look */
.bitcoin-coin::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, 
        #654321 0%, 
        #8B6914 10%, 
        #B8860B 25%,
        #DAA520 50%,
        #B8860B 75%,
        #8B6914 90%,
        #654321 100%
    );
    transform: translateX(-50%) rotateY(90deg) translateZ(0px);
    border-radius: 2px;
    opacity: 0.8;
}

@keyframes spin3d {
    0% {
        transform: rotateY(0deg) rotateX(var(--tilt, 10deg));
    }
    100% {
        transform: rotateY(360deg) rotateX(var(--tilt, 10deg));
    }
}

/* Shimmer effect on coins */
@keyframes shimmer {
    0%, 100% {
        filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.4))
                drop-shadow(0 0 30px rgba(247, 147, 26, 0.2));
    }
    50% {
        filter: drop-shadow(0 0 20px rgba(255, 215, 0, 0.6))
                drop-shadow(0 0 40px rgba(247, 147, 26, 0.3));
    }
}

/* Parallax depth classes */
.coin-depth-1 { --parallax-speed: 0.1; }
.coin-depth-2 { --parallax-speed: 0.2; }
.coin-depth-3 { --parallax-speed: 0.3; }
.coin-depth-4 { --parallax-speed: 0.4; }
.coin-depth-5 { --parallax-speed: 0.5; }

/* ============================================
   Main Content Container
   ============================================ */
.content {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* ============================================
   Header
   ============================================ */
.header {
    text-align: center;
    padding: 2rem 0 3rem;
}

.title {
    font-size: clamp(1.8rem, 5vw, 3rem);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.bitcoin-symbol {
    color: var(--bitcoin-orange);
    margin-right: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ============================================
   Hero: Live Price
   ============================================ */
.hero {
    text-align: center;
    padding: 3rem 0;
    background: linear-gradient(180deg, transparent 0%, rgba(247, 147, 26, 0.03) 50%, transparent 100%);
    border-radius: 20px;
    margin-bottom: 2rem;
}

.price-container {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0.25rem;
}

.price-dollar {
    font-size: clamp(2rem, 6vw, 4rem);
    color: var(--text-secondary);
    font-weight: 300;
    line-height: 1;
    padding-top: 0.5rem;
}

.price-value {
    font-size: clamp(3.5rem, 12vw, 7rem);
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-primary);
    line-height: 1;
    letter-spacing: -0.02em;
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

.price-value.pulse {
    animation: pricePulse 0.5s ease;
}

@keyframes pricePulse {
    0%, 100% {
        text-shadow: 0 0 0 transparent;
    }
    50% {
        text-shadow: 0 0 30px var(--bitcoin-orange);
    }
}

.price-change {
    margin-top: 1rem;
    font-size: clamp(1.2rem, 3vw, 1.8rem);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.change-icon {
    font-weight: bold;
}

.change-value {
    font-weight: 600;
    font-family: var(--font-mono);
}

.change-value.positive,
.change-icon.positive {
    color: var(--positive);
}

.change-value.negative,
.change-icon.negative {
    color: var(--negative);
}

.change-label {
    color: var(--text-muted);
    font-size: 0.9em;
}

.last-updated {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

/* Refresh Button */
.refresh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.refresh-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--bitcoin-orange);
    color: var(--bitcoin-orange);
    transform: scale(1.05);
}

.refresh-btn:active {
    transform: scale(0.95);
}

.refresh-btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.refresh-icon {
    width: 16px;
    height: 16px;
    transition: transform 0.3s ease;
}

.refresh-btn.refreshing .refresh-icon {
    animation: spinRefresh 1s linear infinite;
}

@keyframes spinRefresh {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ============================================
   Stats Grid
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 3rem;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--bitcoin-orange);
}

.stat-card-wide {
    grid-column: span 4;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, rgba(247, 147, 26, 0.08) 100%);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: clamp(1.3rem, 3vw, 1.8rem);
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.stat-card-wide .stat-value {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    color: var(--bitcoin-orange);
}

/* ============================================
   Calculator
   ============================================ */
.calculator {
    margin-bottom: 3rem;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    text-align: center;
}

.calculator-box {
    max-width: 500px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
}

.calc-label {
    display: block;
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.input-wrapper {
    position: relative;
    max-width: 300px;
    margin: 0 auto 1.5rem;
}

.input-prefix {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.5rem;
    color: var(--bitcoin-orange);
    font-weight: 600;
}

.btc-input {
    width: 100%;
    padding: 1rem 1rem 1rem 3rem;
    font-size: 1.5rem;
    font-family: var(--font-mono);
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.btc-input:focus {
    border-color: var(--bitcoin-orange);
    box-shadow: 0 0 0 3px rgba(247, 147, 26, 0.2);
}

.btc-input::placeholder {
    color: var(--text-muted);
}

/* Remove number input spinners */
.btc-input::-webkit-outer-spin-button,
.btc-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.btc-input[type=number] {
    -moz-appearance: textfield;
}

.calc-result {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.equals {
    font-size: 1.5rem;
    color: var(--text-muted);
}

.usd-value {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--positive);
}

.usd-label {
    font-size: 1.2rem;
    color: var(--text-muted);
}

/* ============================================
   Power Law Chart
   ============================================ */
.chart-section {
    margin-bottom: 3rem;
}

.chart-description {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.chart-container {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    height: 450px;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.chart-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chart-loading::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--bitcoin-orange);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.chart-loading.hidden {
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.legend-color {
    width: 20px;
    height: 3px;
    border-radius: 2px;
}

.legend-price {
    background: var(--text-primary);
}

.legend-powerlaw {
    background: var(--bitcoin-orange);
}

/* ============================================
   Footer
   ============================================ */
.footer {
    text-align: center;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.footer a {
    color: var(--bitcoin-orange);
    text-decoration: none;
    transition: opacity 0.2s ease;
}

.footer a:hover {
    opacity: 0.8;
}

.refresh-info {
    margin-top: 0.5rem;
    font-size: 0.8rem;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 900px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .stat-card-wide {
        grid-column: span 2;
    }
}

@media (max-width: 600px) {
    .content {
        padding: 1rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }
    
    .header {
        padding: 1rem 0 1.5rem;
    }
    
    .title {
        font-size: 1.5rem;
    }
    
    .subtitle {
        font-size: 0.8rem;
    }
    
    .hero {
        padding: 2rem 0.5rem;
    }
    
    .price-value {
        font-size: clamp(2.5rem, 14vw, 4rem);
    }
    
    .price-dollar {
        font-size: clamp(1.5rem, 5vw, 2rem);
        padding-top: 0.3rem;
    }
    
    .price-change {
        font-size: 1.1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }
    
    .stat-card {
        padding: 1rem;
        min-height: 80px;
    }
    
    .stat-label {
        font-size: 0.7rem;
    }
    
    .stat-value {
        font-size: 1.1rem;
    }
    
    .stat-card-wide .stat-value {
        font-size: 1.4rem;
    }
    
    .section-title {
        font-size: 1.2rem;
    }
    
    .calculator-box {
        padding: 1.5rem 1rem;
    }
    
    .calc-label {
        font-size: 1rem;
    }
    
    .btc-input {
        font-size: 1.3rem;
        padding: 0.875rem 0.875rem 0.875rem 2.5rem;
        /* Touch-friendly: min 44px height */
        min-height: 48px;
    }
    
    .input-prefix {
        font-size: 1.3rem;
        left: 0.75rem;
    }
    
    .usd-value {
        font-size: 1.8rem;
    }
    
    .refresh-btn {
        width: 40px;
        height: 40px;
        /* Touch-friendly minimum */
        min-width: 44px;
        min-height: 44px;
    }
    
    .refresh-icon {
        width: 18px;
        height: 18px;
    }
    
    .chart-container {
        height: 300px;
        padding: 0.75rem;
    }
    
    .chart-legend {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .footer {
        padding: 1.5rem 0;
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
        font-size: 0.8rem;
    }
}

@media (max-width: 400px) {
    .content {
        padding: 0.75rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }
    
    .stat-card {
        padding: 0.75rem;
    }
    
    .stat-card-wide {
        grid-column: span 2;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    .chart-container {
        height: 280px;
    }
    
    .calculator-box {
        padding: 1.25rem 0.75rem;
    }
}

/* ============================================
   Accessibility: Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .bitcoin-coin {
        animation: none !important;
        opacity: 0.1 !important;
    }
    
    .price-value.pulse {
        animation: none !important;
    }
    
    .refresh-btn.refreshing .refresh-icon {
        animation: none !important;
    }
}

/* ============================================
   iOS Safe Areas
   ============================================ */
@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* ============================================
   Touch Improvements
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Touch device optimizations */
    .stat-card:hover {
        transform: none;
        border-color: var(--border-color);
    }
    
    .stat-card:active {
        transform: scale(0.98);
        border-color: var(--bitcoin-orange);
    }
    
    .refresh-btn:hover {
        transform: none;
    }
    
    .refresh-btn:active {
        transform: scale(0.9);
        background: var(--bitcoin-orange);
        color: var(--bg-primary);
    }
}

/* ============================================
   Utility Classes
   ============================================ */
.hidden {
    display: none !important;
}

.loading {
    opacity: 0.5;
}
