/* ── Stock Simulator - style.css ── */

:root {
    --bg-primary: #0b0b1e;
    --bg-secondary: #111130;
    --bg-card: rgba(255,255,255,0.04);
    --bg-card-hover: rgba(255,255,255,0.07);
    --border: rgba(255,255,255,0.08);
    --border-hover: rgba(255,255,255,0.15);
    --text-primary: #e8e8f0;
    --text-secondary: rgba(255,255,255,0.55);
    --text-muted: rgba(255,255,255,0.35);
    --accent: #00d4ff;
    --accent-dim: rgba(0,212,255,0.15);
    --green: #00e68a;
    --green-bg: rgba(0,230,138,0.12);
    --red: #ff5c5c;
    --red-bg: rgba(255,92,92,0.12);
    --yellow: #ffd166;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
    --radius: 12px;
    --radius-sm: 8px;
}

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

html {
    font-size: 16px;
    background: var(--bg-primary);
}

body {
    font-family: var(--font-sans);
    background: linear-gradient(135deg, #0b0b1e 0%, #0d1a3a 25%, #0b0b1e 50%, #131040 75%, #0b0b1e 100%);
    background-size: 400% 400%;
    animation: gradient-shift 20s ease infinite;
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

@keyframes gradient-shift {
    0% { background-position: 0% 50%; }
    25% { background-position: 100% 50%; }
    50% { background-position: 100% 0%; }
    75% { background-position: 0% 100%; }
    100% { background-position: 0% 50%; }
}

/* ── Focus Visible ── */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
    outline: none;
}

/* ── Ticker Tape ── */
.ticker-tape {
    background: rgba(0,0,0,0.4);
    font-size: 0.8em;
    padding: 6px 0;
    overflow: hidden;
    white-space: nowrap;
    position: relative;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
}

.ticker-tape-inner {
    display: inline-block;
    animation: scroll-left 30s linear infinite;
}

.ticker-tape-inner:hover {
    animation-play-state: paused;
}

@keyframes scroll-left {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

.ticker-item {
    display: inline-block;
    padding: 0 18px;
}

.ticker-symbol {
    color: var(--accent);
    font-weight: 600;
    margin-right: 6px;
}

.ticker-price {
    color: var(--text-primary);
    margin-right: 4px;
}

.ticker-change {
    font-weight: 500;
}

.ticker-change.up { color: var(--green); }
.ticker-change.down { color: var(--red); }

.ticker-separator {
    color: var(--text-muted);
    padding: 0 6px;
}

/* ── Price Change Pulse ── */
@keyframes flash-green { 0% { background: rgba(0,230,138,0.3); } 100% { background: transparent; } }
@keyframes flash-red { 0% { background: rgba(255,92,92,0.3); } 100% { background: transparent; } }

.price-pulse-up {
    animation: flash-green 0.6s ease-out;
    border-radius: 4px;
}

.price-pulse-down {
    animation: flash-red 0.6s ease-out;
    border-radius: 4px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

.app-wrapper {
    max-width: 1340px;
    margin: 0 auto;
    padding: 20px 24px 40px;
}

/* ── Header ── */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.header-left { display: flex; align-items: center; gap: 14px; }

h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
h1 .accent { color: var(--accent); }

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--green);
    background: var(--green-bg);
    padding: 4px 10px;
    border-radius: 20px;
}

.live-dot {
    width: 7px; height: 7px;
    background: var(--green);
    border-radius: 50%;
    animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

.header-balance { text-align: right; }

.balance-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.balance-value {
    font-family: var(--font-mono);
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--green);
}

.balance-profit {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    margin-top: 2px;
}
.balance-profit.up { color: var(--green); }
.balance-profit.down { color: var(--red); }

/* ── Portfolio Summary Bar ── */
.portfolio-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 22px;
}

.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    transition: background 0.2s, border-color 0.2s;
}
.summary-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
}

.summary-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.summary-value {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 600;
}
.summary-value.green { color: var(--green); }
.summary-value.red { color: var(--red); }
.summary-value.accent { color: var(--accent); }

/* ── Main Grid ── */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 20px;
}

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 18px;
    transition: border-color 0.2s;
}
.card:hover { border-color: var(--border-hover); }
.card:last-child { margin-bottom: 0; }

.card-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Stock Selector ── */
.stock-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.stock-btn {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
}
.stock-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
.stock-btn:active {
    transform: scale(0.96);
}
.stock-btn.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Stock Info ── */
.stock-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 18px;
}

.stock-name {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stock-ticker {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.stock-price {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.stock-change-badge {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 6px;
}
.stock-change-badge.up {
    background: var(--green-bg);
    color: var(--green);
}
.stock-change-badge.down {
    background: var(--red-bg);
    color: var(--red);
}

/* ── Chart ── */
.chart-container {
    height: 280px;
    position: relative;
    margin-bottom: 18px;
}

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

/* ── Trade Form ── */
.trade-form {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.trade-form input {
    flex: 1;
    min-width: 0;
    padding: 11px 14px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.2s;
}
.trade-form input::placeholder { color: var(--text-muted); }
.trade-form input:focus { border-color: var(--accent); }

.trade-btn {
    padding: 11px 22px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.15s;
    letter-spacing: 0.02em;
}
.trade-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}
.trade-btn:active {
    transform: scale(0.96);
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.buy-btn { background: var(--green); color: #000; }
.buy-btn:hover { box-shadow: 0 6px 24px rgba(0,230,138,0.35); }
.sell-btn { background: var(--red); color: #fff; }
.sell-btn:hover { box-shadow: 0 6px 24px rgba(255,92,92,0.35); }

/* ── Speed Control ── */
.speed-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.speed-btn {
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    transition: all 0.2s;
}
.speed-btn:hover { border-color: var(--border-hover); color: var(--text-primary); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.25); }
.speed-btn:active { transform: scale(0.96); }
.speed-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }

.reset-btn {
    margin-left: auto;
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--red);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    transition: all 0.2s;
}
.reset-btn:hover { background: var(--red-bg); border-color: var(--red); }

/* ── Portfolio Items ── */
.portfolio-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: rgba(255,255,255,0.02);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border: 1px solid transparent;
    transition: border-color 0.2s, background 0.2s;
    cursor: default;
}
.portfolio-item:hover {
    border-color: var(--border);
    background: var(--bg-card-hover);
}

.portfolio-stock-name {
    font-weight: 600;
    font-size: 0.88rem;
}

.portfolio-shares {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-top: 2px;
}

.portfolio-val {
    text-align: right;
    font-family: var(--font-mono);
    font-size: 0.88rem;
}

.portfolio-pnl {
    font-size: 0.78rem;
    margin-top: 2px;
}
.portfolio-pnl.up { color: var(--green); }
.portfolio-pnl.down { color: var(--red); }

.empty-state {
    text-align: center;
    padding: 28px 16px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ── News ── */
.news-item {
    padding: 12px 14px;
    background: rgba(255,255,255,0.02);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border-left: 3px solid var(--accent);
    transition: background 0.2s;
}
.news-item:hover { background: var(--bg-card-hover); }

.news-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-bottom: 4px;
}

.news-text { font-size: 0.85rem; line-height: 1.4; }

.news-impact {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
}
.news-impact.positive { background: var(--green-bg); color: var(--green); }
.news-impact.negative { background: var(--red-bg); color: var(--red); }
.news-impact.neutral { background: rgba(255,255,255,0.08); color: var(--text-muted); }

/* ── Trade History ── */
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 0.85rem;
}
.history-item:last-child { border-bottom: none; }

.history-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-right: 8px;
}
.history-badge.buy { background: var(--green-bg); color: var(--green); }
.history-badge.sell { background: var(--red-bg); color: var(--red); }

.history-detail { color: var(--text-secondary); font-size: 0.82rem; }
.history-amount { font-family: var(--font-mono); font-size: 0.82rem; }

/* ── Footer ── */
.app-footer {
    text-align: center;
    padding: 12px 0;
    margin-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.app-footer a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.2s;
}
.app-footer a:hover { opacity: 0.8; text-decoration: underline; }

/* ── Toast Notification ── */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
}

.toast {
    padding: 14px 22px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    animation: toastSlideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1), toastFadeOut 0.35s ease 2.65s forwards;
    max-width: 360px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.08);
}
.toast.success {
    background: rgba(0,230,138,0.15);
    color: var(--green);
    border-color: var(--green);
    box-shadow: 0 8px 32px rgba(0,230,138,0.2);
}
.toast.error {
    background: rgba(255,92,92,0.15);
    color: var(--red);
    border-color: var(--red);
    box-shadow: 0 8px 32px rgba(255,92,92,0.2);
}
.toast.info {
    background: rgba(0,212,255,0.15);
    color: var(--accent);
    border-color: #00d4ff;
    box-shadow: 0 8px 32px rgba(0,212,255,0.2);
}

@keyframes toastSlideIn {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes toastFadeOut {
    to { opacity: 0; transform: translateX(40px); }
}

/* ── Animated Value Counter ── */
.value-animate {
    transition: opacity 0.15s ease;
}

/* ── Prefers Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    body {
        animation: none !important;
        background: var(--bg-primary) !important;
    }

    .ticker-tape-inner {
        animation: none !important;
        overflow-x: auto;
    }

    .live-dot {
        animation: none !important;
        opacity: 1;
    }

    .toast {
        animation: none !important;
        opacity: 1;
    }

    .price-pulse-up,
    .price-pulse-down {
        animation: none !important;
    }
}

/* ── Responsive ── */
@media (max-width: 1024px) {
    .main-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    html { font-size: 15px; }

    .app-wrapper { padding: 14px 14px 32px; }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .header-balance { text-align: left; }
    .balance-value { font-size: 1.3rem; }

    .portfolio-summary {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .summary-card { padding: 12px 14px; }
    .summary-value { font-size: 1rem; }

    .stock-price { font-size: 1.5rem; }

    .chart-container { height: 220px; }

    .trade-form {
        flex-wrap: wrap;
    }
    .trade-form input { width: 100%; min-height: 44px; }
    .trade-btn { flex: 1; min-height: 44px; }

    .stock-selector { gap: 6px; flex-wrap: wrap; }
    .stock-btn { padding: 10px 14px; font-size: 0.82rem; min-height: 44px; }
    .speed-btn { padding: 10px 14px; min-height: 44px; }
    .reset-btn { min-height: 44px; padding: 10px 14px; }

    .portfolio-item { padding: 14px; min-height: 48px; }
    .history-item { padding: 12px 0; min-height: 44px; }
}

@media (max-width: 480px) {
    h1 { font-size: 1.25rem; }
    .balance-value { font-size: 1.15rem; }
    .stock-price { font-size: 1.3rem; }
    .chart-container { height: 180px; }
    .summary-value { font-size: 0.9rem; }
    .ticker-tape { font-size: 0.72em; padding: 5px 0; }
    .toast-container { bottom: 12px; right: 12px; left: 12px; }
    .toast { max-width: 100%; }
    .app-footer { padding: 16px 0 8px; margin-top: 16px; }
}

/* ── 375px breakpoint (small phones) ── */
@media (max-width: 375px) {
    .app-wrapper { padding: 10px 10px 24px; }

    h1 { font-size: 1.1rem; }
    .balance-value { font-size: 1rem; }
    .stock-price { font-size: 1.15rem; }
    .chart-container { height: 160px; }

    .portfolio-summary {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .summary-card { padding: 10px 12px; }
    .summary-value { font-size: 0.82rem; }
    .summary-label { font-size: 0.65rem; }

    .stock-selector { gap: 4px; }
    .stock-btn { padding: 8px 10px; font-size: 0.75rem; }

    .trade-form { gap: 6px; }
    .trade-btn { padding: 11px 14px; font-size: 0.82rem; }

    .card { padding: 14px; }
    .card-title { font-size: 0.78rem; }
}
