:root {
    --bg-dark: #0F172A;
    --bg-card: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    
    --text-main: #F8FAFC;
    --text-muted: #94A3B8;
    
    --primary-gradient: linear-gradient(135deg, #3B82F6 0%, #8B5CF6 100%);
    --positive: #10B981;
    --negative: #EF4444;
    
    --glass-blur: blur(12px);
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    overflow-x: hidden;
}

.app-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    min-height: 100vh;
    padding-bottom: 100px;
}

/* Header */
header {
    margin-bottom: 24px;
}

.header-top {
    margin-bottom: 16px;
    padding-top: 10px;
}

h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

h2 {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: -1px;
    margin: 8px 0;
}

h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-main);
}

.asset-card {
    background: var(--primary-gradient);
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(139, 92, 246, 0.25);
    position: relative;
    overflow: hidden;
}

.asset-card::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    filter: blur(40px);
}

.asset-label {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.asset-trend {
    display: inline-block;
    background: rgba(0, 0, 0, 0.2);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    backdrop-filter: blur(4px);
}

.asset-split {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.asset-half {
    flex: 1;
}

.asset-divider {
    width: 1px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    margin: 0 16px;
}

/* Chart */
.chart-section {
    margin-bottom: 32px;
}

.chart-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.chart-toggle {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 4px;
}

.toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.chart-container {
    background: var(--bg-card);
    border-radius: 24px;
    padding: 16px;
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    height: 250px;
    width: 100%;
}

/* History */
.section-header {
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* History item swipe-to-reveal wrapper */
.history-item-wrapper {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
}

/* Action buttons hidden behind each item */
.history-actions {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    display: flex;
    align-items: stretch;
    width: 160px;
}

.action-btn {
    flex: 1;
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 8px;
    transition: filter 0.15s;
}

.action-btn:active { filter: brightness(0.85); }

.action-edit {
    background: #3B82F6;
    color: white;
}

.action-delete {
    background: #EF4444;
    color: white;
    border-radius: 0 16px 16px 0;
}

.history-item {
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* transition handles the snap animation on touchend */
    transition: transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    z-index: 1;
    will-change: transform;
}

.history-item-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-date {
    font-size: 15px;
    font-weight: 600;
}

.history-details {
    font-size: 13px;
    color: var(--text-muted);
}

.history-asset {
    font-size: 16px;
    font-weight: 700;
    text-align: right;
}

.positive { color: var(--positive); }
.negative { color: var(--negative); }
.neutral { color: var(--text-main); }

.loading-state {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
    font-size: 14px;
}

/* FAB */
.fab {
    position: fixed;
    bottom: max(32px, env(safe-area-inset-bottom));
    right: max(32px, env(safe-area-inset-right));
    width: 64px;
    height: 64px;
    border-radius: 32px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    font-size: 32px;
    font-weight: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(139, 92, 246, 0.4);
    cursor: pointer;
    z-index: 100;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.fab:active {
    transform: scale(0.9) rotate(45deg);
}

@media (min-width: 480px) {
    .fab {
        right: calc(50% - 240px + 32px);
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content.glass {
    background: linear-gradient(180deg, #1E293B 0%, #0F172A 100%);
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    border-radius: 32px 32px 0 0;
    padding: 32px 24px;
    padding-bottom: max(32px, env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.modal.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.close-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 18px;
    color: white;
    font-size: 24px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Form */
.form-group {
    margin-bottom: 20px;
}

.input-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-muted);
}

label small {
    font-size: 10px;
    opacity: 0.7;
}

label.earned { color: var(--positive); }
label.spent { color: var(--negative); }
label.exchanged { color: #3B82F6; }

input {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 18px;
    padding: 16px;
    border-radius: 16px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
}

input:focus {
    border-color: #8B5CF6;
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    opacity: 0.5;
}

.margin-top {
    margin-top: 12px;
}

.submit-btn {
    width: 100%;
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 18px;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 600;
    margin-top: 12px;
    box-shadow: 0 10px 20px rgba(139, 92, 246, 0.3);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

/* Lock Screen */
.lock-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: var(--bg-dark);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease-out, visibility 0.5s;
    visibility: visible;
}

.lock-screen:not(.active) {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.lock-content {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    width: 85%;
    max-width: 360px;
    padding: 40px 24px;
    border-radius: 32px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: translateY(0);
    animation: slideUp 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.lock-icon {
    font-size: 48px;
    margin-bottom: 20px;
}

.lock-content h2 {
    margin: 0;
    font-size: 24px;
    margin-bottom: 8px;
}

.lock-content p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 32px;
}

.login-btn {
    width: 100%;
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 600;
    margin-top: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.hidden {
    display: none !important;
}

.error-msg {
    color: var(--negative);
    font-size: 13px;
    margin-top: 16px;
    min-height: 16px;
}
