:root {
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.85);
    --bg-card-hover: rgba(31, 41, 55, 0.9);
    --border-color: rgba(255, 255, 255, 0.06);
    --border-glow: rgba(99, 102, 241, 0.15);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
    --header-bg: rgba(10, 14, 23, 0.92);
    --badge-bg: #22c55e;
    --badge-glow: rgba(34, 197, 94, 0.4);
    --badge-closed-bg: #64748b;
    --ask-bg: rgba(59, 130, 246, 0.08);
    --bid-bg: rgba(239, 68, 68, 0.08);
    --ask-bar: rgba(59, 130, 246, 0.25);
    --bid-bar: rgba(239, 68, 68, 0.25);
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3), 0 1px 4px rgba(0, 0, 0, 0.2);
    --shadow-header: 0 2px 16px rgba(0, 0, 0, 0.4);
    --scrollbar-track: #1e293b;
    --scrollbar-thumb: #334155;
}

[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-card-hover: rgba(248, 250, 252, 1);
    --border-color: rgba(0, 0, 0, 0.06);
    --border-glow: rgba(99, 102, 241, 0.1);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
    --header-bg: rgba(255, 255, 255, 0.92);
    --badge-bg: #22c55e;
    --badge-glow: rgba(34, 197, 94, 0.3);
    --badge-closed-bg: #cbd5e1;
    --ask-bg: rgba(59, 130, 246, 0.06);
    --bid-bg: rgba(239, 68, 68, 0.06);
    --ask-bar: rgba(59, 130, 246, 0.15);
    --bid-bar: rgba(239, 68, 68, 0.15);
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.06), 0 1px 4px rgba(0, 0, 0, 0.04);
    --shadow-header: 0 2px 16px rgba(0, 0, 0, 0.06);
    --scrollbar-track: #e2e8f0;
    --scrollbar-thumb: #cbd5e1;
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background 0.4s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--header-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-header);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-left h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.55rem;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #fff;
    background: var(--badge-bg);
    border-radius: 9999px;
}

.badge.closed {
    background: var(--badge-closed-bg);
    color: #ffffff;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.clock {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-glow);
}

.icon {
    width: 18px;
    height: 18px;
}

.hidden {
    display: none;
}

main {
    max-width: 80%;
    margin: 0 auto;
    padding: 1.25rem 1.5rem 3rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: background 0.4s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem 0;
}

.card-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.time-range {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.chart-container {
    padding: 0.75rem 0.5rem 0.5rem;
    height: 480px;
    position: relative;
}

#chartCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.trade-info-section {
    padding: 1.25rem;
}

.trade-info-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr 1.5fr;
    gap: 1rem;
    align-items: center;
}

.trade-info-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.trade-info-item .label {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.trade-info-item .value {
    font-size: 1.1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
    transition: color 0.2s ease;
}

.trade-info-item.main-price .value {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.trade-info-item .value.time {
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-secondary);
}

.up {
    color: #ef4444 !important;
}

.down {
    color: #3b82f6 !important;
}

.bottom-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.orderbook-container {
    padding: 0 1.25rem 1.25rem;
}

.orderbook-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.orderbook-table thead th {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.orderbook-table tbody td {
    padding: 0.5rem 0.5rem;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    transition: background 0.15s ease;
}

.orderbook-table tbody tr:last-child td {
    border-bottom: none;
}

.orderbook-table tbody tr.ask-row td {
    color: var(--text-primary);
}

.orderbook-table tbody tr.ask-row td.ask-volume {
    color: #3b82f6;
}

.orderbook-table tbody tr.ask-row td.ask-price {
    color: #3b82f6;
    font-weight: 600;
}

.orderbook-table tbody tr.bid-row td {
    color: var(--text-primary);
}

.orderbook-table tbody tr.bid-row td.bid-volume {
    color: #ef4444;
}

.orderbook-table tbody tr.bid-row td.bid-price {
    color: #ef4444;
    font-weight: 600;
}

.orderbook-table tbody td.ask-volume {
    background: var(--ask-bg);
}

.orderbook-table tbody td.bid-volume {
    background: var(--bid-bg);
}

.orderbook-table tbody tr.separator td {
    height: 3px;
    padding: 0;
    background: var(--accent-gradient);
    border: none;
}

.recent-trades-container {
    padding: 0 1.25rem 1.25rem;
}

.recent-trades-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.recent-trades-table thead th {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.recent-trades-table tbody td {
    padding: 0.5rem 0.5rem;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s ease;
}

.recent-trades-table tbody tr:last-child td {
    border-bottom: none;
}

.recent-trades-table tbody tr.trade-up td {
    color: #ef4444;
}

.recent-trades-table tbody tr.trade-down td {
    color: #3b82f6;
}

.recent-trades-table tbody tr.trade-up td.trade-time {
    color: var(--text-secondary);
}

.recent-trades-table tbody tr.trade-down td.trade-time {
    color: var(--text-secondary);
}

footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

@media (max-width: 768px) {
    header {
        padding: 0.6rem 1rem;
    }

    .header-left h1 {
        font-size: 1rem;
    }

    main {
        padding: 0.75rem 0.5rem 2rem;
    }

    .chart-container {
        height: 320px;
    }

    .trade-info-grid {
        grid-template-columns: 1fr 1fr;
    }

    .trade-info-item.main-price .value {
        font-size: 1.4rem;
    }

    .bottom-grid {
        grid-template-columns: 1fr;
    }

    .orderbook-table tbody td,
    .orderbook-table thead th,
    .recent-trades-table tbody td,
    .recent-trades-table thead th {
        font-size: 0.75rem;
        padding: 0.4rem 0.3rem;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    animation: fadeIn 0.5s ease forwards;
}

.trade-info-section {
    animation-delay: 0s;
}

.chart-section {
    animation-delay: 0.1s;
}

.orderbook-section {
    animation-delay: 0.2s;
}

.recent-trades-section {
    animation-delay: 0.3s;
}

@keyframes flashUp {
    0% {
        background: rgba(239, 68, 68, 0.15);
    }

    100% {
        background: transparent;
    }
}

@keyframes flashDown {
    0% {
        background: rgba(59, 130, 246, 0.15);
    }

    100% {
        background: transparent;
    }
}

.flash-up {
    animation: flashUp 0.6s ease;
}

.flash-down {
    animation: flashDown 0.6s ease;
}