:root {
    --bg-color: #1f1f1f;
    --surface-color: #464646;
    --surface-color-hover: #5c5c5c;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --primary-color: #3bf6b8;
    --primary-color-hover: #2fc492;
    --danger-color: #ff0040;
    --danger-color-hover: #ff3869;

    --border-radius: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.15);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    padding-bottom: 90px;
    /* space for FAB */
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background-color: var(--bg-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 20;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.025em;
}

.header-actions {
    display: flex;
    gap: 12px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    background-color: transparent;
}

.icon-btn:hover,
.icon-btn:active {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.1);
}

/* Tracker Grid */
.tracker-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    padding: 20px;
    transition: grid-template-columns 0.3s ease;
}

.tracker-container.list-view {
    grid-template-columns: 1fr;
}

.tracker-card {
    aspect-ratio: 1;
    border-radius: var(--border-radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
    transition: box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.tracker-container.list-view .tracker-card {
    aspect-ratio: auto;
    flex-direction: row;
    justify-content: flex-start;
    padding: 12px 16px;
    gap: 16px;
    /* min-height: 80px; */
}

.tracker-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
}

.tracker-card::after {
    content: '';
    position: absolute;
    inset: 0;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius);
    pointer-events: none;
}

.tracker-title {
    font-size: 0.95rem;
    font-weight: 600;
    opacity: 0.95;
    text-align: center;
    margin-bottom: 4px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    position: relative;
    z-index: 2;
}

.tracker-container.list-view .tracker-title {
    order: 2;
    text-align: left;
    margin-bottom: 0;
    font-size: 1.1rem;
    flex: 1;
}

.tracker-value {
    font-size: 2.5rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    position: relative;
    z-index: 2;
    letter-spacing: -0.05em;
    color: #fff;
    cursor: pointer;
    transition: transform 0.1s ease, color 0.2s ease;
}

.tracker-value:hover {
    transform: scale(1.05);
    color: rgba(255, 255, 255, 0.85);
}

.tracker-container.list-view .tracker-value {
    order: 1;
    font-size: 2rem;
    /* min-width: 65px; */
    text-align: left;
}

/* Drag Handle Options */
.drag-handle {
    display: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: grab;
    padding: 10px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.drag-handle:active {
    cursor: grabbing;
}

.tracker-container.reorder-mode .drag-handle {
    display: flex;
    opacity: 1;
}

.tracker-container:not(.list-view) .drag-handle {
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 5;
    padding: 8px;
    /* Bigger touch target */
}

.tracker-container.list-view .drag-handle {
    order: 4;
}

.tracker-card.is-dragging {
    opacity: 0.9;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.3) !important;
    z-index: 1000 !important;
}

.tracker-card.placeholder {
    opacity: 0.5;
}

.icon-btn.active {
    color: var(--primary-color);
    background-color: rgba(255, 255, 255, 0.1);
}

/* FAB */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), #6366f1);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px 0 rgba(59, 130, 246, 0.39);
    cursor: pointer;
    z-index: 20;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
}

.fab:hover,
.fab:active {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    align-items: flex-start;
    /* Mobile friendly top sheet */
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

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

.modal {
    background-color: var(--surface-color);
    border-radius: 0 0 24px 24px;
    /* Top sheet radius */
    width: 100%;
    max-width: 500px;
    padding: calc(16px + env(safe-area-inset-top, 16px)) 24px 24px;
    box-shadow: var(--shadow-lg);
    transform: translateY(-100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

@media (min-width: 600px) {
    .modal-overlay {
        align-items: center;
        padding: 20px;
    }

    .modal {
        border-radius: var(--border-radius);
        padding: 24px;
        transform: translateY(-20px) scale(0.95);
    }
}

.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}

.modal h2 {
    margin-bottom: 24px;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.form-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

.row-group {
    flex-direction: row;
    gap: 16px;
}

.input-half {
    flex: 1;
    display: flex;
    flex-direction: column;
}

label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 600;
}

input[type="text"],
input[type="number"] {
    background-color: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--text-primary);
    padding: 14px 16px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

input[type="text"]:focus,
input[type="number"]:focus {
    border-color: var(--primary-color);
    background-color: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2), inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    width: 100%;
    height: 50px;
    border-radius: 12px;
    cursor: pointer;
    background-color: transparent;
    padding: 0;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 12px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1) inset, 0 2px 4px rgba(0, 0, 0, 0.1);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 32px;
}

.modal-actions-danger {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.btn {
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background-color: var(--primary-color-hover);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.btn-danger {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--danger-color);
    width: 100%;
}

.btn-danger:hover,
.btn-danger:active {
    background-color: var(--danger-color);
    color: white;
}

/* Tracker Controls */
.tracker-controls {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    /* margin-top: auto; */
    width: 100%;
    position: relative;
    z-index: 10;
}

.tracker-container.list-view .tracker-controls {
    order: 3;
    margin-top: 0;
    width: auto;
    margin-left: auto;
}

.control-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background-color: rgba(0, 0, 0, 0.2);
    color: white;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.1s;
    line-height: 1;
}

.control-btn:hover {
    background-color: rgba(0, 0, 0, 0.4);
}

.control-btn:active {
    transform: scale(0.9);
}